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 | a6eedc3c032e9dd7754b109ebc09b9626d8e86ef (patch) | |
tree | 4e12a84b1a2fa11406d3f67c8884647983d532fb /llvm/lib/VMCore | |
parent | 84559243036b1f7a1ae10b223c613edef15b3921 (diff) | |
download | bcm5719-llvm-a6eedc3c032e9dd7754b109ebc09b9626d8e86ef.tar.gz bcm5719-llvm-a6eedc3c032e9dd7754b109ebc09b9626d8e86ef.zip |
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().
llvm-svn: 99160
Diffstat (limited to 'llvm/lib/VMCore')
-rw-r--r-- | llvm/lib/VMCore/ConstantsContext.h | 4 | ||||
-rw-r--r-- | llvm/lib/VMCore/LLVMContextImpl.cpp | 29 |
2 files changed, 27 insertions, 6 deletions
diff --git a/llvm/lib/VMCore/ConstantsContext.h b/llvm/lib/VMCore/ConstantsContext.h index 560e6c4974f..2f2fac53f06 100644 --- a/llvm/lib/VMCore/ConstantsContext.h +++ b/llvm/lib/VMCore/ConstantsContext.h @@ -600,8 +600,8 @@ public: void freeConstants() { for (typename MapTy::iterator I=Map.begin(), E=Map.end(); I != E; ++I) { - if (I->second->use_empty()) - delete I->second; + // Asserts that use_empty(). + delete I->second; } } diff --git a/llvm/lib/VMCore/LLVMContextImpl.cpp b/llvm/lib/VMCore/LLVMContextImpl.cpp index 176ccf18e4e..b4553ddc1b9 100644 --- a/llvm/lib/VMCore/LLVMContextImpl.cpp +++ b/llvm/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(); |