From: Ted Kremenek Date: Mon, 12 Oct 2009 19:54:17 +0000 (+0000) Subject: Allow BumpVectorContext to conditionally own the underlying BumpPtrAllocator. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=87342dc37237c6efb9e311bacb12547de3ccbc0f;p=clang Allow BumpVectorContext to conditionally own the underlying BumpPtrAllocator. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83884 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/Support/BumpVector.h b/include/clang/Analysis/Support/BumpVector.h index 243332fec0..a5e11a1006 100644 --- a/include/clang/Analysis/Support/BumpVector.h +++ b/include/clang/Analysis/Support/BumpVector.h @@ -21,14 +21,29 @@ #include "llvm/Support/type_traits.h" #include "llvm/Support/Allocator.h" +#include "llvm/ADT/PointerIntPair.h" #include namespace clang { class BumpVectorContext { - llvm::BumpPtrAllocator Alloc; + llvm::PointerIntPair Alloc; public: - llvm::BumpPtrAllocator &getAllocator() { return Alloc; } + /// Construct a new BumpVectorContext that creates a new BumpPtrAllocator + /// and destroys it when the BumpVectorContext object is destroyed. + BumpVectorContext() : Alloc(new llvm::BumpPtrAllocator(), true) {} + + /// Construct a new BumpVectorContext that reuses an existing + /// BumpPtrAllocator. This BumpPtrAllocator is not destroyed when the + /// BumpVectorContext object is destroyed. + BumpVectorContext(llvm::BumpPtrAllocator &A) : Alloc(&A, false) {} + + ~BumpVectorContext() { + if (Alloc.getInt()) + delete Alloc.getPointer(); + } + + llvm::BumpPtrAllocator &getAllocator() { return *Alloc.getPointer(); } }; template