Skip to content

Commit dbf965a

Browse files
Merge pull request #6301 from adrian-prantl/105525639
Fix an iterator invalidation bug
2 parents 4140a68 + 44735aa commit dbf965a

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,7 @@ bool InstrRefBasedLDV::transferDebugValue(const MachineInstr &MI) {
13841384

13851385
// MLocTracker needs to know that this register is read, even if it's only
13861386
// read by a debug inst.
1387+
bool convertToSwiftAsyncEntryValue = false;
13871388
for (const MachineOperand &MO : MI.debug_operands())
13881389
if (MO.isReg() && MO.getReg() != 0) {
13891390
ValueIDNum RegId = MTracker->readReg(MO.getReg());
@@ -1401,16 +1402,18 @@ bool InstrRefBasedLDV::transferDebugValue(const MachineInstr &MI) {
14011402
if (!Expr || !Expr->isEntryValue()) {
14021403
if (TTracker)
14031404
TTracker->recoverAsEntryValue(V, Properties, RegId);
1404-
else {
1405-
const_cast<MachineInstr *>(&MI)
1406-
->getOperand(MI.isDebugValueList() ? 1 : 3)
1407-
.setMetadata(
1408-
DIExpression::prepend(Expr, DIExpression::EntryValue));
1409-
}
1405+
else
1406+
convertToSwiftAsyncEntryValue = true;
14101407
}
14111408
}
14121409
}
1413-
// END SWIFT
1410+
1411+
if (convertToSwiftAsyncEntryValue && Expr && !MI.isDebugValueList()) {
1412+
const_cast<MachineInstr *>(&MI)->getOperand(3).setMetadata(
1413+
DIExpression::prepend(Expr, DIExpression::EntryValue));
1414+
Properties.DIExpr = MI.getDebugExpression();
1415+
}
1416+
// END SWIFT
14141417

14151418
// If we're preparing for the second analysis (variables), the machine value
14161419
// locations are already solved, and we report this DBG_VALUE and the value

llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,10 +2199,12 @@ bool VarLocBasedLDV::ExtendRanges(MachineFunction &MF,
21992199
if (MI.isDebugValue()) {
22002200
// In Swift async functions entry values are preferred, since they
22012201
// can be evaluated in both live frames and virtual backtraces.
2202-
if (SeenDebugVars.insert(DebugVariable(MI.getDebugVariable(),
2203-
MI.getDebugExpression(),
2204-
MI.getDebugLoc()->getInlinedAt())).second &&
2205-
isSwiftAsyncContext(MI)) {
2202+
if (SeenDebugVars
2203+
.insert(DebugVariable(MI.getDebugVariable(),
2204+
MI.getDebugExpression(),
2205+
MI.getDebugLoc()->getInlinedAt()))
2206+
.second &&
2207+
isSwiftAsyncContext(MI) && !MI.isDebugValueList()) {
22062208
// If our instruction is not an entry value yet, make it an entry value.
22072209
if (!MI.getDebugExpression()->isEntryValue()) {
22082210
MI.getOperand(3).setMetadata(DIExpression::prepend(

llvm/test/DebugInfo/MIR/X86/swift-async-entryvalues.mir

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,15 @@ machineFunctionInfo: {}
211211
body: |
212212
bb.0 (%ir-block.3):
213213
liveins: $rdi, $rsi, $r14
214-
214+
215215
DBG_VALUE renamable $r14, 0, !59, !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 64, DW_OP_plus_uconst, 24, DW_OP_deref), debug-location !61
216216
frame-setup PUSH64r $r14, implicit-def $rsp, implicit $rsp
217217
CFI_INSTRUCTION def_cfa_offset 16
218218
$rsp = frame-setup SUB64ri8 $rsp, 32, implicit-def dead $eflags
219219
CFI_INSTRUCTION def_cfa_offset 48
220220
CFI_INSTRUCTION offset $r14, -16
221-
DBG_VALUE renamable $r14, 0, !54, !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 64, DW_OP_plus_uconst, 32), debug-location !58
221+
; This isn't supported, but it also shouldn't crash.
222+
DBG_VALUE_LIST !54, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_deref, DW_OP_plus_uconst, 64, DW_OP_plus_uconst, 32, DW_OP_stack_value), renamable $r14, debug-location !58
222223
$rcx = MOV64rr killed $rsi
223224
renamable $rax = MOV64rm renamable $r14, 1, $noreg, 0, $noreg, debug-location !47 :: (load 8 from %ir.4)
224225
MOV64mr $rsp, 1, $noreg, 24, $noreg, $rax :: (store 8 into %stack.0)

0 commit comments

Comments
 (0)