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: 1867291 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZKbd2xmS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SZyDY2b47z1yRq for ; Wed, 22 Nov 2023 21:30:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 97F74385840F for ; Wed, 22 Nov 2023 10:30:02 +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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 (); +}