[SCEV] Fix usage of invalid IP with FoldingSet

Fix the use of invalid Insertion Point pointer with the UniqueSCEVs FoldingSet,
which caused memory corruption.
This commit is contained in:
Ehud Katz 2020-03-13 18:31:47 +02:00
parent 2543567c41
commit 18eae33122
1 changed files with 4 additions and 0 deletions
llvm/lib/Analysis

View File

@ -3339,6 +3339,10 @@ const SCEV *ScalarEvolution::getUDivExpr(const SCEV *LHS,
}
}
// The Insertion Point (IP) might be invalid by now (due to UniqueSCEVs
// changes). Make sure we get a new one.
IP = nullptr;
if (const SCEV *S = UniqueSCEVs.FindNodeOrInsertPos(ID, IP)) return S;
SCEV *S = new (SCEVAllocator) SCEVUDivExpr(ID.Intern(SCEVAllocator),
LHS, RHS);
UniqueSCEVs.InsertNode(S, IP);