From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DF19E3858CDB; Wed, 24 May 2023 13:01:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DF19E3858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684933274; bh=GTfK5opGCkT+JzaA+4cQvflNz1t1RXQXCO2frA7G+Yk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=N2aSp+3kdG7SklwP87bVqSThTSxQcyvR1wfJTk3+SuL5VBotrinh8j1wv9PkCz4Sm DQRT4PYq5xNN9KMqgzBZgbCd3OMeILpP1tLejt0gNQZu1XIlMa7lOVKgXu9p5v8RW5 Vo7Lk8VJLuBNsC1VOrzu8wiPN62ngUpKdDF8/uVo= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: =?UTF-8?B?W0J1ZyBsaWJzdGRjKysvMTA5OTIxXSBjKysxNy9mbG9hdGluZ19m?= =?UTF-8?B?cm9tX2NoYXJzLmNjOiBjb21waWxlIGVycm9yOiDigJhmcm9tX2NoYXJzX3N0?= =?UTF-8?B?cnRvZOKAmSB3YXMgbm90IGRlY2xhcmVkIGluIHRoaXMgc2NvcGU=?= Date: Wed, 24 May 2023 13:01:14 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.1.0 X-Bugzilla-Keywords: build X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109921 --- Comment #1 from Jonathan Wakely --- The proposed change would result in ABI changes for some targets. I think the correct fix is something more like this: --- a/libstdc++-v3/src/c++17/floating_from_chars.cc +++ b/libstdc++-v3/src/c++17/floating_from_chars.cc @@ -64,7 +64,7 @@ // strtold for __ieee128 extern "C" __ieee128 __strtoieee128(const char*, char**); #elif __FLT128_MANT_DIG__ =3D=3D 113 && __LDBL_MANT_DIG__ !=3D 113 \ - && defined(__GLIBC_PREREQ) + && defined(__GLIBC_PREREQ) && defined(USE_STRTOD_FOR_FROM_CHARS) #define USE_STRTOF128_FOR_FROM_CHARS 1 extern "C" _Float128 __strtof128(const char*, char**) __asm ("strtof128") @@ -77,10 +77,6 @@ extern "C" _Float128 __strtof128(const char*, char**) #if _GLIBCXX_FLOAT_IS_IEEE_BINARY32 && _GLIBCXX_DOUBLE_IS_IEEE_BINARY64 \ && __SIZE_WIDTH__ >=3D 32 # define USE_LIB_FAST_FLOAT 1 -# if __LDBL_MANT_DIG__ =3D=3D __DBL_MANT_DIG__ -// No need to use strtold. -# undef USE_STRTOD_FOR_FROM_CHARS -# endif #endif #if USE_LIB_FAST_FLOAT @@ -1261,7 +1257,7 @@ from_chars_result from_chars(const char* first, const char* last, long double& value, chars_format fmt) noexcept { -#if ! USE_STRTOD_FOR_FROM_CHARS +#if __LDBL_MANT_DIG__ =3D=3D __DBL_MANT_DIG__ || !defined USE_STRTOD_FOR_FROM_CHARS // Either long double is the same as double, or we can't use strtold. // In the latter case, this might give an incorrect result (e.g. values // out of range of double give an error, even if they fit in long double= ). @@ -1329,13 +1325,23 @@ _ZSt10from_charsPKcS0_RDF128_St12chars_format(const char* first, __ieee128& value, chars_format fmt) noexcept __attribute__((alias ("_ZSt10from_charsPKcS0_Ru9__ieee128St12chars_format"= ))); -#elif defined(USE_STRTOF128_FOR_FROM_CHARS) +#else from_chars_result from_chars(const char* first, const char* last, _Float128& value, chars_format fmt) noexcept { +#ifdef USE_STRTOF128_FOR_FROM_CHARS // fast_float doesn't support IEEE binary128 format, but we can use strt= old. return from_chars_strtod(first, last, value, fmt); +#else + // Read a long double. This might give an incorrect result (e.g. values + // out of range of long double give an error, even if they fit in _Float128). + long double ldbl_val; + auto res =3D std::from_chars(first, last, ldbl_val, fmt); + if (rec.ec =3D=3D errc{}) + value =3D ldbl_val; + return res; +#endif } #endif We should not use strtof128 unless we can use strtod. We should not #undef USE_STRTOD_FOR_FROM_CHARS on line 82 just because we d= on't need it for long double, as we might still need it for _Float128.=