Commit 7a506c3c by Jason Merrill Committed by Jason Merrill

PR c++/86586 - -fcompare-debug=-Wsign-compare.

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
parent b8836dbe
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> 2019-04-01 Martin Sebor <msebor@redhat.com>
PR c/89685 PR c/89685
......
...@@ -2073,6 +2073,9 @@ warn_for_sign_compare (location_t location, ...@@ -2073,6 +2073,9 @@ warn_for_sign_compare (location_t location,
else else
sop = orig_op1, uop = orig_op0; sop = orig_op1, uop = orig_op0;
sop = fold_for_warn (sop);
uop = fold_for_warn (uop);
STRIP_TYPE_NOPS (sop); STRIP_TYPE_NOPS (sop);
STRIP_TYPE_NOPS (uop); STRIP_TYPE_NOPS (uop);
base_type = (TREE_CODE (result_type) == COMPLEX_TYPE base_type = (TREE_CODE (result_type) == COMPLEX_TYPE
......
2019-04-03 Jason Merrill <jason@redhat.com> 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. PR c++/89331 - ICE with offsetof in incomplete class.
* semantics.c (finish_offsetof): Handle error_mark_node. * semantics.c (finish_offsetof): Handle error_mark_node.
* typeck.c (build_class_member_access_expr): Call * typeck.c (build_class_member_access_expr): Call
......
...@@ -5486,14 +5486,7 @@ cp_build_binary_op (const op_location_t &location, ...@@ -5486,14 +5486,7 @@ cp_build_binary_op (const op_location_t &location,
&& !enum_cast_to_int (orig_op0) && !enum_cast_to_int (orig_op0)
&& !enum_cast_to_int (orig_op1)) && !enum_cast_to_int (orig_op1))
{ {
tree oop0 = maybe_constant_value (orig_op0); warn_for_sign_compare (location, orig_op0, orig_op1, op0, op1,
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,
result_type, resultcode); result_type, resultcode);
} }
} }
......
/* Test case to check if Multiversioning works. */ /* Test case to check if Multiversioning works. */
/* { dg-do run } */ /* { dg-do run } */
/* { dg-require-ifunc "" } */ /* { dg-require-ifunc "" } */
/* { dg-options "-O2 -fPIC" } */ /* { dg-options "-O2 -fPIC -fcompare-debug=-Wsign-compare" } */
#include <assert.h> #include <assert.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment