public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <rguenther@suse.de>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH][RFC] Map -ftrapv to -fsanitize=signed-integer-overflow -fsanitize-undefined-trap-on-error
Date: Mon, 25 Oct 2021 19:16:05 +0200	[thread overview]
Message-ID: <20211025171605.GW304296@tucnak> (raw)
In-Reply-To: <20on4s19-o945-4686-o662-6n4q48246q92@fhfr.qr>

On Wed, Oct 20, 2021 at 03:22:10PM +0200, Richard Biener via Gcc-patches wrote:
> This maps -ftrapv to -fsanitize=signed-integer-overflow
> -fsanitize-undefined-trap-on-error, effectively removing
> flag_trapv (or rather making it always false).
> 
> This has implications on language support - while -ftrapv
> was formerly universally available the mapping restricts it
> to the C family of frontends.
> 
> It also raises questions on mixing -ftrapv with -fsanitize
> flags, specifically with other recovery options for the
> undefined sanitizer since -fsanitize-undefined-trap-on-error
> cannot be restricted to the signed-integer-overflow part at
> the moment.  To more closely map behavior we could add
> -fsanitize=trapv where with a single option we could also
> simply alias -ftrapv to that.

I think we shouldn't do it this way.
There is no reason not to support it in all FEs, not just C family,
the instrumentation is done during in this case in the ubsan pass anyway.
And it also should cope well with different sanitizers, while
-ftrapv vs. -fsanitize=signed-integer-overflow probably needs to be
either/or, so one of those should take precedence over the other,
e.g. -fsanitize=shift -fsanitize-recover=shift -ftrapv should result
in recovering from shift UBs, not trap on them.

My preference would be new set of ifns for -ftrapv, similar to
.UBSAN_CHECK_{ADD,SUB,MUL}, say .TRAPV_CHECK_{ADD,SUB,MUL,DIV},
that uses moreless the same internal-fn.c expansion as .UBSAN_CHECK_*,
but doesn't call ubsan_build_overflow_builtin and rely on
flag_sanitize_undefined_trap_on_error, instead either emits
the trap call directly, or also uses libcalls if optab isn't
available and libcall is (or for -Os cases if libcall is smaller).
Because some of the -fsanitize=signed-integer-overflow emitted code
for multiplication at least on some architectures is very large...

	Jakub


  parent reply	other threads:[~2021-10-25 17:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-20 13:22 Richard Biener
2021-10-25 16:45 ` Martin Sebor
2021-10-25 17:16 ` Jakub Jelinek [this message]
2021-10-28 23:24 ` Hans-Peter Nilsson
2021-10-29  7:01   ` Richard Biener

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=20211025171605.GW304296@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rguenther@suse.de \
    /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).