public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Marek Polacek <polacek@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] ICE with ~INT_MAX in fold-const.c (PR sanitizer/80875)
Date: Fri, 26 May 2017 09:06:00 -0000	[thread overview]
Message-ID: <CAFiYyc3YJ0Mt7UQvkHJe0z4JxLH_D+6q3o9PToTZGdAsTzVJyg@mail.gmail.com> (raw)
In-Reply-To: <20170525163346.GY3335@redhat.com>

On Thu, May 25, 2017 at 6:33 PM, Marek Polacek <polacek@redhat.com> wrote:
> We ICE on this testcase in
>  9812           /* Transform x * -C into -x * C if x is easily negatable.  */
>  9813           if (TREE_CODE (op1) == INTEGER_CST
>  9814               && tree_int_cst_sgn (op1) == -1
>  9815               && negate_expr_p (op0)
>  9816               && (tem = negate_expr (op1)) != op1
>  9817               && ! TREE_OVERFLOW (tem))
> because fold_negate_expr returns NULL_TREE for INT_MIN, so negate_expr just
> wrapped in into a NEGATE_EXPR, creating NEGATE_EXPR <INT_MIN>.  TREE_OVERFLOW
> crashes on that.  I thought it made sense to check whether we can negate OP1
> first, as done in the patch below.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk and 7?

Ok.

> 2017-05-25  Marek Polacek  <polacek@redhat.com>
>
>         PR sanitizer/80875
>         * fold-const.c (fold_binary_loc) <case MULT_EXPR>: Check if OP1
>         can be negated.
>
>         * c-c++-common/ubsan/pr80875.c: New test.
>
> diff --git gcc/fold-const.c gcc/fold-const.c
> index efc0b10..911ae36 100644
> --- gcc/fold-const.c
> +++ gcc/fold-const.c
> @@ -9813,6 +9813,7 @@ fold_binary_loc (location_t loc,
>           if (TREE_CODE (op1) == INTEGER_CST
>               && tree_int_cst_sgn (op1) == -1
>               && negate_expr_p (op0)
> +             && negate_expr_p (op1)
>               && (tem = negate_expr (op1)) != op1
>               && ! TREE_OVERFLOW (tem))
>             return fold_build2_loc (loc, MULT_EXPR, type,
> diff --git gcc/testsuite/c-c++-common/ubsan/pr80875.c gcc/testsuite/c-c++-common/ubsan/pr80875.c
> index e69de29..e679452 100644
> --- gcc/testsuite/c-c++-common/ubsan/pr80875.c
> +++ gcc/testsuite/c-c++-common/ubsan/pr80875.c
> @@ -0,0 +1,9 @@
> +/* PR sanitizer/80875 */
> +/* { dg-do compile } */
> +/* { dg-options "-fsanitize=undefined" } */
> +
> +int
> +foo (void)
> +{
> +  return ~__INT_MAX__ * (0 / 0); /* { dg-warning "division by zero" } */
> +}
>
>         Marek

      reply	other threads:[~2017-05-26  8:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-25 16:52 Marek Polacek
2017-05-26  9:06 ` Richard Biener [this message]

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=CAFiYyc3YJ0Mt7UQvkHJe0z4JxLH_D+6q3o9PToTZGdAsTzVJyg@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=polacek@redhat.com \
    /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).