From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 0FE3C3858C83; Tue, 19 Apr 2022 14:20:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0FE3C3858C83 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-8194] libstdc++: Stop defining _GLIBCXX_ASSERTIONS in floating_to_chars.cc X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: fdb3f82fb324c3ddd7464d11c8ea60a98f486a0e X-Git-Newrev: cd3964ebd3e94ed0df4ecaadb7fd34e991cec753 Message-Id: <20220419142032.0FE3C3858C83@sourceware.org> Date: Tue, 19 Apr 2022 14:20:32 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Apr 2022 14:20:32 -0000 https://gcc.gnu.org/g:cd3964ebd3e94ed0df4ecaadb7fd34e991cec753 commit r12-8194-gcd3964ebd3e94ed0df4ecaadb7fd34e991cec753 Author: Patrick Palka Date: Tue Apr 19 10:20:04 2022 -0400 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. Diff: --- libstdc++-v3/src/c++17/floating_to_chars.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/src/c++17/floating_to_chars.cc b/libstdc++-v3/src/c++17/floating_to_chars.cc index 66bd457cbe2..4599d68a39c 100644 --- a/libstdc++-v3/src/c++17/floating_to_chars.cc +++ b/libstdc++-v3/src/c++17/floating_to_chars.cc @@ -22,9 +22,6 @@ // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // . -// Activate __glibcxx_assert within this file to shake out any bugs. -#define _GLIBCXX_ASSERTIONS 1 - #include #include @@ -1114,6 +1111,7 @@ template } __glibcxx_assert(false); + __builtin_unreachable(); } template @@ -1202,6 +1200,8 @@ template effective_precision = min(precision, max_eff_scientific_precision); output_specifier = "%.*Lg"; } + else + __builtin_unreachable(); const int excess_precision = (fmt != chars_format::general ? precision - effective_precision : 0); @@ -1234,6 +1234,8 @@ template output_length_upper_bound = sign + strlen("0"); output_length_upper_bound += sizeof(radix) + effective_precision; } + else + __builtin_unreachable(); // Do the sprintf into the local buffer. char buffer[output_length_upper_bound+1]; @@ -1570,6 +1572,7 @@ template } __glibcxx_assert(false); + __builtin_unreachable(); } // Define the overloads for float.