[PATCH] D69723: [RISCV] Fix wrong CFI directives

Shivam Gupta via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 8 07:14:47 PST 2021


xgupta added a comment.
Herald added subscribers: VincentWu, luke957, achieveartificialintelligence, vkmr, frasercrmck, evandro.

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
  }

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?

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


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69723



More information about the llvm-commits mailing list