diff mbox series

C++ PATCH for c++/84171, ICE in warn_for_sign_compare

Message ID 20180302173929.GN16833@redhat.com
State New
Headers show
Series C++ PATCH for c++/84171, ICE in warn_for_sign_compare | expand

Commit Message

Marek Polacek March 2, 2018, 5:39 p.m. UTC
Let's beef up warn_for_sign_compare checks; we'd folded the operands
and they could've become garbage.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-03-02  Marek Polacek  <polacek@redhat.com>

	PR c++/84171
	* c-warn.c (warn_for_sign_compare): Bail out if any of the operands
	is erroneous.

	* g++.dg/warn/Wsign-compare-8.C: New test.


	Marek

Comments

Jason Merrill March 2, 2018, 5:42 p.m. UTC | #1
OK.

On Fri, Mar 2, 2018 at 12:39 PM, Marek Polacek <polacek@redhat.com> wrote:
> Let's beef up warn_for_sign_compare checks; we'd folded the operands
> and they could've become garbage.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2018-03-02  Marek Polacek  <polacek@redhat.com>
>
>         PR c++/84171
>         * c-warn.c (warn_for_sign_compare): Bail out if any of the operands
>         is erroneous.
>
>         * g++.dg/warn/Wsign-compare-8.C: New test.
>
> diff --git gcc/c-family/c-warn.c gcc/c-family/c-warn.c
> index f3fb62c7e62..7c385959c4f 100644
> --- gcc/c-family/c-warn.c
> +++ gcc/c-family/c-warn.c
> @@ -1931,6 +1931,9 @@ warn_for_sign_compare (location_t location,
>                        tree op0, tree op1,
>                        tree result_type, enum tree_code resultcode)
>  {
> +  if (error_operand_p (orig_op0) || error_operand_p (orig_op1))
> +    return;
> +
>    int op0_signed = !TYPE_UNSIGNED (TREE_TYPE (orig_op0));
>    int op1_signed = !TYPE_UNSIGNED (TREE_TYPE (orig_op1));
>    int unsignedp0, unsignedp1;
> diff --git gcc/testsuite/g++.dg/warn/Wsign-compare-8.C gcc/testsuite/g++.dg/warn/Wsign-compare-8.C
> index e69de29bb2d..237ba84d526 100644
> --- gcc/testsuite/g++.dg/warn/Wsign-compare-8.C
> +++ gcc/testsuite/g++.dg/warn/Wsign-compare-8.C
> @@ -0,0 +1,8 @@
> +// PR c++/84171
> +// { dg-options "-Wsign-compare" }
> +
> +bool foo (char c)
> +{
> +  const int i = 0 = 0; // { dg-error "lvalue" }
> +  return c = i;
> +} // { dg-warning "control reaches" }
>
>         Marek
diff mbox series

Patch

diff --git gcc/c-family/c-warn.c gcc/c-family/c-warn.c
index f3fb62c7e62..7c385959c4f 100644
--- gcc/c-family/c-warn.c
+++ gcc/c-family/c-warn.c
@@ -1931,6 +1931,9 @@  warn_for_sign_compare (location_t location,
 		       tree op0, tree op1,
 		       tree result_type, enum tree_code resultcode)
 {
+  if (error_operand_p (orig_op0) || error_operand_p (orig_op1))
+    return;
+
   int op0_signed = !TYPE_UNSIGNED (TREE_TYPE (orig_op0));
   int op1_signed = !TYPE_UNSIGNED (TREE_TYPE (orig_op1));
   int unsignedp0, unsignedp1;
diff --git gcc/testsuite/g++.dg/warn/Wsign-compare-8.C gcc/testsuite/g++.dg/warn/Wsign-compare-8.C
index e69de29bb2d..237ba84d526 100644
--- gcc/testsuite/g++.dg/warn/Wsign-compare-8.C
+++ gcc/testsuite/g++.dg/warn/Wsign-compare-8.C
@@ -0,0 +1,8 @@ 
+// PR c++/84171
+// { dg-options "-Wsign-compare" }
+
+bool foo (char c)
+{
+  const int i = 0 = 0; // { dg-error "lvalue" }
+  return c = i;
+} // { dg-warning "control reaches" }