[llvm] [SandboxIR] Implement UnreachableInst (PR #101856)

Julius Alexandre via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 6 18:43:44 PDT 2024


================
@@ -2037,3 +2037,33 @@ define void @foo(i32 %arg) {
   }
   EXPECT_EQ(NewPHI->getNumIncomingValues(), PHI->getNumIncomingValues());
 }
+
+TEST_F(SandboxIRTest, UnreachableInst) {
+  parseIR(C, R"IR(
+define void @foo() {
+  call void @llvm.donothing()
----------------
medievalghoul wrote:

Base on this IL
```llvm
define void @foo() {
  unreachable
  ret void
}
```

If we're doing a `sandboxir::UnreachableInst::create(/*InsertBefore=*/Ret, Ctx);`, which, If im understanding correctly, creates an `UnreachableInst` and inserts it before the specified argument (in this case, `Ret`). Wouldn't that be redundant and cause issues in this context? Considering that InsertBefore will insert the `unreachable` instruction before ret, and there's already an unreachable instruction preceding the ret instruction.

To avoid redundancy or any sense of issues, I tried adding a `call void @llvm.donothing()` instruction as an intermediary. This way, the unreachable instruction can be inserted before the call instruction rather than duplicating an insertion before an instruction that already has an unreachable before it. I think this adjustment may ensures the test scenario remains meaningful without introducing redundant or logically inconsistent instructions.

and from the [backtrace](https://github.com/llvm/llvm-project/pull/101856#issuecomment-2272422216) it seems to be the `create(llvm::sandboxir::Instruction*, llvm::sandboxir::Context&)` that get's seg faulted. After adding the call instruction, i didn't encounter no issues. Just to be on the safe side, Is there any way you can test this out for yourself? I'm not sure if this is an issue I'm only facing in terms of getting the seg fault.

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


More information about the llvm-commits mailing list