[llvm] [SandboxIR] Implement CatchReturnInst (PR #105605)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 22 16:08:43 PDT 2024


================
@@ -1957,6 +1957,71 @@ define void @foo() {
 #endif // NDEBUG
 }
 
+TEST_F(SandboxIRTest, CatchReturnInst) {
+  parseIR(C, R"IR(
+define void @foo() {
+dispatch:
+  %cs = catchswitch within none [label %catch] unwind to caller
+catch:
+  %catchpad = catchpad within %cs [ptr @foo]
+  catchret from %catchpad to label %continue
+continue:
+  ret void
+catch2:
+  %catchpad2 = catchpad within %cs [ptr @foo]
+  ret void
+}
+)IR");
+  Function &LLVMF = *M->getFunction("foo");
+  BasicBlock *LLVMCatch = getBasicBlockByName(LLVMF, "catch");
+  auto LLVMIt = LLVMCatch->begin();
+  [[maybe_unused]] auto *LLVMCP = cast<llvm::CatchPadInst>(&*LLVMIt++);
----------------
vporpo wrote:

There are two reasons:
1. I wouldn't want to diverge from the Instruction casting pattern, regardless of whether the value is used or not:
```
auto *I0 = cast<...>(&*LLVMIt++);
auto *I1 = cast<...>(&*LLVMIt++);
...
```
2. You have a handle for it to dump it in the debugger. This is especially true for the function `F`, but not so much for the instructions.


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


More information about the llvm-commits mailing list