unique_ptrify LLVMContextImpl::CAZConstants
authorDavid Blaikie <dblaikie@gmail.com>
Tue, 25 Nov 2014 02:13:54 +0000 (02:13 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Tue, 25 Nov 2014 02:13:54 +0000 (02:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222714 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/Constants.cpp
lib/IR/LLVMContextImpl.cpp
lib/IR/LLVMContextImpl.h

index e0cb835c2c675eb5940501102946dad066dd4627..bc51be6259b42ab1431482df45d4179adddb8b55 100644 (file)
@@ -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.
index 3fd0bb37a4d48f71218f3635e8488ef84722a654..1335b3d33b8a7c9478c5ae6062b17452b496f4be 100644 (file)
@@ -87,7 +87,7 @@ LLVMContextImpl::~LLVMContextImpl() {
   ArrayConstants.freeConstants();
   StructConstants.freeConstants();
   VectorConstants.freeConstants();
-  DeleteContainerSeconds(CAZConstants);
+  CAZConstants.clear();
   DeleteContainerSeconds(CPNConstants);
   DeleteContainerSeconds(UVConstants);
   InlineAsms.freeConstants();
index 7a298cfecf31cf27e19253bf755adcf4805cf3bb..65d6774e3357c30acb4ba9890f777450b4169980 100644 (file)
@@ -299,7 +299,10 @@ public:
   // on Context destruction.
   SmallPtrSet<GenericMDNode *, 1> NonUniquedMDNodes;
 
-  DenseMap<Type*, ConstantAggregateZero*> 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<Type*, std::unique_ptr<ConstantAggregateZero>> CAZConstants;
 
   typedef ConstantUniqueMap<ConstantArray> ArrayConstantsTy;
   ArrayConstantsTy ArrayConstants;