[llvm] r335201 - ProvenanceAnalysis: Store WeakTrackingVH instead of Value* in UnderlyingValue Cache.

Michael Zolotukhin via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 20 22:14:00 PDT 2018


Author: mzolotukhin
Date: Wed Jun 20 22:14:00 2018
New Revision: 335201

URL: http://llvm.org/viewvc/llvm-project?rev=335201&view=rev
Log:
ProvenanceAnalysis: Store WeakTrackingVH instead of Value* in UnderlyingValue Cache.

Summary:
Since the value stored in the cache might be deleted or replaced with
something else, we need to use tracking ValueHandlers instead of plain
Value pointers. It was discovered in one of internal builds, and
unfortunately there is no small reproducer for the issue.

The cache was introduced in rL327328.

Reviewers: ahatanak, pete

Subscribers: hiraditya, llvm-commits

Differential Revision: https://reviews.llvm.org/D48407

Modified:
    llvm/trunk/include/llvm/Analysis/ObjCARCAnalysisUtils.h
    llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.h

Modified: llvm/trunk/include/llvm/Analysis/ObjCARCAnalysisUtils.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ObjCARCAnalysisUtils.h?rev=335201&r1=335200&r2=335201&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ObjCARCAnalysisUtils.h (original)
+++ llvm/trunk/include/llvm/Analysis/ObjCARCAnalysisUtils.h Wed Jun 20 22:14:00 2018
@@ -34,6 +34,7 @@
 #include "llvm/IR/InstIterator.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/ValueHandle.h"
 #include "llvm/Pass.h"
 
 namespace llvm {
@@ -89,11 +90,13 @@ inline const Value *GetUnderlyingObjCPtr
 /// A wrapper for GetUnderlyingObjCPtr used for results memoization.
 inline const Value *
 GetUnderlyingObjCPtrCached(const Value *V, const DataLayout &DL,
-                           DenseMap<const Value *, const Value *> &Cache) {
+                           DenseMap<const Value *, WeakTrackingVH> &Cache) {
   if (auto InCache = Cache.lookup(V))
     return InCache;
 
-  return Cache[V] = GetUnderlyingObjCPtr(V, DL);
+  const Value *Computed = GetUnderlyingObjCPtr(V, DL);
+  Cache[V] = const_cast<Value *>(Computed);
+  return Computed;
 }
 
 /// The RCIdentity root of a value \p V is a dominating value U for which

Modified: llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.h?rev=335201&r1=335200&r2=335201&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.h (original)
+++ llvm/trunk/lib/Transforms/ObjCARC/ProvenanceAnalysis.h Wed Jun 20 22:14:00 2018
@@ -28,6 +28,7 @@
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/Analysis/AliasAnalysis.h"
+#include "llvm/IR/ValueHandle.h"
 #include <utility>
 
 namespace llvm {
@@ -56,7 +57,7 @@ class ProvenanceAnalysis {
 
   CachedResultsTy CachedResults;
 
-  DenseMap<const Value *, const Value *> UnderlyingObjCPtrCache;
+  DenseMap<const Value *, WeakTrackingVH> UnderlyingObjCPtrCache;
 
   bool relatedCheck(const Value *A, const Value *B, const DataLayout &DL);
   bool relatedSelect(const SelectInst *A, const Value *B);




More information about the llvm-commits mailing list