llvm.org GIT mirror llvm / eb55f3e
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 Torok Edwin 11 years ago
3 changed file(s) with 32 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
4141 #include "llvm/ExecutionEngine/JIT.h"
4242 #include "llvm/ExecutionEngine/Interpreter.h"
4343 #include "llvm/ExecutionEngine/GenericValue.h"
44 #include "llvm/Support/ManagedStatic.h"
4445 #include "llvm/Support/raw_ostream.h"
4546 using namespace llvm;
4647
108109
109110 // Import result of execution:
110111 outs() << "Result: " << gv.IntVal << "\n";
112 EE->freeMachineCodeForFunction(FooF);
113 delete EE;
114 llvm_shutdown();
111115 return 0;
112116 }
136136 ///
137137 class PATypeHolder {
138138 mutable const Type *Ty;
139 void destroy();
139140 public:
140141 PATypeHolder(const Type *ty) : Ty(ty) {
141142 addRef();
144145 addRef();
145146 }
146147
147 ~PATypeHolder() { dropRef(); }
148 ~PATypeHolder() { if (Ty) dropRef(); }
148149
149150 operator Type *() const { return get(); }
150151 Type *get() const;
172173 private:
173174 void addRef();
174175 void dropRef();
176 friend class TypeMapBase;
175177 };
176178
177179 // simplify_type - Allow clients to treat uses just like values when using
385385 #ifdef DEBUG_MERGE_TYPES
386386 DOUT << "Derived new type: " << *this << "\n";
387387 #endif
388 }
389
390 void PATypeHolder::destroy() {
391 Ty = 0;
388392 }
389393
390394 // dropAllTypeUses - When this (abstract) type is resolved to be equal to
665669 std::multimap TypesByHash;
666670
667671 public:
672 ~TypeMapBase()
673 {
674 //PATypeHolder won't destroy non-abstract types.
675 //We can't destroy them by simply iterating, because
676 //they may contain references to each-other
677
678 for (std::multimap::iterator I
679 = TypesByHash.begin(), E = TypesByHash.end(); I != E; ++I) {
680 Type *Ty = const_cast(I->second.Ty);
681 I->second.destroy();
682 // We can't invoke destroy or delete, because the type may
683 // contain references to already freed types.
684 // So we have to destruct the object the ugly way.
685 if (Ty) {
686 Ty->AbstractTypeUsers.clear();
687 static_cast(Ty)->Type::~Type();
688 operator delete(Ty);
689 }
690 }
691 }
692
668693 void RemoveFromTypesByHash(unsigned Hash, const Type *Ty) {
669694 std::multimap::iterator I =
670695 TypesByHash.lower_bound(Hash);