From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 2A4563858D32; Sat, 3 Jun 2023 14:33:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2A4563858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-65311774e52so913153b3a.3; Sat, 03 Jun 2023 07:33:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685802815; x=1688394815; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=pttvTFxMy2/tdtHhphAKuI/T2M2YnFHf9fGCPstKkX0=; b=AQjXwp3ap9RVsPfcA6oo7gQeZkfuquGi7dVP2cflMDh+/v/k1NyF+TAw20vst4YM9q VGj31COCuTHjjxYIXhFLAXkmmnfk1F7uYnN6fPuALQvLK1beL9w/xz8QWHq2R3ppVv0C RHPEAXyYS0i99EHP0dYZZRTQJ0TYsEIPof+boIuNwDB0Tx2NGTkux1NIk8TqEeMZcP6E QMpAPNnsc/dxe0xRqszZVT3GKgQi7T1DmoWOIv8/ZcpiPjwUAJ/WlSJiPYuqL9kSlChu uaMjPsHufh5CflRuGSPXL45DytpcK1iCKkktckDx850dJKc5tdcmytgQ0hUrmCpK3iF2 AzGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685802815; x=1688394815; 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=pttvTFxMy2/tdtHhphAKuI/T2M2YnFHf9fGCPstKkX0=; b=AeK82BXLcQI41EGrt1fAuYFgA8hW+BNMxGetS8+mV/0iq5XcgSwjw/OhL3zIR4Wf2G l6quwCtI7uKRuJ6z1qyUWNrHFarlPwvXFToSB2XHX8aihYofiaYul4AqQYxlgJO2ZXL1 DAO6VU711FY2m70YmLiwdUYdBqQJtB07KMfbnPuIlFcXfiL3OHZei8pJ3P14mxu++p5k Jw57/Xb93UTjqJlXGT5sYWZ1YCWjrESfxrWZBeas5/z0Sakjoua1MPMOBC36ofRm8rex bXxeQ3onXc3Of8GrA2Vs30CTITBvGqEYu6mBV2lcpNSwd1ULJor0Ue0tEhtegggbH0Xz 9tkg== X-Gm-Message-State: AC+VfDxuEuJ94lcPp5Ua3YlCDw2wGVOWEbLI246wJI7mBNulgC12VPRv krJR1gE7ueJTtvztJbgnYjU= X-Google-Smtp-Source: ACHHUZ4krcImqW2/eo8yzljodqGO8KHzv0ySAXEs2xoV5Wk/VNbXCh0tffoO2l9YW/geZYDIq9uawg== X-Received: by 2002:a05:6a00:843:b0:653:5acf:a802 with SMTP id q3-20020a056a00084300b006535acfa802mr2310902pfk.12.1685802814690; Sat, 03 Jun 2023 07:33:34 -0700 (PDT) Received: from ?IPV6:2607:fb90:469:b40a:c15c:6a92:5516:c5a5? ([2607:fb90:469:b40a:c15c:6a92:5516:c5a5]) by smtp.gmail.com with ESMTPSA id x7-20020aa793a7000000b006475f831838sm2563760pff.30.2023.06.03.07.33.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 03 Jun 2023 07:33:34 -0700 (PDT) Message-ID: <64522f14-0f25-ebf6-05e9-8d10be640114@gmail.com> Date: Sat, 3 Jun 2023 08:33:32 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [PATCH RFC] c++: use __cxa_call_terminate for MUST_NOT_THROW [PR97720] Content-Language: en-US To: Jason Merrill , gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org References: <20230524185559.1285583-1-jason@redhat.com> From: Jeff Law In-Reply-To: <20230524185559.1285583-1-jason@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham 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 5/24/23 12:55, Jason Merrill via Gcc-patches 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. OK on the middle end bits. And I'd tend to agree MUST_NOT_THROW is just a special case of an exception-specification, so if you can make your proposal work it seems like a reasonable approach. jeff