Skip to content

Commit ad68e5d

Browse files
authored
[LiveDebugVariables] Use bundle-aware iterators consistently (#159471)
Most of the pass works in terms of MachineBasicBlock::iterator (MachineInstrBundleIterator), but here one is constructed from an arbitrary instruction which may be within a bundle, causing an assertion.
1 parent 902ddda commit ad68e5d

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

llvm/lib/CodeGen/LiveDebugVariables.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,8 +1973,8 @@ void LiveDebugVariables::LDVImpl::emitDebugValues(VirtRegMap *VRM) {
19731973

19741974
if (MachineInstr *Pos = Slots->getInstructionFromIndex(Idx)) {
19751975
// Insert at the end of any debug instructions.
1976-
auto PostDebug = std::next(Pos->getIterator());
1977-
PostDebug = skipDebugInstructionsForward(PostDebug, MBB->instr_end());
1976+
auto PostDebug = std::next(MachineBasicBlock::iterator(Pos));
1977+
PostDebug = skipDebugInstructionsForward(PostDebug, MBB->end());
19781978
EmitInstsHere(PostDebug);
19791979
} else {
19801980
// Insert position disappeared; walk forwards through slots until we
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# RUN: llc -run-pass=livedebugvars -run-pass=virtregrewriter -o - %s | FileCheck %s
2+
3+
# Regression test for a bug where LiveDebugVariables used the wrong instruction
4+
# iterator type when debugInstrRef=true, and triggered an assertion.
5+
6+
--- |
7+
target triple = "x86_64-unknown-linux-gnu"
8+
9+
define i32 @foo(i32 %a, i32 %b) !dbg !4 {
10+
entry:
11+
ret i32 0, !dbg !10
12+
}
13+
14+
!llvm.dbg.cu = !{!0}
15+
!llvm.module.flags = !{!3}
16+
17+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
18+
!1 = !DIFile(filename: "-", directory: "./")
19+
!2 = !{}
20+
!3 = !{i32 2, !"Debug Info Version", i32 3}
21+
!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !0, retainedNodes: !2)
22+
!5 = !DISubroutineType(types: !6)
23+
!6 = !{!7, !7, !7}
24+
!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
25+
!8 = !DILocalVariable(name: "local_var", scope: !4, file: !1, line: 7, type: !7)
26+
!9 = !DILocation(line: 7, column: 1, scope: !4)
27+
!10 = !DILocation(line: 8, column: 3, scope: !4)
28+
29+
...
30+
---
31+
name: foo
32+
tracksRegLiveness: true
33+
debugInstrRef: true
34+
body: |
35+
bb.0:
36+
$esi = MOV32ri 2, debug-instr-number 1
37+
BUNDLE {
38+
NOOP
39+
}
40+
DBG_INSTR_REF !8, !DIExpression(), dbg-instr-ref(1, 0), debug-location !9
41+
RET 0, undef $eax, debug-location !10
42+
...
43+
44+
# CHECK-LABEL: name: foo
45+
# CHECK: bb.0:
46+
# CHECK: BUNDLE {
47+
# CHECK: }
48+
# CHECK: DBG_INSTR_REF

0 commit comments

Comments
 (0)