Skip to content

Commit 4bc3592

Browse files
authored
[MachinePipeliner] Fix use-after-free coping values of the same DenseMap (#130311)
After #130165. In the code: `VRMap[CurStageNum][Def] = VRMap[CurStageNum][LoopVal]` `VRMap[CurStageNum][LoopVal]` calculates a reference before `VRMap[CurStageNum][Def]` which may rehash the DenseMap. Then the reference can be dead.
1 parent 6a42dc6 commit 4bc3592

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

llvm/lib/CodeGen/ModuloSchedule.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,11 @@ void ModuloScheduleExpander::generateExistingPhis(
410410
Register NewReg = VRMap[PrevStage][LoopVal];
411411
rewriteScheduledInstr(NewBB, InstrMap, CurStageNum, 0, &*BBI, Def,
412412
InitVal, NewReg);
413-
if (VRMap[CurStageNum].count(LoopVal))
414-
VRMap[CurStageNum][Def] = VRMap[CurStageNum][LoopVal];
413+
auto It = VRMap[CurStageNum].find(LoopVal);
414+
if (It != VRMap[CurStageNum].end()) {
415+
Register Reg = It->second;
416+
VRMap[CurStageNum][Def] = Reg;
417+
}
415418
}
416419
// Adjust the number of Phis needed depending on the number of prologs left,
417420
// and the distance from where the Phi is first scheduled. The number of

0 commit comments

Comments
 (0)