PR c++/86586 - -fcompare-debug=-Wsign-compare.
authorJason Merrill <jason@redhat.com>
Wed, 3 Apr 2019 20:12:00 +0000 (16:12 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 3 Apr 2019 20:12:00 +0000 (16:12 -0400)
This patch limits constexpr folding for -Wsign-compare to only cases that we
would warn for without considering constant values, avoiding the folding in
the testcase in question.

gcc/c-family/
* c-warn.c (warn_for_sign_compare): Call fold_for_warn.
gcc/cp/
* typeck.c (cp_build_binary_op): Don't fold for -Wsign-compare.

From-SVN: r270136

gcc/c-family/ChangeLog
gcc/c-family/c-warn.c
gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/g++.target/i386/mv1.C

index cf73a1cad1cf31b966e4d17a3ea73d21b72be16a..ae6b8a7094d016033a937b5ed6d06821a1463a6b 100644 (file)
@@ -1,3 +1,8 @@
+2019-04-03  Jason Merrill  <jason@redhat.com>
+
+       PR c++/86586 - -fcompare-debug=-Wsign-compare.
+       * c-warn.c (warn_for_sign_compare): Call fold_for_warn.
+
 2019-04-01  Martin Sebor  <msebor@redhat.com>
 
        PR c/89685
index d775ff80b452327af52326a7161487bd68e1a217..4785887c1de508333d2090ed776b613662e0c115 100644 (file)
@@ -2073,6 +2073,9 @@ warn_for_sign_compare (location_t location,
       else
        sop = orig_op1, uop = orig_op0;
 
+      sop = fold_for_warn (sop);
+      uop = fold_for_warn (uop);
+
       STRIP_TYPE_NOPS (sop);
       STRIP_TYPE_NOPS (uop);
       base_type = (TREE_CODE (result_type) == COMPLEX_TYPE
index a224517b566052cbf0ec98e0d92d42fa3b766cee..91d14311f1887abcd3c6e3c97926261c9a05dc5a 100644 (file)
@@ -1,5 +1,8 @@
 2019-04-03  Jason Merrill  <jason@redhat.com>
 
+       PR c++/86586 - -fcompare-debug=-Wsign-compare.
+       * typeck.c (cp_build_binary_op): Don't fold for -Wsign-compare.
+
        PR c++/89331 - ICE with offsetof in incomplete class.
        * semantics.c (finish_offsetof): Handle error_mark_node.
        * typeck.c (build_class_member_access_expr): Call
index 56def144a3e14ac57ca5aaefe01c2d60dc622424..03b14024738ff4a28d6abcf6fe748aeb04001e22 100644 (file)
@@ -5486,14 +5486,7 @@ cp_build_binary_op (const op_location_t &location,
          && !enum_cast_to_int (orig_op0)
          && !enum_cast_to_int (orig_op1))
        {
-         tree oop0 = maybe_constant_value (orig_op0);
-         tree oop1 = maybe_constant_value (orig_op1);
-
-         if (TREE_CODE (oop0) != INTEGER_CST)
-           oop0 = cp_fully_fold (orig_op0);
-         if (TREE_CODE (oop1) != INTEGER_CST)
-           oop1 = cp_fully_fold (orig_op1);
-         warn_for_sign_compare (location, oop0, oop1, op0, op1, 
+         warn_for_sign_compare (location, orig_op0, orig_op1, op0, op1,
                                 result_type, resultcode);
        }
     }
index fc713477c1eb999db627f81be48fd3031cf53b91..9e3685061963c29f439141efb85d517f8d324207 100644 (file)
@@ -1,7 +1,7 @@
 /* Test case to check if Multiversioning works.  */
 /* { dg-do run } */
 /* { dg-require-ifunc "" }  */
-/* { dg-options "-O2 -fPIC" } */
+/* { dg-options "-O2 -fPIC -fcompare-debug=-Wsign-compare" } */
 
 #include <assert.h>