From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 6FDE33858D3C for ; Mon, 15 Apr 2024 12:19:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6FDE33858D3C 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 6FDE33858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713183586; cv=none; b=sGNF/cfPC9ARKKse+71Xw2a9yP+ks9jjkE8fpzwQN29d9EopBs2VMzAEUYKajBvurwjRU9UBiws+xTOcYgZLBuRxpS9tVrTxwuWpxlovAc6lk0o20nnRbJ9MlefqOc7EDaPjZUEYS0XF9ioFh9WCbeGOLmNefJYYWyi6ZHIO4Vs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713183586; c=relaxed/simple; bh=lh8kEQmzRiNRwEbh02ekBPQZHD+j4G4McMs1LH+S4SU=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=jupjuhj0cixU5lxDsD1dnohCGYKSt7do3nofeyyO4SJ1GoCoQPt/q1nFjrx+dRnSRkyvD/DtqVZanylKlcSsicoWSuYwy2HQ6RZ/AyNk7EZm9NWhzs0wIM4ecVAcugejElsKBC/TuDpJLXgMa5pR3k5jlB7dKkFK8Z2+wpM2hp4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713183584; 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:in-reply-to:in-reply-to: references:references; bh=KONT8EFAoeau2xlh9BRiWRwsVwBf2nyZ7rLb8VOhI/8=; b=EzHi347jsRdEg0ln16YuM//8rdvPRG5jO3kHvf5r+Cd3oiIkB1y67MJY5XFfDq36dQ39Uf cTHdDWXKGHxjRBR6ABD8VAGOs//jNKlvV1jIojC8/OnIIRHL2iF+Ir3PbtgBlCcCjVamOg AJ44FiQD92VZL3yiEqfEXV4pObL8clc= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-584-0iFjCEWVMqS5SB_PU0G6Tw-1; Mon, 15 Apr 2024 08:19:42 -0400 X-MC-Unique: 0iFjCEWVMqS5SB_PU0G6Tw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 545803C0FC9F for ; Mon, 15 Apr 2024 12:19:42 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 18C032026D06; Mon, 15 Apr 2024 12:19:41 +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 43FCJaI41789096 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 15 Apr 2024 14:19:36 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 43FCJat61789095; Mon, 15 Apr 2024 14:19:36 +0200 Date: Mon, 15 Apr 2024 14:19:36 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++: Fix constexpr evaluation of parameters passed by invisible reference [PR111284] Message-ID: Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-4.7 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 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 Fri, Apr 12, 2024 at 03:05:26PM -0400, Jason Merrill wrote: > > --- gcc/cp/constexpr.cc.jj 2024-02-13 10:29:57.979155641 +0100 > > +++ gcc/cp/constexpr.cc 2024-03-07 19:35:01.032412221 +0100 > > @@ -1877,13 +1877,21 @@ cxx_bind_parameters_in_call (const const > > x = build_address (x); > > } > > if (TREE_ADDRESSABLE (type)) > > - /* Undo convert_for_arg_passing work here. */ > > - x = convert_from_reference (x); > > - /* Normally we would strip a TARGET_EXPR in an initialization context > > - such as this, but here we do the elision differently: we keep the > > - TARGET_EXPR, and use its CONSTRUCTOR as the value of the parm. */ > > - arg = cxx_eval_constant_expression (ctx, x, vc_prvalue, > > - non_constant_p, overflow_p); > > + { > > + /* Undo convert_for_arg_passing work here. */ > > + if (TYPE_REF_P (TREE_TYPE (x)) > > + && !same_type_p (type, TREE_TYPE (TREE_TYPE (x)))) > > + x = cp_fold_convert (build_reference_type (type), x); > > + x = convert_from_reference (x); > > + arg = cxx_eval_constant_expression (ctx, x, vc_glvalue, > > + non_constant_p, overflow_p); > > + } > > + else > > + /* Normally we would strip a TARGET_EXPR in an initialization context > > + such as this, but here we do the elision differently: we keep the > > + TARGET_EXPR, and use its CONSTRUCTOR as the value of the parm. */ > > + arg = cxx_eval_constant_expression (ctx, x, vc_prvalue, > > + non_constant_p, overflow_p); > > It seems simpler to move the convert_for_reference after the > cxx_eval_constant_expression rather than duplicate the call to > cxx_eval_constant_expression. They weren't the same, one was trying to evaluate the convert_from_reference with vc_glvalue, the other evaluates it without that and with vc_prvalue. Now, I guess the + /* Undo convert_for_arg_passing work here. */ + if (TYPE_REF_P (TREE_TYPE (x)) + && !same_type_p (type, TREE_TYPE (TREE_TYPE (x)))) + x = cp_fold_convert (build_reference_type (type), x); part could be thrown away, given the other !same_type_p check (that one is needed because adjust_temp_type can't deal with that), at least when I remove that GXX_TESTSUITE_STDS=98,11,14,17,20,23,26 make check-g++ RUNTESTFLAGS="dg.exp='constexpr-dtor* pr114426.C constexpr-111284.C constexpr-lifetime7.C'" still passes. But if I try to remove even more, like in the patch below, then I see FAIL: g++.dg/cpp2a/constexpr-dtor5.C -std=c++20 (test for excess errors) FAIL: g++.dg/cpp2a/constexpr-dtor5.C -std=c++23 (test for excess errors) FAIL: g++.dg/cpp2a/constexpr-dtor5.C -std=c++26 (test for excess errors) FAIL: g++.dg/cpp2a/constexpr-dtor7.C -std=c++20 (test for errors, line 6) FAIL: g++.dg/cpp2a/constexpr-dtor7.C -std=c++20 (test for excess errors) FAIL: g++.dg/cpp2a/constexpr-dtor7.C -std=c++23 (test for errors, line 6) FAIL: g++.dg/cpp2a/constexpr-dtor7.C -std=c++23 (test for excess errors) FAIL: g++.dg/cpp2a/constexpr-dtor7.C -std=c++26 (test for errors, line 6) FAIL: g++.dg/cpp2a/constexpr-dtor7.C -std=c++26 (test for excess errors) regressions. E.g. .../g++.dg/cpp2a/constexpr-dtor5.C:30:20: error: non-constant condition for static assertion .../g++.dg/cpp2a/constexpr-dtor5.C:13:7: error: modification of '' from outside current evaluation is not a constant expression .../g++.dg/cpp2a/constexpr-dtor5.C:31:20: error: non-constant condition for static assertion .../g++.dg/cpp2a/constexpr-dtor5.C:13:7: error: modification of '' from outside current evaluation is not a constant expression .../g++.dg/cpp2a/constexpr-dtor5.C:32:20: error: non-constant condition for static assertion .../g++.dg/cpp2a/constexpr-dtor5.C:13:7: error: modification of '' from outside current evaluation is not a constant expression .../g++.dg/cpp2a/constexpr-dtor5.C:13:7: error: modification of '' from outside current evaluation is not a constant expression .../g++.dg/cpp2a/constexpr-dtor5.C:13:7: error: modification of '' from outside current evaluation is not a constant expression .../g++.dg/cpp2a/constexpr-dtor5.C:13:7: error: modification of '' from outside current evaluation is not a constant expression --- gcc/cp/constexpr.cc.jj 2024-02-13 10:29:57.979155641 +0100 +++ gcc/cp/constexpr.cc 2024-03-07 19:35:01.032412221 +0100 @@ -1871,9 +1871,6 @@ cxx_bind_parameters_in_call (const const x = ctx->object; x = build_address (x); } - if (TREE_ADDRESSABLE (type)) - /* Undo convert_for_arg_passing work here. */ - x = convert_from_reference (x); /* Normally we would strip a TARGET_EXPR in an initialization context such as this, but here we do the elision differently: we keep the TARGET_EXPR, and use its CONSTRUCTOR as the value of the parm. */ @@ -1904,7 +1901,13 @@ cxx_bind_parameters_in_call (const const { /* Make sure the binding has the same type as the parm. But only for constant args. */ - if (!TYPE_REF_P (type)) + if (TREE_ADDRESSABLE (type)) + { + if (!same_type_p (type, TREE_TYPE (TREE_TYPE (arg)))) + arg = cp_fold_convert (build_reference_type (type), arg); + arg = convert_from_reference (arg); + } + else if (!TYPE_REF_P (type)) arg = adjust_temp_type (type, arg); if (!TREE_CONSTANT (arg)) *non_constant_args = true; @@ -7494,9 +7497,19 @@ cxx_eval_constant_expression (const cons case PARM_DECL: if (lval && !TYPE_REF_P (TREE_TYPE (t))) - /* glvalue use. */; + { + /* glvalue use. */ + if (TREE_ADDRESSABLE (TREE_TYPE (t))) + if (tree v = ctx->global->get_value (t)) + r = v; + } else if (tree v = ctx->global->get_value (t)) - r = v; + { + r = v; + if (TREE_ADDRESSABLE (TREE_TYPE (t))) + r = cxx_eval_constant_expression (ctx, r, vc_prvalue, + non_constant_p, overflow_p); + } else if (lval) /* Defer in case this is only used for its type. */; else if (ctx->global->is_outside_lifetime (t)) Jakub