From 0d5bd59553375dc85ac04c81ef48ef74c9e7193e Mon Sep 17 00:00:00 2001 From: Jeffrey Yasskin Date: Fri, 7 Aug 2009 19:54:29 +0000 Subject: To catch bugs like the one fixed in http://llvm.org/viewvc/llvm-project?view=rev&revision=78127, I'm changing the ExecutionEngine's global mappings to hold AssertingVH. That way, if unregistering a mapping fails to actually unregister it, we'll get an assert. Running the jit nightly tests didn't uncover any actual instances of the problem. This also uncovered the fact that AssertingVH didn't work, so I fixed that too. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78400 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ExecutionEngine/ExecutionEngine.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'lib/ExecutionEngine/ExecutionEngine.cpp') diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index e827d36f86..348190a75b 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -13,17 +13,19 @@ //===----------------------------------------------------------------------===// #define DEBUG_TYPE "jit" +#include "llvm/ExecutionEngine/ExecutionEngine.h" + #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/Module.h" #include "llvm/ModuleProvider.h" #include "llvm/ADT/Statistic.h" #include "llvm/Config/alloca.h" -#include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/GenericValue.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MutexGuard.h" +#include "llvm/Support/ValueHandle.h" #include "llvm/Support/raw_ostream.h" #include "llvm/System/DynamicLibrary.h" #include "llvm/System/Host.h" @@ -128,7 +130,8 @@ void ExecutionEngine::addGlobalMapping(const GlobalValue *GV, void *Addr) { // If we are using the reverse mapping, add it too if (!state.getGlobalAddressReverseMap(locked).empty()) { - const GlobalValue *&V = state.getGlobalAddressReverseMap(locked)[Addr]; + AssertingVH &V = + state.getGlobalAddressReverseMap(locked)[Addr]; assert((V == 0 || GV == 0) && "GlobalMapping already established!"); V = GV; } @@ -149,13 +152,13 @@ void ExecutionEngine::clearGlobalMappingsFromModule(Module *M) { MutexGuard locked(lock); for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI) { - state.getGlobalAddressMap(locked).erase(FI); - state.getGlobalAddressReverseMap(locked).erase(FI); + state.getGlobalAddressMap(locked).erase(&*FI); + state.getGlobalAddressReverseMap(locked).erase(&*FI); } for (Module::global_iterator GI = M->global_begin(), GE = M->global_end(); GI != GE; ++GI) { - state.getGlobalAddressMap(locked).erase(GI); - state.getGlobalAddressReverseMap(locked).erase(GI); + state.getGlobalAddressMap(locked).erase(&*GI); + state.getGlobalAddressReverseMap(locked).erase(&*GI); } } @@ -165,11 +168,12 @@ void ExecutionEngine::clearGlobalMappingsFromModule(Module *M) { void *ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, void *Addr) { MutexGuard locked(lock); - std::map &Map = state.getGlobalAddressMap(locked); + std::map, void *> &Map = + state.getGlobalAddressMap(locked); // Deleting from the mapping? if (Addr == 0) { - std::map::iterator I = Map.find(GV); + std::map, void *>::iterator I = Map.find(GV); void *OldVal; if (I == Map.end()) OldVal = 0; @@ -192,7 +196,8 @@ void *ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, void *Addr) { // If we are using the reverse mapping, add it too if (!state.getGlobalAddressReverseMap(locked).empty()) { - const GlobalValue *&V = state.getGlobalAddressReverseMap(locked)[Addr]; + AssertingVH &V = + state.getGlobalAddressReverseMap(locked)[Addr]; assert((V == 0 || GV == 0) && "GlobalMapping already established!"); V = GV; } @@ -205,8 +210,8 @@ void *ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, void *Addr) { void *ExecutionEngine::getPointerToGlobalIfAvailable(const GlobalValue *GV) { MutexGuard locked(lock); - std::map::iterator I = - state.getGlobalAddressMap(locked).find(GV); + std::map, void*>::iterator I = + state.getGlobalAddressMap(locked).find(GV); return I != state.getGlobalAddressMap(locked).end() ? I->second : 0; } @@ -218,14 +223,14 @@ const GlobalValue *ExecutionEngine::getGlobalValueAtAddress(void *Addr) { // If we haven't computed the reverse mapping yet, do so first. if (state.getGlobalAddressReverseMap(locked).empty()) { - for (std::map::iterator + for (std::map, void *>::iterator I = state.getGlobalAddressMap(locked).begin(), E = state.getGlobalAddressMap(locked).end(); I != E; ++I) state.getGlobalAddressReverseMap(locked).insert(std::make_pair(I->second, I->first)); } - std::map::iterator I = + std::map >::iterator I = state.getGlobalAddressReverseMap(locked).find(Addr); return I != state.getGlobalAddressReverseMap(locked).end() ? I->second : 0; } -- cgit v1.2.3-18-g5258