From patchwork Tue Jan 18 23:07:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 50202 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A98BF3857C4D for ; Tue, 18 Jan 2022 23:08:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A98BF3857C4D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1642547323; bh=YwuPhJePFt0mMB5TeMZUojrl9ivYDDa11qyQ0pDbNPs=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=YqBtwFtQpRjj+Lu0eg2GIWrPuM1bSXtvCD5XI+WiYY1XpMELzGx/X8CYtY5yCFSNH 6xD8cg5+scpZvxfW4aKMfBU4uCZWE0mXyGL4yV6AKeA0+Sq5m6wnZmXqIIYPh4urUu ZPxMUdqwe/auL2yZ/1VpKr3fJdepMmxsjc/n/STE= 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 5927A3858409 for ; Tue, 18 Jan 2022 23:08:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5927A3858409 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-551-QoZJoEH9OUW3qQpwzYDnNg-1; Tue, 18 Jan 2022 18:08:06 -0500 X-MC-Unique: QoZJoEH9OUW3qQpwzYDnNg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4D8781083F61 for ; Tue, 18 Jan 2022 23:08:05 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.40.192.74]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA03D78C1E; Tue, 18 Jan 2022 23:07:52 +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 20IN7onp1996373 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 19 Jan 2022 00:07:50 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 20IN7oPd1996372; Wed, 19 Jan 2022 00:07:50 +0100 Date: Wed, 19 Jan 2022 00:07:49 +0100 To: Jason Merrill Subject: [PATCH] c++, v2: Fix handling of temporaries with consteval ctors and non-trivial dtors [PR104055] Message-ID: <20220118230526.GK2646553@tucnak> References: <20220118101005.GV2646553@tucnak> <2371b1c6-d83b-4d80-ae27-c830a890c07e@redhat.com> <20220118142626.GC2646553@tucnak> <8240fef5-0f7d-1260-c374-e5af5fed7bca@redhat.com> MIME-Version: 1.0 In-Reply-To: <8240fef5-0f7d-1260-c374-e5af5fed7bca@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" On Tue, Jan 18, 2022 at 11:51:31AM -0500, Jason Merrill wrote: > On 1/18/22 09:26, Jakub Jelinek wrote: > > On Tue, Jan 18, 2022 at 09:08:03AM -0500, Jason Merrill wrote: > > > > which makes call a TARGET_EXPR with the dtor in TARGET_EXPR_CLEANUP, > > > > but then call cxx_constant_value on it. In cxx_eval_outermost_constant_expr > > > > it triggers the: > > > > else if (TREE_CODE (t) != CONSTRUCTOR) > > > > { > > > > r = get_target_expr_sfinae (r, tf_warning_or_error | tf_no_cleanup); > > > > TREE_CONSTANT (r) = true; > > > > } > > > > which wraps the CONSTRUCTOR r into a new TARGET_EXPR, but one without > > > > dtors (I think we need e.g. the TREE_CONSTANT for the callers), > > > > and finally build_over_call uses that. > > > > > > Looks like you added the tf_no_cleanup in r10-3661 (constexpr new). Maybe > > > that should only be added if TARGET_EXPR_CLEANUP (t) is null? > > > > I thought about that, but I'm worried that if the cleanup action > > is non-empty, then the TREE_CONSTANT (r) = true; after it isn't appropriate, > > because the TARGET_EXPR has side-effects. > > Hmm. If we e.g. pull out a subobject value from the TARGET_EXPR temporary, > we still need to run the cleanup, so we don't want to optimize the temporary > away, so not setting TREE_CONSTANT sounds right. > > > And the callers like cxx_constant_value_sfinae just return error_mark_node > > if it isn't set: > > if (sfinae && !TREE_CONSTANT (r)) > > r = error_mark_node; > > Yes. Is that wrong? I guess we need to be more careful about adjusting the > arguments to cxx_constant_value_sfinae if we still want a constant value. > > Perhaps we also still want to set tf_no_cleanup if object is nonnull, since > in that case we know the prvalue is going to be an initializer rather than a > temporary. This passed bootstrap/regtest on i686-linux and bootstrap on x86_64-linux (regtest still pending): 2022-01-18 Jakub Jelinek PR c++/104055 * constexpr.cc (cxx_eval_outermost_constant_expr): If t is a TARGET_EXPR with TARGET_EXPR_CLEANUP, use get_target_expr rather than get_target_expr_sfinae with tf_no_cleanup, and don't set TREE_CONSTANT. * g++.dg/cpp2a/consteval27.C: New test. Jakub --- gcc/cp/constexpr.cc.jj 2022-01-18 11:58:59.296986142 +0100 +++ gcc/cp/constexpr.cc 2022-01-18 20:07:28.362485336 +0100 @@ -7821,7 +7821,11 @@ cxx_eval_outermost_constant_expr (tree t if (TREE_CODE (t) == TARGET_EXPR && TARGET_EXPR_INITIAL (t) == r) return t; - else if (TREE_CODE (t) != CONSTRUCTOR) + else if (TREE_CODE (t) == CONSTRUCTOR) + ; + else if (TREE_CODE (t) == TARGET_EXPR && TARGET_EXPR_CLEANUP (t)) + r = get_target_expr (r); + else { r = get_target_expr_sfinae (r, tf_warning_or_error | tf_no_cleanup); TREE_CONSTANT (r) = true; --- gcc/testsuite/g++.dg/cpp2a/consteval27.C.jj 2022-01-18 20:12:55.326006216 +0100 +++ gcc/testsuite/g++.dg/cpp2a/consteval27.C 2022-01-18 20:13:01.442921759 +0100 @@ -0,0 +1,18 @@ +// PR c++/104055 +// { dg-do run { target c++20 } } + +int g; + +struct A { + ~A () { if (a != 17 || b != 26) __builtin_abort (); g = 42; } + consteval A () : a (17), b (26) {} + int a, b; +}; + +int +main () +{ + A{}; + if (g != 42) + __builtin_abort (); +}