Skip to content

Commit 6fab33b

Browse files
committed
[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.
1 parent a4ccfd9 commit 6fab33b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

mlir/lib/Target/LLVMIR/DebugTranslation.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,11 @@ DebugTranslation::translateLoc(Location loc, llvm::DILocalScope *scope,
110110
return nullptr;
111111

112112
// Check for a cached instance.
113-
const auto *&llvmLoc = locationToLoc[std::make_pair(loc, scope)];
114-
if (llvmLoc)
115-
return llvmLoc;
113+
auto existingIt = locationToLoc.find(std::make_pair(loc, scope));
114+
if (existingIt != locationToLoc.end())
115+
return existingIt->second;
116116

117+
const llvm::DILocation *llvmLoc = nullptr;
117118
switch (loc->getKind()) {
118119
case StandardAttributes::CallSiteLocation: {
119120
auto callLoc = loc.dyn_cast<CallSiteLoc>();
@@ -154,6 +155,7 @@ DebugTranslation::translateLoc(Location loc, llvm::DILocalScope *scope,
154155
default:
155156
llvm_unreachable("unknown location kind");
156157
}
158+
locationToLoc.try_emplace(std::make_pair(loc, scope), llvmLoc);
157159
return llvmLoc;
158160
}
159161

0 commit comments

Comments
 (0)