[Bug c/110634] New: Incorrect RISC-V assembly with -fno-omit-frame-pointer

2023-07-11 Thread bjorn at kernel dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110634

Bug ID: 110634
   Summary: Incorrect RISC-V assembly with -fno-omit-frame-pointer
   Product: gcc
   Version: 12.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: bjorn at kernel dot org
  Target Milestone: ---

Is see inconsistencies when comparing -fno-omit-frame-pointer GCC and clang
builds. 

$ cat foo.c
int foo(int a, int b) {
  return a + b;
}

$ clang-17 --target=riscv64-linux-gnu -O3 -fno-omit-frame-pointer -c foo.c -o
foo.o && riscv64-linux-gnu-objdump -d foo.o 

foo.o: file format elf64-littleriscv


Disassembly of section .text:

 :
   0:   1141add sp,sp,-16
   2:   e406sd  ra,8(sp)
   4:   e022sd  s0,0(sp)
   6:   0800add s0,sp,16
   8:   9d2daddwa0,a0,a1
   a:   60a2ld  ra,8(sp)
   c:   6402ld  s0,0(sp)
   e:   0141add sp,sp,16
  10:   8082ret


Where GCC yields:

$ riscv64-linux-gnu-gcc -O3 -fno-omit-frame-pointer -c foo.c -o foo.o &&
riscv64-linux-gnu-objdump -d foo.o 

foo.o: file format elf64-littleriscv


Disassembly of section .text:

 :
   0:   1141add sp,sp,-16
   2:   e422sd  s0,8(sp)
   4:   0800add s0,sp,16
   6:   6422ld  s0,8(sp)
   8:   9d2daddwa0,a0,a1
   a:   0141add sp,sp,16
   c:   8082ret


I would expect GCC to store "ra" similar to clang, but the spec is a bit vague
[1].

https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc#frame-pointer-convention

[Bug target/110634] Incorrect RISC-V assembly with -fno-omit-frame-pointer

2023-07-11 Thread bjorn at kernel dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110634

--- Comment #2 from Björn Töpel  ---
(In reply to Andrew Pinski from comment #1)
> I don't see where in any of the spec mentioned that storing of ra is needed
> at all. That is it does not read ambigous to me at all. It just mentions for
> a frame pointer, the frame pointer needs to be saved and nothing about ra.
> 
> This is totally different from the power ABI.

Hmm, but is a frame-pointer w/o the ability to unwind useful? Or am I missing
something?