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

            Bug ID: 114399
           Summary: [14] RISC-V rv32i miscompile
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: patrick at rivosinc dot com
  Target Milestone: ---

Testcase:
int a;
struct b {
  long long c;
};
struct d {
  short e;
  long long f;
};
union {
  struct b g;
  struct d h;
} i;
int main() {
  i.h.f++;
  a = i.g.c >> 1;
  __builtin_printf("%X\n", a);
}

Commands:
> gcc red.c -o red.out -m32 -fno-strict-aliasing -static
> ./red.out
80000000

> riscv64-unknown-linux-gnu-gcc -mabi=ilp32 -march=rv32i red.c -o red.out 
> -fno-strict-aliasing -static
> /scratch/tc-testing/tc-mar-19/build-rv32-64-gcv/bin/qemu-riscv32 red.out
0

Discovered/tested with r14-9544-gc7a774edbf8 (not bisected)

Found via fuzzer.

I don't think this has any undefined behavior but the combo of union/struct has
me a bit wary.

Reply via email to