diff options
author | Jeffrey Yasskin <jyasskin@google.com> | 2009-10-09 22:10:27 +0000 |
---|---|---|
committer | Jeffrey Yasskin <jyasskin@google.com> | 2009-10-09 22:10:27 +0000 |
commit | c89d27a440370455336202b2a8f25eb9c73e67bc (patch) | |
tree | 351ff9e37997f9d3a55f8d5a16a1f07919217f99 /lib/ExecutionEngine | |
parent | 769b7f89534caed11d7595b5c84aa47d3de30ad9 (diff) | |
download | external_llvm-c89d27a440370455336202b2a8f25eb9c73e67bc.zip external_llvm-c89d27a440370455336202b2a8f25eb9c73e67bc.tar.gz external_llvm-c89d27a440370455336202b2a8f25eb9c73e67bc.tar.bz2 |
ExecutionEngine::clearGlobalMappingsFromModule failed to remove reverse
mappings, which could cause errors and assert-failures. This patch fixes that,
adds a test, and refactors the global-mapping-removal code into a single place.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83678 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r-- | lib/ExecutionEngine/ExecutionEngine.cpp | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index 52718eb..700ae5e 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -113,6 +113,22 @@ Function *ExecutionEngine::FindFunctionNamed(const char *FnName) { } +void *ExecutionEngineState::RemoveMapping( + const MutexGuard &, const GlobalValue *ToUnmap) { + std::map<AssertingVH<const GlobalValue>, void *>::iterator I = + GlobalAddressMap.find(ToUnmap); + void *OldVal; + if (I == GlobalAddressMap.end()) + OldVal = 0; + else { + OldVal = I->second; + GlobalAddressMap.erase(I); + } + + GlobalAddressReverseMap.erase(OldVal); + return OldVal; +} + /// addGlobalMapping - Tell the execution engine that the specified global is /// at the specified location. This is used internally as functions are JIT'd /// and as global variables are laid out in memory. It can and should also be @@ -151,13 +167,11 @@ 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.RemoveMapping(locked, 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.RemoveMapping(locked, GI); } } @@ -172,18 +186,7 @@ void *ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, void *Addr) { // Deleting from the mapping? if (Addr == 0) { - std::map<AssertingVH<const GlobalValue>, void *>::iterator I = Map.find(GV); - void *OldVal; - if (I == Map.end()) - OldVal = 0; - else { - OldVal = I->second; - Map.erase(I); - } - - if (!state.getGlobalAddressReverseMap(locked).empty()) - state.getGlobalAddressReverseMap(locked).erase(OldVal); - return OldVal; + return state.RemoveMapping(locked, GV); } void *&CurVal = Map[GV]; |