Skip to content

Commit 43de305

Browse files
committed
[DebugInfo][InstrRef] Fix a tombstone-in-DenseMap crash from D117877
This is a follow-up to D117877: variable assignments of DBG_VALUE $noreg, or DBG_INSTR_REFs where no value can be found, are represented by a DbgValue object with Kind "Undef", explicitly meaning "there is no value". In D117877 I added a special-case to some assignment accounting faster, without considering this scenario. It causes variables to be given the value ValueIDNum::EmptyValue, which then ends up being a DenseMap key. The DenseMap asserts, because EmptyValue is the tombstone key. Fix this by handling the assign-undef scenario in the special case, to match what happens in the general case: the variable has no value if it's only ever assigned $noreg / undef. Differential Revision: https://reviews.llvm.org/D118715
1 parent c5fff90 commit 43de305

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2796,6 +2796,11 @@ void InstrRefBasedLDV::placePHIsForSingleVarDefinition(
27962796
auto ValueIt = VLocs.Vars.find(Var);
27972797
const DbgValue &Value = ValueIt->second;
27982798

2799+
// If it's an explicit assignment of "undef", that means there is no location
2800+
// anyway, anywhere.
2801+
if (Value.Kind == DbgValue::Undef)
2802+
return;
2803+
27992804
// Assign the variable value to entry to each dominated block that's in scope.
28002805
// Skip the definition block -- it's assigned the variable value in the middle
28012806
// of the block somewhere.

llvm/test/DebugInfo/MIR/InstrRef/single-assign-propagation.mir

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# RUN: llc %s -march=x86-64 -run-pass=livedebugvalues -o - \
22
# RUN: -experimental-debug-variable-locations=true \
3-
# RUN: | FileCheck %s -implicit-check-not=DBG_VALUE
3+
# RUN: | FileCheck %s -implicit-check-not=DBG_VALUE \
4+
# RUN: --check-prefixes=CHECK,COMMON
45
# RUN: llc %s -march=x86-64 -run-pass=livedebugvalues -o - \
56
# RUN: -experimental-debug-variable-locations=false \
6-
# RUN: | FileCheck %s --check-prefixes=VARLOC -implicit-check-not=DBG_VALUE
7+
# RUN: | FileCheck %s -implicit-check-not=DBG_VALUE \
8+
# RUN: --check-prefixes=VARLOC,COMMON
79
#
810
# This test is designed to stimulate a simplification of variable-value
911
# propagation in InstrRefBasedLDV. When we only have a single assignment of
@@ -63,12 +65,23 @@
6365
# VARLOC-LABEL: bb.3:
6466
# VARLOC: DBG_VALUE
6567
#
68+
## Common tail for 'test2' -- this is checking that the assignment of undef or
69+
## $noreg in single-assignment mode doesn't lead to trouble further down the
70+
## line, specifically assertion failures.
71+
#
72+
# COMMON-LABEL: name: test2
73+
# COMMON: DBG_VALUE $noreg
6674
--- |
6775
define i32 @_Z8bb_to_bb() local_unnamed_addr !dbg !12 {
6876
entry:
6977
ret i32 0, !dbg !17
7078
}
7179

80+
define i32 @test2() local_unnamed_addr !dbg !112 {
81+
entry:
82+
ret i32 0, !dbg !117
83+
}
84+
7285
!llvm.dbg.cu = !{!0}
7386
!llvm.module.flags = !{!7, !8, !9, !10}
7487
!llvm.ident = !{!11}
@@ -94,6 +107,13 @@
94107
!18 = distinct !DILexicalBlock(scope: !12, file: !1, line: 1, column: 1)
95108
!19 = distinct !DILexicalBlock(scope: !12, file: !1, line: 1, column: 1)
96109
!20 = !DILocation(line: 10, scope: !19)
110+
!112 = distinct !DISubprogram(name: "test2", linkageName: "102", scope: !1, file: !1, line: 6, type: !13, scopeLine: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !115)
111+
!115 = !{!116}
112+
!116 = !DILocalVariable(name: "myVar", scope: !118, file: !1, line: 7, type: !6)
113+
!117 = !DILocation(line: 10, scope: !118)
114+
!118 = distinct !DILexicalBlock(scope: !112, file: !1, line: 1, column: 1)
115+
!119 = distinct !DILexicalBlock(scope: !112, file: !1, line: 1, column: 1)
116+
!120 = !DILocation(line: 10, scope: !119)
97117

98118
...
99119
---
@@ -136,3 +156,44 @@ body: |
136156
137157
bb.6:
138158
RET 0, debug-location !17
159+
...
160+
---
161+
name: test2
162+
debugValueSubstitutions:
163+
- { srcinst: 4, srcop: 0, dstinst: 3, dstop: 0, subreg: 0 }
164+
body: |
165+
bb.0.entry:
166+
successors: %bb.1, %bb.5, %bb.6
167+
168+
$rax = MOV64ri 1, debug-instr-number 1, debug-location !117
169+
JCC_1 %bb.5, 1, implicit $eflags
170+
JCC_1 %bb.6, 2, implicit $eflags
171+
JMP_1 %bb.1
172+
173+
bb.1:
174+
successors: %bb.2, %bb.3
175+
176+
DBG_VALUE $noreg, $noreg, !116, !DIExpression(), debug-location !117
177+
JCC_1 %bb.3, 1, implicit $eflags, debug-location !117
178+
179+
bb.2:
180+
successors: %bb.4
181+
182+
JMP_1 %bb.4, debug-location !120
183+
184+
bb.3:
185+
successors: %bb.4
186+
187+
JMP_1 %bb.4, debug-location !117
188+
189+
bb.4:
190+
successors: %bb.5, %bb.6
191+
192+
JCC_1 %bb.5, 1, implicit $eflags, debug-location !117
193+
JMP_1 %bb.6, debug-location !117
194+
195+
bb.5:
196+
RET 0, debug-location !117
197+
198+
bb.6:
199+
RET 0, debug-location !117

0 commit comments

Comments
 (0)