Skip to content

Commit 30343ef

Browse files
Merge pull request #5082 from adrian-prantl/97226240
Fix LDV InstrRefBasedImpl to not crash when encountering unreachable blocks
2 parents accf2a2 + 2131501 commit 30343ef

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
lines changed

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ class TransferTracker {
318318
for (auto Location : MTracker->locations()) {
319319
LocIdx Idx = Location.Idx;
320320
ValueIDNum &VNum = MLocs[Idx.asU64()];
321+
if (VNum == ValueIDNum::EmptyValue)
322+
continue;
321323
VarLocs.push_back(VNum);
322324

323325
// Is there a variable that wants a location for this value? If not, skip.
@@ -2970,12 +2972,17 @@ void InstrRefBasedLDV::initialSetup(MachineFunction &MF) {
29702972
// Compute mappings of block <=> RPO order.
29712973
ReversePostOrderTraversal<MachineFunction *> RPOT(&MF);
29722974
unsigned int RPONumber = 0;
2973-
for (MachineBasicBlock *MBB : RPOT) {
2975+
auto processMBB = [&](MachineBasicBlock *MBB) {
29742976
OrderToBB[RPONumber] = MBB;
29752977
BBToOrder[MBB] = RPONumber;
29762978
BBNumToRPO[MBB->getNumber()] = RPONumber;
29772979
++RPONumber;
2978-
}
2980+
};
2981+
for (MachineBasicBlock *MBB : RPOT)
2982+
processMBB(MBB);
2983+
for (MachineBasicBlock &MBB : MF)
2984+
if (BBToOrder.find(&MBB) == BBToOrder.end())
2985+
processMBB(&MBB);
29792986

29802987
// Order value substitutions by their "source" operand pair, for quick lookup.
29812988
llvm::sort(MF.DebugValueSubstitutions);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# RUN: llc -mtriple=x86_64-apple-macos %s -start-before=livedebugvalues -filetype=obj -o - | llvm-dwarfdump - | FileCheck %s
2+
# CHECK: DW_TAG_subprogram
3+
# Test that LiveDebugValues can handle MBBs that are not reachable in a RPOT.
4+
--- |
5+
define hidden zeroext i1 @__foo_block_invoke(i8* nocapture noundef readonly %.block_descriptor, i64 noundef %type) !dbg !5 {
6+
entry:
7+
%call2.i = tail call zeroext i8 @foo_len(), !dbg !10
8+
%cmp.i102.i = icmp ult i8 %call2.i, 64, !dbg !10
9+
br i1 %cmp.i102.i, label %bar_length.exit105.i, label %if.else.i103.i, !dbg !10
10+
if.else.i103.i: ; preds = %sw.bb.i
11+
br label %bar_length.exit105.i
12+
bar_length.exit105.i: ; preds = %if.else.i103.i, %sw.bb.i
13+
unreachable
14+
baz_size.exit: ; preds = %bar_length.exit131.i, %bar_length.exit105.i, %bar_length.exit.i.baz_size.exit_crit_edge
15+
unreachable
16+
}
17+
declare zeroext i8 @foo_len() local_unnamed_addr
18+
!llvm.dbg.cu = !{!0}
19+
!llvm.module.flags = !{!3, !4}
20+
!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")
21+
!2 = !{}
22+
!3 = !{i32 2, !"Debug Info Version", i32 3}
23+
!4 = !{i32 1, !"LTOPostLink", i32 1}
24+
!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)
25+
!6 = !DIFile(filename: "t.c", directory: "")
26+
!7 = !DISubroutineType(types: !2)
27+
!10 = !DILocation(line: 558, column: 7, scope: !12)
28+
!12 = distinct !DILexicalBlock(scope: !5, file: !6, line: 557, column: 50)
29+
name: __foo_block_invoke
30+
body: |
31+
bb.0.entry:
32+
JCC_1 %bb.1, 5, implicit $eflags, debug-location !10
33+
bb.28.baz_size.exit:
34+
RET64 $al, debug-location !10
35+
bb.1:
36+
successors:
37+
bb.25.if.else.i103.i (address-taken):
38+
JMP_1 %bb.28
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# RUN: llc -mtriple=x86_64-apple-macos %s -start-before=livedebugvalues -filetype=obj -o - | llvm-dwarfdump - | FileCheck %s
2+
# CHECK: DW_TAG_subprogram
3+
# Test that LiveDebugValues can handle MBBs that are not reachable in a RPOT.
4+
--- |
5+
define hidden zeroext i1 @__foo_block_invoke(i8* nocapture noundef readonly %.block_descriptor, i64 noundef %type) !dbg !7 {
6+
entry:
7+
unreachable
8+
do.body.i129.i: ; preds = %if.else6.i128.i
9+
unreachable
10+
}
11+
!llvm.dbg.cu = !{!3}
12+
!llvm.module.flags = !{!5, !6}
13+
!2 = !{}
14+
!3 = distinct !DICompileUnit(language: DW_LANG_C99, file: !4, producer: "clang", runtimeVersion: 0, emissionKind: FullDebug)
15+
!4 = !DIFile(filename: "t.c", directory: "/")
16+
!5 = !{i32 2, !"Debug Info Version", i32 3}
17+
!6 = !{i32 1, !"LTOPostLink", i32 1}
18+
!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)
19+
!9 = !DISubroutineType(types: !2)
20+
!11 = !DILocalVariable(name: ".block_descriptor", arg: 1, scope: !7, file: !4, line: 557, type: !12, flags: DIFlagArtificial)
21+
!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
22+
!13 = !DICompositeType(tag: DW_TAG_structure_type, name: "__block_literal_1", scope: !4, file: !4, line: 557, size: 392, elements: !2)
23+
!15 = !DILocation(line: 558, column: 7, scope: !7)
24+
name: __foo_block_invoke
25+
body: |
26+
bb.0.entry:
27+
DBG_VALUE $rdi, $noreg, !11, !DIExpression(), debug-location !15
28+
$ecx = MOV32rr undef $edi, implicit $dil, debug-location !15
29+
bb.2:
30+
successors:
31+
TRAP
32+
bb.21.do.body.i129.i (address-taken):

0 commit comments

Comments
 (0)