re PR c/69768 (Bogus -Waddress warning)
authorJakub Jelinek <jakub@redhat.com>
Thu, 11 Feb 2016 22:55:02 +0000 (23:55 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 11 Feb 2016 22:55:02 +0000 (23:55 +0100)
PR c/69768
* c-typeck.c (parser_build_binary_op): Strip nops from integer_zerop
arguments for -Waddress warning.

* typeck.c (cp_build_binary_op): cp_fully_fold integer_zerop
arguments for -Waddress warning.  Fix up formatting.

* c-c++-common/Waddress-1.c: New test.

From-SVN: r233357

gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/Waddress-1.c [new file with mode: 0644]

index 931e51d03d86de3fc089319925ce9da5c1fe44f2..b595b81676dbb30f1166924290613ea005f910d6 100644 (file)
@@ -1,3 +1,9 @@
+2016-02-11  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/69768
+       * c-typeck.c (parser_build_binary_op): Strip nops from integer_zerop
+       arguments for -Waddress warning.
+
 2016-02-04  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/69669
index 65925cbc8e7f87f7ed8f5ed8170bda500459a685..82efacf1389f81a86a7ec77c4f84b39adf194a02 100644 (file)
@@ -3597,8 +3597,10 @@ parser_build_binary_op (location_t location, enum tree_code code,
      of testing for equality or inequality of a string literal with NULL.  */
   if (code == EQ_EXPR || code == NE_EXPR)
     {
-      if ((code1 == STRING_CST && !integer_zerop (arg2.value))
-         || (code2 == STRING_CST && !integer_zerop (arg1.value)))
+      if ((code1 == STRING_CST
+          && !integer_zerop (tree_strip_nop_conversions (arg2.value)))
+         || (code2 == STRING_CST
+             && !integer_zerop (tree_strip_nop_conversions (arg1.value))))
        warning_at (location, OPT_Waddress,
                    "comparison with string literal results in unspecified behavior");
     }
index 7a80565e0591fecb064b6e3108bfa0af17aeb02b..1b4ebd3f495155d31b8889073e73a047b4ce5330 100644 (file)
@@ -1,3 +1,9 @@
+2016-02-11  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/69768
+       * typeck.c (cp_build_binary_op): cp_fully_fold integer_zerop
+       arguments for -Waddress warning.  Fix up formatting.
+
 2016-02-11  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/68726
index c9fa11290088da425b27813198e6455d07b27428..3a247d850c2efdaac69d2d92fc18c13d2687853f 100644 (file)
@@ -4487,9 +4487,12 @@ cp_build_binary_op (location_t location,
        warning (OPT_Wfloat_equal,
                 "comparing floating point with == or != is unsafe");
       if ((complain & tf_warning)
-         && ((TREE_CODE (orig_op0) == STRING_CST && !integer_zerop (op1))
-             || (TREE_CODE (orig_op1) == STRING_CST && !integer_zerop (op0))))
-       warning (OPT_Waddress, "comparison with string literal results in unspecified behaviour");
+         && ((TREE_CODE (orig_op0) == STRING_CST
+              && !integer_zerop (cp_fully_fold (op1)))
+             || (TREE_CODE (orig_op1) == STRING_CST
+                 && !integer_zerop (cp_fully_fold (op0)))))
+       warning (OPT_Waddress, "comparison with string literal results "
+                              "in unspecified behaviour");
 
       build_type = boolean_type_node;
       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
index c99f7639760e6d05afbaa3dff5b64263b4d670d3..baf28f5339f32e3b090aff9d927a0c68bfb6a4aa 100644 (file)
@@ -1,3 +1,8 @@
+2016-02-11  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/69768
+       * c-c++-common/Waddress-1.c: New test.
+
 2016-02-11  Andre Vehreschild  <vehre@gcc.gnu.org>
 
        PR fortran/69296
diff --git a/gcc/testsuite/c-c++-common/Waddress-1.c b/gcc/testsuite/c-c++-common/Waddress-1.c
new file mode 100644 (file)
index 0000000..a5d128f
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR c/69768 */
+/* { dg-do compile } */
+/* { dg-options "-Waddress" } */
+
+static int e;
+
+int
+foo ()
+{
+  return "foo1" != (void *) 0  /* { dg-bogus "comparison with string literal results in unspecified behaviou?r" } */
+        && "foo2" != (const char *) ((void *) 0)       /* { dg-bogus "comparison with string literal results in unspecified behaviou?r" } */
+        && "foo3" != (const char *) ((void *) (10 - 10))       /* { dg-bogus "comparison with string literal results in unspecified behaviou?r" } */
+        && "foo4" != (const char *) ((void *) (&e - &e))       /* { dg-warning "comparison with string literal results in unspecified behaviou?r" "" { target c } } */
+        && "foo5" != "foo6";   /* { dg-warning "comparison with string literal results in unspecified behaviou?r" } */
+}