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

            Bug ID: 127791
           Summary: Separate IEEE alternate exception handling from
                    -ftrapping-math
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
                CC: ebotcazou at gcc dot gnu.org, jsm28 at gcc dot gnu.org
  Target Milestone: ---

When using -fnon-call-exceptions together with -ftrapping-math (the default),
any operation with a possible IEEE exception will cause EH code to be emitted
regardless of whether alternate IEEE exception handling is enabled and thus
an exception would be delivered.  The -fnon-call-exceptions + -ftrapping-math
combination does _not_ raise exceptions when just IEEE flags are set.

Testcase:

double z;
double foo (double x, double y)
{
  try
    {
      z = x + y;
      return z;
    }
  catch (...)
    {
      return 0.;
    }
}

Proposal: -ftrapping-math[={standard,trap,[no-]trap-<exception-kind>}]
with -ftrapping-math aliasing to -ftrapping-math=standard and in that
mode -fnon-call-exceptions should not consider IEEE exceptions to raise
exceptions.

Ada seems to do

  /* Assume that FP operations can trap if S'Machine_Overflow is true,
     but don't override the user if not.  */
  if (Machine_Overflows_On_Target)  
    flag_trapping_math = 1;
  else if (!OPTION_SET_P (flag_trapping_math))
    flag_trapping_math = 0;

but I'm not sure if it requires/enables alternate exception handling?

Reply via email to