[PATCH v2] math.h: Do use __MATH_TG_BUILTIN_CLASSIFY for C++

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Wed Dec 31 11:09:17 GMT 2025



On 30/12/25 19:56, H.J. Lu wrote:

>> diff --git a/sysdeps/x86/fpu/test-builtin-denormal-cxx.cc b/sysdeps/x86/fpu/test-builtin-denormal-cxx.cc
>> new file mode 100644
>> index 0000000000..0b7e8e8728
>> --- /dev/null
>> +++ b/sysdeps/x86/fpu/test-builtin-denormal-cxx.cc
>> @@ -0,0 +1 @@
>> +#include "test-builtin-denormal.c"
>> diff --git a/sysdeps/x86/fpu/test-builtin-denormal.c b/sysdeps/x86/fpu/test-builtin-denormal.c
>> index bddcd59387..789f1e3535 100644
>> --- a/sysdeps/x86/fpu/test-builtin-denormal.c
>> +++ b/sysdeps/x86/fpu/test-builtin-denormal.c
>> @@ -40,15 +40,23 @@ static const ieee_long_double_shape_type inputs[] = {
>>  static int
>>  do_test (void)
>>  {
>> -  for (int i = 0; i < array_length (inputs); i++)
>> +  for (unsigned int i = 0; i < array_length (inputs); i++)
>>      {
>>        TEST_COMPARE (feclearexcept (FE_INVALID), 0);
>>        TEST_COMPARE (fpclassify (inputs[i].value), FP_NAN);
>> +#ifndef __cplusplus
>> +      /* C++ uses the builtin, which does not trigger FE_INVALID for
>> +        pseudo-numbers (GCC BZ 123161 and LLVM issue 172533.  */
>>        TEST_COMPARE (fetestexcept (FE_INVALID), 0);
> 
> Shouldn't the C++ builtin be disabled?

The main problem is we have multiple ways in C++ to provide the fpclassify
and isinf, either by including math.h or by cmath. For the latter the C++ l
ibrary will have to provide its own by overriding the C one (or similar 
method) and I think it is out of scope of glibc.

For the former we still need to provide an implementation and we need it to
work with current C++ library way to override it if necessary. I tried to use
the same strategy we use for issignaling (function overloading in the global
namespace), but I found out some issue while boostrapping libstdc++ because
it does use provide its own implementation of fpclassify/isinf (different
than issignaling).

That's why I kept the current way for C++, since the expected way to use
such definition is to use the definition from cmath.


More information about the Libc-alpha mailing list