From patchwork Thu Jul 15 15:26:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1505764 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: 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=oukgpnGj; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 ozlabs.org (Postfix) with ESMTPS id 4GQdZq64dHz9sV8 for ; Fri, 16 Jul 2021 01:29:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6FB1B398843F for ; Thu, 15 Jul 2021 15:29:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6FB1B398843F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1626362961; bh=CzZhO9EAmkDUIGApUmaSNaBn8AwEnR3GZpfdGYVZEGw=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=oukgpnGjTNBkC4Ppt0Fwd7pSNd7Ujih0PkDmck8EvexuT8t4UpqMUSoR5e6cjh6sk Op9niKQHhrvbZOcGEb86dlPML30NXvCdlgEl9YBNsCKmJq+w7H42fV+CUtfi0sGUNc Lzijjm+hsXUyuZEbzax97l5WNWLIUqch/eUJzL8Y= 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 ESMTP id D0A6E398841C for ; Thu, 15 Jul 2021 15:26:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D0A6E398841C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-580-a9M5TVPlMAagVbFH_DoFdw-1; Thu, 15 Jul 2021 11:26:02 -0400 X-MC-Unique: a9M5TVPlMAagVbFH_DoFdw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E88A98030B5; Thu, 15 Jul 2021 15:26:01 +0000 (UTC) Received: from localhost (unknown [10.33.37.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 860A56091B; Thu, 15 Jul 2021 15:26:01 +0000 (UTC) Date: Thu, 15 Jul 2021 16:26:00 +0100 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add noexcept to __replacement_assert [PR101429] Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-15.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable 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: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This results in slightly smaller code when assertions are enabled when either using Clang (because it adds code to call std::terminate when potentially-throwing functions are called in a noexcept function) or a freestanding or non-verbose build (because it doesn't use printf). Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: PR libstdc++/101429 * include/bits/c++config (__replacement_assert): Add noexcept. [!_GLIBCXX_VERBOSE] (__glibcxx_assert_impl): Use __builtin_trap instead of __replacement_assert. Tested powerpc64le-linux. Committed to trunk. commit 1f7182d68c24985dace2a94422c671ff987c262c Author: Jonathan Wakely Date: Wed Jul 14 12:25:11 2021 libstdc++: Add noexcept to __replacement_assert [PR101429] This results in slightly smaller code when assertions are enabled when either using Clang (because it adds code to call std::terminate when potentially-throwing functions are called in a noexcept function) or a freestanding or non-verbose build (because it doesn't use printf). Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: PR libstdc++/101429 * include/bits/c++config (__replacement_assert): Add noexcept. [!_GLIBCXX_VERBOSE] (__glibcxx_assert_impl): Use __builtin_trap instead of __replacement_assert. diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config index 9314117aed8..69ace386dd7 100644 --- a/libstdc++-v3/include/bits/c++config +++ b/libstdc++-v3/include/bits/c++config @@ -500,6 +500,7 @@ namespace std // Assert. #if defined(_GLIBCXX_ASSERTIONS) \ || defined(_GLIBCXX_PARALLEL) || defined(_GLIBCXX_PARALLEL_ASSERTIONS) +# if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE namespace std { // Avoid the use of assert, because we're trying to keep the @@ -508,6 +509,7 @@ namespace std inline void __replacement_assert(const char* __file, int __line, const char* __function, const char* __condition) + _GLIBCXX_NOEXCEPT { __builtin_printf("%s:%d: %s: Assertion '%s' failed.\n", __file, __line, __function, __condition); @@ -517,10 +519,18 @@ namespace std #define __glibcxx_assert_impl(_Condition) \ if (__builtin_expect(!bool(_Condition), false)) \ { \ - __glibcxx_constexpr_assert(_Condition); \ + __glibcxx_constexpr_assert(false); \ std::__replacement_assert(__FILE__, __LINE__, __PRETTY_FUNCTION__, \ #_Condition); \ } +# else // ! VERBOSE +# define __glibcxx_assert_impl(_Condition) \ + if (__builtin_expect(!bool(_Condition), false)) \ + { \ + __glibcxx_constexpr_assert(false); \ + __builtin_abort(); \ + } +#endif #endif #if defined(_GLIBCXX_ASSERTIONS)