public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/112855] New: [14] RISC-V vector: overwriting stack args
@ 2023-12-05  5:21 patrick at rivosinc dot com
  2023-12-05 18:54 ` [Bug target/112855] [14] RISC-V vector: vsetivli clobbers variable value patrick at rivosinc dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: patrick at rivosinc dot com @ 2023-12-05  5:21 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112855
           Summary: [14] RISC-V vector: overwriting stack args
           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: ---

reduced testcase:
int printf(char *, ...);
int a;
int b = 100;
int c[25];
int d;
int main() {
  int e;
  d = 0;
  for (; d < 5; d++) {
    e = 0;
    for (; e < 5; e++)
      c[d * 5 + e] = 0;
  }
  if (b)
    if (a)
      for (;;)
        ;
  b++;
  int volatile f = *c;
  printf("%d\n", b);
}

Tested using qemu with these commands:
> ./bin/riscv64-unknown-linux-gnu-gcc -march=rv64gcv -mabi=lp64d -O3 red.c -o rv64gcv.out

> ./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,Zve32f=true,Zve64f=true ./bin/qemu-riscv64 rv64gc.out
101

> QEMU_CPU=rv64,vlen=128,v=true,vext_spec=v1.0,Zve32f=true,Zve64f=true ./bin/qemu-riscv64 rv64gcv.out
5

rv64gcv should match rv64gc and output 101. I'm not sure where it's getting "5"
from.

When you comment out the b++, the behavior is fixed (and both rv64gcv and
rv64gc output 100):
https://godbolt.org/z/chqGo6fj8

Changing other aspects of the program will also fix the behavior, it's just
that commenting out b++ was the least-disruptive change on the assembly code
that I could find.

You can also set b to zero. I just have it at 100 to make it more obvious that
the arg is getting overwritten, not just added/subtracted.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-06 18:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-05  5:21 [Bug target/112855] New: [14] RISC-V vector: overwriting stack args patrick at rivosinc dot com
2023-12-05 18:54 ` [Bug target/112855] [14] RISC-V vector: vsetivli clobbers variable value patrick at rivosinc dot com
2023-12-06 14:36 ` cvs-commit at gcc dot gnu.org
2023-12-06 18:54 ` patrick at rivosinc dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).