Skip to content

Commit c850ad5

Browse files
Merge pull request #6684 from adrian-prantl/instr-ref-patch
Fix an invalid iterator dereference in LiveDebugValues.
2 parents 8891a07 + 3f1e4c8 commit c850ad5

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,11 @@ class TransferTracker {
626626
void redefVar(const MachineInstr &MI) {
627627
DebugVariable Var(MI.getDebugVariable(), MI.getDebugExpression(),
628628
MI.getDebugLoc()->getInlinedAt());
629+
// BEGIN SWIFT
630+
if (IsSwiftAsyncFunction && MI.getDebugExpression() &&
631+
MI.getDebugExpression()->isEntryValue())
632+
return;
633+
// END SWIFT
629634
DbgValueProperties Properties(MI);
630635

631636
// Ignore non-register locations, we don't transfer those.
@@ -763,6 +768,10 @@ class TransferTracker {
763768
if (!NewLoc && !MakeUndef) {
764769
// Try and recover a few more locations with entry values.
765770
for (const auto &Var : ActiveMLocIt->second) {
771+
// BEGIN SWIFT
772+
if (ActiveVLocs.find(Var) == ActiveVLocs.end())
773+
continue;
774+
// END SWIFT
766775
auto &Prop = ActiveVLocs.find(Var)->second.Properties;
767776
recoverAsEntryValue(Var, Prop, OldValue);
768777
}
@@ -777,6 +786,11 @@ class TransferTracker {
777786
SmallVector<std::pair<LocIdx, DebugVariable>> LostMLocs;
778787
for (const auto &Var : ActiveMLocIt->second) {
779788
auto ActiveVLocIt = ActiveVLocs.find(Var);
789+
// BEGIN SWIFT
790+
if (ActiveVLocs.find(Var) == ActiveVLocs.end())
791+
continue;
792+
// END SWIFT
793+
780794
// Re-state the variable location: if there's no replacement then NewLoc
781795
// is None and a $noreg DBG_VALUE will be created. Otherwise, a DBG_VALUE
782796
// identifying the alternative location will be emitted.
@@ -788,8 +802,8 @@ class TransferTracker {
788802
SmallVector<ResolvedDbgOp> DbgOps;
789803
// BEGIN SWIFT
790804
// Async support: Don't track spills for entry values.
791-
if (IsSwiftAsyncFunction && ActiveVLocIt->second.Properties.DIExpr &&
792-
ActiveVLocIt->second.Properties.DIExpr->isEntryValue())
805+
if (IsSwiftAsyncFunction && Properties.DIExpr &&
806+
Properties.DIExpr->isEntryValue())
793807
DbgOps.push_back(MLoc);
794808
else
795809
// END SWIFT
@@ -864,18 +878,19 @@ class TransferTracker {
864878
ResolvedDbgOp DstOp(Dst);
865879
for (const auto &Var : MovingVars) {
866880
auto ActiveVLocIt = ActiveVLocs.find(Var);
867-
assert(ActiveVLocIt != ActiveVLocs.end());
868-
869881
// BEGIN SWIFT
870882
// Async support: Don't track transfers for entry values.
871-
if (IsSwiftAsyncFunction && ActiveVLocIt->second.Properties.DIExpr &&
872-
ActiveVLocIt->second.Properties.DIExpr->isEntryValue()) {
883+
if (ActiveVLocIt == ActiveVLocs.end()) {
873884
// Leave SrcOp in-situ.
874-
} else
885+
continue;
886+
}
875887
// END SWIFT
876-
// Update all instances of Src in the variable's tracked values to Dst.
877-
std::replace(ActiveVLocIt->second.Ops.begin(),
878-
ActiveVLocIt->second.Ops.end(), SrcOp, DstOp);
888+
889+
assert(ActiveVLocIt != ActiveVLocs.end());
890+
891+
// Update all instances of Src in the variable's tracked values to Dst.
892+
std::replace(ActiveVLocIt->second.Ops.begin(),
893+
ActiveVLocIt->second.Ops.end(), SrcOp, DstOp);
879894

880895
MachineInstr *MI = MTracker->emitLoc(ActiveVLocIt->second.Ops, Var,
881896
ActiveVLocIt->second.Properties);

0 commit comments

Comments
 (0)