Make C2X imply -fno-fp-int-builtin-inexact
diff mbox series

Message ID alpine.DEB.2.21.1910080037520.19789@digraph.polyomino.org.uk
State New
Headers show
Series
  • Make C2X imply -fno-fp-int-builtin-inexact
Related show

Commit Message

Joseph Myers Oct. 8, 2019, 12:38 a.m. UTC
Since TS 18661-1 has been integrated into C2X, this patch makes C2X
imply -fno-fp-int-builtin-inexact.

Bootstrapped with no regressions on x86_64-pc-linux-gnu.  Applied to 
mainline.

gcc:
2019-10-08  Joseph Myers  <joseph@codesourcery.com>

	* doc/invoke.texi (-ffp-int-builtin-inexact): Document
	-fno-fp-int-builtin-inexact default for C2X.

gcc/c-family:
2019-10-08  Joseph Myers  <joseph@codesourcery.com>

	* c-opts.c (c_common_post_options): Set
	-fno-fp-int-builtin-inexact for C2X.

gcc/testsuite:
2019-10-08  Joseph Myers  <joseph@codesourcery.com>

	* gcc.dg/torture/builtin-fp-int-inexact-c2x.c: New test.

Comments

Rainer Orth Oct. 9, 2019, 11:39 a.m. UTC | #1
Hi Joseph,

> gcc/testsuite:
> 2019-10-08  Joseph Myers  <joseph@codesourcery.com>
>
> 	* gcc.dg/torture/builtin-fp-int-inexact-c2x.c: New test.
[...]
> Index: gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-c2x.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-c2x.c	(nonexistent)
> +++ gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-c2x.c	(working copy)
> @@ -0,0 +1,7 @@
> +/* Test C2X enables -fno-fp-int-builtin-inexact.  */
> +/* { dg-do run } */
> +/* { dg-options "-std=c2x" } */
> +/* { dg-add-options c99_runtime } */
> +/* { dg-require-effective-target fenv_exceptions } */
> +
> +#include "builtin-fp-int-inexact.c"

the new test FAILs on Solaris/x86, both 32 and 64-bit:

FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O0  execution test
FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O1  execution test
FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O2  execution test
FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O2 -flto  execution test
FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O2 -flto -flto-partition=none  execution test
FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O3 -g  execution test

The test aborts.  This happens because dg-add-options c99_runtime
appends -std=c99 to the options, yielding -std=c2x -std=c99.  If I
manually omit the -std=c99, the test PASSes.  I'm uncertain yet how to
handle this.  Maybe prepending -std=c99 is an option, but that may well
break other tests...

	Rainer
Joseph Myers Oct. 9, 2019, 8:54 p.m. UTC | #2
On Wed, 9 Oct 2019, Rainer Orth wrote:

> the new test FAILs on Solaris/x86, both 32 and 64-bit:
> 
> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O0  execution test
> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O1  execution test
> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O2  execution test
> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O2 -flto  execution test
> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O2 -flto -flto-partition=none  execution test
> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O3 -g  execution test
> 
> The test aborts.  This happens because dg-add-options c99_runtime
> appends -std=c99 to the options, yielding -std=c2x -std=c99.  If I
> manually omit the -std=c99, the test PASSes.  I'm uncertain yet how to
> handle this.  Maybe prepending -std=c99 is an option, but that may well
> break other tests...

Since the default standard is now gnu11, I'd hope that dg-add-options 
c99_runtime doesn't actually need to add any options at all.  (Unless 
there are tests using it with an explicit pre-C99 standard, which would 
seem rather nonsensical.)
Rainer Orth Oct. 10, 2019, 9:37 a.m. UTC | #3
Hi Joseph,

> On Wed, 9 Oct 2019, Rainer Orth wrote:
>
>> the new test FAILs on Solaris/x86, both 32 and 64-bit:
>> 
>> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O0  execution test
>> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O1  execution test
>> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O2  execution test
>> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O2 -flto  execution test
>> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c -O2 -flto
>> -flto-partition=none execution test
>> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O3 -g  execution test
>> 
>> The test aborts.  This happens because dg-add-options c99_runtime
>> appends -std=c99 to the options, yielding -std=c2x -std=c99.  If I
>> manually omit the -std=c99, the test PASSes.  I'm uncertain yet how to
>> handle this.  Maybe prepending -std=c99 is an option, but that may well
>> break other tests...
>
> Since the default standard is now gnu11, I'd hope that dg-add-options 
> c99_runtime doesn't actually need to add any options at all.  (Unless 
> there are tests using it with an explicit pre-C99 standard, which would 
> seem rather nonsensical.)

sometimes one misses the obvious ;-)  I'll give the Solaris bootstrap a
try with the Solaris handling in add_options_for_c99_runtime removed.

No idea about Darwin/PowerPC though.  If pre-10.3 is supposed to be
supported, the -mmacosx-version-min=10.3 probably needs to go into
rs6000/darwin.h first.  Iain?

Once this is resolved, all uses of dg-add-options c99_runtime in the
testsuite can go.

	Rainer
Iain Sandoe Oct. 10, 2019, 10 a.m. UTC | #4
Hi Rainer,

Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> wrote:

> Hi Joseph,
>
>> On Wed, 9 Oct 2019, Rainer Orth wrote:
>>
>>> the new test FAILs on Solaris/x86, both 32 and 64-bit:
>>>
>>> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O0  execution test
>>> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O1  execution test
>>> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O2  execution test
>>> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O2 -flto   
>>> execution test
>>> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c -O2 -flto
>>> -flto-partition=none execution test
>>> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O3 -g  execution  
>>> test
>>>
>>> The test aborts.  This happens because dg-add-options c99_runtime
>>> appends -std=c99 to the options, yielding -std=c2x -std=c99.  If I
>>> manually omit the -std=c99, the test PASSes.  I'm uncertain yet how to
>>> handle this.  Maybe prepending -std=c99 is an option, but that may well
>>> break other tests...
>>
>> Since the default standard is now gnu11, I'd hope that dg-add-options
>> c99_runtime doesn't actually need to add any options at all.  (Unless
>> there are tests using it with an explicit pre-C99 standard, which would
>> seem rather nonsensical.)
>
> sometimes one misses the obvious ;-)  I'll give the Solaris bootstrap a
> try with the Solaris handling in add_options_for_c99_runtime removed.
>
> No idea about Darwin/PowerPC though.

Right now, anything < 10.4 is not a viable host (without jumping through
a lot of hoops, regardless of the c99 requirements)...

… but It would be good to continue to support these earlier versions as  
cross-
targets (however, it’s low on my priority list to do any serious lifting  
there).

>  If pre-10.3 is supposed to be
> supported, the -mmacosx-version-min=10.3 probably needs to go into
> rs6000/darwin.h first.  Iain?

I’m not quite sure what you’re proposing here (probably missing something
obvious).

> Once this is resolved, all uses of dg-add-options c99_runtime in the
> testsuite can go.

cheers
Iain
Rainer Orth Oct. 10, 2019, 11:23 a.m. UTC | #5
Hi Iain,

> Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> wrote:
>
>> Hi Joseph,
>>
>>> On Wed, 9 Oct 2019, Rainer Orth wrote:
>>>
>>>> the new test FAILs on Solaris/x86, both 32 and 64-bit:
>>>>
>>>> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O0  execution test
>>>> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O1  execution test
>>>> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O2  execution test
>>>> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O2 -flto
>>>> execution test
>>>> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c -O2 -flto
>>>> -flto-partition=none execution test
>>>> FAIL: gcc.dg/torture/builtin-fp-int-inexact-c2x.c   -O3 -g  execution
>>>> test
>>>>
>>>> The test aborts.  This happens because dg-add-options c99_runtime
>>>> appends -std=c99 to the options, yielding -std=c2x -std=c99.  If I
>>>> manually omit the -std=c99, the test PASSes.  I'm uncertain yet how to
>>>> handle this.  Maybe prepending -std=c99 is an option, but that may well
>>>> break other tests...
>>>
>>> Since the default standard is now gnu11, I'd hope that dg-add-options
>>> c99_runtime doesn't actually need to add any options at all.  (Unless
>>> there are tests using it with an explicit pre-C99 standard, which would
>>> seem rather nonsensical.)
>>
>> sometimes one misses the obvious ;-)  I'll give the Solaris bootstrap a
>> try with the Solaris handling in add_options_for_c99_runtime removed.
>>
>> No idea about Darwin/PowerPC though.
>
> Right now, anything < 10.4 is not a viable host (without jumping through
> a lot of hoops, regardless of the c99 requirements)...
>
> … but It would be good to continue to support these earlier versions as
> cross-
> targets (however, it’s low on my priority list to do any serious lifting
> there).

ok, good to know.

>>  If pre-10.3 is supposed to be
>> supported, the -mmacosx-version-min=10.3 probably needs to go into
>> rs6000/darwin.h first.  Iain?
>
> I’m not quite sure what you’re proposing here (probably missing something
> obvious).

At the moment, gcc/testsuite/lib/target-supports.exp
(add_options_for_c99_runtime) adds -mmacosx-version-min=10.3 to the
testcase flags on powerpc-*-darwin*.  Since, as Joseph mentioned, gcc
now defaults to -std=gnu11 (which implies a C99 runtime), this (or
something similar) would always be needed now (unless someone forces,
say, -std=c90) and should be handled in the Darwin/PowerPC driver code,
not just the testsuite.

	Rainer
Iain Sandoe Oct. 10, 2019, 11:46 a.m. UTC | #6
Hi Rainer,

Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> wrote:

>> Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> wrote:
>>

>>> No idea about Darwin/PowerPC though.
>>
>> Right now, anything < 10.4 is not a viable host (without jumping through
>> a lot of hoops, regardless of the c99 requirements)...
>>
>> … but It would be good to continue to support these earlier versions as
>> cross-
>> targets (however, it’s low on my priority list to do any serious lifting
>> there).
>
> ok, good to know.
>
>>> If pre-10.3 is supposed to be
>>> supported, the -mmacosx-version-min=10.3 probably needs to go into
>>> rs6000/darwin.h first.  Iain?
>>
>> I’m not quite sure what you’re proposing here (probably missing something
>> obvious).
>
> At the moment, gcc/testsuite/lib/target-supports.exp
> (add_options_for_c99_runtime) adds -mmacosx-version-min=10.3 to the
> testcase flags on powerpc-*-darwin*.  Since, as Joseph mentioned, gcc
> now defaults to -std=gnu11 (which implies a C99 runtime), this (or
> something similar) would always be needed now (unless someone forces,
> say, -std=c90) and should be handled in the Darwin/PowerPC driver code,
> not just the testsuite.

The driver has the following rules:

   * if the user puts -mmacosx-version-min= on the command line that trumps all

   * else we pick a default using the following priority.
     1. MACOSX_DEPLOYMENT_TARGET env var.
     2. (native)
          - what the kernel returns for the system version.
         (cross)
          - what was set at configure time for DEF_MIN_OSX_VERSION (which will
            be >= 10.3.9 as things stand)

So, of course, if we were hosted on 10.2.8 - that would create a problem  
(2, native)
but if the system doesn’t have c99 support, that’s a problem anyway.

Otherwise, deliberate mis-configuration or passing -mmacosx-version-min=  in
RUNTESTFLAGS … but we don’t need to support that.

Therefore, I suspect that the addition of the "-mmacosx-version-min=10.3”  
is not
necessary and is a hang-over from older toolchains.

Perhaps, we could have a target_supports_c99 (maybe we already do), since  
it’s
feasible that some embedded platforms might also want that exclusion - that  
would
cover earlier Darwin “automagically” assuming folks remember to apply it.

In any event, there’s no need to hold up fixing this issue,
If there’s any fallout from it on powerpc-darwin9, I should pick it up  
quite quickly, since
it’s tested regularly.

thanks,
Iain
Rainer Orth Oct. 10, 2019, 12:22 p.m. UTC | #7
Hi Iain,

>>> I’m not quite sure what you’re proposing here (probably missing something
>>> obvious).
>>
>> At the moment, gcc/testsuite/lib/target-supports.exp
>> (add_options_for_c99_runtime) adds -mmacosx-version-min=10.3 to the
>> testcase flags on powerpc-*-darwin*.  Since, as Joseph mentioned, gcc
>> now defaults to -std=gnu11 (which implies a C99 runtime), this (or
>> something similar) would always be needed now (unless someone forces,
>> say, -std=c90) and should be handled in the Darwin/PowerPC driver code,
>> not just the testsuite.
>
> The driver has the following rules:
>
>   * if the user puts -mmacosx-version-min= on the command line that trumps all
>
>   * else we pick a default using the following priority.
>     1. MACOSX_DEPLOYMENT_TARGET env var.
>     2. (native)
>          - what the kernel returns for the system version.
>         (cross)
>          - what was set at configure time for DEF_MIN_OSX_VERSION (which will
>            be >= 10.3.9 as things stand)
>
> So, of course, if we were hosted on 10.2.8 - that would create a problem
> (2, native)
> but if the system doesn’t have c99 support, that’s a problem anyway.
>
> Otherwise, deliberate mis-configuration or passing -mmacosx-version-min=  in
> RUNTESTFLAGS … but we don’t need to support that.

Right: users should be allowed to shoot themselves ;-)

> Therefore, I suspect that the addition of the "-mmacosx-version-min=10.3”
> is not
> necessary and is a hang-over from older toolchains.

I know now what's going on...

> Perhaps, we could have a target_supports_c99 (maybe we already do), since
> it’s
> feasible that some embedded platforms might also want that exclusion - that
> would
> cover earlier Darwin “automagically” assuming folks remember to apply it.

We do, and it's unsurprisingly called c99_runtime, too: in this as in a
few other cases where a specific feature may need additional options to
enable it, we have dg-add-options <option keyword> corresponding to the
<effective target keyword>.

What's happening for c99_runtime, as can be seen in
lib/target-supports.exp (check_effective_target_c99_runtime) is that it
checks gcc.dg/builtins-config.h for a definition of HAVE_C99_RUNTIME.

In the Darwin/PowerPC case, that isn't defined before 10.3, skipping the
affected tests.  However, if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
isn't defined, builtins-config.h #error's out.  Fortunately, gcc on
Darwin always passes -mmacosx-version-min now, so there's no need to
explicitly pass it in add_options_for_c99_runtime and that proc together
with all calls to dg-add-options c99_runtime can go unless something
really unexpected comes up during Solaris testing.

> In any event, there’s no need to hold up fixing this issue,
> If there’s any fallout from it on powerpc-darwin9, I should pick it up
> quite quickly, since
> it’s tested regularly.

Amazing, 14 years after the end of OS updates.  And I thought I were
dealing with software versions right from the museum ;-)

	Rainer
Rainer Orth Oct. 13, 2019, 11:46 a.m. UTC | #8
Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> writes:

>>>> I’m not quite sure what you’re proposing here (probably missing something
>>>> obvious).
>>>
>>> At the moment, gcc/testsuite/lib/target-supports.exp
>>> (add_options_for_c99_runtime) adds -mmacosx-version-min=10.3 to the
>>> testcase flags on powerpc-*-darwin*.  Since, as Joseph mentioned, gcc
>>> now defaults to -std=gnu11 (which implies a C99 runtime), this (or
>>> something similar) would always be needed now (unless someone forces,
>>> say, -std=c90) and should be handled in the Darwin/PowerPC driver code,
>>> not just the testsuite.
>>
>> The driver has the following rules:
>>
>>   * if the user puts -mmacosx-version-min= on the command line that trumps all
>>
>>   * else we pick a default using the following priority.
>>     1. MACOSX_DEPLOYMENT_TARGET env var.
>>     2. (native)
>>          - what the kernel returns for the system version.
>>         (cross)
>>          - what was set at configure time for DEF_MIN_OSX_VERSION (which will
>>            be >= 10.3.9 as things stand)
>>
>> So, of course, if we were hosted on 10.2.8 - that would create a problem
>> (2, native)
>> but if the system doesn’t have c99 support, that’s a problem anyway.
>>
>> Otherwise, deliberate mis-configuration or passing -mmacosx-version-min=  in
>> RUNTESTFLAGS … but we don’t need to support that.
>
> Right: users should be allowed to shoot themselves ;-)
>
>> Therefore, I suspect that the addition of the "-mmacosx-version-min=10.3”
>> is not
>> necessary and is a hang-over from older toolchains.
>
> I know now what's going on...
>
>> Perhaps, we could have a target_supports_c99 (maybe we already do), since
>> it’s
>> feasible that some embedded platforms might also want that exclusion - that
>> would
>> cover earlier Darwin “automagically” assuming folks remember to apply it.
>
> We do, and it's unsurprisingly called c99_runtime, too: in this as in a
> few other cases where a specific feature may need additional options to
> enable it, we have dg-add-options <option keyword> corresponding to the
> <effective target keyword>.
>
> What's happening for c99_runtime, as can be seen in
> lib/target-supports.exp (check_effective_target_c99_runtime) is that it
> checks gcc.dg/builtins-config.h for a definition of HAVE_C99_RUNTIME.
>
> In the Darwin/PowerPC case, that isn't defined before 10.3, skipping the
> affected tests.  However, if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
> isn't defined, builtins-config.h #error's out.  Fortunately, gcc on
> Darwin always passes -mmacosx-version-min now, so there's no need to
> explicitly pass it in add_options_for_c99_runtime and that proc together
> with all calls to dg-add-options c99_runtime can go unless something
> really unexpected comes up during Solaris testing.

Here's what I installed after successful i386-pc-solaris2.11,
sparc-sun-solaris2.11, and x86_64-pc-linux-gnu testing.

	Rainer

Patch
diff mbox series

Index: gcc/c-family/c-opts.c
===================================================================
--- gcc/c-family/c-opts.c	(revision 276655)
+++ gcc/c-family/c-opts.c	(working copy)
@@ -826,6 +826,12 @@  c_common_post_options (const char **pfilename)
   else
     flag_permitted_flt_eval_methods = PERMITTED_FLT_EVAL_METHODS_C11;
 
+  /* C2X Annex F does not permit certain built-in functions to raise
+     "inexact".  */
+  if (flag_isoc2x
+      && !global_options_set.x_flag_fp_int_builtin_inexact)
+    flag_fp_int_builtin_inexact = 0;
+
   /* By default we use C99 inline semantics in GNU99 or C99 mode.  C99
      inline semantics are not supported in GNU89 or C89 mode.  */
   if (flag_gnu89_inline == -1)
Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi	(revision 276655)
+++ gcc/doc/invoke.texi	(working copy)
@@ -10810,12 +10810,12 @@  Do not allow the built-in functions @code{ceil}, @
 double} variants, to generate code that raises the ``inexact''
 floating-point exception for noninteger arguments.  ISO C99 and C11
 allow these functions to raise the ``inexact'' exception, but ISO/IEC
-TS 18661-1:2014, the C bindings to IEEE 754-2008, does not allow these
-functions to do so.
+TS 18661-1:2014, the C bindings to IEEE 754-2008, as integrated into
+ISO C2X, does not allow these functions to do so.
 
 The default is @option{-ffp-int-builtin-inexact}, allowing the
-exception to be raised.  This option does nothing unless
-@option{-ftrapping-math} is in effect.
+exception to be raised, unless C2X or a later C standard is selected.
+This option does nothing unless @option{-ftrapping-math} is in effect.
 
 Even if @option{-fno-fp-int-builtin-inexact} is used, if the functions
 generate a call to a library function then the ``inexact'' exception
Index: gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-c2x.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-c2x.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-c2x.c	(working copy)
@@ -0,0 +1,7 @@ 
+/* Test C2X enables -fno-fp-int-builtin-inexact.  */
+/* { dg-do run } */
+/* { dg-options "-std=c2x" } */
+/* { dg-add-options c99_runtime } */
+/* { dg-require-effective-target fenv_exceptions } */
+
+#include "builtin-fp-int-inexact.c"