From patchwork Tue Oct 27 00:44:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 1388229 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CKtJJ64wlz9sT6 for ; Tue, 27 Oct 2020 11:44:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 57303386180A; Tue, 27 Oct 2020 00:44:27 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id B72113857C61 for ; Tue, 27 Oct 2020 00:44:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B72113857C61 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=joseph_myers@mentor.com IronPort-SDR: jrAVqZDQLFj+aF74aa07Jfz06jkAhvrHKLlCDrv/+I1oBB7uyc22o9JSbGom84EmiRbnpYx4MU qpBzzmH7u6A3FfRaAu2F8Q8Nl0F7Xoso5LHS8Z9qDh343+130v/JxuyEIOVIyLih3rA0pdZhvC Bc8U/KP6L7DbmHtesLoxZk6a9PIl2pnWIDretRF4Ynt9vLXxsGX91OmMpzJFqxcRfjQeH0df29 QEkBpqu2alnK+hjelmeoPJfT0UMLNEK7zyq2X0Fq2F9MHmVwmNWSND/wDws2SgE2tfY7WPTki2 qes= X-IronPort-AV: E=Sophos;i="5.77,421,1596528000"; d="scan'208";a="54353078" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 26 Oct 2020 16:44:21 -0800 IronPort-SDR: lfbsaLWhXEF81Mta3HSluPhb9BQJih+GzDXGgpFUV2XfidFjC7k+TOFovKZ7fCgZ0zHasxCHRu tI26leElJQNiZA53KFrZ4cJV+RJsbCIkGGIc4X2Gg4h3wcxgZ64JPvP3GMixwUm9UkTApt1c5U ZKhzMH7hz+RdKJPOzQ9ClMIWt/zdgoMzncoGzWp3qRc5v1CZEiXNfphoXLJ+yeXoip0wZChCq0 7hY/2i6Di/KWp49nlnwkwAk4LdgsDtuC/+hFcuNC0G4Ft82KtIlgUKRx5f6p2fs6WOCu+RjSGD OH4= Date: Tue, 27 Oct 2020 00:44:14 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: Subject: float.h: C2x NaN and Inf macros Message-ID: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-09.mgc.mentorg.com (139.181.222.9) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-3132.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" C2x adds macros for NaNs and infinities to , some of them previously in (and some still in as well in C2x as an obsolescent feature). Add these macros to GCC's implementation. This omits the macros for DFP signaling NaNs, leaving those to be added in a separate patch which will also need to add corresponding built-in functions (GCC doesn't currently have built-in functions for DFP signaling NaNs, only quiet ones). However, it includes the _FloatN / _FloatNx macros (conditional on __STDC_WANT_IEC_60559_TYPES_EXT__) in the current draft version of the integration of TS 18661-3 into C2x as an Annex. As GCC allows duplicate macro definitions with different expansions in system headers, it should be OK if defines INFINITY or NAN with a slightly different expansion (e.g. different choice of whether there is whitespace between tokens); tests are added including and in either order. Because uses #undef on all macros before defining them, even with -Wsystem-headers there could only ever be issues when is included after . Bootstrapped with no regressions on x86_64-pc-linux-gnu. OK to commit? gcc/ 2020-10-27 Joseph Myers * ginclude/float.h (INFINITY, NAN, FLT_SNAN, DBL_SNAN, LDBL_SNAN) (FLT16_SNAN, FLT32_SNAN, FLT64_SNAN, FLT128_SNAN, FLT32X_SNAN) (FLT64X_SNAN, FLT128X_SNAN, DEC_INFINITY, DEC_NAN): New C2x macros. * doc/sourcebuild.texi (Effective-Target Keywords): Document inff. gcc/testsuite/ 2020-10-27 Joseph Myers * lib/target-supports.exp (check_effective_target_inff): New. * gcc.dg/c11-float-4.c, gcc.dg/c11-float-5.c, gcc.dg/c11-float-dfp-2.c, gcc.dg/c2x-float-2.c, gcc.dg/c2x-float-3.c, gcc.dg/c2x-float-4.c, gcc.dg/c2x-float-5.c, gcc.dg/c2x-float-6.c, gcc.dg/c2x-float-7.c, gcc.dg/c2x-float-8.c, gcc.dg/c2x-float-9.c, gcc.dg/c2x-float-no-dfp-3.c, gcc.dg/c2x-float-no-dfp-4.c, gcc.dg/dfp/c2x-float-dfp-4.c, gcc.dg/dfp/c2x-float-dfp-5.c, gcc.dg/dfp/c2x-float-dfp-6.c, gcc.dg/torture/float128-nan-floath.c, gcc.dg/torture/float128x-nan-floath.c, gcc.dg/torture/float16-nan-floath.c, gcc.dg/torture/float32-nan-floath.c, gcc.dg/torture/float32x-nan-floath.c, gcc.dg/torture/float64-nan-floath.c, gcc.dg/torture/float64x-nan-floath.c, gcc.dg/torture/floatn-nan-floath.h: New tests. diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi index 49316a5d0ff..726f1c96dab 100644 --- a/gcc/doc/sourcebuild.texi +++ b/gcc/doc/sourcebuild.texi @@ -1443,6 +1443,10 @@ Target has runtime support for any options added with @item inf Target supports floating point infinite (@code{inf}) for type @code{double}. + +@item inff +Target supports floating point infinite (@code{inf}) for type +@code{float}. @end table @subsubsection Fortran-specific attributes diff --git a/gcc/ginclude/float.h b/gcc/ginclude/float.h index 9c4b0385568..77446995515 100644 --- a/gcc/ginclude/float.h +++ b/gcc/ginclude/float.h @@ -248,6 +248,32 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define DBL_NORM_MAX __DBL_NORM_MAX__ #define LDBL_NORM_MAX __LDBL_NORM_MAX__ +/* Infinity in type float, or overflow if infinity not supported. */ +#undef INFINITY +#define INFINITY (__builtin_inff ()) + +/* Quiet NaN, if supported for float. */ +#if __FLT_HAS_QUIET_NAN__ +#undef NAN +#define NAN (__builtin_nanf ("")) +#endif + +/* Signaling NaN, if supported for each type. All formats supported + by GCC support either both quiet and signaling NaNs, or neither + kind of NaN. */ +#if __FLT_HAS_QUIET_NAN__ +#undef FLT_SNAN +#define FLT_SNAN (__builtin_nansf ("")) +#endif +#if __DBL_HAS_QUIET_NAN__ +#undef DBL_SNAN +#define DBL_SNAN (__builtin_nans ("")) +#endif +#if __LDBL_HAS_QUIET_NAN__ +#undef LDBL_SNAN +#define LDBL_SNAN (__builtin_nansl ("")) +#endif + #endif /* C2X */ #ifdef __STDC_WANT_IEC_60559_BFP_EXT__ @@ -284,6 +310,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define FLT16_DECIMAL_DIG __FLT16_DECIMAL_DIG__ #undef FLT16_TRUE_MIN #define FLT16_TRUE_MIN __FLT16_DENORM_MIN__ +#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L +#undef FLT16_SNAN +#define FLT16_SNAN (__builtin_nansf16 ("")) +#endif /* C2X */ #endif /* __FLT16_MANT_DIG__. */ #ifdef __FLT32_MANT_DIG__ @@ -309,6 +339,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define FLT32_DECIMAL_DIG __FLT32_DECIMAL_DIG__ #undef FLT32_TRUE_MIN #define FLT32_TRUE_MIN __FLT32_DENORM_MIN__ +#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L +#undef FLT32_SNAN +#define FLT32_SNAN (__builtin_nansf32 ("")) +#endif /* C2X */ #endif /* __FLT32_MANT_DIG__. */ #ifdef __FLT64_MANT_DIG__ @@ -334,6 +368,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define FLT64_DECIMAL_DIG __FLT64_DECIMAL_DIG__ #undef FLT64_TRUE_MIN #define FLT64_TRUE_MIN __FLT64_DENORM_MIN__ +#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L +#undef FLT64_SNAN +#define FLT64_SNAN (__builtin_nansf64 ("")) +#endif /* C2X */ #endif /* __FLT64_MANT_DIG__. */ #ifdef __FLT128_MANT_DIG__ @@ -359,6 +397,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define FLT128_DECIMAL_DIG __FLT128_DECIMAL_DIG__ #undef FLT128_TRUE_MIN #define FLT128_TRUE_MIN __FLT128_DENORM_MIN__ +#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L +#undef FLT128_SNAN +#define FLT128_SNAN (__builtin_nansf128 ("")) +#endif /* C2X */ #endif /* __FLT128_MANT_DIG__. */ #ifdef __FLT32X_MANT_DIG__ @@ -384,6 +426,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define FLT32X_DECIMAL_DIG __FLT32X_DECIMAL_DIG__ #undef FLT32X_TRUE_MIN #define FLT32X_TRUE_MIN __FLT32X_DENORM_MIN__ +#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L +#undef FLT32X_SNAN +#define FLT32X_SNAN (__builtin_nansf32x ("")) +#endif /* C2X */ #endif /* __FLT32X_MANT_DIG__. */ #ifdef __FLT64X_MANT_DIG__ @@ -409,6 +455,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define FLT64X_DECIMAL_DIG __FLT64X_DECIMAL_DIG__ #undef FLT64X_TRUE_MIN #define FLT64X_TRUE_MIN __FLT64X_DENORM_MIN__ +#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L +#undef FLT64X_SNAN +#define FLT64X_SNAN (__builtin_nansf64x ("")) +#endif /* C2X */ #endif /* __FLT64X_MANT_DIG__. */ #ifdef __FLT128X_MANT_DIG__ @@ -434,6 +484,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define FLT128X_DECIMAL_DIG __FLT128X_DECIMAL_DIG__ #undef FLT128X_TRUE_MIN #define FLT128X_TRUE_MIN __FLT128X_DENORM_MIN__ +#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L +#undef FLT128X_SNAN +#define FLT128X_SNAN (__builtin_nansf128x ("")) +#endif /* C2X */ #endif /* __FLT128X_MANT_DIG__. */ #endif /* __STDC_WANT_IEC_60559_TYPES_EXT__. */ @@ -537,6 +591,18 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #endif /* __STDC_WANT_IEC_60559_DFP_EXT__ || C2X. */ +#if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L + +/* Infinity in type _Decimal32. */ +#undef DEC_INFINITY +#define DEC_INFINITY (__builtin_infd32 ()) + +/* Quiet NaN in type _Decimal32. */ +#undef DEC_NAN +#define DEC_NAN (__builtin_nand32 ("")) + +#endif /* C2X */ + #endif /* __DEC32_MANT_DIG__ */ #endif /* _FLOAT_H___ */ diff --git a/gcc/testsuite/gcc.dg/c11-float-4.c b/gcc/testsuite/gcc.dg/c11-float-4.c new file mode 100644 index 00000000000..ceac6ef5063 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-float-4.c @@ -0,0 +1,25 @@ +/* Test infinity and NaN macros not defined for C11. */ +/* { dg-do preprocess } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include + +#ifdef INFINITY +#error "INFINITY defined" +#endif + +#ifdef NAN +#error "NAN defined" +#endif + +#ifdef FLT_SNAN +#error "FLT_SNAN defined" +#endif + +#ifdef DBL_SNAN +#error "DBL_SNAN defined" +#endif + +#ifdef LDBL_SNAN +#error "LDBL_SNAN defined" +#endif diff --git a/gcc/testsuite/gcc.dg/c11-float-5.c b/gcc/testsuite/gcc.dg/c11-float-5.c new file mode 100644 index 00000000000..bb48695599b --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-float-5.c @@ -0,0 +1,35 @@ +/* Test sNaN macros for _FloatN and _FloatNx not defined for C11 with + __STDC_WANT_IEC_60559_TYPES_EXT__. */ +/* { dg-do preprocess } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#define __STDC_WANT_IEC_60559_TYPES_EXT__ +#include + +#ifdef FLT16_SNAN +#error "FLT16_SNAN defined" +#endif + +#ifdef FLT32_SNAN +#error "FLT32_SNAN defined" +#endif + +#ifdef FLT64_SNAN +#error "FLT64_SNAN defined" +#endif + +#ifdef FLT128_SNAN +#error "FLT128_SNAN defined" +#endif + +#ifdef FLT32X_SNAN +#error "FLT32X_SNAN defined" +#endif + +#ifdef FLT64X_SNAN +#error "FLT64X_SNAN defined" +#endif + +#ifdef FLT128X_SNAN +#error "FLT128X_SNAN defined" +#endif diff --git a/gcc/testsuite/gcc.dg/c11-float-dfp-2.c b/gcc/testsuite/gcc.dg/c11-float-dfp-2.c new file mode 100644 index 00000000000..e63ebbcb0f2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-float-dfp-2.c @@ -0,0 +1,6 @@ +/* Test DFP macros not defined in for C11. Infinity and NaN + macros. */ +/* { dg-do compile } */ +/* { dg-options "-std=c11" } */ + +#include "c2x-float-no-dfp-3.c" diff --git a/gcc/testsuite/gcc.dg/c2x-float-2.c b/gcc/testsuite/gcc.dg/c2x-float-2.c new file mode 100644 index 00000000000..4f669fd39bc --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-float-2.c @@ -0,0 +1,23 @@ +/* Test INFINITY macro. Generic test even if infinities not + supported. */ +/* { dg-do run } */ +/* { dg-options "-std=c2x -w" } */ +/* { dg-add-options ieee } */ + +#include + +#ifndef INFINITY +#error "INFINITY undefined" +#endif + +extern void abort (void); +extern void exit (int); + +int +main (void) +{ + (void) _Generic (INFINITY, float : 0); + if (!(INFINITY >= FLT_MAX)) + abort (); + exit (0); +} diff --git a/gcc/testsuite/gcc.dg/c2x-float-3.c b/gcc/testsuite/gcc.dg/c2x-float-3.c new file mode 100644 index 00000000000..7c6298b8efb --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-float-3.c @@ -0,0 +1,27 @@ +/* Test INFINITY macro. Test when infinities supported. */ +/* { dg-do run } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-add-options ieee } */ +/* { dg-require-effective-target inff } */ + +#include + +#ifndef INFINITY +#error "INFINITY undefined" +#endif + +volatile float f = INFINITY; + +extern void abort (void); +extern void exit (int); + +int +main (void) +{ + (void) _Generic (INFINITY, float : 0); + if (!(INFINITY > FLT_MAX)) + abort (); + if (!(f > FLT_MAX)) + abort (); + exit (0); +} diff --git a/gcc/testsuite/gcc.dg/c2x-float-4.c b/gcc/testsuite/gcc.dg/c2x-float-4.c new file mode 100644 index 00000000000..bca843547c5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-float-4.c @@ -0,0 +1,33 @@ +/* Test NAN macro. */ +/* { dg-do run } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-add-options ieee } */ + +#include + +/* This should be defined if and only if quiet NaNs are supported for + type float. If the testsuite gains effective-target support for + targets not supporting NaNs, or not supporting them for all types, + this test should be split into versions for targets with and + without NaNs for float. */ +#ifndef NAN +#error "NAN undefined" +#endif + +volatile float f = NAN; + +extern void abort (void); +extern void exit (int); + +int +main (void) +{ + (void) _Generic (NAN, float : 0); + if (!__builtin_isnan (NAN)) + abort (); + if (!__builtin_isnan (f)) + abort (); + if (!__builtin_isnan (f + f)) + abort (); + exit (0); +} diff --git a/gcc/testsuite/gcc.dg/c2x-float-5.c b/gcc/testsuite/gcc.dg/c2x-float-5.c new file mode 100644 index 00000000000..477f9cf09c6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-float-5.c @@ -0,0 +1,32 @@ +/* Test NAN macro. Runtime exceptions test, to verify NaN is quiet + not signaling. */ +/* { dg-do run } */ +/* { dg-require-effective-target fenv_exceptions } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ +/* { dg-add-options ieee } */ + +#include +#include + +/* This should be defined if and only if quiet NaNs are supported for + type float. If the testsuite gains effective-target support for + targets not supporting NaNs, or not supporting them for all types, + this test should only be run for targets supporting quiet NaNs for + float. */ +#ifndef NAN +#error "NAN undefined" +#endif + +volatile float f = NAN; + +extern void abort (void); +extern void exit (int); + +int +main (void) +{ + f += f; + if (fetestexcept (FE_INVALID)) + abort (); + exit (0); +} diff --git a/gcc/testsuite/gcc.dg/c2x-float-6.c b/gcc/testsuite/gcc.dg/c2x-float-6.c new file mode 100644 index 00000000000..573540b0381 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-float-6.c @@ -0,0 +1,49 @@ +/* Test SNAN macros. */ +/* { dg-do run } */ +/* { dg-options "-std=c2x -pedantic-errors -fsignaling-nans" } */ +/* { dg-add-options ieee } */ + +#include + +/* These should be defined if and only if signaling NaNs are supported + for the given types. If the testsuite gains effective-target + support for targets not supporting signaling NaNs, or not + supporting them for all types, this test should be made + appropriately conditional. */ +#ifndef FLT_SNAN +#error "FLT_SNAN undefined" +#endif +#ifndef DBL_SNAN +#error "DBL_SNAN undefined" +#endif +#ifndef LDBL_SNAN +#error "LDBL_SNAN undefined" +#endif + +volatile float f = FLT_SNAN; +volatile double d = DBL_SNAN; +volatile long double ld = LDBL_SNAN; + +extern void abort (void); +extern void exit (int); + +int +main (void) +{ + (void) _Generic (FLT_SNAN, float : 0); + (void) _Generic (DBL_SNAN, double : 0); + (void) _Generic (LDBL_SNAN, long double : 0); + if (!__builtin_isnan (FLT_SNAN)) + abort (); + if (!__builtin_isnan (f)) + abort (); + if (!__builtin_isnan (DBL_SNAN)) + abort (); + if (!__builtin_isnan (d)) + abort (); + if (!__builtin_isnan (LDBL_SNAN)) + abort (); + if (!__builtin_isnan (ld)) + abort (); + exit (0); +} diff --git a/gcc/testsuite/gcc.dg/c2x-float-7.c b/gcc/testsuite/gcc.dg/c2x-float-7.c new file mode 100644 index 00000000000..0c90ff24165 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-float-7.c @@ -0,0 +1,49 @@ +/* Test SNAN macros. Runtime exceptions test, to verify NaN is + signaling. */ +/* { dg-do run } */ +/* { dg-require-effective-target fenv_exceptions } */ +/* { dg-options "-std=c2x -pedantic-errors -fsignaling-nans" } */ +/* { dg-add-options ieee } */ + +#include +#include + +/* These should be defined if and only if signaling NaNs are supported + for the given types. If the testsuite gains effective-target + support for targets not supporting signaling NaNs, or not + supporting them for all types, this test should be made + appropriately conditional. */ +#ifndef FLT_SNAN +#error "FLT_SNAN undefined" +#endif +#ifndef DBL_SNAN +#error "DBL_SNAN undefined" +#endif +#ifndef LDBL_SNAN +#error "LDBL_SNAN undefined" +#endif + +volatile float f = FLT_SNAN; +volatile double d = DBL_SNAN; +volatile long double ld = LDBL_SNAN; + +extern void abort (void); +extern void exit (int); + +int +main (void) +{ + feclearexcept (FE_ALL_EXCEPT); + f += f; + if (!fetestexcept (FE_INVALID)) + abort (); + feclearexcept (FE_ALL_EXCEPT); + d += d; + if (!fetestexcept (FE_INVALID)) + abort (); + feclearexcept (FE_ALL_EXCEPT); + ld += ld; + if (!fetestexcept (FE_INVALID)) + abort (); + exit (0); +} diff --git a/gcc/testsuite/gcc.dg/c2x-float-8.c b/gcc/testsuite/gcc.dg/c2x-float-8.c new file mode 100644 index 00000000000..b10cb850091 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-float-8.c @@ -0,0 +1,7 @@ +/* Test including then does not result in errors + from duplicate NAN and INFINITY macros. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ + +#include +#include diff --git a/gcc/testsuite/gcc.dg/c2x-float-9.c b/gcc/testsuite/gcc.dg/c2x-float-9.c new file mode 100644 index 00000000000..0a54bc2ad4c --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-float-9.c @@ -0,0 +1,7 @@ +/* Test including then does not result in errors + from duplicate NAN and INFINITY macros. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ + +#include +#include diff --git a/gcc/testsuite/gcc.dg/c2x-float-no-dfp-3.c b/gcc/testsuite/gcc.dg/c2x-float-no-dfp-3.c new file mode 100644 index 00000000000..d8a239c787e --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-float-no-dfp-3.c @@ -0,0 +1,14 @@ +/* Test DFP macros not defined in if no DFP support. + Infinity and NaN macros. */ +/* { dg-do compile { target { ! dfp } } } */ +/* { dg-options "-std=c2x" } */ + +#include + +#ifdef DEC_INFINITY +# error "DEC_INFINITY defined" +#endif + +#ifdef DEC_NAN +# error "DEC_NAN defined" +#endif diff --git a/gcc/testsuite/gcc.dg/c2x-float-no-dfp-4.c b/gcc/testsuite/gcc.dg/c2x-float-no-dfp-4.c new file mode 100644 index 00000000000..855922a47b6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-float-no-dfp-4.c @@ -0,0 +1,10 @@ +/* Test DFP macros not defined in if no DFP support. + Infinity and NaN macros. Test with feature test macros + defined. */ +/* { dg-do compile { target { ! dfp } } } */ +/* { dg-options "-std=c2x" } */ + +#define __STDC_WANT_DEC_FP__ +#define __STDC_WANT_IEC_60559_DFP_EXT__ + +#include "c2x-float-no-dfp-3.c" diff --git a/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-4.c b/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-4.c new file mode 100644 index 00000000000..58ee74db484 --- /dev/null +++ b/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-4.c @@ -0,0 +1,25 @@ +/* Test DEC_INFINITY defined in with DFP support. */ +/* { dg-do run } */ +/* { dg-options "-std=c2x" } */ + +#include + +#ifndef DEC_INFINITY +# error "DEC_INFINITY not defined" +#endif + +volatile _Decimal32 d = DEC_INFINITY; + +extern void abort (void); +extern void exit (int); + +int +main (void) +{ + (void) _Generic (DEC_INFINITY, _Decimal32 : 0); + if (!(DEC_INFINITY > DEC32_MAX)) + abort (); + if (!(d > DEC32_MAX)) + abort (); + exit (0); +} diff --git a/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-5.c b/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-5.c new file mode 100644 index 00000000000..8d097255e0e --- /dev/null +++ b/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-5.c @@ -0,0 +1,25 @@ +/* Test DEC_NAN defined in with DFP support. */ +/* { dg-do run } */ +/* { dg-options "-std=c2x" } */ + +#include + +#ifndef DEC_NAN +# error "DEC_NAN not defined" +#endif + +volatile _Decimal32 d = DEC_NAN; + +extern void abort (void); +extern void exit (int); + +int +main (void) +{ + (void) _Generic (DEC_NAN, _Decimal32 : 0); + if (!__builtin_isnan (DEC_NAN)) + abort (); + if (!__builtin_isnan (d)) + abort (); + exit (0); +} diff --git a/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-6.c b/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-6.c new file mode 100644 index 00000000000..4533c61e8e9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-6.c @@ -0,0 +1,28 @@ +/* Test DEC_NAN macro. Runtime exceptions test, to verify NaN is + quiet not signaling. (This would only actually fail for a + signaling NaN in the hardware DFP case, because the software DFP + support in libgcc does not integrate with hardware exceptions.) */ +/* { dg-do run } */ +/* { dg-require-effective-target fenv_exceptions } */ +/* { dg-options "-std=c2x" } */ + +#include +#include + +#ifndef DEC_NAN +# error "DEC_NAN not defined" +#endif + +volatile _Decimal32 d = DEC_NAN; + +extern void abort (void); +extern void exit (int); + +int +main (void) +{ + d += d; + if (fetestexcept (FE_INVALID)) + abort (); + exit (0); +} diff --git a/gcc/testsuite/gcc.dg/torture/float128-nan-floath.c b/gcc/testsuite/gcc.dg/torture/float128-nan-floath.c new file mode 100644 index 00000000000..69fd45a6375 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/float128-nan-floath.c @@ -0,0 +1,11 @@ +/* Test _Float128 NaNs in . */ +/* { dg-do run } */ +/* { dg-options "-std=c2x -fsignaling-nans" } */ +/* { dg-add-options float128 } */ +/* { dg-add-options ieee } */ +/* { dg-require-effective-target float128_runtime } */ +/* { dg-require-effective-target fenv_exceptions } */ + +#define WIDTH 128 +#define EXT 0 +#include "floatn-nan-floath.h" diff --git a/gcc/testsuite/gcc.dg/torture/float128x-nan-floath.c b/gcc/testsuite/gcc.dg/torture/float128x-nan-floath.c new file mode 100644 index 00000000000..5be4c07787d --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/float128x-nan-floath.c @@ -0,0 +1,11 @@ +/* Test _Float128x NaNs in . */ +/* { dg-do run } */ +/* { dg-options "-std=c2x -fsignaling-nans" } */ +/* { dg-add-options float128x } */ +/* { dg-add-options ieee } */ +/* { dg-require-effective-target float128x_runtime } */ +/* { dg-require-effective-target fenv_exceptions } */ + +#define WIDTH 128 +#define EXT 1 +#include "floatn-nan-floath.h" diff --git a/gcc/testsuite/gcc.dg/torture/float16-nan-floath.c b/gcc/testsuite/gcc.dg/torture/float16-nan-floath.c new file mode 100644 index 00000000000..cf03b45a34b --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/float16-nan-floath.c @@ -0,0 +1,11 @@ +/* Test _Float16 NaNs in . */ +/* { dg-do run } */ +/* { dg-options "-std=c2x -fsignaling-nans" } */ +/* { dg-add-options float16 } */ +/* { dg-add-options ieee } */ +/* { dg-require-effective-target float16_runtime } */ +/* { dg-require-effective-target fenv_exceptions } */ + +#define WIDTH 16 +#define EXT 0 +#include "floatn-nan-floath.h" diff --git a/gcc/testsuite/gcc.dg/torture/float32-nan-floath.c b/gcc/testsuite/gcc.dg/torture/float32-nan-floath.c new file mode 100644 index 00000000000..2976a40aec4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/float32-nan-floath.c @@ -0,0 +1,11 @@ +/* Test _Float32 NaNs in . */ +/* { dg-do run } */ +/* { dg-options "-std=c2x -fsignaling-nans" } */ +/* { dg-add-options float32 } */ +/* { dg-add-options ieee } */ +/* { dg-require-effective-target float32_runtime } */ +/* { dg-require-effective-target fenv_exceptions } */ + +#define WIDTH 32 +#define EXT 0 +#include "floatn-nan-floath.h" diff --git a/gcc/testsuite/gcc.dg/torture/float32x-nan-floath.c b/gcc/testsuite/gcc.dg/torture/float32x-nan-floath.c new file mode 100644 index 00000000000..0aab4be26ca --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/float32x-nan-floath.c @@ -0,0 +1,11 @@ +/* Test _Float32x NaNs in . */ +/* { dg-do run } */ +/* { dg-options "-std=c2x -fsignaling-nans" } */ +/* { dg-add-options float32x } */ +/* { dg-add-options ieee } */ +/* { dg-require-effective-target float32x_runtime } */ +/* { dg-require-effective-target fenv_exceptions } */ + +#define WIDTH 32 +#define EXT 1 +#include "floatn-nan-floath.h" diff --git a/gcc/testsuite/gcc.dg/torture/float64-nan-floath.c b/gcc/testsuite/gcc.dg/torture/float64-nan-floath.c new file mode 100644 index 00000000000..1f5298bd399 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/float64-nan-floath.c @@ -0,0 +1,11 @@ +/* Test _Float64 NaNs in . */ +/* { dg-do run } */ +/* { dg-options "-std=c2x -fsignaling-nans" } */ +/* { dg-add-options float64 } */ +/* { dg-add-options ieee } */ +/* { dg-require-effective-target float64_runtime } */ +/* { dg-require-effective-target fenv_exceptions } */ + +#define WIDTH 64 +#define EXT 0 +#include "floatn-nan-floath.h" diff --git a/gcc/testsuite/gcc.dg/torture/float64x-nan-floath.c b/gcc/testsuite/gcc.dg/torture/float64x-nan-floath.c new file mode 100644 index 00000000000..fbc86766d8e --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/float64x-nan-floath.c @@ -0,0 +1,11 @@ +/* Test _Float64x NaNs in . */ +/* { dg-do run } */ +/* { dg-options "-std=c2x -fsignaling-nans" } */ +/* { dg-add-options float64x } */ +/* { dg-add-options ieee } */ +/* { dg-require-effective-target float64x_runtime } */ +/* { dg-require-effective-target fenv_exceptions } */ + +#define WIDTH 64 +#define EXT 1 +#include "floatn-nan-floath.h" diff --git a/gcc/testsuite/gcc.dg/torture/floatn-nan-floath.h b/gcc/testsuite/gcc.dg/torture/floatn-nan-floath.h new file mode 100644 index 00000000000..9892fd0cf63 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/floatn-nan-floath.h @@ -0,0 +1,36 @@ +/* Tests for _FloatN / _FloatNx types: compile and execution tests for + NaNs, SNAN macros in . Before including this file, define + WIDTH as the value N; define EXT to 1 for _FloatNx and 0 for + _FloatN. */ + +#define CONCATX(X, Y) X ## Y +#define CONCAT(X, Y) CONCATX (X, Y) +#define CONCAT3(X, Y, Z) CONCAT (CONCAT (X, Y), Z) +#define CONCAT4(W, X, Y, Z) CONCAT (CONCAT (CONCAT (W, X), Y), Z) + +#if EXT +# define TYPE CONCAT3 (_Float, WIDTH, x) +# define SNAN CONCAT3 (FLT, WIDTH, X_SNAN) +#else +# define TYPE CONCAT (_Float, WIDTH) +# define SNAN CONCAT3 (FLT, WIDTH, _SNAN) +#endif + +#define __STDC_WANT_IEC_60559_TYPES_EXT__ +#include +#include + +extern void exit (int); +extern void abort (void); + +volatile TYPE nans_cst = SNAN; + +int +main (void) +{ + volatile TYPE r; + r = nans_cst + nans_cst; + if (!fetestexcept (FE_INVALID)) + abort (); + exit (0); +} diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index 8439720baea..cbf618f7b37 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -10301,6 +10301,13 @@ proc check_effective_target_inf { } { }] } +# Return 1 if target supports floating point "infinite" for float. +proc check_effective_target_inff { } { + return [check_no_compiler_messages supports_inff assembly { + const float pinf = __builtin_inff (); + }] +} + # Return 1 if the target supports ARMv8.3 Adv.SIMD Complex instructions # instructions, 0 otherwise. The test is valid for ARM and for AArch64. # Record the command line options needed.