From bf3afab75ac34e7fce1476c5e98fddc1547e84e0 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Tue, 25 Nov 2014 02:13:54 +0000 Subject: [PATCH] unique_ptrify LLVMContextImpl::CAZConstants git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222714 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Constants.cpp | 8 ++++---- lib/IR/LLVMContextImpl.cpp | 2 +- lib/IR/LLVMContextImpl.h | 5 ++++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/IR/Constants.cpp b/lib/IR/Constants.cpp index e0cb835c2c6..bc51be6259b 100644 --- a/lib/IR/Constants.cpp +++ b/lib/IR/Constants.cpp @@ -1330,12 +1330,12 @@ bool ConstantFP::isValueValidForType(Type *Ty, const APFloat& Val) { ConstantAggregateZero *ConstantAggregateZero::get(Type *Ty) { assert((Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy()) && "Cannot create an aggregate zero of non-aggregate type!"); - - ConstantAggregateZero *&Entry = Ty->getContext().pImpl->CAZConstants[Ty]; + + auto &Entry = Ty->getContext().pImpl->CAZConstants[Ty]; if (!Entry) - Entry = new ConstantAggregateZero(Ty); + Entry.reset(new ConstantAggregateZero(Ty)); - return Entry; + return Entry.get(); } /// destroyConstant - Remove the constant from the constant table. diff --git a/lib/IR/LLVMContextImpl.cpp b/lib/IR/LLVMContextImpl.cpp index 3fd0bb37a4d..1335b3d33b8 100644 --- a/lib/IR/LLVMContextImpl.cpp +++ b/lib/IR/LLVMContextImpl.cpp @@ -87,7 +87,7 @@ LLVMContextImpl::~LLVMContextImpl() { ArrayConstants.freeConstants(); StructConstants.freeConstants(); VectorConstants.freeConstants(); - DeleteContainerSeconds(CAZConstants); + CAZConstants.clear(); DeleteContainerSeconds(CPNConstants); DeleteContainerSeconds(UVConstants); InlineAsms.freeConstants(); diff --git a/lib/IR/LLVMContextImpl.h b/lib/IR/LLVMContextImpl.h index 7a298cfecf3..65d6774e335 100644 --- a/lib/IR/LLVMContextImpl.h +++ b/lib/IR/LLVMContextImpl.h @@ -299,7 +299,10 @@ public: // on Context destruction. SmallPtrSet NonUniquedMDNodes; - DenseMap CAZConstants; + // Value is indirected through pointer to keep pointer validity over mutations + // of this map. Replace if/when we have an efficient map that guarantees + // pointer validity over mutations. + DenseMap> CAZConstants; typedef ConstantUniqueMap ArrayConstantsTy; ArrayConstantsTy ArrayConstants; -- 2.40.0