public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/102129] New: -ftrapping-math is broken or badly documented
@ 2021-08-30 14:32 vincent-gcc at vinc17 dot net
  2021-08-30 15:00 ` [Bug middle-end/102129] " vincent-gcc at vinc17 dot net
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2021-08-30 14:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102129
           Summary: -ftrapping-math is broken or badly documented
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincent-gcc at vinc17 dot net
  Target Milestone: ---

Testcase:

void g (void);
double f (double x)
{
  double r = x * 5.0;
  g ();
  return r;
}

In the generated code with -O1 and above, one can see that the multiplication
is done after g is called, even if -ftrapping-math is used (which is the
default). This is incorrect as x * 5.0 may trap, terminating the program with a
floating-point exception, in which case g must not be executed.

There is a similar discussion in PR29186 (which is actually about flag
reading), and -ftrapping-math is also mentioned in PR34678 ("I suspect that if
-ftrapping-math actually implemented everything required for the floating-point
exceptions aspects of FENV_ACCESS, [...]").

The STDC FENV_ACCESS pragma is not implemented, but by definition of
-ftrapping-math, it should imply some behavior similar to this pragma being on.
This bug is different from PR34678 because not everything from this pragma
needs to be implemented, just a subset of the "when a program might [...] run
under non-default floating-point control modes." part. This seems to be the
whole purpose of this option.

Note also that https://gcc.gnu.org/wiki/FloatingPointMath doesn't mention a
limitation for traps (only for the change of the rounding mode).

For the reference, the current documentation:

  -fno-trapping-math

    Compile code assuming that floating-point operations cannot generate
user-visible traps. These traps include division by zero, overflow, underflow,
inexact result and invalid operation. This option requires that
-fno-signaling-nans be in effect. Setting this option may allow faster code if
one relies on “non-stop” IEEE arithmetic, for example.

    This option should never be turned on by any -O option since it can result
in incorrect output for programs that depend on an exact implementation of IEEE
or ISO rules/specifications for math functions.

    The default is -ftrapping-math.

(from https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html).

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-08-31  9:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-30 14:32 [Bug middle-end/102129] New: -ftrapping-math is broken or badly documented vincent-gcc at vinc17 dot net
2021-08-30 15:00 ` [Bug middle-end/102129] " vincent-gcc at vinc17 dot net
2021-08-30 19:49 ` joseph at codesourcery dot com
2021-08-31  0:37 ` vincent-gcc at vinc17 dot net
2021-08-31  7:12 ` rguenth at gcc dot gnu.org
2021-08-31  7:18 ` rguenth at gcc dot gnu.org
2021-08-31  8:25 ` rguenth at gcc dot gnu.org
2021-08-31  8:26 ` rguenth at gcc dot gnu.org
2021-08-31  8:49 ` rguenth at gcc dot gnu.org
2021-08-31  9:38 ` cvs-commit at gcc dot gnu.org
2021-08-31  9:38 ` rguenth at gcc dot gnu.org

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).