[llvm] [SandboxIR] Implement UnreachableInst (PR #101856)
Julius Alexandre via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 3 23:41:04 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 =
----------------
medievalghoul wrote:
maybe we shouldn't do a test for InsertAtEnd and remove the `static UnreachableInst *create(BasicBlock *InsertAtEnd, Context &Ctx);` function?
the bot is failing due to
```
SandboxIR.cpp:289: BBIterator &llvm::sandboxir::BBIterator::operator++(): Assertion `It != ItE && "Already at end!"' failed.
```
https://github.com/llvm/llvm-project/pull/101856
More information about the llvm-commits
mailing list