This revision was automatically updated to reflect the committed changes. Closed by commit rG620cef91207b: [analyzer] MallocSizeof: sizeof pointer type is compatible with void* (authored by TH3CHARLie).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D103358/new/ 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<PointerType>()) return true; + // sizeof(pointer type) is compatible with void* + if (A->isVoidPointerType() && B->getAs<PointerType>()) + 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<PointerType>()) return true; + // sizeof(pointer type) is compatible with void* + if (A->isVoidPointerType() && B->getAs<PointerType>()) + 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