From 4bc3592bd2cb5fae6dfb5b3958727bae4115a800 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Fri, 7 Mar 2025 11:09:57 -0800 Subject: [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. --- llvm/lib/CodeGen/ModuloSchedule.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'llvm/lib/CodeGen/ModuloSchedule.cpp') diff --git a/llvm/lib/CodeGen/ModuloSchedule.cpp b/llvm/lib/CodeGen/ModuloSchedule.cpp index c6d1a41..bff0b7a 100644 --- a/llvm/lib/CodeGen/ModuloSchedule.cpp +++ b/llvm/lib/CodeGen/ModuloSchedule.cpp @@ -410,8 +410,11 @@ void ModuloScheduleExpander::generateExistingPhis( Register NewReg = VRMap[PrevStage][LoopVal]; rewriteScheduledInstr(NewBB, InstrMap, CurStageNum, 0, &*BBI, Def, InitVal, NewReg); - if (VRMap[CurStageNum].count(LoopVal)) - VRMap[CurStageNum][Def] = VRMap[CurStageNum][LoopVal]; + auto It = VRMap[CurStageNum].find(LoopVal); + if (It != VRMap[CurStageNum].end()) { + Register Reg = It->second; + VRMap[CurStageNum][Def] = Reg; + } } // Adjust the number of Phis needed depending on the number of prologs left, // and the distance from where the Phi is first scheduled. The number of -- cgit v1.1