[PATCH] D48407: ProvenanceAnalysis: Store WeakTrackingVH instead of Value* in UnderlyingValue Cache.

Michael Zolotukhin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 20 16:28:24 PDT 2018


mzolotukhin created this revision.
mzolotukhin added reviewers: ahatanak, pete.
Herald added a subscriber: hiraditya.

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 https://reviews.llvm.org/rL327328.


Repository:
  rL LLVM

https://reviews.llvm.org/D48407

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


Index: llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h
===================================================================
--- llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h
+++ llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h
@@ -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 @@
 
   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);
Index: llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h
===================================================================
--- llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h
+++ llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h
@@ -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 @@
 /// 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48407.152201.patch
Type: text/x-patch
Size: 1798 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180620/d1d3d545/attachment.bin>


More information about the llvm-commits mailing list