https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112929
Bug ID: 112929
Summary: [14] RISC-V vector: Variable clobbered at runtime
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(char *, ...);
int a, b, l, i, p, q, t, n, o;
int *volatile c;
static int j;
static struct pack_1_struct d;
long e;
char m = 5;
short s;
#pragma pack(1)
struct pack_1_struct {
long c;
int d;
int e;
int f;
int g;
int h;
int i;
} h, r = {1}, *f = &h, *volatile g;
int main() {
int u;
j = 0;
for (; j < 9; ++j) {
u = ++t ? a : 0;
if (u) {
int *v = &d.d;
*v = g || e;
*c = 0;
*f = h;
}
s = l && c;
o = i;
d.f || (p = 0);
q |= n;
}
r = *f;
printf("b: %d\n", b);
printf("m: %d\n", m);
}
Commands:
rv64gc:
> /scratch/tc-testing/tc-dec-8-trunk/build-rv64gcv/bin/riscv64-unknown-linux-gnu-gcc
> -march=rv64gc -mabi=lp64d -O3 red.c -o rv64gc.out
> QEMU_CPU=rv64,vlen=128,v=true,vext_spec=v1.0
> /scratch/tc-testing/tc-dec-8-trunk/build-rv64gcv/bin/qemu-riscv64 rv64gc.out
b: 0
m: 5
rv64gcv:
> /scratch/tc-testing/tc-dec-8-trunk/build-rv64gcv/bin/riscv64-unknown-linux-gnu-gcc
> -march=rv64gcv -mabi=lp64d -O3 red.c -o rv64gcv.out
> QEMU_CPU=rv64,vlen=128,v=true,vext_spec=v1.0
> /scratch/tc-testing/tc-dec-8-trunk/build-rv64gcv/bin/qemu-riscv64 rv64gcv.out
b: 0
m: 0
Nothing touches the m variable so at the end it should equal 5.
Commenting out the preceding printf("b: %d\n", b); statement causes the
testcase to pass successfully (and doesn't cause much change to the assembly):
https://godbolt.org/z/Erzzqxo8q