Skip to content

Commit

Permalink
Free all Constants in ~LLVMConstantImpl. We avoid assertion failures
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jyasskin committed Mar 22, 2010
1 parent d592e1a commit c1dc067
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/VMCore/ConstantsContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,8 @@ class ConstantUniqueMap : public AbstractTypeUser {
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;
}
}

Expand Down
29 changes: 25 additions & 4 deletions lib/VMCore/LLVMContextImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//

#include "LLVMContextImpl.h"
#include <algorithm>

LLVMContextImpl::LLVMContextImpl(LLVMContext &C)
: TheTrueVal(0), TheFalseVal(0),
Expand All @@ -34,24 +35,44 @@ 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();
UndefValueConstants.freeConstants();
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();
Expand Down
4 changes: 4 additions & 0 deletions tools/bugpoint/BugDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ BugDriver::BugDriver(const char *toolname, bool as_child, bool find_bugs,
run_as_child(as_child), run_find_bugs(find_bugs), Timeout(timeout),
MemoryLimit(memlimit), UseValgrind(use_valgrind) {}

BugDriver::~BugDriver() {
delete Program;
}


/// ParseInputFile - Given a bitcode or assembly input filename, parse and
/// return it, or return null if not possible.
Expand Down
1 change: 1 addition & 0 deletions tools/bugpoint/BugDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class BugDriver {
BugDriver(const char *toolname, bool as_child, bool find_bugs,
unsigned timeout, unsigned memlimit, bool use_valgrind,
LLVMContext& ctxt);
~BugDriver();

const char *getToolName() const { return ToolName; }

Expand Down

0 comments on commit c1dc067

Please sign in to comment.