[PATCH] D149000: Update with warning message for comparison to NULL pointer

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 26 11:34:19 PDT 2023


aaron.ballman added a comment.

Precommit CI is still failing on test/SemaCXX/constant-expression-cxx2a.cpp with a false positive warning. You'll need to investigate why that's happening, but I suspect that the warning logic isn't aware that `dynamic_cast` can return null.



================
Comment at: clang/lib/Sema/SemaChecking.cpp:14726
 
-  if (UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) {
+  if (UnaryOperator *UO = dyn_cast<UnaryOperator>(E->IgnoreParenCasts())) {
     if (UO->getOpcode() != UO_AddrOf)
----------------



================
Comment at: clang/test/Sema/warn-tautological-compare.c:97-100
+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}}
----------------



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149000/new/

https://reviews.llvm.org/D149000



More information about the cfe-commits mailing list