From patchwork Thu Apr 14 19:47:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1617432 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=sW8F/iZT; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfVPP2PDqz9sFy for ; Fri, 15 Apr 2022 05:48:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 199C83857405 for ; Thu, 14 Apr 2022 19:48:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 199C83857405 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1649965685; bh=Lzw9/xlkzS4YP3C3w/5c6sk12xleiPonGbRULt/sF6E=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=sW8F/iZTfmSdg/Vx6QAFTiktRpH/stQP0UgfQ9dLW+wE1CoS6F79RFZMWSXDRmh/b KQAwH3imJDsh3aD/yDmOF8ipHpWBlxbOeQQPJ7tZN66IttUFvfAJDspbz5oXLinAZH qLyRFUSXXhdD2alU274IFboCcvzfgGEP6yjkk9fM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id CCECC3858C53 for ; Thu, 14 Apr 2022 19:47:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CCECC3858C53 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-392-nOB8j-ZrOAu2otndI5p_tQ-1; Thu, 14 Apr 2022 15:47:21 -0400 X-MC-Unique: nOB8j-ZrOAu2otndI5p_tQ-1 Received: by mail-qk1-f197.google.com with SMTP id bq12-20020a05620a468c00b0069c6527969dso3034248qkb.8 for ; Thu, 14 Apr 2022 12:47:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Lzw9/xlkzS4YP3C3w/5c6sk12xleiPonGbRULt/sF6E=; b=TktfeMaeL8vtOehRUBU0+PUd+rBMeu+rve3AIwCNDtjHszmGihZ+qHUsHk2k5kHojU AmoFn4qNGQTn8NHI2Vo3Vr8SbMzDnKEeyLpDX3+VOZ2L/20VEK7utjf3jxTbV3+6QWka s7IMavJtbzae0FMQzCIW40KXRfXyZUR3vZScWr5VG5kx1iGgLjJuKvlCeAltWWtjRFHP zIAuI+Qg0koP6dC4qB6uoIwnUyZm86ebWTlPOoN8OT3aU1UGqb0zDu6XkCCZcbd/+b1y W5yPj7uEY+4R1AlM7WP9yHU8d61f4thAZW/2hoosFQZ3gDg1mrQO9S2hf1dFfji+Zz30 wedQ== X-Gm-Message-State: AOAM5337RTHu5JIhCPasJwSssZEvMx8cEpHvEL84qBhAEf8afYSvCKSK BzSf8vJ5lLn1wWOzw+hFpd2JFrgLpwrBxdkVVYG6qXGDCd30o/88ve1Pj9liQxO5F/XcKT4hUtI D/yC7I81D+Pc3TOqgXfQMtfS3JS5bFBcyqRttHkC8VUi3DN2la2wDl4HGkyfJ60RBCHk= X-Received: by 2002:ad4:5cc3:0:b0:441:1959:cb51 with SMTP id iu3-20020ad45cc3000000b004411959cb51mr5003228qvb.112.1649965640954; Thu, 14 Apr 2022 12:47:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykPN6/tKNKdVABqRWJAxpA7IqTz400UZwB+eoknTUFSXZ5s09Mv6yuACmWmX6yfGCojVf5Jw== X-Received: by 2002:ad4:5cc3:0:b0:441:1959:cb51 with SMTP id iu3-20020ad45cc3000000b004411959cb51mr5003207qvb.112.1649965640574; Thu, 14 Apr 2022 12:47:20 -0700 (PDT) Received: from localhost.localdomain (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id n7-20020ac85a07000000b002f1421dac8csm1647698qta.80.2022.04.14.12.47.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 12:47:19 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Stop defining _GLIBCXX_ASSERTIONS in floating_to_chars.cc Date: Thu, 14 Apr 2022 15:47:16 -0400 Message-Id: <20220414194716.334032-1-ppalka@redhat.com> X-Mailer: git-send-email 2.36.0.rc2.10.g1ac7422e39 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Cc: libstdc++@gcc.gnu.org Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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, in particular for the hex formatting which is around 25% slower with assertions enabled. This seems too high of 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). Tested on x86_64-pc-linux-gnu, does this look OK for trunk? libstdc++-v3/ChangeLog: * src/c++17/floating_to_chars.cc: Don't define _GLIBCXX_ASSERTIONS. (__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 | 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.