[llvm] [SandboxIR] Implement UnreachableInst (PR #101856)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 3 23:47:38 PDT 2024
================
@@ -2037,3 +2037,32 @@ define void @foo(i32 %arg) {
}
EXPECT_EQ(NewPHI->getNumIncomingValues(), PHI->getNumIncomingValues());
}
+
+TEST_F(SandboxIRTest, UnreachableInst) {
+ parseIR(C, R"IR(
+define void @foo() {
+ ret void
+ unreachable
+}
+)IR");
+ llvm::Function *LLVMF = &*M->getFunction("foo");
+ sandboxir::Context Ctx(C);
+ sandboxir::Function *F = Ctx.createFunction(LLVMF);
+ auto *BB = &*F->begin();
+ auto It = BB->begin();
+ auto *Ret = &*It++;
+ auto *UI = cast<sandboxir::UnreachableInst>(&*It++);
+
+ EXPECT_EQ(UI->getNumSuccessors(), 0u);
+ EXPECT_EQ(UI->getNumOfIRInstrs(), 1u);
+ // Check create(InsertBefore)
+ sandboxir::UnreachableInst *NewUI =
+ sandboxir::UnreachableInst::create(/*InsertBefore=*/Ret, Ctx);
+ EXPECT_NE(NewUI, nullptr);
+ EXPECT_EQ(NewUI->getParent(), BB);
+ // Check create(InsertAtEnd)
+ sandboxir::UnreachableInst *NewUIEnd =
----------------
vporpo wrote:
It might have to do with the fact that in the ll code above you have placed `unreachalbe` after `ret`.
Could you try the opposite:
```
define void @foo() {
unreachable
ret void
}
```
https://github.com/llvm/llvm-project/pull/101856
More information about the llvm-commits
mailing list