diff options
author | Lang Hames <lhames@gmail.com> | 2014-09-05 23:38:35 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2014-09-05 23:38:35 +0000 |
commit | 018452e6bc79f5f7599ee9df0ba87fa90516081b (patch) | |
tree | 9dcddc612724433e9719e89a6f89bd19fa86ab55 /llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp | |
parent | f5f9a836682d297f2caeb92f5a6c01b58ea839b3 (diff) | |
download | llvm-018452e6bc79f5f7599ee9df0ba87fa90516081b.zip llvm-018452e6bc79f5f7599ee9df0ba87fa90516081b.tar.gz llvm-018452e6bc79f5f7599ee9df0ba87fa90516081b.tar.bz2 |
[MCJIT] Fix an iterator invalidation bug in MCJIT::finalizeObject.
The finalizeObject method calls generateCodeForModule on each of the currently
'added' objects, but generateCodeForModule moves objects out of the 'added'
set as it's called. To avoid iterator invalidation issues, the added set is
copied out before any calls to generateCodeForModule.
This should fix http://llvm.org/PR20851 .
llvm-svn: 217291
Diffstat (limited to 'llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp')
-rw-r--r-- | llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp index 3dd2057..8ff41ff 100644 --- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp +++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp @@ -225,12 +225,14 @@ void MCJIT::finalizeLoadedModules() { void MCJIT::finalizeObject() { MutexGuard locked(lock); - for (ModulePtrSet::iterator I = OwnedModules.begin_added(), - E = OwnedModules.end_added(); - I != E; ++I) { - Module *M = *I; + // Generate code for module is going to move objects out of the 'added' list, + // so we need to copy that out before using it: + SmallVector<Module*, 16> ModsToAdd; + for (auto M : OwnedModules.added()) + ModsToAdd.push_back(M); + + for (auto M : ModsToAdd) generateCodeForModule(M); - } finalizeLoadedModules(); } |