Skip to content

Commit 71809cf

Browse files
authored
[DebugInfo][RemoveDIs] Avoid leaking trailing DPMarkers (#74458)
In the debug-info-splice implementation, we need to be careful to delete trailing DPMarkers from blocks when we splice their contents out. This is equivalent to removing the terminator from a block, then splicing the rest of it's contents to another block: any DPValues trailing at the end of the block get moved and we need to clean up afterwards.
1 parent 80fa796 commit 71809cf

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

llvm/lib/IR/BasicBlock.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ void BasicBlock::flushTerminatorDbgValues() {
770770

771771
// Transfer DPValues from the trailing position onto the terminator.
772772
Term->DbgMarker->absorbDebugValues(*TrailingDPValues, false);
773+
TrailingDPValues->eraseFromParent();
773774
deleteTrailingDPValues();
774775
}
775776

@@ -813,6 +814,7 @@ void BasicBlock::spliceDebugInfoEmptyBlock(BasicBlock::iterator Dest,
813814

814815
DPMarker *M = Dest->DbgMarker;
815816
M->absorbDebugValues(*SrcTrailingDPValues, InsertAtHead);
817+
SrcTrailingDPValues->eraseFromParent();
816818
Src->deleteTrailingDPValues();
817819
return;
818820
}
@@ -920,6 +922,7 @@ void BasicBlock::spliceDebugInfoImpl(BasicBlock::iterator Dest, BasicBlock *Src,
920922
// Use this flag to signal the abnormal case, where we don't want to copy the
921923
// DPValues ahead of the "Last" position.
922924
bool ReadFromTail = !Last.getTailBit();
925+
bool LastIsEnd = (Last == Src->end());
923926

924927
/*
925928
Here's an illustration of what we're about to do. We have two blocks, this
@@ -995,12 +998,16 @@ void BasicBlock::spliceDebugInfoImpl(BasicBlock::iterator Dest, BasicBlock *Src,
995998
DPMarker *OntoDest = getMarker(Dest);
996999
DPMarker *FromLast = Src->getMarker(Last);
9971000
OntoDest->absorbDebugValues(*FromLast, true);
1001+
if (LastIsEnd) {
1002+
FromLast->eraseFromParent();
1003+
deleteTrailingDPValues();
1004+
}
9981005
}
9991006

10001007
// If we're _not_ reading from the head of First, i.e. the "++++" DPValues,
10011008
// move their markers onto Last. They remain in the Src block. No action
10021009
// needed.
1003-
if (!ReadFromHead) {
1010+
if (!ReadFromHead && First->hasDbgValues()) {
10041011
DPMarker *OntoLast = Src->createMarker(Last);
10051012
DPMarker *FromFirst = Src->createMarker(First);
10061013
OntoLast->absorbDebugValues(*FromFirst,
@@ -1030,6 +1037,7 @@ void BasicBlock::spliceDebugInfoImpl(BasicBlock::iterator Dest, BasicBlock *Src,
10301037
DPMarker *TrailingDPValues = getTrailingDPValues();
10311038
if (TrailingDPValues) {
10321039
FirstMarker->absorbDebugValues(*TrailingDPValues, true);
1040+
TrailingDPValues->eraseFromParent();
10331041
deleteTrailingDPValues();
10341042
}
10351043
}

0 commit comments

Comments
 (0)