summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorok Edwin <edwintorok@gmail.com>2009-04-07 17:23:02 +0000
committerTorok Edwin <edwintorok@gmail.com>2009-04-07 17:23:02 +0000
commiteb55f3ea3c6a12e5d098f72f3f9a16d4b7e77645 (patch)
treeb793da35332f1226c35e906bebdd064a19c92915
parentce8f9fe3c9ea50127eab28930506fc3b93390553 (diff)
downloadllvm-eb55f3ea3c6a12e5d098f72f3f9a16d4b7e77645.tar.gz
llvm-eb55f3ea3c6a12e5d098f72f3f9a16d4b7e77645.tar.bz2
llvm-eb55f3ea3c6a12e5d098f72f3f9a16d4b7e77645.tar.xz
Another attempt at fixing PR2975.
Types can have references to eachother, so we can't just call destroy on them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68523 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--examples/HowToUseJIT/HowToUseJIT.cpp4
-rw-r--r--include/llvm/AbstractTypeUser.h4
-rw-r--r--lib/VMCore/Type.cpp25
3 files changed, 32 insertions, 1 deletions
diff --git a/examples/HowToUseJIT/HowToUseJIT.cpp b/examples/HowToUseJIT/HowToUseJIT.cpp
index 0482df6248..b5c6d11191 100644
--- a/examples/HowToUseJIT/HowToUseJIT.cpp
+++ b/examples/HowToUseJIT/HowToUseJIT.cpp
@@ -42,6 +42,7 @@
#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/ExecutionEngine/Interpreter.h"
#include "llvm/ExecutionEngine/GenericValue.h"
+#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
@@ -109,5 +110,8 @@ int main() {
// Import result of execution:
outs() << "Result: " << gv.IntVal << "\n";
+ EE->freeMachineCodeForFunction(FooF);
+ delete EE;
+ llvm_shutdown();
return 0;
}
diff --git a/include/llvm/AbstractTypeUser.h b/include/llvm/AbstractTypeUser.h
index 80656d89b7..c1216baabf 100644
--- a/include/llvm/AbstractTypeUser.h
+++ b/include/llvm/AbstractTypeUser.h
@@ -137,6 +137,7 @@ public:
///
class PATypeHolder {
mutable const Type *Ty;
+ void destroy();
public:
PATypeHolder(const Type *ty) : Ty(ty) {
addRef();
@@ -145,7 +146,7 @@ public:
addRef();
}
- ~PATypeHolder() { dropRef(); }
+ ~PATypeHolder() { if (Ty) dropRef(); }
operator Type *() const { return get(); }
Type *get() const;
@@ -173,6 +174,7 @@ public:
private:
void addRef();
void dropRef();
+ friend class TypeMapBase;
};
// simplify_type - Allow clients to treat uses just like values when using
diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp
index c14d5119e5..9f93d17d9f 100644
--- a/lib/VMCore/Type.cpp
+++ b/lib/VMCore/Type.cpp
@@ -388,6 +388,10 @@ OpaqueType::OpaqueType() : DerivedType(OpaqueTyID) {
#endif
}
+void PATypeHolder::destroy() {
+ Ty = 0;
+}
+
// dropAllTypeUses - When this (abstract) type is resolved to be equal to
// another (more concrete) type, we must eliminate all references to other
// types, to avoid some circular reference problems.
@@ -666,6 +670,27 @@ protected:
std::multimap<unsigned, PATypeHolder> TypesByHash;
public:
+ ~TypeMapBase()
+ {
+ //PATypeHolder won't destroy non-abstract types.
+ //We can't destroy them by simply iterating, because
+ //they may contain references to each-other
+
+ for (std::multimap<unsigned, PATypeHolder>::iterator I
+ = TypesByHash.begin(), E = TypesByHash.end(); I != E; ++I) {
+ Type *Ty = const_cast<Type*>(I->second.Ty);
+ I->second.destroy();
+ // We can't invoke destroy or delete, because the type may
+ // contain references to already freed types.
+ // So we have to destruct the object the ugly way.
+ if (Ty) {
+ Ty->AbstractTypeUsers.clear();
+ static_cast<const Type*>(Ty)->Type::~Type();
+ operator delete(Ty);
+ }
+ }
+ }
+
void RemoveFromTypesByHash(unsigned Hash, const Type *Ty) {
std::multimap<unsigned, PATypeHolder>::iterator I =
TypesByHash.lower_bound(Hash);