From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 6F1ED3858C50 for ; Mon, 5 Jun 2023 19:10:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6F1ED3858C50 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685992216; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MXMevnA7Pajs5D25ML1GdSWt4MmCogyRePquRkoTJPc=; b=YAeI1v8W4lR9n3bF3BF3CqkbKTUuh1VCs8UIf/FnT/QH1L9Jh9uj5Sd5di0C+02j5M7+lu eVEY9N2Cx2XS69WFyxniMx2YuB46vEh4ezdC9XlFhZowrirfOFFpzgg2FdztCnmxBv5BWF LJqqpHQome72qn+psuwisF8Rrl5uWDM= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-644-9cbp4t4AOf2CRr2_xlh1iA-1; Mon, 05 Jun 2023 15:10:13 -0400 X-MC-Unique: 9cbp4t4AOf2CRr2_xlh1iA-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-6260f03b8eeso47522406d6.0 for ; Mon, 05 Jun 2023 12:10:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685992213; x=1688584213; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MXMevnA7Pajs5D25ML1GdSWt4MmCogyRePquRkoTJPc=; b=aSfMo+j/vm9RyJuTzXDS/c6e68rNeWiRX7HlwTRoKXIQ3LNP1p9SGIVnYlykPpX6fE XqrNCNCHqNZBxkhWpw+uaabZZIT7+TASRjAhyBMmpuTIk9D0i9egBgZyAXE30uZDnFkD SpROSjQkiOfqN7Dw00L8pEnktjssEyzZVqlZzLoUu84b9Md4xdaa9SihTaogg3+yJmao pzcHa0a+IT+dMtadMOOx3zBmNk8FSut09Pi3qf0iWntbyEW16uPe6DOC3PBvS+o9vWtj hd8PJy/RlTNLwA9Uo5Q6V7FzKPj2Z8W7iDeXwmTytViYFMQ75wcHgnKC6MKtYfXM+OfL scxQ== X-Gm-Message-State: AC+VfDzt/QFtbqhdugiLZ6zSzqY41i41WHBsQOVjbDH11eF2KcWKWBYD uIcNPeMCgxszx0n2GkAaxXUtFWV36xX15xAREg6vn+xFTR70+iGSBdMpWJJKAwOsrQcucU95Ufq 64pPMFun+SvkKbUyL9w== X-Received: by 2002:a05:6214:c4c:b0:5e3:d150:3163 with SMTP id r12-20020a0562140c4c00b005e3d1503163mr10761660qvj.20.1685992213280; Mon, 05 Jun 2023 12:10:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6NcQoYtYcY6y/zDIOAj+lVFyjUs5O2t8gytb3xgP94nkicNBzf2htWOrS3Sa8ZBKKVvXhLsQ== X-Received: by 2002:a05:6214:c4c:b0:5e3:d150:3163 with SMTP id r12-20020a0562140c4c00b005e3d1503163mr10761647qvj.20.1685992212982; Mon, 05 Jun 2023 12:10:12 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id c1-20020a05621401c100b005dd8b9345dbsm4787326qvt.115.2023.06.05.12.10.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Jun 2023 12:10:12 -0700 (PDT) Message-ID: <84ebddb0-7547-f3a7-1a70-934b49b7e69e@redhat.com> Date: Mon, 5 Jun 2023 15:10:11 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.2 Subject: Re: PING Re: [PATCH RFA (tree-eh)] c++: use __cxa_call_terminate for MUST_NOT_THROW [PR97720] To: Richard Biener Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org References: <20230524185559.1285583-1-jason@redhat.com> <8b75c557-6b03-8456-dc6e-48f1969c7900@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 6/5/23 02:09, Richard Biener wrote: > On Fri, Jun 2, 2023 at 6:57 PM Jason Merrill via Gcc-patches > wrote: >> >> Since Jonathan approved the library change, I'm looking for middle-end >> approval for the tree-eh change, even without advice on the potential >> follow-up. >> >> On 5/24/23 14:55, Jason Merrill wrote: >>> Middle-end folks: any thoughts about how best to make the change described in >>> the last paragraph below? >>> >>> Library folks: any thoughts on the changes to __cxa_call_terminate? >>> >>> -- 8< -- >>> >>> [except.handle]/7 says that when we enter std::terminate due to a throw, >>> that is considered an active handler. We already implemented that properly >>> for the case of not finding a handler (__cxa_throw calls __cxa_begin_catch >>> before std::terminate) and the case of finding a callsite with no landing >>> pad (the personality function calls __cxa_call_terminate which calls >>> __cxa_begin_catch), but for the case of a throw in a try/catch in a noexcept >>> function, we were emitting a cleanup that calls std::terminate directly >>> without ever calling __cxa_begin_catch to handle the exception. >>> >>> A straightforward way to fix this seems to be calling __cxa_call_terminate >>> instead. However, that requires exporting it from libstdc++, which we have >>> not previously done. Despite the name, it isn't actually part of the ABI >>> standard. Nor is __cxa_call_unexpected, as far as I can tell, but that one >>> is also used by clang. For this case they use __clang_call_terminate; it >>> seems reasonable to me for us to stick with __cxa_call_terminate. >>> >>> I also change __cxa_call_terminate to take void* for simplicity in the front >>> end (and consistency with __cxa_call_unexpected) but that isn't necessary if >>> it's undesirable for some reason. >>> >>> This patch does not fix the issue that representing the noexcept as a >>> cleanup is wrong, and confuses the handler search; since it looks like a >>> cleanup in the EH tables, the unwinder keeps looking until it finds the >>> catch in main(), which it should never have gotten to. Without the >>> try/catch in main, the unwinder would reach the end of the stack and say no >>> handler was found. The noexcept is a handler, and should be treated as one, >>> as it is when the landing pad is omitted. >>> >>> The best fix for that issue seems to me to be to represent an >>> ERT_MUST_NOT_THROW after an ERT_TRY in an action list as though it were an >>> ERT_ALLOWED_EXCEPTIONS (since indeed it is an exception-specification). The >>> actual code generation shouldn't need to change (apart from the change made >>> by this patch), only the action table entry. >>> >>> PR c++/97720 >>> >>> gcc/cp/ChangeLog: >>> >>> * cp-tree.h (enum cp_tree_index): Add CPTI_CALL_TERMINATE_FN. >>> (call_terminate_fn): New macro. >>> * cp-gimplify.cc (gimplify_must_not_throw_expr): Use it. >>> * except.cc (init_exception_processing): Set it. >>> (cp_protect_cleanup_actions): Return it. >>> >>> gcc/ChangeLog: >>> >>> * tree-eh.cc (lower_resx): Pass the exception pointer to the >>> failure_decl. >>> * except.h: Tweak comment. >>> >>> libstdc++-v3/ChangeLog: >>> >>> * libsupc++/eh_call.cc (__cxa_call_terminate): Take void*. >>> * config/abi/pre/gnu.ver: Add it. >>> >>> gcc/testsuite/ChangeLog: >>> >>> * g++.dg/eh/terminate2.C: New test. >>> --- >>> gcc/cp/cp-tree.h | 2 ++ >>> gcc/except.h | 2 +- >>> gcc/cp/cp-gimplify.cc | 2 +- >>> gcc/cp/except.cc | 5 ++++- >>> gcc/testsuite/g++.dg/eh/terminate2.C | 30 ++++++++++++++++++++++++++++ >>> gcc/tree-eh.cc | 16 ++++++++++++++- >>> libstdc++-v3/libsupc++/eh_call.cc | 4 +++- >>> libstdc++-v3/config/abi/pre/gnu.ver | 7 +++++++ >>> 8 files changed, 63 insertions(+), 5 deletions(-) >>> create mode 100644 gcc/testsuite/g++.dg/eh/terminate2.C >>> >>> diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h >>> index a1b882f11fe..a8465a988b5 100644 >>> --- a/gcc/cp/cp-tree.h >>> +++ b/gcc/cp/cp-tree.h >>> @@ -217,6 +217,7 @@ enum cp_tree_index >>> definitions. */ >>> CPTI_ALIGN_TYPE, >>> CPTI_TERMINATE_FN, >>> + CPTI_CALL_TERMINATE_FN, >>> CPTI_CALL_UNEXPECTED_FN, >>> >>> /* These are lazily inited. */ >>> @@ -358,6 +359,7 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX]; >>> /* Exception handling function declarations. */ >>> #define terminate_fn cp_global_trees[CPTI_TERMINATE_FN] >>> #define call_unexpected_fn cp_global_trees[CPTI_CALL_UNEXPECTED_FN] >>> +#define call_terminate_fn cp_global_trees[CPTI_CALL_TERMINATE_FN] >>> #define get_exception_ptr_fn cp_global_trees[CPTI_GET_EXCEPTION_PTR_FN] >>> #define begin_catch_fn cp_global_trees[CPTI_BEGIN_CATCH_FN] >>> #define end_catch_fn cp_global_trees[CPTI_END_CATCH_FN] >>> diff --git a/gcc/except.h b/gcc/except.h >>> index 5ecdbc0d1dc..378a9e4cb77 100644 >>> --- a/gcc/except.h >>> +++ b/gcc/except.h >>> @@ -155,7 +155,7 @@ struct GTY(()) eh_region_d >>> struct eh_region_u_must_not_throw { >>> /* A function decl to be invoked if this region is actually reachable >>> from within the function, rather than implementable from the runtime. >>> - The normal way for this to happen is for there to be a CLEANUP region >>> + The normal way for this to happen is for there to be a TRY region > > I only wondered about this, whether it shouldn't say CLEANUP or TRY instead > of just TRY? Do you know of other frontends making use of MUST_NOT_THROW? If there are only CLEANUPs within the MUST_NOT_THROW, we optimize them away and omit the landing pad, so the region is not actually reachable. Jason