diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp +++ b/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(); diff --git a/clang/test/Analysis/malloc-sizeof.c b/clang/test/Analysis/malloc-sizeof.c --- a/clang/test/Analysis/malloc-sizeof.c +++ b/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.