Skip to content

add a unit test for the segfault in rust after https://reviews.llvm.org/D159485 #66491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions llvm/lib/IR/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -886,8 +886,15 @@ Instruction::getPrevNonDebugInstruction(bool SkipPseudoOp) const {
}

const DebugLoc &Instruction::getStableDebugLoc() const {
if (isa<DbgInfoIntrinsic>(this))
return getNextNonDebugInstruction()->getDebugLoc();
if (isa<DbgInfoIntrinsic>(this)) {
if (const Instruction* Next = getNextNonDebugInstruction()) {
return Next->getDebugLoc();
}

// FIXME: remove, just to demonstrate the test causes Next above to be null.
llvm::errs() << "error: getStableDebugLoc:getNextNonDebugInstruction is NULL\n";
exit(1);
}
return getDebugLoc();
}

Expand Down
18 changes: 18 additions & 0 deletions llvm/unittests/IR/DebugInfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,24 @@ TEST(AssignmentTrackingTest, Utils) {
EXPECT_FALSE(at::getAssignmentMarkers(&Fun2Alloca).empty());
}

TEST(IRBuilder, GetSetInsertionPointWithEmptyBasicBlock) {
LLVMContext C;
std::unique_ptr<BasicBlock> BB(BasicBlock::Create(C, "start"));
Module *M = new Module("module", C);
IRBuilder<> Builder(BB.get());
Function *DbgDeclare = Intrinsic::getDeclaration(M, Intrinsic::dbg_declare);
Value *DIV = MetadataAsValue::get(C, (Metadata *)nullptr);
SmallVector<Value *, 3> Args = {DIV, DIV, DIV};
Builder.CreateCall(DbgDeclare, Args);

// FIXME: remove the dump(), just for debugging.
M->dump();
BB->dump();

auto IP = BB->getFirstInsertionPt();
Builder.SetInsertPoint(BB.get(), IP);
}

TEST(AssignmentTrackingTest, InstrMethods) {
// Test the assignment tracking Instruction methods.
// This includes:
Expand Down