Fix map insertion that is elided in release build.

The assert() macro doesn't actually execute its body in Release builds, so using
it to check cache invariants requires that the insertion be outside of the
assert() statement. This change does that, and also makes sure to return the
actual map contents.

llvm-svn: 284898
This commit is contained in:
David L. Jones 2016-10-21 23:30:39 +00:00
parent 0a8e85fca2
commit 664039935e

View File

@ -558,10 +558,10 @@ namespace llvm {
auto It = RewriteResults.find(S);
if (It != RewriteResults.end())
return It->second;
auto *Result = SCEVVisitor<SC, const SCEV *>::visit(S);
assert(RewriteResults.insert({S, Result}).second &&
"Should insert a new entry");
return Result;
auto* Visited = SCEVVisitor<SC, const SCEV *>::visit(S);
auto Result = RewriteResults.try_emplace(S, Visited);
assert(Result.second && "Should insert a new entry");
return Result.first->second;
}
const SCEV *visitConstant(const SCEVConstant *Constant) {