[PATCH] D131707: [analyzer][NFC] Cache the result of getLocationType in TypedValueRegion

Denys Petrov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 15 08:45:02 PDT 2022


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 {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131707.452689.patch
Type: text/x-patch
Size: 1389 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220815/94f70785/attachment.bin>


More information about the cfe-commits mailing list