Skip to content

Commit f2c7c3c

Browse files
committed
[ObjC][ARC] Invalidate an entry of UnderlyingObjCPtrCache when the
instruction the key points to is deleted Use weak value handles for both the key and the value. The entry is invalid if either value handle is null. This fixes an assertion failure in BasicAAResult::alias that is caused by UnderlyingObjCPtrCache returning a wrong value. I don't have a test case for this patch that fails reliably. rdar://83984790
1 parent 4438201 commit f2c7c3c

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)