https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129281

            Bug ID: 129281
           Summary: x86-64 ABI: #pragma pack(2) struct { int x : 32; }
                    member makes the outer struct MEMORY
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: ABI, wrong-code
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jeffchen006 at gmail dot com
  Target Milestone: ---
            Target: x86_64-pc-linux-gnu

Tested with gcc version 17.0.0 20261203 (experimental), r17-7143-g592f605117e,
x86_64-pc-linux-gnu.

int printf(const char *, ...);
#pragma pack(push, 2)
struct P { int x : 32; };
#pragma pack(pop)
struct S { char c; struct P p; };
#ifndef CALLER
void f(struct S s) { printf("%d %d\n", s.c, s.p.x); }
#else
void f(struct S);
#endif
#ifndef CALLEE
int main(void) { struct S s = { 7, { -5 } }; f(s); }
#endif

$ gcc -O0 t.c && ./a.out
7 -5
$ gcc -O0 -DCALLER -c t.c -o caller.o && clang -O0 -DCALLEE -c t.c -o callee.o
&& gcc caller.o callee.o && ./a.out
1 0

No flag changes it (ABI). GCC passes S on the stack, Clang in %rdi. p
(alignment 2) is at offset 2, so nothing is unaligned. With `int x : 31` (same
layout) GCC also uses %rdi and all combinations agree.
Not bisectable (wrong since at least 2005). place_field (stor-layout.cc) clears
DECL_BIT_FIELD for `x : 32` because it fits SImode (not done when DECL_PACKED;
#pragma pack does not set it). classify_argument (config/i386/i386.cc) tests
DECL_BIT_FIELD for the "bit-fields are INTEGER" case, so x goes to the scalar
path as SImode at bit 16 of S, which looks misaligned: MEMORY. The ARM/AArch64
fix for PR88469 used DECL_BIT_FIELD_TYPE for the same issue.
  • [Bug target/129281] New: x86-64 ... jeffchen006 at gmail dot com via Gcc-bugs

Reply via email to