This revision was automatically updated to reflect the committed changes. Closed by commit rG20e81a80e9cb: Update with warning message for comparison to NULL pointer (authored by Krishna-13-cyber, committed by aaron.ballman).
Changed prior to commit: https://reviews.llvm.org/D149000?vs=531243&id=531279#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D149000/new/ https://reviews.llvm.org/D149000 Files: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaChecking.cpp clang/test/Sema/conditional-expr.c clang/test/Sema/warn-tautological-compare.c Index: clang/test/Sema/warn-tautological-compare.c =================================================================== --- clang/test/Sema/warn-tautological-compare.c +++ clang/test/Sema/warn-tautological-compare.c @@ -93,3 +93,8 @@ x = array ? 1 : 0; // expected-warning {{address of array}} x = &x ? 1 : 0; // expected-warning {{address of 'x'}} } + +void test4(void) { + int *a = (void *) 0; + int b = (&a) == ((void *) 0); // expected-warning {{comparison of address of 'a' equal to a null pointer is always false}} +} Index: clang/test/Sema/conditional-expr.c =================================================================== --- clang/test/Sema/conditional-expr.c +++ clang/test/Sema/conditional-expr.c @@ -86,7 +86,8 @@ int Postgresql(void) { char x; - return ((((&x) != ((void *) 0)) ? (*(&x) = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids conditional expressions with only one void side}} + return ((((&x) != ((void *) 0)) ? (*(&x) = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); /* expected-warning {{C99 forbids conditional expressions with only one void side}} + expected-warning {{comparison of address of 'x' not equal to a null pointer is always true}} */ } #define nil ((void*) 0) Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -14844,7 +14844,7 @@ bool IsAddressOf = false; - if (UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) { + if (auto *UO = dyn_cast<UnaryOperator>(E->IgnoreParens())) { if (UO->getOpcode() != UO_AddrOf) return; IsAddressOf = true; Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -340,6 +340,8 @@ can be controlled using ``-fcaret-diagnostics-max-lines=``. - Clang no longer emits ``-Wunused-variable`` warnings for variables declared with ``__attribute__((cleanup(...)))`` to match GCC's behavior. +- Clang now issues expected warnings for situations of comparing with NULL pointers. + (`#42992: <https://github.com/llvm/llvm-project/issues/42992>`_) Bug Fixes in This Version -------------------------
Index: clang/test/Sema/warn-tautological-compare.c =================================================================== --- clang/test/Sema/warn-tautological-compare.c +++ clang/test/Sema/warn-tautological-compare.c @@ -93,3 +93,8 @@ x = array ? 1 : 0; // expected-warning {{address of array}} x = &x ? 1 : 0; // expected-warning {{address of 'x'}} } + +void test4(void) { + int *a = (void *) 0; + int b = (&a) == ((void *) 0); // expected-warning {{comparison of address of 'a' equal to a null pointer is always false}} +} Index: clang/test/Sema/conditional-expr.c =================================================================== --- clang/test/Sema/conditional-expr.c +++ clang/test/Sema/conditional-expr.c @@ -86,7 +86,8 @@ int Postgresql(void) { char x; - return ((((&x) != ((void *) 0)) ? (*(&x) = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids conditional expressions with only one void side}} + return ((((&x) != ((void *) 0)) ? (*(&x) = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); /* expected-warning {{C99 forbids conditional expressions with only one void side}} + expected-warning {{comparison of address of 'x' not equal to a null pointer is always true}} */ } #define nil ((void*) 0) Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -14844,7 +14844,7 @@ bool IsAddressOf = false; - if (UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) { + if (auto *UO = dyn_cast<UnaryOperator>(E->IgnoreParens())) { if (UO->getOpcode() != UO_AddrOf) return; IsAddressOf = true; Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -340,6 +340,8 @@ can be controlled using ``-fcaret-diagnostics-max-lines=``. - Clang no longer emits ``-Wunused-variable`` warnings for variables declared with ``__attribute__((cleanup(...)))`` to match GCC's behavior. +- Clang now issues expected warnings for situations of comparing with NULL pointers. + (`#42992: <https://github.com/llvm/llvm-project/issues/42992>`_) Bug Fixes in This Version -------------------------
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits