[PATCH] D38718: [Sema] No -Wtautological-pointer-compare warning on variables within parentheses
Erik Viktorsson via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 10 04:29:30 PDT 2017
erikv updated this revision to Diff 118347.
erikv added a comment.
Added new test
Repository:
rL LLVM
https://reviews.llvm.org/D38718
Files:
lib/Sema/SemaChecking.cpp
test/Sema/conditional-expr.c
test/Sema/warn-tautological-compare.c
Index: test/Sema/conditional-expr.c
===================================================================
--- test/Sema/conditional-expr.c
+++ test/Sema/conditional-expr.c
@@ -79,9 +79,9 @@
(test0 ? (test0 ? adr2 : adr2) : nonconst_int); // expected-warning {{pointer type mismatch}} expected-warning {{expression result unused}}
}
-int Postgresql() {
- 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}}
+int Postgresql(char *x) {
+ //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}}
}
#define nil ((void*) 0)
Index: lib/Sema/SemaChecking.cpp
===================================================================
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -9933,7 +9933,7 @@
IsInAnyMacroBody(SM, Range.getBegin()))
return;
}
- E = E->IgnoreImpCasts();
+ E = E->IgnoreParenImpCasts();
const bool IsCompare = NullKind != Expr::NPCK_NotNull;
Index: test/Sema/warn-tautological-compare.c
===================================================================
--- test/Sema/warn-tautological-compare.c
+++ test/Sema/warn-tautological-compare.c
@@ -93,3 +93,11 @@
x = array ? 1 : 0; // expected-warning {{address of array}}
x = &x ? 1 : 0; // expected-warning {{address of 'x'}}
}
+
+void test_parentesens(short arg) {
+ if (0 ==
+ (&arg)) { // expected-warning {{comparison of address of 'arg' equal to a null pointer is always false}}
+ } else if (0 ==
+ &arg) { // expected-warning {{comparison of address of 'arg' equal to a null pointer is always false}}
+ }
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38718.118347.patch
Type: text/x-patch
Size: 1842 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171010/8e70281e/attachment.bin>
More information about the cfe-commits
mailing list