libstdc++: Stop defining _GLIBCXX_ASSERTIONS in floating_to_chars.cc
authorPatrick Palka <ppalka@redhat.com>
Tue, 19 Apr 2022 14:20:04 +0000 (10:20 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 19 Apr 2022 14:20:04 +0000 (10:20 -0400)
commitcd3964ebd3e94ed0df4ecaadb7fd34e991cec753
tree00c3cf8f67d2df5ea7a7d20968921cc85cbf5d4e
parentfdb3f82fb324c3ddd7464d11c8ea60a98f486a0e
libstdc++: Stop defining _GLIBCXX_ASSERTIONS in floating_to_chars.cc

Assertions were originally enabled in the compiled-in floating-point
std::to_chars implementation to help shake out any bugs, but they
apparently impose a significant performance penalty, most notably for
the hex formatting which is around 25% slower with assertions enabled.
This seems too high a cost for unconditionally enabling them.

The newly added calls to __builtin_unreachable work around the compiler
no longer knowing that the set of valid values of 'fmt' is limited (which
was previously upheld by an assert).

libstdc++-v3/ChangeLog:

* src/c++17/floating_to_chars.cc (_GLIBCXX_ASSERTIONS): Don't
define.
(__floating_to_chars_shortest): Add __builtin_unreachable calls to
squelch false-positive -Wmaybe-uninitialized and -Wreturn-type
warnings.
(__floating_to_chars_precision): Likewise.
libstdc++-v3/src/c++17/floating_to_chars.cc