Hi, The following code produces incorrect results under -O1 (or higher), but works fine under -O0 for gcc 4.1.2 and 4.2.3. gcc 3.4.6 produces the correct result for all optimization levels.
# 1 "t.c" # 1 "<built-in>" # 1 "<command line>" # 1 "t.c" extern int printf(const char *format, ...); typedef struct Bar { char c[129]; } Bar __attribute__((__aligned__(128))); typedef struct Foo { Bar bar[4]; } Foo; Foo foo[4]; int main() { int i, j; Foo *foop = &foo[0]; for (i=0; i < 4; i++) { Bar *bar = &foop->bar[i]; for (j=0; j < 129; j++) { bar->c[j] = 'a' + i; } } printf("foo[0].bar[3].c[128] = %c\n", foo[0].bar[3].c[128]); return 0; } The expected behavior when the resulting program is run is: foo[0].bar[3].c[128] = d The actual behavior is: foo[0].bar[3].c[128] = Output from gcc -v: Using built-in specs. Target: i686-linux Configured with: ../gcc-4.1.2/configure --prefix=/build/toolchain/lin32/gcc-4.1.2-2 --disable-nls --enable-shared --enable-threads=posix --enable-languages=c,c++ --with-gnu-as --with-gnu-ld --target=i686-linux --with-as=/build/toolchain/lin32/binutils-2.17.50.0.15/bin/i686-linux-as --with-ld=/build/toolchain/lin32/binutils-2.17.50.0.15/bin/i686-linux-ld --enable-__cxa_atexit --with-sysroot=/build/toolchain/lin32/glibc-2.2.5-44 --disable-tls --enable-clocale=gnu Thread model: posix gcc version 4.1.2 and Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7) Thanks for taking a look. -- Summary: __align__ produces incorrect results in certain cases Product: gcc Version: 4.2.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: zhirsch at vmware dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36093