Skip to content

Commit b7ae8c8

Browse files
committed
Avoid using temporary DebugLoc object when possible.
1 parent 56294b8 commit b7ae8c8

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

llvm/lib/Transforms/Scalar/StructurizeCFG.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -996,10 +996,13 @@ BasicBlock *StructurizeCFG::getNextFlow(BasicBlock *Dominator) {
996996
Func, Insert);
997997
FlowSet.insert(Flow);
998998

999-
auto *Term = Dominator->getTerminator();
1000-
if (const DebugLoc &DL =
1001-
Term ? Term->getDebugLoc() : TermDL.lookup(Dominator))
1002-
TermDL[Flow] = DL;
999+
if (auto *Term = Dominator->getTerminator()) {
1000+
if (const DebugLoc &DL = Term->getDebugLoc())
1001+
TermDL[Flow] = DL;
1002+
} else if (DebugLoc DLTemp = TermDL.lookup(Dominator))
1003+
// use a temporary variable to avoid a use-after-free if the map's storage
1004+
// is reallocated
1005+
TermDL[Flow] = DLTemp;
10031006

10041007
DT->addNewBlock(Flow, Dominator);
10051008
ParentRegion->getRegionInfo()->setRegionFor(Flow, ParentRegion);

0 commit comments

Comments
 (0)