[Mlir-commits] [mlir] 6fab33b - [mlir][LLVMDebugTranslation] Only insert the location mapping after translation

River Riddle llvmlistbot at llvm.org
Mon Apr 27 16:49:54 PDT 2020


Author: River Riddle
Date: 2020-04-27T16:49:18-07:00
New Revision: 6fab33b20abf28d65b0000cfc3d1254c5e6e250b

URL: https://github.com/llvm/llvm-project/commit/6fab33b20abf28d65b0000cfc3d1254c5e6e250b
DIFF: https://github.com/llvm/llvm-project/commit/6fab33b20abf28d65b0000cfc3d1254c5e6e250b.diff

LOG: [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.

Added: 
    

Modified: 
    mlir/lib/Target/LLVMIR/DebugTranslation.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
index 3b0709a838af..74dd0d15f441 100644
--- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
@@ -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;
 }
 


        


More information about the Mlir-commits mailing list