bash-3.2$ cat x.c #include <stdio.h> #include <stddef.h> #include <stdlib.h>
#ifndef ALIGNMENT #define ALIGNMENT 16 #endif typedef int aligned __attribute__((aligned(ALIGNMENT))); int global; void check (int *i) { *i = 20; if ((((ptrdiff_t) i) & (__alignof__(aligned) - 1)) != 0) { printf("\nUnalign address (%d): %p!\n", __alignof__(aligned), i); abort (); } } void foo (void) { aligned j; void bar () { aligned i; check (&i); check (&j); j = -20; } bar (); if (j != -20) abort (); check (&j); if (j != 20) abort (); } int main() { foo (); return 0; } bash-3.2$ /usr/gcc-4.3/bin/gcc -m32 x.c bash-3.2$ ./a.out Unalign address (16): 0xffc8c3cc! Aborted bash-3.2$ -- Summary: gcc doesn't properly align variable on stack for nested function Product: gcc Version: 4.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: hjl dot tools at gmail dot com GCC target triplet: i686-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34847