TH3CHARLie created this revision.
TH3CHARLie added a reviewer: NoQ.
Herald added subscribers: manas, steakhal, ASDenysPetrov, martong, dkrupp,
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware,
xazax.hun.
TH3CHARLie requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
source: https://bugs.llvm.org/show_bug.cgi?id=50214
Make sizeof pointer type is compatible with void* in MallocSizeofChecker.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D103358
Files:
clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp
clang/test/Analysis/malloc-sizeof.c
Index: clang/test/Analysis/malloc-sizeof.c
===
--- clang/test/Analysis/malloc-sizeof.c
+++ clang/test/Analysis/malloc-sizeof.c
@@ -26,6 +26,8 @@
struct A *ap5 = calloc(4, sizeof(struct B)); // expected-warning {{Result of
'calloc' is converted to a pointer of type 'struct A', which is incompatible
with sizeof operand type 'struct B'}}
struct A *ap6 = realloc(ap5, sizeof(struct A));
struct A *ap7 = realloc(ap5, sizeof(struct B)); // expected-warning {{Result
of 'realloc' is converted to a pointer of type 'struct A', which is
incompatible with sizeof operand type 'struct B'}}
+
+ void **vpp1 = (void **)malloc(sizeof(struct A*)); // no warning
}
// Don't warn when the types differ only by constness.
Index: clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp
@@ -139,6 +139,10 @@
if (B->isVoidPointerType() && A->getAs())
return true;
+ // sizeof(pointer type) is compatible with void*
+ if (A->isVoidPointerType() && B->getAs())
+return true;
+
while (true) {
A = A.getCanonicalType();
B = B.getCanonicalType();
Index: clang/test/Analysis/malloc-sizeof.c
===
--- clang/test/Analysis/malloc-sizeof.c
+++ clang/test/Analysis/malloc-sizeof.c
@@ -26,6 +26,8 @@
struct A *ap5 = calloc(4, sizeof(struct B)); // expected-warning {{Result of 'calloc' is converted to a pointer of type 'struct A', which is incompatible with sizeof operand type 'struct B'}}
struct A *ap6 = realloc(ap5, sizeof(struct A));
struct A *ap7 = realloc(ap5, sizeof(struct B)); // expected-warning {{Result of 'realloc' is converted to a pointer of type 'struct A', which is incompatible with sizeof operand type 'struct B'}}
+
+ void **vpp1 = (void **)malloc(sizeof(struct A*)); // no warning
}
// Don't warn when the types differ only by constness.
Index: clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp
@@ -139,6 +139,10 @@
if (B->isVoidPointerType() && A->getAs())
return true;
+ // sizeof(pointer type) is compatible with void*
+ if (A->isVoidPointerType() && B->getAs())
+return true;
+
while (true) {
A = A.getCanonicalType();
B = B.getCanonicalType();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits