diff --git a/llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h b/llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h index 62bdade95d960..547397d1ed480 100644 --- a/llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h +++ b/llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h @@ -78,14 +78,17 @@ inline const Value *GetUnderlyingObjCPtr(const Value *V) { } /// A wrapper for GetUnderlyingObjCPtr used for results memoization. -inline const Value * -GetUnderlyingObjCPtrCached(const Value *V, - DenseMap &Cache) { - if (auto InCache = Cache.lookup(V)) - return InCache; +inline const Value *GetUnderlyingObjCPtrCached( + const Value *V, + DenseMap> &Cache) { + // The entry is invalid if either value handle is null. + auto InCache = Cache.lookup(V); + if (InCache.first && InCache.second) + return InCache.second; const Value *Computed = GetUnderlyingObjCPtr(V); - Cache[V] = const_cast(Computed); + Cache[V] = + std::make_pair(const_cast(V), const_cast(Computed)); return Computed; } diff --git a/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h b/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h index a63e356ce1fc1..6d0a67c91cfaf 100644 --- a/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h +++ b/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h @@ -56,7 +56,8 @@ class ProvenanceAnalysis { CachedResultsTy CachedResults; - DenseMap UnderlyingObjCPtrCache; + DenseMap> + UnderlyingObjCPtrCache; bool relatedCheck(const Value *A, const Value *B); bool relatedSelect(const SelectInst *A, const Value *B);