From patchwork Tue Oct 4 14:11:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1685 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp149598wrs; Tue, 4 Oct 2022 07:14:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4CQIpCaOb2HyR4LdFaZbOGcsi5dPWPVVrIh4zduDOKrlR603aQE/8TPp/lKvGpUPiqbHBL X-Received: by 2002:a05:6402:40cc:b0:452:697e:da18 with SMTP id z12-20020a05640240cc00b00452697eda18mr23205478edb.288.1664892896643; Tue, 04 Oct 2022 07:14:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664892896; cv=none; d=google.com; s=arc-20160816; b=a/c9SLddbqdUHmDAXJ9OpUZuqT5VHYfZtQlo0qcxt+M9PiZ7BUo5N6Dy/hHJtHlKLN NFj6Z7WEIphh0oxtZncF/N8JkeVZm1dSQra9NVtb4pRmthxxy4ltIesuWlevBSjBpqHE MrbY2CsH20pbdVv46CyAA1MWxyVKvLLDqZ5QS7Zlmmi0y5VMJw4CLKx5D7VHnz6R8lw6 sidgiAJLhhCHVG3xCmLtukcmcntfdoEqrcTAQ3uJr1XUUc9RgOUg32DLm9gzlqZgQPeL apjjqqJcGrRr9IUP5cAf44AE2buWM10UDsMAxRlIHTy9r6iMu7nuKEFBgVf50u5ZcFaR XBSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=OcKLexceoE2X6Er4bQn/QDyCGGzbKbObnTWsxN4uOHk=; b=uuuqWEyeer8wwz/7cmm2z37bzv5t8I4P40j8LdigfothzxymVbgiPVccH6ndZ3b1zn AOw7kMUytonYSZZ2LSoVFGaGSBLvmavmv2L36lqQiKaH01LLYFqUaKiGJP5tQ0WkPfoV KPPlxKdedRGO0R5NznkdanKcxT/7lhHAGHjWFtxKQ3CKDaKGsVNFl5K2q/OJgj/c/37F l0lx+HEI9zqL4gfjlO42diUgKNSu1p07s51/CdDS5TqE4BWaWOC+ar/EcmgMah+ayeQA YNN9FBlBoMO6WdF2tqh/KyR5nNPTquSst3u3ERi/CnRlfhwAMwlOrk+32wQ+rXSP/cWy sorw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=aCy7V0P4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 15-20020a170906310f00b0077b287e3adesi10765671ejx.190.2022.10.04.07.14.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 07:14:56 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=aCy7V0P4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92278385021A for ; Tue, 4 Oct 2022 14:13:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 92278385021A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664892800; bh=OcKLexceoE2X6Er4bQn/QDyCGGzbKbObnTWsxN4uOHk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=aCy7V0P4Bj6yvDFXpJ2bzG3sNV+8fr+X6pxeXl1oThaiM6DwAGFfL1Dj6rqeAw7jd X4TaDtBc+pixmEsszWcxyI3q/ILYZC+OtiSQtModRiVwXSnZf1O6pc+SqIthk3Y78P gQE4nnYYDQhvE8axpQy8AWXl0nUwQKtsoiV1vXis= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 136723857C52 for ; Tue, 4 Oct 2022 14:12:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 136723857C52 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-411-b9NalezvOM2FVk4EVq3Cfg-1; Tue, 04 Oct 2022 10:12:05 -0400 X-MC-Unique: b9NalezvOM2FVk4EVq3Cfg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A6D8C882822; Tue, 4 Oct 2022 14:11:39 +0000 (UTC) Received: from localhost (unknown [10.33.36.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6FE6B2027061; Tue, 4 Oct 2022 14:11:39 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Define functions for freestanding [PR107135] Date: Tue, 4 Oct 2022 15:11:35 +0100 Message-Id: <20221004141138.530214-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 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, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745766733609878603?= X-GMAIL-MSGID: =?utf-8?q?1745766733609878603?= Tested powerpc64le-linux, and x86_64-linux with -ffreestanding. Pushed to trunk. -- >8 -- We don't compile src/c++11/functexcept.cc for freestanding, so just define the functions used by freestanding entities as inline calls to std::terminate. libstdc++-v3/ChangeLog: PR libstdc++/107135 * include/bits/functexcept.h [!_GLIBCXX_HOSTED] (__throw_invalid_argument, __throw_out_of_range) (__throw_out_of_range_fmt, __throw_runtime_error) (__throw_overflow_error): Define inline. * include/std/bitset (_M_copy_from_ptr) [!_GLIBCXX_HOSTED]: Replace __builtin_abort with __throw_invalid_argument. --- libstdc++-v3/include/bits/functexcept.h | 25 +++++++++++++++++++++++++ libstdc++-v3/include/std/bitset | 8 +------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/libstdc++-v3/include/bits/functexcept.h b/libstdc++-v3/include/bits/functexcept.h index a78a17b2e04..7fad4b13316 100644 --- a/libstdc++-v3/include/bits/functexcept.h +++ b/libstdc++-v3/include/bits/functexcept.h @@ -43,6 +43,7 @@ namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION +#if _GLIBCXX_HOSTED // Helper for exception objects in void __throw_bad_exception(void) __attribute__((__noreturn__)); @@ -112,6 +113,30 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void __throw_bad_function_call() __attribute__((__noreturn__)); +#else // ! HOSTED + + __attribute__((__noreturn__)) inline void + __throw_invalid_argument(const char*) + { std::__terminate(); } + + __attribute__((__noreturn__)) inline void + __throw_out_of_range(const char*) + { std::__terminate(); } + + __attribute__((__noreturn__)) inline void + __throw_out_of_range_fmt(const char*, ...) + { std::__terminate(); } + + __attribute__((__noreturn__)) inline void + __throw_runtime_error(const char*) + { std::__terminate(); } + + __attribute__((__noreturn__)) inline void + __throw_overflow_error(const char*) + { std::__terminate(); } + +#endif // HOSTED + _GLIBCXX_END_NAMESPACE_VERSION } // namespace diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset index afabeb4ba01..1f3f68fefce 100644 --- a/libstdc++-v3/include/std/bitset +++ b/libstdc++-v3/include/std/bitset @@ -1514,13 +1514,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER else if (_Traits::eq(__c, __one)) _Unchecked_set(__i - 1); else - { -#if _GLIBCXX_HOSTED - __throw_invalid_argument(__N("bitset::_M_copy_from_ptr")); -#else - __builtin_abort(); -#endif - } + __throw_invalid_argument(__N("bitset::_M_copy_from_ptr")); } }