summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-02-14 16:46:55 +0000
committerJonathan Wakely <jwakely@redhat.com>2022-02-14 17:19:08 +0000
commit3d50dede07de0923f0f320d385162e546445e640 (patch)
tree16cc21ce2695ca23db1045a731d1ab9ee36f9850 /libstdc++-v3/include
parent02a981a8e512934a990d1427d14e8e884409fade (diff)
downloadgcc-3d50dede07de0923f0f320d385162e546445e640.tar.gz
libstdc++: Fix stream extraction of IEEE128 long double [PR100912]
The std::__convert_from_v helper that formats double and long double values into a char buffer was not being duplicated for the two long double ABIs. This resulted in an ODR violation inside the library, where some callers needed it to use snprintf to format __ibm128 values and other callers needed it to use __snprintfieee128 to format __ieee128 values. The linker discarded one of the definitions, leaving one set of callers using the wrong code. This puts __convert_from_v in the __gnu_cxx_ieee128 inline namespace when long double is __ieee128, so that there are two different definitions of the function. The std::money_put::__do_put overload for __ibm128 values needs a different fix, because that is defined when long double is __ieee128 and so would call the one in the inline namespace. That can be fixed by just inlining the code directly into the function and using an asm alias to call the right version of snprintf for the __ibm128 format. The code to do that can be simpler than __convert_from_v because if we're defining the ALT128_COMPAT symbols we know that we have a recent glibc and so we can assume that uselocale and snprintf are supported. libstdc++-v3/ChangeLog: PR libstdc++/100912 * config/locale/gnu/c_locale.h (__convert_from_v): Use inline namespace for IEEE128 long double mode. * config/os/gnu-linux/ldbl-ieee128-extra.ver: Add new symbol version and export __gnu_cxx_ieee128::__convert_from_v. * include/bits/locale_facets_nonio.tcc (money_put::__do_put): Make __ibm128 overload use snprintf directly * testsuite/util/testsuite_abi.cc: Add new symbol version. Remove stable IEEE128/LDBL versions.
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r--libstdc++-v3/include/bits/locale_facets_nonio.tcc23
1 files changed, 10 insertions, 13 deletions
diff --git a/libstdc++-v3/include/bits/locale_facets_nonio.tcc b/libstdc++-v3/include/bits/locale_facets_nonio.tcc
index 64737823374..98442418f51 100644
--- a/libstdc++-v3/include/bits/locale_facets_nonio.tcc
+++ b/libstdc++-v3/include/bits/locale_facets_nonio.tcc
@@ -635,6 +635,9 @@ _GLIBCXX_BEGIN_NAMESPACE_LDBL_OR_CXX11
#if defined _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT \
&& defined __LONG_DOUBLE_IEEE128__
+extern "C"
+__typeof__(__builtin_snprintf) __glibcxx_snprintfibm128 __asm__("snprintf");
+
template<typename _CharT, typename _OutIter>
_OutIter
money_put<_CharT, _OutIter>::
@@ -643,30 +646,24 @@ _GLIBCXX_BEGIN_NAMESPACE_LDBL_OR_CXX11
{
const locale __loc = __io.getloc();
const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
-#if _GLIBCXX_USE_C99_STDIO
// First try a buffer perhaps big enough.
int __cs_size = 64;
char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
+ const __c_locale __old = __gnu_cxx::__uselocale(_S_get_c_locale());
+
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 328. Bad sprintf format modifier in money_put<>::do_put()
- int __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
- "%.*Lf", 0, __units);
+ int __len = __glibcxx_snprintfibm128(__cs, __cs_size, "%.*Lf", 0,
+ __units);
// If the buffer was not large enough, try again with the correct size.
if (__len >= __cs_size)
{
__cs_size = __len + 1;
__cs = static_cast<char*>(__builtin_alloca(__cs_size));
- __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size,
- "%.*Lf", 0, __units);
+ __len = __glibcxx_snprintfibm128(__cs, __cs_size, "%.*Lf", 0,
+ __units);
}
-#else
- // max_exponent10 + 1 for the integer part, + 2 for sign and '\0'.
- const int __cs_size =
- __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 3;
- char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
- int __len = std::__convert_from_v(_S_get_c_locale(), __cs, 0, "%.*Lf",
- 0, __units);
-#endif
+ __gnu_cxx::__uselocale(__old);
string_type __digits(__len, char_type());
__ctype.widen(__cs, __cs + __len, &__digits[0]);
return __intl ? _M_insert<true>(__s, __io, __fill, __digits)