[PATCH] D149000: Update with warning message for comparison to NULL pointer
Krishna Narayanan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 14 02:46:52 PDT 2023
Krishna-13-cyber updated this revision to Diff 531243.
Krishna-13-cyber removed a reviewer: Quuxplusone.
Krishna-13-cyber added a comment.
- Update with the given suggestion
- Add release notes
Thanks a lot @aaron.ballman for the instant assistance.
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,9 @@
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
-------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149000.531243.patch
Type: text/x-patch
Size: 2451 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230614/8ba79eeb/attachment-0001.bin>
More information about the cfe-commits
mailing list