diff options
author | Owen Anderson <resistor@mac.com> | 2010-09-08 18:03:32 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2010-09-08 18:03:32 +0000 |
commit | 30268be89df6444f5ffb585439b3fbfec9055197 (patch) | |
tree | f9ba791b35b94fe6acf0aeab46e1e4f394b23b73 /lib/VMCore/LLVMContextImpl.cpp | |
parent | 1485cc2bb386aa07c2598f65e4cc10edd2f0a065 (diff) |
Clarify the ownership model of LLVMContext and Module. Namely, contexts own
modules are instantiated in them. If the context is deleted, all of its owned
modules are also deleted.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113374 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/LLVMContextImpl.cpp')
-rw-r--r-- | lib/VMCore/LLVMContextImpl.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/VMCore/LLVMContextImpl.cpp b/lib/VMCore/LLVMContextImpl.cpp index 93a075f0fc..610c5027c3 100644 --- a/lib/VMCore/LLVMContextImpl.cpp +++ b/lib/VMCore/LLVMContextImpl.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "LLVMContextImpl.h" +#include "llvm/Module.h" #include <algorithm> using namespace llvm; @@ -51,6 +52,15 @@ struct DropReferences { } LLVMContextImpl::~LLVMContextImpl() { + // NOTE: We need to delete the contents of OwnedModules, but we have to + // duplicate it into a temporary vector, because the destructor of Module + // will try to remove itself from OwnedModules set. This would cause + // iterator invalidation if we iterated on the set directly. + std::vector<Module*> Modules(OwnedModules.begin(), OwnedModules.end()); + for (std::vector<Module*>::iterator I = Modules.begin(), E = Modules.end(); + I != E; ++I) + delete *I; + std::for_each(ExprConstants.map_begin(), ExprConstants.map_end(), DropReferences()); std::for_each(ArrayConstants.map_begin(), ArrayConstants.map_end(), |