public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 3/3] Do not use generic selection in C++ mode
  2017-08-15 17:47 [PATCH 0/3] Fix math.h uses of C++ features Gabriel F. T. Gomes
  2017-08-15 17:47 ` [PATCH 2/3] Provide a C++ version of issignaling that does not use __MATH_TG Gabriel F. T. Gomes
@ 2017-08-15 17:47 ` Gabriel F. T. Gomes
  2017-08-15 19:57   ` Joseph Myers
  2017-08-15 17:48 ` [PATCH 1/3] Do not use __builtin_types_compatible_p in C++ mode (bug 21930) Gabriel F. T. Gomes
  2 siblings, 1 reply; 8+ messages in thread
From: Gabriel F. T. Gomes @ 2017-08-15 17:47 UTC (permalink / raw)
  To: libc-alpha

The logic to protect the use of generic selection (_Generic) does not
check for C or C++ mode, however, generic selection is a C-only
feature.

Tested for powerpc64le.

	* misc/sys/cdefs.h (__HAVE_GENERIC_SELECTION): Define to 0, if
	in C++ mode.
---
 misc/sys/cdefs.h | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
index b3e7f3be96..cfd39d5302 100644
--- a/misc/sys/cdefs.h
+++ b/misc/sys/cdefs.h
@@ -463,17 +463,18 @@
 # define __glibc_macro_warning(msg)
 #endif
 
-/* Support for generic selection (ISO C11) is available in GCC since
-   version 4.9.  Previous versions do not provide generic selection,
-   even though they might set __STDC_VERSION__ to 201112L, when in
-   -std=c11 mode.  Thus, we must check for !defined __GNUC__ when
-   testing __STDC_VERSION__ for generic selection support.
+/* Generic selection (ISO C11) is a C-only feature, available in GCC
+   since version 4.9.  Previous versions do not provide generic
+   selection, even though they might set __STDC_VERSION__ to 201112L,
+   when in -std=c11 mode.  Thus, we must check for !defined __GNUC__
+   when testing __STDC_VERSION__ for generic selection support.
    On the other hand, Clang also defines __GNUC__, so a clang-specific
    check is required to enable the use of generic selection.  */
-#if __GNUC_PREREQ (4, 9) \
-    || __glibc_clang_has_extension (c_generic_selections) \
-    || (!defined __GNUC__ && defined __STDC_VERSION__ \
-	&& __STDC_VERSION__ >= 201112L)
+#if !defined __cplusplus \
+    && (__GNUC_PREREQ (4, 9) \
+	|| __glibc_clang_has_extension (c_generic_selections) \
+	|| (!defined __GNUC__ && defined __STDC_VERSION__ \
+	    && __STDC_VERSION__ >= 201112L))
 # define __HAVE_GENERIC_SELECTION 1
 #else
 # define __HAVE_GENERIC_SELECTION 0
-- 
2.13.5

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

* [PATCH 2/3] Provide a C++ version of issignaling that does not use __MATH_TG
  2017-08-15 17:47 [PATCH 0/3] Fix math.h uses of C++ features Gabriel F. T. Gomes
@ 2017-08-15 17:47 ` Gabriel F. T. Gomes
  2017-08-15 19:59   ` Joseph Myers
  2017-08-15 17:47 ` [PATCH 3/3] Do not use generic selection in C++ mode Gabriel F. T. Gomes
  2017-08-15 17:48 ` [PATCH 1/3] Do not use __builtin_types_compatible_p in C++ mode (bug 21930) Gabriel F. T. Gomes
  2 siblings, 1 reply; 8+ messages in thread
From: Gabriel F. T. Gomes @ 2017-08-15 17:47 UTC (permalink / raw)
  To: libc-alpha

The macro __MATH_TG contains the logic to select between long double and
_Float128, when these types are ABI-distinct.  This logic relies on
__builtin_types_compatible_p, which is not available in C++ mode.

On the other hand, C++ function overloading provides the means to
distinguish between the floating-point types.  The overloading
resolution will match the correct parameter regardless of type
qualifiers, i.e.: const and volatile.

Tested for powerpc64le.

	* math/math.h [defined __cplusplus] (issignaling): Provide a C++
	definition for issignaling that does not rely on __MATH_TG,
	since __MATH_TG uses __builtin_types_compatible_p, which is only
	available in C mode.
---
 math/math.h | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/math/math.h b/math/math.h
index dea8dbe1ae..1d6cdb0685 100644
--- a/math/math.h
+++ b/math/math.h
@@ -474,7 +474,24 @@ enum
 # include <bits/iscanonical.h>
 
 /* Return nonzero value if X is a signaling NaN.  */
-# define issignaling(x) __MATH_TG ((x), __issignaling, (x))
+# ifndef __cplusplus
+#  define issignaling(x) __MATH_TG ((x), __issignaling, (x))
+# else
+   /* In C++ mode, __MATH_TG cannot be used, because it relies on
+      __builtin_types_compatible_p, which is a C-only builtin.  On the
+      other hand, overloading provides the means to distinguish between
+      the floating-point types.  The overloading resolution will match
+      the correct parameter (regardless of type qualifiers (i.e.: const
+      and volatile).  */
+extern "C++" {
+int issignaling (float __val) { return __issignalingf (__val); }
+int issignaling (double __val) { return __issignaling (__val); }
+int issignaling (long double __val) { return __issignalingl (__val); }
+#if __HAVE_DISTINCT_FLOAT128
+int issignaling (_Float128  __val) { return __issignalingf128 (__val); }
+#endif
+} /* extern C++ */
+# endif
 
 /* Return nonzero value if X is subnormal.  */
 # define issubnormal(x) (fpclassify (x) == FP_SUBNORMAL)
-- 
2.13.5

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

* [PATCH 0/3] Fix math.h uses of C++ features
@ 2017-08-15 17:47 Gabriel F. T. Gomes
  2017-08-15 17:47 ` [PATCH 2/3] Provide a C++ version of issignaling that does not use __MATH_TG Gabriel F. T. Gomes
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Gabriel F. T. Gomes @ 2017-08-15 17:47 UTC (permalink / raw)
  To: libc-alpha



Gabriel F. T. Gomes (3):
  Do not use __builtin_types_compatible_p in C++ mode (bug 21930)
  Provide a C++ version of issignaling that does not use __MATH_TG
  Do not use generic selection in C++ mode

 math/math.h      | 25 ++++++++++++++++++++++---
 misc/sys/cdefs.h | 19 ++++++++++---------
 2 files changed, 32 insertions(+), 12 deletions(-)

-- 
2.13.5

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

* [PATCH 1/3] Do not use __builtin_types_compatible_p in C++ mode (bug 21930)
  2017-08-15 17:47 [PATCH 0/3] Fix math.h uses of C++ features Gabriel F. T. Gomes
  2017-08-15 17:47 ` [PATCH 2/3] Provide a C++ version of issignaling that does not use __MATH_TG Gabriel F. T. Gomes
  2017-08-15 17:47 ` [PATCH 3/3] Do not use generic selection in C++ mode Gabriel F. T. Gomes
@ 2017-08-15 17:48 ` Gabriel F. T. Gomes
  2017-08-15 19:56   ` Joseph Myers
  2 siblings, 1 reply; 8+ messages in thread
From: Gabriel F. T. Gomes @ 2017-08-15 17:48 UTC (permalink / raw)
  To: libc-alpha

The logic to define isinf for float128 depends on the availability of
__builtin_types_compatible_p, which is only available in C mode,
however, the conditionals do not check for C or C++ mode.  This lead to
an error in libstdc++ configure, as reported by bug 21930.

This patch adds a conditional for C mode in the definition of isinf for
float128.  No definition is provided in C++ mode, since libstdc++
headers undefine isinf.

Tested for powerpc64le (glibc test suite and libstdc++-v3 configure).

	[BZ #21930]
	* math/math.h (isinf): Check if in C or C++ mode before using
	__builtin_types_compatible_p, since this is a C mode feature.
---
 math/math.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/math/math.h b/math/math.h
index e21708045a..dea8dbe1ae 100644
--- a/math/math.h
+++ b/math/math.h
@@ -442,8 +442,12 @@ enum
 
 /* Return nonzero value if X is positive or negative infinity.  */
 # if __HAVE_DISTINCT_FLOAT128 && !__GNUC_PREREQ (7,0) \
-     && !defined __SUPPORT_SNAN__
-   /* __builtin_isinf_sign is broken for float128 only before GCC 7.0.  */
+     && !defined __SUPPORT_SNAN__ && !defined __cplusplus
+   /* Since __builtin_isinf_sign is broken for float128 before GCC 7.0,
+      use the helper function, __isinff128, with older compilers.  This is
+      only provided for C mode, because in C++ mode, GCC has no support
+      for __builtin_types_compatible_p (and when in C++ mode, this macro is
+      not used anyway, because libstdc++ headers undefine it).  */
 #  define isinf(x) \
     (__builtin_types_compatible_p (__typeof (x), _Float128) \
      ? __isinff128 (x) : __builtin_isinf_sign (x))
-- 
2.13.5

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

* Re: [PATCH 1/3] Do not use __builtin_types_compatible_p in C++ mode (bug 21930)
  2017-08-15 17:48 ` [PATCH 1/3] Do not use __builtin_types_compatible_p in C++ mode (bug 21930) Gabriel F. T. Gomes
@ 2017-08-15 19:56   ` Joseph Myers
  2017-08-18 15:28     ` Gabriel F. T. Gomes
  0 siblings, 1 reply; 8+ messages in thread
From: Joseph Myers @ 2017-08-15 19:56 UTC (permalink / raw)
  To: Gabriel F. T. Gomes; +Cc: libc-alpha

On Tue, 15 Aug 2017, Gabriel F. T. Gomes wrote:

> The logic to define isinf for float128 depends on the availability of
> __builtin_types_compatible_p, which is only available in C mode,
> however, the conditionals do not check for C or C++ mode.  This lead to
> an error in libstdc++ configure, as reported by bug 21930.
> 
> This patch adds a conditional for C mode in the definition of isinf for
> float128.  No definition is provided in C++ mode, since libstdc++
> headers undefine isinf.

OK.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH 3/3] Do not use generic selection in C++ mode
  2017-08-15 17:47 ` [PATCH 3/3] Do not use generic selection in C++ mode Gabriel F. T. Gomes
@ 2017-08-15 19:57   ` Joseph Myers
  0 siblings, 0 replies; 8+ messages in thread
From: Joseph Myers @ 2017-08-15 19:57 UTC (permalink / raw)
  To: Gabriel F. T. Gomes; +Cc: libc-alpha

On Tue, 15 Aug 2017, Gabriel F. T. Gomes wrote:

> The logic to protect the use of generic selection (_Generic) does not
> check for C or C++ mode, however, generic selection is a C-only
> feature.

OK.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH 2/3] Provide a C++ version of issignaling that does not use __MATH_TG
  2017-08-15 17:47 ` [PATCH 2/3] Provide a C++ version of issignaling that does not use __MATH_TG Gabriel F. T. Gomes
@ 2017-08-15 19:59   ` Joseph Myers
  0 siblings, 0 replies; 8+ messages in thread
From: Joseph Myers @ 2017-08-15 19:59 UTC (permalink / raw)
  To: Gabriel F. T. Gomes; +Cc: libc-alpha

On Tue, 15 Aug 2017, Gabriel F. T. Gomes wrote:

> The macro __MATH_TG contains the logic to select between long double and
> _Float128, when these types are ABI-distinct.  This logic relies on
> __builtin_types_compatible_p, which is not available in C++ mode.
> 
> On the other hand, C++ function overloading provides the means to
> distinguish between the floating-point types.  The overloading
> resolution will match the correct parameter regardless of type
> qualifiers, i.e.: const and volatile.

I think this should include a C++ testcase for issignaling (cf. 
test-math-iszero.cc, but the issignaling test should cover float128 when 
supported).

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH 1/3] Do not use __builtin_types_compatible_p in C++ mode (bug 21930)
  2017-08-15 19:56   ` Joseph Myers
@ 2017-08-18 15:28     ` Gabriel F. T. Gomes
  0 siblings, 0 replies; 8+ messages in thread
From: Gabriel F. T. Gomes @ 2017-08-18 15:28 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha

On Tue, 15 Aug 2017 19:56:44 +0000
Joseph Myers <joseph@codesourcery.com> wrote:

> On Tue, 15 Aug 2017, Gabriel F. T. Gomes wrote:
> 
> > The logic to define isinf for float128 depends on the availability of
> > __builtin_types_compatible_p, which is only available in C mode,
> > however, the conditionals do not check for C or C++ mode.  This lead to
> > an error in libstdc++ configure, as reported by bug 21930.
> > 
> > This patch adds a conditional for C mode in the definition of isinf for
> > float128.  No definition is provided in C++ mode, since libstdc++
> > headers undefine isinf.  
> 
> OK.
> 

Thanks.  I pushed patches 1 and 3 in this thread.  Patch 2 still needs
more changes.

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

end of thread, other threads:[~2017-08-18 15:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-15 17:47 [PATCH 0/3] Fix math.h uses of C++ features Gabriel F. T. Gomes
2017-08-15 17:47 ` [PATCH 2/3] Provide a C++ version of issignaling that does not use __MATH_TG Gabriel F. T. Gomes
2017-08-15 19:59   ` Joseph Myers
2017-08-15 17:47 ` [PATCH 3/3] Do not use generic selection in C++ mode Gabriel F. T. Gomes
2017-08-15 19:57   ` Joseph Myers
2017-08-15 17:48 ` [PATCH 1/3] Do not use __builtin_types_compatible_p in C++ mode (bug 21930) Gabriel F. T. Gomes
2017-08-15 19:56   ` Joseph Myers
2017-08-18 15:28     ` Gabriel F. T. Gomes

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