Skip to content

IRBuilder: avoid crash when seeking to start of a BasicBlock with only DebugInfo #66266

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

Merged
merged 1 commit into from
Sep 15, 2023
Merged
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
3 changes: 2 additions & 1 deletion llvm/lib/IR/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,8 @@ Instruction::getPrevNonDebugInstruction(bool SkipPseudoOp) const {

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

Expand Down
13 changes: 13 additions & 0 deletions llvm/unittests/IR/DebugInfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,19 @@ 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);
auto IP = BB->getFirstInsertionPt();
Builder.SetInsertPoint(BB.get(), IP);
}

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