Skip to content

Fix LDV InstrRefBasedImpl to not crash when encountering unreachable blocks #5082

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 2 commits into from
Aug 10, 2022
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
11 changes: 9 additions & 2 deletions llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ class TransferTracker {
for (auto Location : MTracker->locations()) {
LocIdx Idx = Location.Idx;
ValueIDNum &VNum = MLocs[Idx.asU64()];
if (VNum == ValueIDNum::EmptyValue)
continue;
VarLocs.push_back(VNum);

// Is there a variable that wants a location for this value? If not, skip.
Expand Down Expand Up @@ -2970,12 +2972,17 @@ void InstrRefBasedLDV::initialSetup(MachineFunction &MF) {
// Compute mappings of block <=> RPO order.
ReversePostOrderTraversal<MachineFunction *> RPOT(&MF);
unsigned int RPONumber = 0;
for (MachineBasicBlock *MBB : RPOT) {
auto processMBB = [&](MachineBasicBlock *MBB) {
OrderToBB[RPONumber] = MBB;
BBToOrder[MBB] = RPONumber;
BBNumToRPO[MBB->getNumber()] = RPONumber;
++RPONumber;
}
};
for (MachineBasicBlock *MBB : RPOT)
processMBB(MBB);
for (MachineBasicBlock &MBB : MF)
if (BBToOrder.find(&MBB) == BBToOrder.end())
processMBB(&MBB);

// Order value substitutions by their "source" operand pair, for quick lookup.
llvm::sort(MF.DebugValueSubstitutions);
Expand Down
38 changes: 38 additions & 0 deletions llvm/test/DebugInfo/MIR/X86/ldv_unreachable_blocks.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# RUN: llc -mtriple=x86_64-apple-macos %s -start-before=livedebugvalues -filetype=obj -o - | llvm-dwarfdump - | FileCheck %s
# CHECK: DW_TAG_subprogram
# Test that LiveDebugValues can handle MBBs that are not reachable in a RPOT.
--- |
define hidden zeroext i1 @__foo_block_invoke(i8* nocapture noundef readonly %.block_descriptor, i64 noundef %type) !dbg !5 {
entry:
%call2.i = tail call zeroext i8 @foo_len(), !dbg !10
%cmp.i102.i = icmp ult i8 %call2.i, 64, !dbg !10
br i1 %cmp.i102.i, label %bar_length.exit105.i, label %if.else.i103.i, !dbg !10
if.else.i103.i: ; preds = %sw.bb.i
br label %bar_length.exit105.i
bar_length.exit105.i: ; preds = %if.else.i103.i, %sw.bb.i
unreachable
baz_size.exit: ; preds = %bar_length.exit131.i, %bar_length.exit105.i, %bar_length.exit.i.baz_size.exit_crit_edge
unreachable
}
declare zeroext i8 @foo_len() local_unnamed_addr
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4}
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6, producer: "Apple clang", isOptimized: true, flags: "-fsanitize=fuzzer-no-link,address", runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, splitDebugInlining: false, nameTableKind: None, sysroot: "/", sdk: "MacOSX.sdk")
!2 = !{}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = !{i32 1, !"LTOPostLink", i32 1}
!5 = distinct !DISubprogram(name: "__foo_block_invoke", linkageName: "__foo_block_invoke", scope: !6, file: !6, line: 557, type: !7, scopeLine: 557, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
!6 = !DIFile(filename: "t.c", directory: "")
!7 = !DISubroutineType(types: !2)
!10 = !DILocation(line: 558, column: 7, scope: !12)
!12 = distinct !DILexicalBlock(scope: !5, file: !6, line: 557, column: 50)
name: __foo_block_invoke
body: |
bb.0.entry:
JCC_1 %bb.1, 5, implicit $eflags, debug-location !10
bb.28.baz_size.exit:
RET64 $al, debug-location !10
bb.1:
successors:
bb.25.if.else.i103.i (address-taken):
JMP_1 %bb.28
32 changes: 32 additions & 0 deletions llvm/test/DebugInfo/MIR/X86/ldv_unreachable_blocks2.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# RUN: llc -mtriple=x86_64-apple-macos %s -start-before=livedebugvalues -filetype=obj -o - | llvm-dwarfdump - | FileCheck %s
# CHECK: DW_TAG_subprogram
# Test that LiveDebugValues can handle MBBs that are not reachable in a RPOT.
--- |
define hidden zeroext i1 @__foo_block_invoke(i8* nocapture noundef readonly %.block_descriptor, i64 noundef %type) !dbg !7 {
entry:
unreachable
do.body.i129.i: ; preds = %if.else6.i128.i
unreachable
}
!llvm.dbg.cu = !{!3}
!llvm.module.flags = !{!5, !6}
!2 = !{}
!3 = distinct !DICompileUnit(language: DW_LANG_C99, file: !4, producer: "clang", runtimeVersion: 0, emissionKind: FullDebug)
!4 = !DIFile(filename: "t.c", directory: "/")
!5 = !{i32 2, !"Debug Info Version", i32 3}
!6 = !{i32 1, !"LTOPostLink", i32 1}
!7 = distinct !DISubprogram(name: "__foo_block_invoke", scope: !4, file: !4, line: 573, type: !9, scopeLine: 573, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !3, retainedNodes: !2)
!9 = !DISubroutineType(types: !2)
!11 = !DILocalVariable(name: ".block_descriptor", arg: 1, scope: !7, file: !4, line: 557, type: !12, flags: DIFlagArtificial)
!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
!13 = !DICompositeType(tag: DW_TAG_structure_type, name: "__block_literal_1", scope: !4, file: !4, line: 557, size: 392, elements: !2)
!15 = !DILocation(line: 558, column: 7, scope: !7)
name: __foo_block_invoke
body: |
bb.0.entry:
DBG_VALUE $rdi, $noreg, !11, !DIExpression(), debug-location !15
$ecx = MOV32rr undef $edi, implicit $dil, debug-location !15
bb.2:
successors:
TRAP
bb.21.do.body.i129.i (address-taken):