From patchwork Mon Feb 14 09:54:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1592370 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=f6pLhYFR; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jy0301H8yz9s5B for ; Mon, 14 Feb 2022 20:55:39 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3406F3858000 for ; Mon, 14 Feb 2022 09:55:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3406F3858000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1644832534; bh=1xCbwSEZwuLOQtMWJw3W1RBaWQlwU8RZkD5UtmCZ+w4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=f6pLhYFRnF+el4p6CEI1eYEXvliT0IVpWsKAVew8w2P9P68rEnicS7dztJ0tRxj3i iZxQLYYSry3UTnqrk2ApneoB/ZwUfyrXLSGQG6ivtneq/GIfLPRIylTWc+UF70u06J A5ZWxjBzvKCKJr7dAWia3BZDYxWnF16xk4XhuA7A= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id B0872385840A for ; Mon, 14 Feb 2022 09:54:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B0872385840A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-416-QHDFG3iOPS29rV80uy5OFg-1; Mon, 14 Feb 2022 04:54:45 -0500 X-MC-Unique: QHDFG3iOPS29rV80uy5OFg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AE672801B32 for ; Mon, 14 Feb 2022 09:54:44 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.125]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4683D1084186; Mon, 14 Feb 2022 09:54:38 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 21E9sZZm2415578 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 14 Feb 2022 10:54:36 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 21E9sZMY2415577; Mon, 14 Feb 2022 10:54:35 +0100 Date: Mon, 14 Feb 2022 10:54:35 +0100 To: Jason Merrill Subject: [PATCH] c++: Don't reject GOTO_EXPRs to cdtor_label in potential_constant_expression_1 [PR104513] Message-ID: <20220214095435.GF2646553@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi! return in ctors on targetm.cxx.cdtor_returns_this () target like arm is emitted as GOTO_EXPR cdtor_label where at cdtor_label it emits RETURN_EXPR with the this. Similarly, in all dtors regardless of targetm.cxx.cdtor_returns_this () a return is emitted similarly. potential_constant_expression_1 was rejecting these gotos and so we incorrectly rejected these testcases, but actual cxx_eval* is apparently handling these just fine. I was a little bit worried that for the destruction of bases we wouldn't evaluate something we should, but as the testcase shows, that is evaluated through try ... finally and there is nothing after the cdtor_label. For arm there is RETURN_EXPR this; but we don't really care about the return value from ctors and dtors during the constexpr evaluation. Bootstrapped/regtested on {x86_64,i686,aarch64,powerpc64le,s390x}-linux and armv7hl-linux-gnueabi, ok for trunk? I must say I don't see much the point of cdtor_labels at all, I'd think that with try ... finally around it for non-arm we could just RETURN_EXPR instead of the GOTO_EXPR and the try/finally gimplification would DTRT, and we could just add the right return value for the arm case. 2022-02-14 Jakub Jelinek PR c++/104513 * constexpr.cc (potential_constant_expression_1) : Don't punt if returns (target). * g++.dg/cpp1y/constexpr-104513.C: New test. * g++.dg/cpp2a/constexpr-dtor12.C: New test. Jakub --- gcc/cp/constexpr.cc.jj 2022-02-11 13:52:32.697425776 +0100 +++ gcc/cp/constexpr.cc 2022-02-12 13:51:21.000274390 +0100 @@ -9364,7 +9364,7 @@ potential_constant_expression_1 (tree t, { tree *target = &TREE_OPERAND (t, 0); - /* Gotos representing break and continue are OK. */ - if (breaks (target) || continues (target)) + /* Gotos representing break, continue and cdtor return are OK. */ + if (breaks (target) || continues (target) || returns (target)) { *jump_target = *target; return true; --- gcc/testsuite/g++.dg/cpp1y/constexpr-104513.C.jj 2022-02-12 19:05:14.374101202 +0100 +++ gcc/testsuite/g++.dg/cpp1y/constexpr-104513.C 2022-02-12 19:06:09.745332658 +0100 @@ -0,0 +1,10 @@ +// PR c++/104513 +// { dg-do compile { target c++14 } } + +struct A { + int a1; + short a2, a3; + long a4; + constexpr A() : a1(42), a2(42), a3(42), a4(42) { return; } +}; +constexpr A a; --- gcc/testsuite/g++.dg/cpp2a/constexpr-dtor12.C.jj 2022-02-12 19:04:41.610555957 +0100 +++ gcc/testsuite/g++.dg/cpp2a/constexpr-dtor12.C 2022-02-12 19:04:18.473877087 +0100 @@ -0,0 +1,13 @@ +// PR c++/104513 +// { dg-do compile { target c++20 } } + +struct S { + constexpr S () : s (nullptr) {} + constexpr ~S () { delete s; } + int *s; +}; +struct T : S { + constexpr T () : S () {} + constexpr ~T () { s = new int (42); return; } +}; +constexpr T t;