From patchwork Wed Nov 22 10:29:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 168292 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp1225304vqb; Wed, 22 Nov 2023 02:30:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IFX87nGpbxit43F3bkQo4K8SVtz9ob2h5c3H2/QavrZqEtq9NzILq+WUh9jB3S7Zu4QsIGZ X-Received: by 2002:a05:622a:2d3:b0:417:a209:c258 with SMTP id a19-20020a05622a02d300b00417a209c258mr2310911qtx.41.1700649014669; Wed, 22 Nov 2023 02:30:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700649014; cv=pass; d=google.com; s=arc-20160816; b=DzMDOy0llxrDByRmNLeNSEq2+Hs3vlo7k2M2KXrDj1puDfWja71SYs/wVTu+3KxKi7 4yzeERKqBqngvTfBB3QPsLcf3pQPzq9nzuP7y18yIK8qRg1QoBgPiU9t6Q5FbiVz2WiI VMmYqcxVeWPramRpbMevF6p42LizsDnScFY7MirgMmHKQJYg3/CAOoEipSN2qNpk/jWv 8ZeO9k05qojU8pEsJbd8EiUp5WE/5K1ENNfcjj13PtTOSz8pjIvYmE0ZvJ0bkUeid3lH ar4rGP1tkpTEGW7UP2BCdwCCV5X51mA/aQR+pS5QJkfZaIkLHqZ7ESgI00jpoEwQz68t 1PQg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=JoHJUB3RlC3fvgJKrhAgB5NKriPARW+Z1E2I7vgJhAg=; fh=J0Jxiv2Ku1JDqrQpD3wvi8+rVqX+Ce+7zdQ8crw7oWQ=; b=xcZJmb6M2Nrs68bDS0oSkn5EdcokNzg7vcvJhQx7wn81ZS1XLxtq1GFAPuIlqVM5O1 7aZ6YylQIXzs5STfVYWeCe/qkPIyAaSLN9KsddKT0vgY/uJTw/I7F31RnMGsqMouM2Zd 3oUfvZbf0gerLWtVq62ZI2KQGGZCT7qs12FMXOfnzYqdlvyFURwL8CU1IZYlyyx2nLjG mownF0r/iRsLqvRN/msubxkMDhLk6Q3jDCC39FQa4iv3u0EYdXz9PFtwk7+eOSlN6JE5 J91vHarP1XxMjtXglSvFum2nEPlpij5Q2oes1iQcs9zesnVZD1dgjshGC5fpauZJy6ZF dxYg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZKbd2xmS; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id p19-20020a05622a049300b00421b0a870a9si10633661qtx.71.2023.11.22.02.30.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 02:30:14 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZKbd2xmS; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 610AD385840F for ; Wed, 22 Nov 2023 10:30:14 +0000 (GMT) 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 D713C3858D35 for ; Wed, 22 Nov 2023 10:29:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D713C3858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D713C3858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700648992; cv=none; b=lvqGE0NkQsiOPQLsn5aIIX4lioRXR8y8JO2ogD7Le6meFWtzTrSzApHFssIpYij3kx0NeQQAek3vF6WF2s01oPrJrdyc91VVgPPRfMBJYt7gCabpe9r5w00lM4s/buAj9YL8nwYB+7f/BYSl8ki7oawMKMWZd6n8Q4K3vdxuTBI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700648992; c=relaxed/simple; bh=UMRfFVPu+XFs31ZMYVgHn1Q8qi8cj2UHLZTJoe+eS08=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=isU4hZj1E65TrTzQSIIdYnkiulj21QzaAujnrOivFnIOpH/J6WL6mBm9tA7yAJ++hAEVZm6bqV+EyQ2ZffrNGtN7z+i0eG9t5gjC5TMH3B+RFEvphh50cQ6JhcE6IRu8klsDL1NQQ0wlajPlJPdez528SO+moFhs9Ynu/pxD1zY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700648990; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=JoHJUB3RlC3fvgJKrhAgB5NKriPARW+Z1E2I7vgJhAg=; b=ZKbd2xmSkay0VHGoA1jiShPZMW++nJQhFDv1bGsEf4I4G7CcdKapFd4tmkrGc56cM0SASV mWkMdd7u8FljTTCCh+IPEDQKuMbliy0g9qYWSzogOPcdLJ3fXUG4UcvQdG1ZMhd3S/nf85 GxSEhOOvJ6OPn5hjc9FsEXrqPjb/gNU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-29-YyasQFjKMT6lobnSuzRgmQ-1; Wed, 22 Nov 2023 05:29:47 -0500 X-MC-Unique: YyasQFjKMT6lobnSuzRgmQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F123C85A58A; Wed, 22 Nov 2023 10:29:46 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B44072166B26; Wed, 22 Nov 2023 10:29:46 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3AMATidL2485223 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 22 Nov 2023 11:29:44 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3AMAThc72485222; Wed, 22 Nov 2023 11:29:43 +0100 Date: Wed, 22 Nov 2023 11:29:43 +0100 From: Jakub Jelinek To: Richard Biener , Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] tree: Fix up try_catch_may_fallthru [PR112619] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783259741209097970 X-GMAIL-MSGID: 1783259741209097970 Hi! The following testcase ICEs with -std=c++98 since r14-5086 because block_may_fallthru is called on a TRY_CATCH_EXPR whose second operand is a MODIFY_EXPR rather than STATEMENT_LIST, which try_catch_may_fallthru apparently expects. I've been wondering whether that isn't some kind of FE bug and whether there isn't some unwritten rule that second operand of TRY_CATCH_EXPR must be a STATEMENT_LIST, but then I tried Jakub --- gcc/gimplify.cc 2023-07-19 14:23:42.409875238 +0200 +++ gcc/gimplify.cc 2023-11-22 11:07:50.511000206 +0100 @@ -16730,6 +16730,10 @@ gimplify_expr (tree *expr_p, gimple_seq Note that this only affects the destructor calls in FINALLY/CATCH block, and will automatically reset to its original value by the end of gimplify_expr. */ + if (TREE_CODE (*expr_p) == TRY_CATCH_EXPR + && TREE_OPERAND (*expr_p, 1) + && TREE_CODE (TREE_OPERAND (*expr_p, 1)) != STATEMENT_LIST) + gcc_unreachable (); input_location = UNKNOWN_LOCATION; eval = cleanup = NULL; gimplify_and_add (TREE_OPERAND (*expr_p, 0), &eval); hack in gcc 13 and triggered on hundreds of tests there within just 5 seconds of running make check-g++ -j32 (and in cases I looked at had nothing to do with the r14-5086 backports), so I believe this is just bad assumption on the try_catch_may_fallthru side, gimplify.cc certainly doesn't care, it just calls gimplify_and_add (TREE_OPERAND (*expr_p, 1), &cleanup); on it. So, IMHO non-STATEMENT_LIST in the second operand is equivalent to a STATEMENT_LIST containing a single statement. Unfortunately, I don't see an easy way to create an artificial tree iterator from just a single tree statement, so the patch duplicates what the loops later do (after all, it is very simple, just didn't want to duplicate also the large comments explaning it, so the 3 See below. comments). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Shall it go to branches as well given that r14-5086 has been backported to those branches as well? 2023-11-22 Jakub Jelinek PR c++/112619 * tree.cc (try_catch_may_fallthru): If second operand of TRY_CATCH_EXPR is not a STATEMENT_LIST, handle it as if it was a STATEMENT_LIST containing a single statement. * g++.dg/eh/pr112619.C: New test. --- gcc/tree.cc.jj 2023-11-14 09:24:28.436530018 +0100 +++ gcc/tree.cc 2023-11-21 19:19:19.384347469 +0100 @@ -12573,6 +12573,24 @@ try_catch_may_fallthru (const_tree stmt) if (block_may_fallthru (TREE_OPERAND (stmt, 0))) return true; + switch (TREE_CODE (TREE_OPERAND (stmt, 1))) + { + case CATCH_EXPR: + /* See below. */ + return block_may_fallthru (CATCH_BODY (TREE_OPERAND (stmt, 1))); + + case EH_FILTER_EXPR: + /* See below. */ + return block_may_fallthru (EH_FILTER_FAILURE (TREE_OPERAND (stmt, 1))); + + case STATEMENT_LIST: + break; + + default: + /* See below. */ + return false; + } + i = tsi_start (TREE_OPERAND (stmt, 1)); switch (TREE_CODE (tsi_stmt (i))) { --- gcc/testsuite/g++.dg/eh/pr112619.C.jj 2023-11-21 19:22:47.437439283 +0100 +++ gcc/testsuite/g++.dg/eh/pr112619.C 2023-11-21 19:22:24.887754376 +0100 @@ -0,0 +1,15 @@ +// PR c++/112619 +// { dg-do compile } + +struct S { S (); ~S (); }; + +S +foo (int a, int b) +{ + if (a || b) + { + S s; + return s; + } + return S (); +}