[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
This commit is contained in:
Akira Hatanaka 2021-11-08 14:39:16 -08:00
parent 443820179a
commit f2c7c3c7c7
2 changed files with 11 additions and 7 deletions

View File

@ -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<const Value *, WeakTrackingVH> &Cache) {
if (auto InCache = Cache.lookup(V))
return InCache;
inline const Value *GetUnderlyingObjCPtrCached(
const Value *V,
DenseMap<const Value *, std::pair<WeakVH, WeakTrackingVH>> &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<Value *>(Computed);
Cache[V] =
std::make_pair(const_cast<Value *>(V), const_cast<Value *>(Computed));
return Computed;
}

View File

@ -56,7 +56,8 @@ class ProvenanceAnalysis {
CachedResultsTy CachedResults;
DenseMap<const Value *, WeakTrackingVH> UnderlyingObjCPtrCache;
DenseMap<const Value *, std::pair<WeakVH, WeakTrackingVH>>
UnderlyingObjCPtrCache;
bool relatedCheck(const Value *A, const Value *B);
bool relatedSelect(const SelectInst *A, const Value *B);