public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches@gcc.gnu.org, Jason Merrill <jason@redhat.com>,
	 Jan Hubicka <hubicka@ucw.cz>
Subject: Re: [PATCH] gimple, internal-fn: Add IFN_TRAP and use it for __builtin_unreachable [PR106099]
Date: Wed, 27 Jul 2022 11:14:46 +0000 (UTC)	[thread overview]
Message-ID: <nycvar.YFH.7.77.849.2207271113501.6583@jbgna.fhfr.qr> (raw)
In-Reply-To: <YuEQ0xiJK7ESGb8B@tucnak>

On Wed, 27 Jul 2022, Jakub Jelinek wrote:

> On Wed, Jul 27, 2022 at 10:09:34AM +0000, Richard Biener wrote:
> > > We chose to sanitize not just explicit user __builtin_unreachable calls,
> > > but also the internally generated __builtin_unreachable calls (with the
> > > one exception of fall through to end of C++ function returning non-void,
> > > which had before a separate sanitizer) and we've been doing it since 2013
> > > when ubsan was added.
> > > Even for the internally generated unreachable calls like those from
> > > devirtualization or other reasons like ivcanon/unrolling, having the
> > > possibility to get some runtime diagnostics or trap can be useful over
> > > just falling through to random following code.
> > 
> > So at least for the unrolling use the intent is to have the
> > unreachable () fully elided by later passes.  Honza can correct me
> > if I'm wrong.  Using __builtin_trap from the start until sanopt
> > may prevent some of that from happening, keeping dead conditions
> > live, no?
> 
> That is true.
> I guess changing the sanopt gate back and building __builtin_unreachable
> only in the ivcanon/unrolling case is possible too.
> 
> Without or with this patch then, the advantage of the patch would be that
> we wouldn't need to recompute vops if we replace unreachables with traps
> during the sanopt pass.

Yes, as I said on that ground the patch is OK, but I think it doesn't
really address the few PRs that popped up after the earlier change.

Richard.

> > 
> > > Previously we'd always emit __builtin_unreachable, then perhaps in some
> > > cases could e.g. optimize it away (say if there is a guarding condition
> > > around the implicitly added unreachable turning the condition into VRP
> > > info and optimizing the conditional away), otherwise the sanopt pass
> > > would turn those __builtin_unreachable calls into __builtin_trap.
> > > With the recent changes, we don't run the sanopt pass when only
> > > doing -fsanitize=unreachable (or -funrechable-traps) though, so we need
> > > to emit the trap/__ubsan_handle_unreachable/__builtin_unreachable right
> > > away.
> > 
> > Why did the recent changes not just replace __builtin_unreachable
> > at RTL expansion time?  Was the intent really to force the paths
> > to be kept live?  I can see that for user or frontend generated
> > unreachables but not so much for some of the middle-end ones.
> 
> It is easier on GIMPLE and perhaps allows e.g. sharing the data for
> __ubsan_handle_unreachable calls.  sanopt pass is quite late anyway.

  reply	other threads:[~2022-07-27 11:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-27  9:26 Jakub Jelinek
2022-07-27  9:33 ` Richard Biener
2022-07-27  9:55   ` Jakub Jelinek
2022-07-27 10:09     ` Richard Biener
2022-07-27 10:17       ` Jakub Jelinek
2022-07-27 11:14         ` Richard Biener [this message]
2022-08-06 22:36       ` Jason Merrill

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=nycvar.YFH.7.77.849.2207271113501.6583@jbgna.fhfr.qr \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hubicka@ucw.cz \
    --cc=jakub@redhat.com \
    --cc=jason@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).