public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@ucw.cz>
To: "Martin Liška" <mliska@suse.cz>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Fix UBSAN errors in ipa-cp.
Date: Wed, 23 Sep 2020 14:32:01 +0200	[thread overview]
Message-ID: <20200923123201.GB41023@kam.mff.cuni.cz> (raw)
In-Reply-To: <7115ce43-bf35-c6e4-46b6-56b386e5cb34@suse.cz>

> I see the following UBSAN errors:
> 
> ./xgcc -B. /home/marxin/Programming/gcc/gcc/testsuite/g++.dg/ipa/pr96806.C -std=c++11 -O -fipa-cp -fipa-cp-clone --param=ipa-cp-max-recursive-depth=94 --param=logical-op-non-short-circuit=0
> /home/marxin/Programming/gcc2/gcc/ipa-cp.c:3866:20: runtime error: signed integer overflow: 64 + 2147483584 cannot be represented in type 'int'
> /home/marxin/Programming/gcc2/gcc/ipa-cp.c:3843:16: runtime error: signed integer overflow: -2147483648 + -2147483648 cannot be represented in type 'int'
> /home/marxin/Programming/gcc2/gcc/ipa-cp.c:3864:20: runtime error: signed integer overflow: 1 + 2147483647 cannot be represented in type 'int'
> 
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> 
> Ready to be installed?
> Thanks,
> Martin
> 
> gcc/ChangeLog:
> 
> 	* ipa-cp.c (safe_add): Handle also very small negative values.
> 	(value_topo_info::propagate_effects): Use properly safe_add.

Perhaps it is time to turn the profile count scaled valued to sreals
like we do in inline heuristics and other places?

Honza
> ---
>  gcc/ipa-cp.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
> index b3e7d41ea10..e39ee28726d 100644
> --- a/gcc/ipa-cp.c
> +++ b/gcc/ipa-cp.c
> @@ -3832,13 +3832,15 @@ propagate_constants_topo (class ipa_topo_info *topo)
>  /* Return the sum of A and B if none of them is bigger than INT_MAX/2, return
> -   the bigger one if otherwise.  */
> +   the bigger one if otherwise.  Similarly for negative numbers.  */
>  static int
>  safe_add (int a, int b)
>  {
>    if (a > INT_MAX/2 || b > INT_MAX/2)
>      return a > b ? a : b;
> +  else if (a < -INT_MAX/2 || b < -INT_MAX/2)
> +    return a > b ? b : a;
>    else
>      return a + b;
>  }
> @@ -3861,9 +3863,10 @@ value_topo_info<valtype>::propagate_effects ()
>        for (val = base; val; val = val->scc_next)
>  	{
> -	  time = safe_add (time,
> -			   val->local_time_benefit + val->prop_time_benefit);
> -	  size = safe_add (size, val->local_size_cost + val->prop_size_cost);
> +	  time = safe_add (time, val->local_time_benefit);
> +	  time = safe_add (time, val->prop_time_benefit);
> +	  size = safe_add (size, val->local_size_cost);
> +	  size = safe_add (size, val->prop_size_cost);
>  	}
>        for (val = base; val; val = val->scc_next)
> -- 
> 2.28.0
> 

  reply	other threads:[~2020-09-23 12:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-23 12:19 Martin Liška
2020-09-23 12:32 ` Jan Hubicka [this message]
2020-09-23 12:39   ` Martin Liška
2020-09-23 13:50     ` Martin Liška
2020-09-23 13:57       ` Jan Hubicka
2020-09-23 14:32         ` Martin Jambor
2020-09-23 15:02       ` Martin Jambor
2020-09-24  7:20         ` Martin Liška

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=20200923123201.GB41023@kam.mff.cuni.cz \
    --to=hubicka@ucw.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mliska@suse.cz \
    /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).