https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114247
Bug ID: 114247
Summary: RISC-V: miscompile at -O3
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 printf(const char *, ...);
union a {
unsigned short b;
int c;
signed short d;
};
int e, f = 1, g;
long h;
const int **i;
void j(union a k, int l, unsigned m) {
const int *a[100];
i = &a[0];
h = k.d;
}
static int o(union a k) {
k.d = -1;
while (1)
if (f)
break;
j(k, g, e);
return 0;
}
int main() {
union a n = {1};
o(n);
printf("dec: %ld\n", h);
printf("hex: %lX\n", h);
}
Commands:
> riscv64-unknown-linux-gnu-gcc -O3 red.c -o red.out -fno-strict-aliasing
> -fwrapv -fno-aggressive-loop-optimizations
> qemu-riscv64 red.out
dec: 65535
hex: FFFF
> riscv64-unknown-linux-gnu-gcc -O2 red.c -o red.out -fno-strict-aliasing
> -fwrapv -fno-aggressive-loop-optimizations
> qemu-riscv64 red.out
dec: -1
hex: FFFFFFFFFFFFFFFF
This testcase looks very suspect but AFAICT it doesn't contain any UB.
Found via fuzzer