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

            Bug ID: 128670
           Summary: [x86-64 SysV] Struct return loses live data in an
                    array of padded structs
           Product: gcc
           Version: 16.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mete at varto dot com
  Target Milestone: ---

The following program should return 42, but GCC 16.2.0 on x86_64-linux-gnu
returns an incorrect value at -O0 when a function returns this struct. I
suppose inlining masks the bug at the higher optimization levels. The same
source returns 42 with GCC on 32-bit x86 Linux, ARM64 Linux, x86-64 Windows
(MinGW), and s390x Linux.

struct S {
    char pad[5];
    struct { char x; int : 0; } a[2];
} f(void) {
    return (struct S){ .a[1].x = 42 };
}

int main(void) { return f().a[1].x; }

Cross-platform comparison:
https://godbolt.org/z/oWK4d1rTv

Reply via email to