diff options
| author | Jeffrey Yasskin <jyasskin@google.com> | 2009-12-17 19:55:06 +0000 |
|---|---|---|
| committer | Jeffrey Yasskin <jyasskin@google.com> | 2009-12-17 19:55:06 +0000 |
| commit | 28f244863eae2e1a6be0c837f97e494c0bea66b3 (patch) | |
| tree | cd5eeb04124647093ab2bceea2af5683fbf36674 /llvm/lib | |
| parent | da7d55a4a880f858e3d9e80bb4deb3d870f27756 (diff) | |
| download | bcm5719-llvm-28f244863eae2e1a6be0c837f97e494c0bea66b3.tar.gz bcm5719-llvm-28f244863eae2e1a6be0c837f97e494c0bea66b3.zip | |
This fixes a memory leak in OpaqueType found by Google's internal heapchecker.
llvm-svn: 91611
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/VMCore/LLVMContextImpl.h | 11 | ||||
| -rw-r--r-- | llvm/lib/VMCore/Type.cpp | 17 |
2 files changed, 28 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/LLVMContextImpl.h b/llvm/lib/VMCore/LLVMContextImpl.h index 8a2378ec7c9..2ea2d5e910e 100644 --- a/llvm/lib/VMCore/LLVMContextImpl.h +++ b/llvm/lib/VMCore/LLVMContextImpl.h @@ -27,6 +27,7 @@ #include "llvm/ADT/APInt.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/FoldingSet.h" +#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/StringMap.h" #include <vector> @@ -159,6 +160,11 @@ public: TypeMap<StructValType, StructType> StructTypes; TypeMap<IntegerValType, IntegerType> IntegerTypes; + // Opaque types are not structurally uniqued, so don't use TypeMap. + typedef SmallPtrSet<const OpaqueType*, 8> OpaqueTypesTy; + OpaqueTypesTy OpaqueTypes; + + /// ValueHandles - This map keeps track of all of the value handles that are /// watching a Value*. The Value::HasValueHandle bit is used to know // whether or not a value has an entry in this map. @@ -201,6 +207,11 @@ public: delete I->second; } MDNodeSet.clear(); + for (OpaqueTypesTy::iterator I = OpaqueTypes.begin(), E = OpaqueTypes.end(); + I != E; ++I) { + (*I)->AbstractTypeUsers.clear(); + delete *I; + } } }; diff --git a/llvm/lib/VMCore/Type.cpp b/llvm/lib/VMCore/Type.cpp index 739c463d91b..310d0e3a29a 100644 --- a/llvm/lib/VMCore/Type.cpp +++ b/llvm/lib/VMCore/Type.cpp @@ -79,6 +79,9 @@ void Type::destroy() const { operator delete(const_cast<Type *>(this)); return; + } else if (const OpaqueType *opaque_this = dyn_cast<OpaqueType>(this)) { + LLVMContextImpl *pImpl = this->getContext().pImpl; + pImpl->OpaqueTypes.erase(opaque_this); } // For all the other type subclasses, there is either no contained types or @@ -955,6 +958,20 @@ bool PointerType::isValidElementType(const Type *ElemTy) { //===----------------------------------------------------------------------===// +// Opaque Type Factory... +// + +OpaqueType *OpaqueType::get(LLVMContext &C) { + OpaqueType *OT = new OpaqueType(C); // All opaque types are distinct + + LLVMContextImpl *pImpl = C.pImpl; + pImpl->OpaqueTypes.insert(OT); + return OT; +} + + + +//===----------------------------------------------------------------------===// // Derived Type Refinement Functions //===----------------------------------------------------------------------===// |

