Skip to content

Fix an iterator invalidation bug #6301

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
Feb 17, 2023
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
17 changes: 10 additions & 7 deletions llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,7 @@ bool InstrRefBasedLDV::transferDebugValue(const MachineInstr &MI) {

// MLocTracker needs to know that this register is read, even if it's only
// read by a debug inst.
bool convertToSwiftAsyncEntryValue = false;
for (const MachineOperand &MO : MI.debug_operands())
if (MO.isReg() && MO.getReg() != 0) {
ValueIDNum RegId = MTracker->readReg(MO.getReg());
Expand All @@ -1401,16 +1402,18 @@ bool InstrRefBasedLDV::transferDebugValue(const MachineInstr &MI) {
if (!Expr || !Expr->isEntryValue()) {
if (TTracker)
TTracker->recoverAsEntryValue(V, Properties, RegId);
else {
const_cast<MachineInstr *>(&MI)
->getOperand(MI.isDebugValueList() ? 1 : 3)
.setMetadata(
DIExpression::prepend(Expr, DIExpression::EntryValue));
}
else
convertToSwiftAsyncEntryValue = true;
}
}
}
// END SWIFT

if (convertToSwiftAsyncEntryValue && Expr && !MI.isDebugValueList()) {
const_cast<MachineInstr *>(&MI)->getOperand(3).setMetadata(
DIExpression::prepend(Expr, DIExpression::EntryValue));
Properties.DIExpr = MI.getDebugExpression();
}
// END SWIFT

// If we're preparing for the second analysis (variables), the machine value
// locations are already solved, and we report this DBG_VALUE and the value
Expand Down
10 changes: 6 additions & 4 deletions llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2199,10 +2199,12 @@ bool VarLocBasedLDV::ExtendRanges(MachineFunction &MF,
if (MI.isDebugValue()) {
// In Swift async functions entry values are preferred, since they
// can be evaluated in both live frames and virtual backtraces.
if (SeenDebugVars.insert(DebugVariable(MI.getDebugVariable(),
MI.getDebugExpression(),
MI.getDebugLoc()->getInlinedAt())).second &&
isSwiftAsyncContext(MI)) {
if (SeenDebugVars
.insert(DebugVariable(MI.getDebugVariable(),
MI.getDebugExpression(),
MI.getDebugLoc()->getInlinedAt()))
.second &&
isSwiftAsyncContext(MI) && !MI.isDebugValueList()) {
// If our instruction is not an entry value yet, make it an entry value.
if (!MI.getDebugExpression()->isEntryValue()) {
MI.getOperand(3).setMetadata(DIExpression::prepend(
Expand Down
5 changes: 3 additions & 2 deletions llvm/test/DebugInfo/MIR/X86/swift-async-entryvalues.mir
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,15 @@ machineFunctionInfo: {}
body: |
bb.0 (%ir-block.3):
liveins: $rdi, $rsi, $r14

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
frame-setup PUSH64r $r14, implicit-def $rsp, implicit $rsp
CFI_INSTRUCTION def_cfa_offset 16
$rsp = frame-setup SUB64ri8 $rsp, 32, implicit-def dead $eflags
CFI_INSTRUCTION def_cfa_offset 48
CFI_INSTRUCTION offset $r14, -16
DBG_VALUE renamable $r14, 0, !54, !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 64, DW_OP_plus_uconst, 32), debug-location !58
; This isn't supported, but it also shouldn't crash.
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
$rcx = MOV64rr killed $rsi
renamable $rax = MOV64rm renamable $r14, 1, $noreg, 0, $noreg, debug-location !47 :: (load 8 from %ir.4)
MOV64mr $rsp, 1, $noreg, 24, $noreg, $rax :: (store 8 into %stack.0)
Expand Down