Skip to content

Commit 62a4708

Browse files
authored
Merge pull request #3516 from apple/PR-83984790
[ObjC][ARC] Invalidate an entry of UnderlyingObjCPtrCache when the instruction the key points to is deleted
2 parents 3a71538 + 4de0748 commit 62a4708

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,17 @@ inline const Value *GetUnderlyingObjCPtr(const Value *V) {
7878
}
7979

8080
/// A wrapper for GetUnderlyingObjCPtr used for results memoization.
81-
inline const Value *
82-
GetUnderlyingObjCPtrCached(const Value *V,
83-
DenseMap<const Value *, WeakTrackingVH> &Cache) {
84-
if (auto InCache = Cache.lookup(V))
85-
return InCache;
81+
inline const Value *GetUnderlyingObjCPtrCached(
82+
const Value *V,
83+
DenseMap<const Value *, std::pair<WeakVH, WeakTrackingVH>> &Cache) {
84+
// The entry is invalid if either value handle is null.
85+
auto InCache = Cache.lookup(V);
86+
if (InCache.first && InCache.second)
87+
return InCache.second;
8688

8789
const Value *Computed = GetUnderlyingObjCPtr(V);
88-
Cache[V] = const_cast<Value *>(Computed);
90+
Cache[V] =
91+
std::make_pair(const_cast<Value *>(V), const_cast<Value *>(Computed));
8992
return Computed;
9093
}
9194

llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class ProvenanceAnalysis {
5656

5757
CachedResultsTy CachedResults;
5858

59-
DenseMap<const Value *, WeakTrackingVH> UnderlyingObjCPtrCache;
59+
DenseMap<const Value *, std::pair<WeakVH, WeakTrackingVH>>
60+
UnderlyingObjCPtrCache;
6061

6162
bool relatedCheck(const Value *A, const Value *B);
6263
bool relatedSelect(const SelectInst *A, const Value *B);

0 commit comments

Comments
 (0)