[PATCH] D111519: [WIP] [RISCV] Emit cfi directives for function epilogue

Jessica Clarke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 8 07:22:30 PST 2021


jrtc27 added a comment.

In D111519#3115513 <https://reviews.llvm.org/D111519#3115513>, @xgupta wrote:

> Hello @luismarques,
>
> can you please tell me how you have generated this assembly mentioned in the commit summary(.c file)?
>
>   define void @branch_and_tail_call(i1 %a) {
>   ; RV32-LABEL: branch_and_tail_call:
>   ; RV32:       # %bb.0:
>   ; RV32-NEXT:    addi sp, sp, -16
>   ; RV32-NEXT:    .cfi_def_cfa_offset 16
>   ; RV32-NEXT:    sw ra, 12(sp)
>   ; RV32-NEXT:    .cfi_offset ra, -4
>   ; RV32-NEXT:    andi a0, a0, 1
>   ; RV32-NEXT:    beqz a0, .LBB2_2
>   ; RV32-NEXT:  # %bb.1: # %blue_pill
>   ; RV32-NEXT:    lw ra, 12(sp)
>   ; RV32-NEXT:    .cfi_restore ra
>   ; RV32-NEXT:    addi sp, sp, 16
>   ; RV32-NEXT:    .cfi_def_cfa_offset 0
>   ; RV32-NEXT:    tail foo
>   ; RV32-NEXT:  .LBB2_2: # %red_pill
>   ; RV32-NEXT:    call bar
>   ; RV32-NEXT:    lw ra, 12(sp)
>   ; RV32-NEXT:    .cfi_restore ra
>   ; RV32-NEXT:    addi sp, sp, 16
>   ; RV32-NEXT:    .cfi_def_cfa_offset 0
>   ; RV32-NEXT:    ret
>   }

This is clearly the branch_and_tail_call test case in frame-info.ll that had the `; FIXME: fix use of .cfi_restore with wrong CFAs`.

> For instance, without this patch the following program will not correctly unwind, and will get stuck (compile with clang, link with a gnu toolchain, test with qemu):
>
>   void three() {
>       throw 7;
>   }
>   
>   void two(void) {
>       try {
>           three();
>       } catch(int &c) {
>           throw 42;
>       }
>   }
>   
>   int main() {
>       try {
>           two();
>       }
>       catch(...) {
>       }
>       return 0;
>   }
>
> When you say it get `stuck`, can you please tell me what steps you have run?

I'm going to assume as he said: "compile with clang, link with a gnu toolchain, test with qemu". Presumably the bogus DWARF leads it to get stuck in an unwind loop, with an early prologue meaning the call site is incorrectly (by correctly decoding the DWARF) determined to be a leaf, but RA is the call site itself, not the caller, so every iteration does nothing.

> PS I want to revert this patch to fix https://bugs.llvm.org/show_bug.cgi?id=51864 in https://reviews.llvm.org/D111519.

I'm getting tired of saying this, but the underlying target-independent deficiency in LLVM needs fixing before you can think about reverting this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111519/new/

https://reviews.llvm.org/D111519



More information about the llvm-commits mailing list