re PR c++/86569 (-Wnonnull-compare affects code generation since r233684)
authorJakub Jelinek <jakub@redhat.com>
Mon, 23 Jul 2018 07:48:56 +0000 (09:48 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 23 Jul 2018 07:48:56 +0000 (09:48 +0200)
PR c++/86569
* cp-gimplify.c (cp_fold): Don't fold comparisons into other kind
of expressions other than INTEGER_CST regardless of TREE_NO_WARNING
or warn_nonnull_compare.

* g++.dg/warn/Wnonnull-compare-9.C: New test.

From-SVN: r262928

gcc/cp/ChangeLog
gcc/cp/cp-gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wnonnull-compare-9.C [new file with mode: 0644]

index 125f169c16723f5b721392d24feb9257d5b416b0..f1185c4f03d08a9283072c15262a275f11c0400d 100644 (file)
@@ -1,3 +1,10 @@
+2018-07-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/86569
+       * cp-gimplify.c (cp_fold): Don't fold comparisons into other kind
+       of expressions other than INTEGER_CST regardless of TREE_NO_WARNING
+       or warn_nonnull_compare.
+
 2018-07-19  Paolo Carlini  <paolo.carlini@oracle.com>
 
        Revert fix for c++/59480 (and testsuite followup)
index 356b188e00b9d0c4f833696e4f2e5be219b4cdc2..28802b5a3be747263057c2bf050cd26a00bd5559 100644 (file)
@@ -2381,21 +2381,26 @@ cp_fold (tree x)
       else
        x = fold (x);
 
-      if (TREE_NO_WARNING (org_x)
-         && warn_nonnull_compare
-         && COMPARISON_CLASS_P (org_x))
+      /* This is only needed for -Wnonnull-compare and only if
+        TREE_NO_WARNING (org_x), but to avoid that option affecting code
+        generation, we do it always.  */
+      if (COMPARISON_CLASS_P (org_x))
        {
          if (x == error_mark_node || TREE_CODE (x) == INTEGER_CST)
            ;
          else if (COMPARISON_CLASS_P (x))
-           TREE_NO_WARNING (x) = 1;
+           {
+             if (TREE_NO_WARNING (org_x) && warn_nonnull_compare)
+               TREE_NO_WARNING (x) = 1;
+           }
          /* Otherwise give up on optimizing these, let GIMPLE folders
             optimize those later on.  */
          else if (op0 != TREE_OPERAND (org_x, 0)
                   || op1 != TREE_OPERAND (org_x, 1))
            {
              x = build2_loc (loc, code, TREE_TYPE (org_x), op0, op1);
-             TREE_NO_WARNING (x) = 1;
+             if (TREE_NO_WARNING (org_x) && warn_nonnull_compare)
+               TREE_NO_WARNING (x) = 1;
            }
          else
            x = org_x;
index ecf7b054b01923a49f8ffae17074e80058f3f670..b5e2a54e9b2f93c5fac7e9e1bf5b7e55ff5a9723 100644 (file)
@@ -1,3 +1,8 @@
+2018-07-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/86569
+       * g++.dg/warn/Wnonnull-compare-9.C: New test.
+
 2018-07-20  Martin Sebor  <msebor@redhat.com>
 
        PR middle-end/82063
diff --git a/gcc/testsuite/g++.dg/warn/Wnonnull-compare-9.C b/gcc/testsuite/g++.dg/warn/Wnonnull-compare-9.C
new file mode 100644 (file)
index 0000000..f8fa3c0
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/86569
+// { dg-do compile }
+// { dg-options "-fcompare-debug=-Wnonnull-compare" }
+
+bool b;
+
+int
+main ()
+{
+  return ((!b) != 0);
+}