[PATCH] D159412: [analyzer]FieldRegion in getStaticSize should return size of pointee type
Qizhi Hu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 3 19:45:11 PDT 2023
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:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159412.555645.patch
Type: text/x-patch
Size: 679 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230904/f42df6d3/attachment.bin>
More information about the cfe-commits
mailing list