[mlir][LLVMDebugTranslation] Only insert the location mapping after translation

This fixes an iteration invalidation bug when the map grows beyond capacity and the iterator for the location to translate becomes invalid.
This commit is contained in:
River Riddle 2020-04-27 16:42:58 -07:00
parent a4ccfd9565
commit 6fab33b20a
1 changed files with 5 additions and 3 deletions

View File

@ -110,10 +110,11 @@ DebugTranslation::translateLoc(Location loc, llvm::DILocalScope *scope,
return nullptr;
// Check for a cached instance.
const auto *&llvmLoc = locationToLoc[std::make_pair(loc, scope)];
if (llvmLoc)
return llvmLoc;
auto existingIt = locationToLoc.find(std::make_pair(loc, scope));
if (existingIt != locationToLoc.end())
return existingIt->second;
const llvm::DILocation *llvmLoc = nullptr;
switch (loc->getKind()) {
case StandardAttributes::CallSiteLocation: {
auto callLoc = loc.dyn_cast<CallSiteLoc>();
@ -154,6 +155,7 @@ DebugTranslation::translateLoc(Location loc, llvm::DILocalScope *scope,
default:
llvm_unreachable("unknown location kind");
}
locationToLoc.try_emplace(std::make_pair(loc, scope), llvmLoc);
return llvmLoc;
}