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.
ArrayConstants.freeConstants();
StructConstants.freeConstants();
VectorConstants.freeConstants();
- DeleteContainerSeconds(CAZConstants);
+ CAZConstants.clear();
DeleteContainerSeconds(CPNConstants);
DeleteContainerSeconds(UVConstants);
InlineAsms.freeConstants();
// 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;