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

            Bug ID: 128052
           Summary: wrong code at -O1 and above for a _BitInt(510)
                    bit-field read after a constant store to a union
                    member
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kyuwoncho18 at gmail dot com
  Target Milestone: ---
            Target: x86_64-pc-linux-gnu

union U {
  _BitInt(1024) big;
  struct __attribute__((packed)) { unsigned a : 3; unsigned _BitInt(510) f :
510; } s;
};
int main(void) {
  union U u;
  u.big = (_BitInt(1024))1 << 512;
  if (u.s.f >> 509 != 1)
    __builtin_abort();
}

godbolt: https://godbolt.org/z/a9xTT1nTM

u.s.f holds bits 3..512 of u, so its top bit is bit 512 of u.big, which is 1.
With -O0, or -O2 -fno-tree-fre, the program exits normally; with -O1, -O2 or
-O3 that bit reads as 0 and the program aborts.

Reply via email to