[llvm] [SjLjEHPrepare] Configure call sites correctly (PR #117656)

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 25 18:02:01 PST 2024


================
@@ -0,0 +1,44 @@
+; RUN: opt -p sjlj-eh-prepare %s -S -o - | FileCheck %s
+
+; Check that callsites are set up correctly:
+; 1. Throwing call in the entry block does not set call_site
+;    (function context hasn't been configured yet).
+; 2. Throwing call not in the entry block sets call_site to -1
+;    (reset to the initial state).
+; 3. Invoke instructions set call_site to the correct call site number.
+; 4. Resume instruction sets call_site to -1 (reset to the initial state).
+
+define void @test_call_sites() personality ptr @__gxx_personality_sj0 {
+entry:
+  ; CHECK-NOT: store volatile
+  ; CHECK:     call void @may_throw()
+  call void @may_throw()
+
+  ; CHECK:      store volatile i32 1
+  ; CHECK-NEXT: call void @llvm.eh.sjlj.callsite(i32 1)
+  ; CHECK-NEXT: invoke void @may_throw()
+  invoke void @may_throw() to label %invoke.cont unwind label %lpad
+
+invoke.cont:
+  ; CHECK:      store volatile i32 2
+  ; CHECK-NEXT: call void @llvm.eh.sjlj.callsite(i32 2)
+  ; CHECK-NEXT: invoke void @may_throw()
+  invoke void @may_throw() to label %try.cont unwind label %lpad
----------------
s-barannikov wrote:

IR before this change:
```llvm
invoke.cont:                                      ; preds = %entry
  %call_site2 = getelementptr { ptr, i32, [4 x i32], ptr, ptr, [5 x ptr] }, ptr %fn_context, i32 0, i32 1
  store volatile i32 2, ptr %call_site2, align 4
  call void @llvm.eh.sjlj.callsite(i32 2)
  %call_site3 = getelementptr { ptr, i32, [4 x i32], ptr, ptr, [5 x ptr] }, ptr %fn_context, i32 0, i32 1
  store volatile i32 -1, ptr %call_site3, align 4
  invoke void @may_throw()
          to label %try.cont unwind label %lpad
```


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


More information about the llvm-commits mailing list