This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/16786] New: alignment incorrect on a structure field, on win32
- From: "antoine_labour at playstation dot sony dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 27 Jul 2004 18:45:30 -0000
- Subject: [Bug c/16786] New: alignment incorrect on a structure field, on win32
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
There seems to be a problem with alignment on win32 targets (cygwin, mingw).
I use gcc 3.3.1, either the one in cygwin :
$ gcc -v
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/specs
Configured with: /GCC/gcc-3.3.1-3/configure --with-gcc --with-gnu-ld
--with-gnu-as --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc
--libdir=/usr/lib --libexecdir=/usr/sbin --mandir=/usr/share/man
--infodir=/usr/share/info --enable-languages=c,ada,c++,f77,pascal,java,objc
--enable-libgcj --enable-threads=posix --with-system-zlib --enable-nls
--without-included-gettext --enable-interpreter --enable-sjlj-exceptions
--disable-version-specific-runtime-libs --enable-shared --disable-win32-registry
--enable-java-gc=boehm --disable-hash-synchronization --verbose
--target=i686-pc-cygwin --host=i686-pc-cygwin --build=i686-pc-cygwin
Thread model: posix
gcc version 3.3.1 (cygming special)
or the linux->win32 cross compiler in debian:
$ i586-mingw32msvc-gcc -v
Reading specs from /usr/lib/gcc-lib/i586-mingw32msvc/3.3.1/specs
Configured with:
/home/ron/devel/debian/mingw32/mingw32-3.3.1.20030804.1/build_dir/src/gcc-3.3.1-20030804-1/configure
-v --prefix=/usr --target=i586-mingw32msvc --enable-languages=c,c++
--enable-threads --disable-multilib --enable-version-specific-runtime-libs
Thread model: win32
gcc version 3.3.1 (mingw special 20030804-1)
The compiler seems to ignore alignment requirement on struct fields which are
declared with a type having some alignment requirement set with the align attribute:
typedef struct
{
int a;
} __attribute__((aligned (16))) A;
typedef struct
{
int b;
A a;
} B;
B.a seems to be aligned on a 8-byte boundary, whereas it should be on a 16-byte
boundary. The size seems correct though.
See attached file for test case.
To compile, I used:
$ gcc prog.i -o prog.exe -Wall
It gives no warning.
Its output is the following:
$ ./prog.exe
offsetof(B,a)=0x8
sizeof(A)=0x10
sizeof(B)=0x18
alignof(A)=10
alignof(B)=8
I can see the correct behaviour with linux i386 gcc, both 3.3.4 and 3.2.3
$ gcc -v
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.4/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib
--enable-nls --without-included-gettext --enable-__cxa_atexit
--enable-clocale=gnu --enable-debug --enable-java-gc=boehm
--enable-java-awt=xlib --enable-objc-gc i486-linux
Thread model: posix
gcc version 3.3.4 (Debian)
$ gcc-3.2 -v
Reading specs from /usr/lib/gcc-lib/i386-linux/3.2.3/specs
Configured with: ../src/configure -v --enable-languages=c,c++,f77,objc,ada
--prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info
--with-gxx-include-dir=/usr/include/c++/3.2 --enable-shared --with-system-zlib
--enable-nls --without-included-gettext --enable-__cxa_atexit
--enable-clocale=gnu --enable-objc-gc i386-linux
Thread model: posix
gcc version 3.2.3 (Debian)
$ gcc prog.i -o prog -Wall
$./prog
offsetof(B,a)=0x10
sizeof(A)=0x10
sizeof(B)=0x20
alignof(A)=10
alignof(B)=10
--
Summary: alignment incorrect on a structure field, on win32
Product: gcc
Version: 3.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: antoine_labour at playstation dot sony dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC target triplet: i686-pc-cygwin
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16786