https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94452
Bug ID: 94452 Summary: I386 ABI: How to determine the alignment of struct or union determined when passes them on stack? Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: chen3.liu at intel dot com Target Milestone: --- For example: #include <immintrin.h> typedef __attribute__((aligned(16))) int alignedint; struct __attribute__((aligned(64))) X { int x; // __m128 y; // alignedint y; }; void g(int x, struct X); _Static_assert(_Alignof(struct X) == 64); struct X gx; void f() { g(1, gx); } In this case, the gx will align to 4 byte. If we uncomment either the __m128 or alignedint y, and gcc aligns to 64 bytes. The logic of gcc alignment we now think is as below: StackAlignmentForType(T): 1. If T's alignment is < 16 bytes(any type, including struct and union), return 4. 2. If T is a struct/union/array type, then: • recursively calculate on each member's type ( ignores any attribute((aligned(N))) directly on the fields of a struct, but not those that appear on typedefs, or the underlying types ?). • If all of those calls return alignments < 16, then return 4. 3. Otherwise, return the alignment of T. Is this logic correct for gcc? We want to make clang compatible with gcc. Thanks.