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 C8E543857829 for ; Fri, 10 Jun 2022 19:57:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C8E543857829 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-318-zSWzptflNmKQoMiDy83xsw-1; Fri, 10 Jun 2022 15:57:09 -0400 X-MC-Unique: zSWzptflNmKQoMiDy83xsw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3E2261C068CD for ; Fri, 10 Jun 2022 19:57:09 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.11]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F1B6940CF8EF; Fri, 10 Jun 2022 19:57:08 +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 25AJv6Pb3461237 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 10 Jun 2022 21:57:06 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 25AJv6bF3461235; Fri, 10 Jun 2022 21:57:06 +0200 Date: Fri, 10 Jun 2022 21:57:06 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++: Add support for __real__/__imag__ modifications in constant expressions [PR88174] Message-ID: Reply-To: Jakub Jelinek References: <4d9319d5-1890-7c99-6c1b-d940f873a590@redhat.com> MIME-Version: 1.0 In-Reply-To: <4d9319d5-1890-7c99-6c1b-d940f873a590@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 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.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Jun 2022 19:57:12 -0000 On Fri, Jun 10, 2022 at 01:27:28PM -0400, Jason Merrill wrote: > > --- gcc/cp/constexpr.cc.jj 2022-06-08 08:21:02.973448193 +0200 > > +++ gcc/cp/constexpr.cc 2022-06-08 17:13:04.986040449 +0200 > > @@ -5707,6 +5707,20 @@ cxx_eval_store_expression (const constex > > } > > break; > > + case REALPART_EXPR: > > + gcc_assert (probe == target); > > Doesn't this assert mean that complex_expr will always be == valp? No, even when handling the pushed *PART_EXPR, it will set valp = &TREE_OPERAND (*valp, index != integer_zero_node); So, valp will be either &TREE_OPERAND (*complex_expr, 0) or &TREE_OPERAND (*complex_expr, 1). As *valp = init; is what is usually then stored and we want to store there the scalar. > > @@ -5946,6 +5984,24 @@ cxx_eval_store_expression (const constex > > = get_or_insert_ctor_field (*valp, indexes[i], index_pos_hints[i]); > > valp = &cep->value; > > } > > + if (complex_part != -1) > > + { > > + if (TREE_CODE (*valp) == COMPLEX_CST) > > + *valp = build2 (COMPLEX_EXPR, TREE_TYPE (*valp), > > + TREE_REALPART (*valp), > > + TREE_IMAGPART (*valp)); > > + else if (TREE_CODE (*valp) == CONSTRUCTOR > > + && CONSTRUCTOR_NELTS (*valp) == 0 > > + && CONSTRUCTOR_NO_CLEARING (*valp)) > > + { > > + tree r = build_constructor (TREE_TYPE (TREE_TYPE (*valp)), NULL); > > + CONSTRUCTOR_NO_CLEARING (r) = 1; > > + *valp = build2 (COMPLEX_EXPR, TREE_TYPE (*valp), r, r); > > + } > > + gcc_assert (TREE_CODE (*valp) == COMPLEX_EXPR); > > + complex_expr = valp; > > + valp = &TREE_OPERAND (*valp, complex_part); > > I don't understand this block; shouldn't valp point to the real or imag part > of the complex number at this point? How could complex_part be set without > us handling the complex case in the loop already? Because for most references, the code will do: vec_safe_push (ctors, *valp); vec_safe_push (indexes, index); I chose not to do this for *PART_EXPR, because the COMPLEX_EXPR isn't a CONSTRUCTOR and code later on e.g. walks all the ctors and accesses CONSTRUCTOR_NO_CLEARING on them etc. As the *PART_EXPR is asserted to be outermost only, complex_expr is a variant of that ctors push and complex_part of the indexes. The reason for the above if is just in case the evaluation of the rhs of the store would store to the complex and could e.g. make it a COMPLEX_CST again. > > + } > > } > > if (*non_constant_p) > > @@ -6016,6 +6072,22 @@ cxx_eval_store_expression (const constex > > if (TREE_CODE (TREE_TYPE (elt)) == UNION_TYPE) > > CONSTRUCTOR_NO_CLEARING (elt) = false; > > } > > + if (complex_expr) > > I might have added the COMPLEX_EXPR to ctors instead of a separate variable, > but this is fine too. See above. The COMPLEX_EXPR needs special handling (conversion into COMPLEX_CST if it is constant) anyway. Jakub