summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Zolotukhin <mzolotukhin@apple.com>2018-06-21 05:14:00 +0000
committerMichael Zolotukhin <mzolotukhin@apple.com>2018-06-21 05:14:00 +0000
commit336d75cc73ee268d9b4d08b585a5532c3eb54f73 (patch)
tree3538f5d78ad5e4aaadcadba01b90530c162e25b2
parent2da60bc231859b846d3cbcb0681c2cb6510f8187 (diff)
downloadbcm5719-llvm-336d75cc73ee268d9b4d08b585a5532c3eb54f73.tar.gz
bcm5719-llvm-336d75cc73ee268d9b4d08b585a5532c3eb54f73.zip
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 llvm-svn: 335201
-rw-r--r--llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h7
-rw-r--r--llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h3
2 files changed, 7 insertions, 3 deletions
diff --git a/llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h b/llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h
index 4179544f7cf..07beb0bb60a 100644
--- a/llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h
+++ b/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 @@ inline const Value *GetUnderlyingObjCPtr(const Value *V,
/// 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
diff --git a/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h b/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h
index 8a2e16e65fb..1276f564a02 100644
--- a/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h
+++ b/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 @@ 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);
OpenPOWER on IntegriCloud