diff options
author | Jeffrey Yasskin <jyasskin@google.com> | 2010-03-22 05:23:37 +0000 |
---|---|---|
committer | Jeffrey Yasskin <jyasskin@google.com> | 2010-03-22 05:23:37 +0000 |
commit | c1dc0679706f7538cd17169b920967c54661e5b6 (patch) | |
tree | 815521d8e780e580649eadf2a1d71bdaeac048e8 /lib/VMCore/LLVMContextImpl.cpp | |
parent | d592e1a809c0322cac26ddc630a00e46639eaf32 (diff) | |
download | llvm-c1dc0679706f7538cd17169b920967c54661e5b6.tar.gz llvm-c1dc0679706f7538cd17169b920967c54661e5b6.tar.bz2 llvm-c1dc0679706f7538cd17169b920967c54661e5b6.tar.xz |
Free all Constants in ~LLVMConstantImpl. We avoid assertion failures
by dropping all references from all constants that can use other
constants before trying to destroy any of them.
I also had to free bugpoint's Module in ~BugDriver().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99160 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/LLVMContextImpl.cpp')
-rw-r--r-- | lib/VMCore/LLVMContextImpl.cpp | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/lib/VMCore/LLVMContextImpl.cpp b/lib/VMCore/LLVMContextImpl.cpp index 176ccf18e4..b4553ddc1b 100644 --- a/lib/VMCore/LLVMContextImpl.cpp +++ b/lib/VMCore/LLVMContextImpl.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "LLVMContextImpl.h" +#include <algorithm> LLVMContextImpl::LLVMContextImpl(LLVMContext &C) : TheTrueVal(0), TheFalseVal(0), @@ -34,10 +35,32 @@ LLVMContextImpl::LLVMContextImpl(LLVMContext &C) OpaqueTypes.insert(AlwaysOpaqueTy); } +namespace { +struct DropReferences { + // Takes the value_type of a ConstantUniqueMap's internal map, whose 'second' + // is a Constant*. + template<typename PairT> + void operator()(const PairT &P) { + P.second->dropAllReferences(); + } +}; +} + LLVMContextImpl::~LLVMContextImpl() { + std::for_each(ExprConstants.map_begin(), ExprConstants.map_end(), + DropReferences()); + std::for_each(ArrayConstants.map_begin(), ArrayConstants.map_end(), + DropReferences()); + std::for_each(StructConstants.map_begin(), StructConstants.map_end(), + DropReferences()); + std::for_each(UnionConstants.map_begin(), UnionConstants.map_end(), + DropReferences()); + std::for_each(VectorConstants.map_begin(), VectorConstants.map_end(), + DropReferences()); ExprConstants.freeConstants(); ArrayConstants.freeConstants(); StructConstants.freeConstants(); + UnionConstants.freeConstants(); VectorConstants.freeConstants(); AggZeroConstants.freeConstants(); NullPtrConstants.freeConstants(); @@ -45,13 +68,11 @@ LLVMContextImpl::~LLVMContextImpl() { InlineAsms.freeConstants(); for (IntMapTy::iterator I = IntConstants.begin(), E = IntConstants.end(); I != E; ++I) { - if (I->second->use_empty()) - delete I->second; + delete I->second; } for (FPMapTy::iterator I = FPConstants.begin(), E = FPConstants.end(); I != E; ++I) { - if (I->second->use_empty()) - delete I->second; + delete I->second; } AlwaysOpaqueTy->dropRef(); for (OpaqueTypesTy::iterator I = OpaqueTypes.begin(), E = OpaqueTypes.end(); |