public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenther at suse dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/54192] -fno-trapping-math by default?
Date: Tue, 21 Sep 2021 06:36:42 +0000	[thread overview]
Message-ID: <bug-54192-4-s34EtvdKvj@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-54192-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54192

--- Comment #6 from rguenther at suse dot de <rguenther at suse dot de> ---
On Tue, 21 Sep 2021, gabravier at gmail dot com wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54192
> 
> Gabriel Ravier <gabravier at gmail dot com> changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |gabravier at gmail dot com
> 
> --- Comment #5 from Gabriel Ravier <gabravier at gmail dot com> ---
> Also of note should be the fact that Clang's current default is
> `-fno-trapping-math`.
> 
> I'm myself kind of curious about how exactly `-ftrapping-math` is interpreted.
> It certainly doesn't seem to remove every single kind of non-trapping
> math-based optimization: GCC will remove such statements as `(void)1/x;` even
> with `-ftrapping-math`, even though that could fault with `x == 0`, and will
> optimize things like `float x = 3412897421;` to not do a conversion even though
> that conversion could raise an exception (as 3412897421 cannot be exactly
> represented as a float), whereas Clang won't do that kind of optimization and
> will keep those operations as-is.

Yes, as said in other contexts GCC happily _removes_ traps if trapping
is the only side-effect.  _Unless_ you also have -fnon-call-exceptions
enabled which is the only way to observe traps.  So we consider
a trap invoking undefined behavior unless you make them well-defined
via -fnon-call-exceptions.

I suppose that argues for a tighter coupling of -fnon-call-exceptions
and -ftrapping-math and in particular not enabling -ftrapping-math
by default (unless -fnon-call-exceptions is enabled?).

Btw, the issue also repeatedly comes up in the context of -ftrapv.

I guess I'll propose a documentation enhancement where we can then
discuss the best way forward.

Note that options like -ftrapv and -ftrapping-math also make GCC
avoid transforms that may turn expressions that do not trap into
expressions that do.  For both that is re-association which can
lead to intermediate integer overflows and intermediate inexact
exception traps.

  parent reply	other threads:[~2021-09-21  6:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-07 12:40 [Bug c/54192] New: " glisse at gcc dot gnu.org
2012-08-07 12:50 ` [Bug c/54192] " rguenth at gcc dot gnu.org
2012-08-07 13:14 ` glisse at gcc dot gnu.org
2021-09-21  0:51 ` gabravier at gmail dot com
2021-09-21  6:36 ` rguenther at suse dot de [this message]
2021-09-21  7:48 ` ebotcazou at gcc dot gnu.org
2021-09-21 20:00 ` joseph at codesourcery dot com
2021-09-22  6:20 ` rguenther at suse dot de
2023-08-09 10:45 ` rguenth at gcc dot gnu.org
2023-08-09 10:50 ` rguenth at gcc dot gnu.org

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=bug-54192-4-s34EtvdKvj@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).