[llvm] [RISCV][CFI] add function epilogue cfi information (PR #110810)

Sam Elliott via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 15 07:43:49 PDT 2024


================
@@ -146,7 +151,10 @@ define i32 @va1(ptr %fmt, ...) {
 ; RV64-WITHFP-NEXT:    lw a0, 0(a0)
 ; RV64-WITHFP-NEXT:    ld ra, 24(sp) # 8-byte Folded Reload
 ; RV64-WITHFP-NEXT:    ld s0, 16(sp) # 8-byte Folded Reload
+; RV64-WITHFP-NEXT:    .cfi_restore ra
----------------
lenary wrote:

I'm not sure this CFI information is correct.

There's a `.cfi_def_cfa s0, 64` earlier in the function. I think the effect of this needs to be undone (i.e., telling the CFI to not calculate the CFA using `s0`) before you do the `ld s0, 16(sp)` - or else after that instruction (but before the `ret`) a debugger will try to calculate the address of frame entries using the restored `s0`.

I'll add another comment to point out where, but I do notice you do insert a `.cfi_def_cfa` in some other functions before restoring `s0`, so I'm not sure what went wrong for this function.

https://github.com/llvm/llvm-project/pull/110810


More information about the llvm-commits mailing list