jcsxky created this revision.
jcsxky added reviewers: steakhal, balazske, aaron.ballman, NoQ.
jcsxky added projects: clang, clang-c.
Herald added subscribers: manas, ASDenysPetrov, martong, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: All.
jcsxky requested review of this revision.
Herald added a subscriber: cfe-commits.

In `getStaticSize`, case of FieldRegionKind should return size of pointee type 
of the member. In the following example:

  struct B {
        int x;
        int y;
        int z;
  };
  
  class A{
  public:
        void foo(){
                m++;
        }
  private:
        B *m;
  };

`getDynamicElementCount` of `m` region, if `getDynamicExtent` return the 
pointer size, `getDynamicElementCount` returns 0 in 64bit architecture(since 
pointer size is 8 while size of pointee type is 12). Use pointee type instead, 
it will return 1.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159412

Files:
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp


Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -800,6 +800,12 @@
       return UnknownVal();
 
     QualType Ty = cast<TypedValueRegion>(SR)->getDesugaredValueType(Ctx);
+    if (Ty->isPointerType()) {
+      QualType PointeeTy = Ty->getPointeeType();
+      if(!PointeeTy->isIncompleteType() && PointeeTy->isObjectType()){
+        Ty = PointeeTy;
+      }
+    }
     const DefinedOrUnknownSVal Size = getElementExtent(Ty, SVB);
 
     // We currently don't model flexible array members (FAMs), which are:


Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -800,6 +800,12 @@
       return UnknownVal();
 
     QualType Ty = cast<TypedValueRegion>(SR)->getDesugaredValueType(Ctx);
+    if (Ty->isPointerType()) {
+      QualType PointeeTy = Ty->getPointeeType();
+      if(!PointeeTy->isIncompleteType() && PointeeTy->isObjectType()){
+        Ty = PointeeTy;
+      }
+    }
     const DefinedOrUnknownSVal Size = getElementExtent(Ty, SVB);
 
     // We currently don't model flexible array members (FAMs), which are:
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to