ASDenysPetrov updated this revision to Diff 452689.
ASDenysPetrov added a comment.

Add assertion accroding to the remark.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131707/new/

https://reviews.llvm.org/D131707

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h


Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
===================================================================
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
@@ -529,6 +529,8 @@
 
 /// TypedValueRegion - An abstract class representing regions having a typed 
value.
 class TypedValueRegion : public TypedRegion {
+  mutable QualType CachedLocationType;
+
   void anchor() override;
 
 protected:
@@ -540,12 +542,15 @@
   virtual QualType getValueType() const = 0;
 
   QualType getLocationType() const override {
-    // FIXME: We can possibly optimize this later to cache this value.
-    QualType T = getValueType();
-    ASTContext &ctx = getContext();
-    if (T->getAs<ObjCObjectType>())
-      return ctx.getObjCObjectPointerType(T);
-    return ctx.getPointerType(getValueType());
+    if (CachedLocationType.isNull()) {
+      QualType T = getValueType();
+      ASTContext &C = getContext();
+      CachedLocationType = T->isObjCObjectType() ? 
C.getObjCObjectPointerType(T)
+                                                 : C.getPointerType(T);
+      assert(!CachedLocationType.isNull() &&
+             "Cached value supposed to be non-null.");
+    }
+    return CachedLocationType;
   }
 
   QualType getDesugaredValueType(ASTContext &Context) const {


Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
===================================================================
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
@@ -529,6 +529,8 @@
 
 /// TypedValueRegion - An abstract class representing regions having a typed value.
 class TypedValueRegion : public TypedRegion {
+  mutable QualType CachedLocationType;
+
   void anchor() override;
 
 protected:
@@ -540,12 +542,15 @@
   virtual QualType getValueType() const = 0;
 
   QualType getLocationType() const override {
-    // FIXME: We can possibly optimize this later to cache this value.
-    QualType T = getValueType();
-    ASTContext &ctx = getContext();
-    if (T->getAs<ObjCObjectType>())
-      return ctx.getObjCObjectPointerType(T);
-    return ctx.getPointerType(getValueType());
+    if (CachedLocationType.isNull()) {
+      QualType T = getValueType();
+      ASTContext &C = getContext();
+      CachedLocationType = T->isObjCObjectType() ? C.getObjCObjectPointerType(T)
+                                                 : C.getPointerType(T);
+      assert(!CachedLocationType.isNull() &&
+             "Cached value supposed to be non-null.");
+    }
+    return CachedLocationType;
   }
 
   QualType getDesugaredValueType(ASTContext &Context) const {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to