This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/65146] New: alignment of _Atomic structure member is not correct
- From: "alexey.lapshin at oracle dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 20 Feb 2015 19:29:04 +0000
- Subject: [Bug c/65146] New: alignment of _Atomic structure member is not correct
- Auto-submitted: auto-generated
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