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 EC6D93858D38 for ; Mon, 23 Jan 2023 15:17:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC6D93858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674487071; 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=n14eTqYbSAAMMTnV8dnWi0K4sEMS2M8FPu9PaCjPD74=; b=RuRscI/i72Z41JLtbG3VZ0U6FfkEgJtrUzQdznOdI5rSxy26mFEkW9ZCU/M3W2llLsz/KV 2Kl5Yhj5RZF2clCR1432er9oqBNO4y7qjz+syQfYEvYbDsAQdy9xSs3nbFsI9xdYJTMB+Y V9SgCGvo3IOQlfRQ1Xk5IcjUyyDkje0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-94-eXFAFIqkO3qxEJKoiBcM3w-1; Mon, 23 Jan 2023 10:17:48 -0500 X-MC-Unique: eXFAFIqkO3qxEJKoiBcM3w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 09D30101A55E; Mon, 23 Jan 2023 15:17:48 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B4E3039DCA; Mon, 23 Jan 2023 15:17:47 +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 30NFHi9M444726 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 23 Jan 2023 16:17:44 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 30NFHhpS444725; Mon, 23 Jan 2023 16:17:43 +0100 Date: Mon, 23 Jan 2023 16:17:43 +0100 From: Jakub Jelinek To: Richard Biener Cc: Jason Merrill , Jan Hubicka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++, cgraphbuild: Handle DECL_VALUE_EXPRs in record_reference [PR108474] Message-ID: Reply-To: Jakub Jelinek References: <799bfe17-b60d-7353-d676-5296e64b3769@redhat.com> <6f8e0faf-55eb-cf20-e796-a1828197bb23@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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=-3.5 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_H2,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 Mon, Jan 23, 2023 at 12:37:59PM +0000, Richard Biener wrote: > Guess it should work. Do we (accidentially?) do anything special > to static var initializers in nested functions? I don't think we touch those, we walk the bodies of functions, I don't think we traverse static var DECL_INITIALs. > Can you think of > any other C/C++ construct that would have DECL_VALUE_EXPR in them? A lot of them, coroutines, FE NRV, anon union vars, lambdas, in modules, OpenMP privatized members, structured bindings, __FUNCTION__ etc., later VLAs, tree-nested, OpenMP lowering. But anon union vars and structured bindings are the only ones known for which this is actually needed in static initializers. I'm afraid no idea about modules case, for OpenMP one needs executable code, tried the __FUNCTION__ case and while there is DECL_VALUE_EXPR used, the initializer is already replaced by STRING_CST in the FE somewhere, VLAs aren't allowed. BTW, the patch successfully passed bootstrap/regtested on x86_64-linux and i686-linux. > > 2023-01-23 Jakub Jelinek > > > > PR c++/108474 > > * cgraphbuild.cc: Include gimplify.h. > > (record_reference): Replace VAR_DECLs with DECL_HAS_VALUE_EXPR_P with > > their corresponding DECL_VALUE_EXPR expressions after unsharing. > > > > * cp-gimplify.cc (cp_fold_r): Revert 2023-01-19 changes. > > > > * g++.dg/cpp1z/decomp57.C: New test. > > * g++.dg/cpp1z/decomp58.C: New test. > > > > --- gcc/cgraphbuild.cc.jj 2023-01-02 09:32:34.889104620 +0100 > > +++ gcc/cgraphbuild.cc 2023-01-23 12:10:35.042067571 +0100 > > @@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. > > #include "gimple-walk.h" > > #include "ipa-utils.h" > > #include "except.h" > > +#include "gimplify.h" > > > > /* Context of record_reference. */ > > struct record_reference_ctx > > @@ -79,6 +80,17 @@ record_reference (tree *tp, int *walk_su > > > > if (VAR_P (decl)) > > { > > + /* Replace vars with their DECL_VALUE_EXPR if any. > > + This is normally done during gimplification, but > > + static var initializers are never gimplified. */ > > + if (DECL_HAS_VALUE_EXPR_P (decl)) > > + { > > + tree *p; > > + for (p = tp; *p != decl; p = &TREE_OPERAND (*p, 0)) > > + ; > > + *p = unshare_expr (DECL_VALUE_EXPR (decl)); > > + return record_reference (tp, walk_subtrees, data); > > + } > > varpool_node *vnode = varpool_node::get_create (decl); > > ctx->varpool_node->create_reference (vnode, IPA_REF_ADDR); > > } > > --- gcc/cp/cp-gimplify.cc.jj 2023-01-23 11:47:49.889875804 +0100 > > +++ gcc/cp/cp-gimplify.cc 2023-01-23 11:49:01.227841759 +0100 > > @@ -1010,16 +1010,6 @@ cp_fold_r (tree *stmt_p, int *walk_subtr > > } > > break; > > > > - case VAR_DECL: > > - /* In initializers replace anon union artificial VAR_DECLs > > - with their DECL_VALUE_EXPRs, as nothing will do it later. */ > > - if (DECL_ANON_UNION_VAR_P (stmt) && !data->genericize) > > - { > > - *stmt_p = stmt = unshare_expr (DECL_VALUE_EXPR (stmt)); > > - break; > > - } > > - break; > > - > > default: > > break; > > } > > --- gcc/testsuite/g++.dg/cpp1z/decomp57.C.jj 2023-01-23 11:48:36.367202107 +0100 > > +++ gcc/testsuite/g++.dg/cpp1z/decomp57.C 2023-01-23 11:48:36.367202107 +0100 > > @@ -0,0 +1,27 @@ > > +// PR c++/108474 > > +// { dg-do link { target c++17 } } > > + > > +struct T { int i, j; }; > > +T h; > > +auto [i, j] = h; > > +int &r = i; > > +int s = i; > > +int *t = &i; > > + > > +void > > +foo (int **p, int *q) > > +{ > > + static int &u = i; > > + static int v = i; > > + static int *w = &i; > > + int &x = i; > > + int y = i; > > + int *z = &i; > > + *p = &i; > > + *q = i; > > +} > > + > > +int > > +main () > > +{ > > +} > > --- gcc/testsuite/g++.dg/cpp1z/decomp58.C.jj 2023-01-23 11:48:36.367202107 +0100 > > +++ gcc/testsuite/g++.dg/cpp1z/decomp58.C 2023-01-23 11:48:36.367202107 +0100 > > @@ -0,0 +1,39 @@ > > +// PR c++/108474 > > +// { dg-do link { target c++17 } } > > + > > +namespace std { > > + template struct tuple_size; > > + template struct tuple_element; > > +} > > + > > +struct A { > > + int i; > > + template int& get() { return i; } > > +}; > > + > > +template <> struct std::tuple_size { static const int value = 2; }; > > +template struct std::tuple_element { using type = int; }; > > + > > +struct A a; > > +auto [i, j] = a; > > +int &r = i; > > +int s = i; > > +int *t = &i; > > + > > +void > > +foo (int **p, int *q) > > +{ > > + static int &u = i; > > + static int v = i; > > + static int *w = &i; > > + int &x = i; > > + int y = i; > > + int *z = &i; > > + *p = &i; > > + *q = i; > > +} > > + > > +int > > +main () > > +{ > > +} Jakub