public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/65146] New: alignment of _Atomic structure member is not correct
@ 2015-02-20 19:58 alexey.lapshin at oracle dot com
  2015-02-20 21:43 ` [Bug c/65146] " joseph at codesourcery dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: alexey.lapshin at oracle dot com @ 2015-02-20 19:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65146

            Bug ID: 65146
           Summary: alignment of _Atomic structure member is not correct
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alexey.lapshin at oracle dot com

Alignment of single _Atomic object match with documentation :
https://gcc.gnu.org/wiki/Atomic/GCCMM/UnalignedPolicy . 
Alignment of _Atomic structure member does not match. 

~/atomic_test$ cat unaligned_atomic.c

#include <stdatomic.h>
#include <stdio.h>

typedef struct {
    char c [8];
} power_of_two_obj;

typedef struct {
   char c[1];
   _Atomic power_of_two_obj ao;
} container_struct; 

int main ( void ) {

    _Atomic power_of_two_obj obj1;
    container_struct         obj2; 


    printf("\n Size and Alignment of _Atomic  object "); 
    printf(" : sizeof(obj1) %d __alignof__(obj1) %d ", sizeof(obj1),
__alignof__(obj1) );

    printf("\n Size and Alignment of _Atomic member object "); 
    printf(" : sizeof(obj2.ao) %d __alignof__(obj2.ao) %d \n", sizeof(obj2.ao),
__alignof__(obj2.ao) );

    return 0;
}

~/atomic_test$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/gcc/libexec/gcc/i386-pc-solaris2.11/4.9.2/lto-wrapper
Target: i386-pc-solaris2.11
Configured with: ./configure --prefix=/opt/gcc/
Thread model: posix
gcc version 4.9.2 (GCC) 

~/atomic_test$ gcc -O -latomic -std=c11 unaligned_atomic.c -m32

~/atomic_test$ ./a.out

 Size and Alignment of _Atomic  object  : sizeof(obj1) 8 __alignof__(obj1) 8 
 Size and Alignment of _Atomic member object  : sizeof(obj2.ao) 8
__alignof__(obj2.ao) 4 


According to the documentation
https://gcc.gnu.org/wiki/Atomic/GCCMM/UnalignedPolicy alignment of both "obj1"
and "obj2.ao" should be 8 bytes.
But in the above test case alignment of obj2.ao is 4 bytes.

The bug is found on Solaris x86 -m32


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-12-04 10:10 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-20 19:58 [Bug c/65146] New: alignment of _Atomic structure member is not correct alexey.lapshin at oracle dot com
2015-02-20 21:43 ` [Bug c/65146] " joseph at codesourcery dot com
2015-02-20 22:51 ` alexey.lapshin at oracle dot com
2015-02-20 23:32 ` joseph at codesourcery dot com
2020-08-26 14:59 ` [Bug target/65146] " jason at gcc dot gnu.org
2020-08-26 16:03 ` jakub at gcc dot gnu.org
2020-08-26 17:33 ` jakub at gcc dot gnu.org
2020-08-26 17:58 ` hjl.tools at gmail dot com
2020-08-27 16:45 ` cvs-commit at gcc dot gnu.org
2022-04-27 12:37 ` peter at cordes dot ca
2023-12-04 10:10 ` egallager at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).