public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Joseph Myers <joseph@codesourcery.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: float.h: Do not define INFINITY for C2x when infinities not supported
Date: Thu, 15 Sep 2022 08:40:32 +0200	[thread overview]
Message-ID: <CAFiYyc2sa5NcWVLsYw8hF7yDmmRQAH3CXRBPN05XHHFPnMprTg@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2209142301140.3158477@digraph.polyomino.org.uk>

On Thu, Sep 15, 2022 at 1:02 AM Joseph Myers <joseph@codesourcery.com> wrote:
>
> C2x has changed the rules for defining INFINITY in <float.h> so it is
> no longer defined when float does not support infinities, instead of
> being defined to an expression that overflows at translation time.
> Thus, make the definition conditional on __FLT_HAS_INFINITY__ (this is
> already inside a C2x-conditional part of <float.h>, because previous C
> standard versions only had this macro in <math.h>).
>
> Bootstrapped with no regressions for x86_64-pc-linux-gnu.  Also did a
> spot test of the case of no infinities supported by building cc1 for
> vax-netbsdelf and testing compiling the new c2x-float-11.c test with
> it.

Ok

> gcc/
>         * ginclude/float.h (INFINITY): Define only if
>         [__FLT_HAS_INFINITY__].
>
> gcc/testsuite/
>         * gcc.dg/c2x-float-2.c: Require inff effective-target.
>         * gcc.dg/c2x-float-11.c: New test.
>
> diff --git a/gcc/ginclude/float.h b/gcc/ginclude/float.h
> index 9d368c4afa5..afe4a712878 100644
> --- a/gcc/ginclude/float.h
> +++ b/gcc/ginclude/float.h
> @@ -257,9 +257,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
>  #define DBL_IS_IEC_60559       __DBL_IS_IEC_60559__
>  #define LDBL_IS_IEC_60559      __LDBL_IS_IEC_60559__
>
> -/* Infinity in type float, or overflow if infinity not supported.  */
> +/* Infinity in type float; not defined if infinity not supported.  */
> +#if __FLT_HAS_INFINITY__
>  #undef INFINITY
>  #define INFINITY       (__builtin_inff ())
> +#endif
>
>  /* Quiet NaN, if supported for float.  */
>  #if __FLT_HAS_QUIET_NAN__
> diff --git a/gcc/testsuite/gcc.dg/c2x-float-11.c b/gcc/testsuite/gcc.dg/c2x-float-11.c
> new file mode 100644
> index 00000000000..0e2f3c0c97a
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/c2x-float-11.c
> @@ -0,0 +1,9 @@
> +/* Test INFINITY macro.  Test when infinities not supported.  */
> +/* { dg-do compile { target { ! inff } } } */
> +/* { dg-options "-std=c2x" } */
> +
> +#include <float.h>
> +
> +#ifdef INFINITY
> +#error "INFINITY defined"
> +#endif
> diff --git a/gcc/testsuite/gcc.dg/c2x-float-2.c b/gcc/testsuite/gcc.dg/c2x-float-2.c
> index 4f669fd39bc..61a77f6f2db 100644
> --- a/gcc/testsuite/gcc.dg/c2x-float-2.c
> +++ b/gcc/testsuite/gcc.dg/c2x-float-2.c
> @@ -1,8 +1,8 @@
> -/* Test INFINITY macro.  Generic test even if infinities not
> -   supported.  */
> +/* Test INFINITY macro.  Generic test.  */
>  /* { dg-do run } */
>  /* { dg-options "-std=c2x -w" } */
>  /* { dg-add-options ieee } */
> +/* { dg-require-effective-target inff } */
>
>  #include <float.h>
>
>
> --
> Joseph S. Myers
> joseph@codesourcery.com

      reply	other threads:[~2022-09-15  6:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-14 23:02 Joseph Myers
2022-09-15  6:40 ` Richard Biener [this message]

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=CAFiYyc2sa5NcWVLsYw8hF7yDmmRQAH3CXRBPN05XHHFPnMprTg@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    /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).