https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111107
Bug ID: 111107 Summary: i686-w64-mingw32 does not realign stack when __attribute__((aligned)) or __attribute__((vector_size)) are used Product: gcc Version: 12.2.0 Status: UNCONFIRMED Keywords: ABI, wrong-code Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: zfigura at codeweavers dot com Target Milestone: --- Target: i686-w64-mingw32 Minimal example: typedef int myint[4] __attribute__((aligned(16))); extern void g(void *); void f(void) { myint a; g(&a); } The same thing happens if __attribute__((aligned(16))) is applied to the variable instead of the typedef. This seems to also prevent __m128 from being aligned correctly (which uses the "vector_size" attribute rather than "aligned", but I would assume that "vector_size" implies "aligned"). -mincoming-stack-boundary=2 works as a workaround; so does -mstackrealign. Neither should be necessary, though. I've seen some disagreement [1] [2] as to whether the stack alignment for i686-w64-mingw32 *should* be 16 or 4, but as far as I can tell it really should be 4. It's explicitly called out in a code comment [3]; it shows up when -msse2 is used [4], and, well, it reflects the actual ABI of programs that exist in the wild. We do regularly come across programs in Wine that don't align the stack to a 16-byte boundary before calling win32 functions, and while -mstackrealign and similar functions exist, they imply that we either waste time and space unnecessarily aligning *every* function, or we manually align any function that might use an aligned type, which is in general something that's treated as the compiler's responsibility. [1] https://github.com/mingw-w64/mingw-w64/issues/30#issuecomment-1685487779 [2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110273#c5 [3] https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/i386/cygming.h;h=d539f8d0699d69b014e9d3378e78d690ea289f14;hb=HEAD#l34 [4] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110273#c6