public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <law@redhat.com>
To: Marek Polacek <polacek@redhat.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>,
	Jakub Jelinek <jakub@redhat.com>
Subject: Re: [PATCH] Disable type demotion for sanitizer (PR sanitizer/82072)
Date: Mon, 04 Sep 2017 06:08:00 -0000	[thread overview]
Message-ID: <f72dea64-8a2d-da98-78c6-12d947f4a2b6@redhat.com> (raw)
In-Reply-To: <20170901174714.GB20631@redhat.com>

On 09/01/2017 11:47 AM, Marek Polacek wrote:
> Here, do_narrow and convert_to_integer_1 is demoting signed types to unsigned,
> e.g. for
>   i = i - lmin
> where i is int and lmin is long int, so what we should produce is
>   i = (int) ((long int) i - lmin)
> but instead it produces
>   i = (int) ((unsigned int) i - (unsigned int) lmin);
> which hides the overflow.  Similarly for NEGATE_EXPR.  This patch prevents
> such demoting when the sanitizer is on.
> 
> There still might be a similar issue with division or shifting, but I couldn't
> trigger that.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
> 
> 2017-09-01  Marek Polacek  <polacek@redhat.com>
> 
> 	PR sanitizer/82072
> 	* convert.c (do_narrow): When sanitizing signed integer overflows,
> 	bail out for signed types.
> 	(convert_to_integer_1) <case NEGATE_EXPR>: Likewise.
> 
> 	* c-c++-common/ubsan/pr82072.c: New test.
OK.  There's probably other places that may need similar treatment.  You
might want to peek at shorten_binary_op and shorten_compare to see if
they suffer from similar problems.  We really want them to go away, but
we haven't gotten back to that project since Kai left.

Jeff

      reply	other threads:[~2017-09-04  6:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-01 17:47 Marek Polacek
2017-09-04  6:08 ` Jeff Law [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=f72dea64-8a2d-da98-78c6-12d947f4a2b6@redhat.com \
    --to=law@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --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).