Skip to content

Commit 33af16f

Browse files
authored
[DebugInfo][RemoveDIs] Final cleanup for enabling non-instr-debuginfo (#74497)
Some final errors have turned up when doing stage2clang builds: * We can insert before end(), which won't have an attached DPMarker, thus we can have a nullptr DPMarker in Instruction::insertBefore. Add a null check there. * We need to use the iterator-returning form of getFirstNonPHI to ensure we don't insert any PHIs behind debug-info at the start of a block.
1 parent 7563eb6 commit 33af16f

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

llvm/lib/IR/Instruction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ void Instruction::moveBeforeImpl(BasicBlock &BB, InstListType::iterator I,
218218

219219
// If we're inserting at point I, and not in front of the DPValues attached
220220
// there, then we should absorb the DPValues attached to I.
221-
if (!InsertAtHead)
221+
if (NextMarker && !InsertAtHead)
222222
DbgMarker->absorbDebugValues(*NextMarker, false);
223223
}
224224

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
12951295
// the same predecessors BB had.
12961296
// Copy over any phi, debug or lifetime instruction.
12971297
BB->getTerminator()->eraseFromParent();
1298-
Succ->splice(Succ->getFirstNonPHI()->getIterator(), BB);
1298+
Succ->splice(Succ->getFirstNonPHIIt(), BB);
12991299
} else {
13001300
while (PHINode *PN = dyn_cast<PHINode>(&BB->front())) {
13011301
// We explicitly check for such uses for merging phis.

llvm/unittests/IR/BasicBlockDbgInfoTest.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,5 +1481,58 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceToEmpty2) {
14811481

14821482
UseNewDbgInfoFormat = false;
14831483
}
1484+
1485+
// What if we moveBefore end() -- there might be no debug-info there, in which
1486+
// case we shouldn't crash.
1487+
TEST(BasicBlockDbgInfoTest, DbgMoveToEnd) {
1488+
LLVMContext C;
1489+
UseNewDbgInfoFormat = true;
1490+
1491+
std::unique_ptr<Module> M = parseIR(C, R"(
1492+
define i16 @f(i16 %a) !dbg !6 {
1493+
entry:
1494+
br label %exit
1495+
1496+
exit:
1497+
ret i16 0, !dbg !11
1498+
}
1499+
declare void @llvm.dbg.value(metadata, metadata, metadata) #0
1500+
attributes #0 = { nounwind readnone speculatable willreturn }
1501+
1502+
!llvm.dbg.cu = !{!0}
1503+
!llvm.module.flags = !{!5}
1504+
1505+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
1506+
!1 = !DIFile(filename: "t.ll", directory: "/")
1507+
!2 = !{}
1508+
!5 = !{i32 2, !"Debug Info Version", i32 3}
1509+
!6 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: !1, line: 1, type: !7, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
1510+
!7 = !DISubroutineType(types: !2)
1511+
!8 = !{!9}
1512+
!9 = !DILocalVariable(name: "1", scope: !6, file: !1, line: 1, type: !10)
1513+
!10 = !DIBasicType(name: "ty16", size: 16, encoding: DW_ATE_unsigned)
1514+
!11 = !DILocation(line: 1, column: 1, scope: !6)
1515+
)");
1516+
1517+
Function &F = *M->getFunction("f");
1518+
BasicBlock &Entry = F.getEntryBlock();
1519+
BasicBlock &Exit = *Entry.getNextNode();
1520+
M->convertToNewDbgValues();
1521+
1522+
// Move the return to the end of the entry block.
1523+
Instruction *Br = Entry.getTerminator();
1524+
Instruction *Ret = Exit.getTerminator();
1525+
EXPECT_EQ(Entry.getTrailingDPValues(), nullptr);
1526+
Ret->moveBefore(Entry, Entry.end());
1527+
Br->eraseFromParent();
1528+
1529+
// There should continue to not be any debug-info anywhere.
1530+
EXPECT_EQ(Entry.getTrailingDPValues(), nullptr);
1531+
EXPECT_EQ(Exit.getTrailingDPValues(), nullptr);
1532+
EXPECT_FALSE(Ret->hasDbgValues());
1533+
1534+
UseNewDbgInfoFormat = false;
1535+
}
1536+
14841537
} // End anonymous namespace.
14851538
#endif // EXPERIMENTAL_DEBUGINFO_ITERATORS

0 commit comments

Comments
 (0)