public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "aldyh at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/108647] [13 Regression] ICE in upper_bound, at value-range.h:950 with -O3 since r13-2974-g67166c9ec35d58ef
Date: Fri, 03 Feb 2023 16:16:15 +0000	[thread overview]
Message-ID: <bug-108647-4-kR8N4jylez@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-108647-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108647

--- Comment #12 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #7)
> So
> --- gcc/range-op.cc.jj	2023-02-03 10:51:40.699003658 +0100
> +++ gcc/range-op.cc	2023-02-03 16:04:39.264159294 +0100
> @@ -642,7 +642,8 @@ operator_equal::op1_range (irange &r, tr
>      case BRS_FALSE:
>        // If the result is false, the only time we know anything is
>        // if OP2 is a constant.
> -      if (wi::eq_p (op2.lower_bound(), op2.upper_bound()))
> +      if (!op2.undefined_p ()
> +	  && wi::eq_p (op2.lower_bound(), op2.upper_bound()))
>  	{
>  	  r = op2;
>  	  r.invert ();
> @@ -755,7 +756,8 @@ operator_not_equal::op1_range (irange &r
>      case BRS_TRUE:
>        // If the result is true, the only time we know anything is if
>        // OP2 is a constant.
> -      if (wi::eq_p (op2.lower_bound(), op2.upper_bound()))
> +      if (!op2.undefined_p ()
> +	  && wi::eq_p (op2.lower_bound(), op2.upper_bound()))
>  	{
>  	  r = op2;
>  	  r.invert ();
> @@ -920,6 +922,9 @@ operator_lt::op1_range (irange &r, tree
>  			const irange &op2,
>  			relation_trio) const
>  {
> +  if (op2.undefined_p ())
> +    return false;
> +
>    switch (get_bool_state (r, lhs, type))
>      {
>      case BRS_TRUE:
> @@ -942,6 +947,9 @@ operator_lt::op2_range (irange &r, tree
>  			const irange &op1,
>  			relation_trio) const
>  {
> +  if (op1.undefined_p ())
> +    return false;
> +
>    switch (get_bool_state (r, lhs, type))
>      {
>      case BRS_TRUE:
> @@ -1031,6 +1039,9 @@ operator_le::op1_range (irange &r, tree
>  			const irange &op2,
>  			relation_trio) const
>  {
> +  if (op2.undefined_p ())
> +    return false;
> +
>    switch (get_bool_state (r, lhs, type))
>      {
>      case BRS_TRUE:
> @@ -1053,6 +1064,9 @@ operator_le::op2_range (irange &r, tree
>  			const irange &op1,
>  			relation_trio) const
>  {
> +  if (op1.undefined_p ())
> +    return false;
> +
>    switch (get_bool_state (r, lhs, type))
>      {
>      case BRS_TRUE:
> @@ -1141,6 +1155,9 @@ operator_gt::op1_range (irange &r, tree
>  			const irange &lhs, const irange &op2,
>  			relation_trio) const
>  {
> +  if (op2.undefined_p ())
> +    return false;
> +
>    switch (get_bool_state (r, lhs, type))
>      {
>      case BRS_TRUE:
> @@ -1163,6 +1180,9 @@ operator_gt::op2_range (irange &r, tree
>  			const irange &op1,
>  			relation_trio) const
>  {
> +  if (op1.undefined_p ())
> +    return false;
> +
>    switch (get_bool_state (r, lhs, type))
>      {
>      case BRS_TRUE:
> @@ -1252,6 +1272,9 @@ operator_ge::op1_range (irange &r, tree
>  			const irange &op2,
>  			relation_trio) const
>  {
> +  if (op2.undefined_p ())
> +    return false;
> +
>    switch (get_bool_state (r, lhs, type))
>      {
>      case BRS_TRUE:
> @@ -1274,6 +1297,9 @@ operator_ge::op2_range (irange &r, tree
>  			const irange &op1,
>  			relation_trio) const
>  {
> +  if (op1.undefined_p ())
> +    return false;
> +
>    switch (get_bool_state (r, lhs, type))
>      {
>      case BRS_TRUE:
> then plus testcase?

Looks good to me.

Do you mind adding this bit to your testing?

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 136b709385c..fdc0a6c05fd 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -2678,7 +2678,6 @@ operator_cast::op1_range (irange &r, tree type,
   if (lhs.undefined_p ())
     return false;
   tree lhs_type = lhs.type ();
-  gcc_checking_assert (types_compatible_p (op2.type(), type));

   // If we are calculating a pointer, shortcut to what we really care about.
   if (POINTER_TYPE_P (type))
@@ -2705,6 +2704,8 @@ operator_cast::op1_range (irange &r, tree type,
       return true;
     }

+  if (op2.undefined_p ())
+    return false;
   if (truncating_cast_p (op2, lhs))
     {
       if (lhs.varying_p ())

This catches the cast operator which will ICE in truncating_cast_p when op2 is
undefined.

I've removed the checking assert since any number of operations further down
will ICE if the types don't match.

  parent reply	other threads:[~2023-02-03 16:16 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-02 21:21 [Bug tree-optimization/108647] New: [13 Regression] ICE in upper_bound, at value-range.h:950 with -O3 vsevolod.livinskiy at gmail dot com
2023-02-03  1:45 ` [Bug tree-optimization/108647] " pinskia at gcc dot gnu.org
2023-02-03  8:04 ` rguenth at gcc dot gnu.org
2023-02-03  9:21 ` [Bug tree-optimization/108647] [13 Regression] ICE in upper_bound, at value-range.h:950 with -O3 since r13-2974-g67166c9ec35d58ef marxin at gcc dot gnu.org
2023-02-03  9:29 ` jakub at gcc dot gnu.org
2023-02-03  9:54 ` jakub at gcc dot gnu.org
2023-02-03 12:46 ` aldyh at gcc dot gnu.org
2023-02-03 14:54 ` amacleod at redhat dot com
2023-02-03 15:11 ` jakub at gcc dot gnu.org
2023-02-03 15:15 ` jakub at gcc dot gnu.org
2023-02-03 15:20 ` amacleod at redhat dot com
2023-02-03 15:23 ` jakub at gcc dot gnu.org
2023-02-03 15:28 ` amacleod at redhat dot com
2023-02-03 16:16 ` aldyh at gcc dot gnu.org [this message]
2023-02-03 16:31 ` aldyh at gcc dot gnu.org
2023-02-03 16:33 ` jakub at gcc dot gnu.org
2023-02-03 16:35 ` aldyh at gcc dot gnu.org
2023-02-03 20:31 ` cvs-commit at gcc dot gnu.org
2023-02-03 20:39 ` cvs-commit at gcc dot gnu.org
2023-02-03 20:43 ` jakub at gcc dot gnu.org
2023-02-04  1:35 ` raj.khem at gmail dot com
2023-02-04  4:28 ` jakub at gcc dot gnu.org
2023-02-04  5:25 ` jakub at gcc dot gnu.org
2023-02-04  7:26 ` raj.khem at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-108647-4-kR8N4jylez@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).