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

            Bug ID: 127967
           Summary: [13/14/15/16/17 Regression] wrong code at -O2 with
                    bit-field of a struct passed by value (ipa-cp)
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kyuwoncho18 at gmail dot com
  Target Milestone: ---
            Target: x86_64-pc-linux-gnu

struct S { unsigned p : 4, q : 8; };

__attribute__((noinline)) static int f(struct S s) { return s.q; }

int main() {
  union { unsigned char b[4]; struct S s; } u = {{16}};
  return f(u.s);
}

godbolt: https://godbolt.org/z/v88TTEd4s

With -O0, -O1 or clang -O2, it returns 1, but with GCC -O2, -O3 or -Os, it
returns 16. -fno-ipa-cp avoids it; GCC 13.3, 14.4, 15.3 and 16.2 are also
affected, GCC 12.5 returns 1.

Disclaimer: This test case was generated by a fuzzer, and the report was
written with LLM assistance.

Reply via email to