From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DC1A13858433; Tue, 5 Dec 2023 05:21:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC1A13858433 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701753703; bh=cfu8KPpk9iNRl49UHhw7h07YbL1rbJ+SpshBmhpXOzU=; h=From:To:Subject:Date:From; b=FpSYhEw1gJ4uZGUX0Ueg5UiKUDcpTkXMxgjNU6FBkyn6O/nw7QuUZgBVZgrsC7w01 FJ8qwimJBvWn8LoZ4ZAYPpUIn1RTuLMIRO46X+heoCfr35TvsrDVmcOq1KcLprY+sD z5EB2Mtx9hYpna93BAi9zlXfngDx6sZfbxc1A75k= From: "patrick at rivosinc dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/112855] New: [14] RISC-V vector: overwriting stack args Date: Tue, 05 Dec 2023 05:21:43 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: patrick at rivosinc dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D112855 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 =3D 100; int c[25]; int d; int main() { int e; d =3D 0; for (; d < 5; d++) { e =3D 0; for (; e < 5; e++) c[d * 5 + e] =3D 0; } if (b) if (a) for (;;) ; b++; int volatile f =3D *c; printf("%d\n", b); } Tested using qemu with these commands: > ./bin/riscv64-unknown-linux-gnu-gcc -march=3Drv64gcv -mabi=3Dlp64d -O3 re= d.c -o rv64gcv.out > ./bin/riscv64-unknown-linux-gnu-gcc -march=3Drv64gc -mabi=3Dlp64d -O3 red= .c -o rv64gc.out > QEMU_CPU=3Drv64,vlen=3D128,v=3Dtrue,vext_spec=3Dv1.0,Zve32f=3Dtrue,Zve64f= =3Dtrue ./bin/qemu-riscv64 rv64gc.out 101 > QEMU_CPU=3Drv64,vlen=3D128,v=3Dtrue,vext_spec=3Dv1.0,Zve32f=3Dtrue,Zve64f= =3Dtrue ./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 t= hat the arg is getting overwritten, not just added/subtracted.=