From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 64486 invoked by alias); 19 Dec 2018 23:14:16 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 64454 invoked by uid 89); 19 Dec 2018 23:14:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=shorter X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Dec 2018 23:14:14 +0000 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 mx1.redhat.com (Postfix) with ESMTPS id 0B78F88308 for ; Wed, 19 Dec 2018 23:14:13 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-214.ams2.redhat.com [10.36.117.214]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A5C0A100194A; Wed, 19 Dec 2018 23:14:12 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id wBJNEAEQ012965; Thu, 20 Dec 2018 00:14:11 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id wBJNEAqW012964; Thu, 20 Dec 2018 00:14:10 +0100 Date: Wed, 19 Dec 2018 23:14:00 -0000 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: Re: [C++ PATCH] Constexpr fold even some TREE_CONSTANT ctors (PR c++/87934) Message-ID: <20181219231410.GK23305@tucnak> Reply-To: Jakub Jelinek References: <20181218204517.GS23305@tucnak> <20181218231937.GW23305@tucnak> <89ec010c-1b82-47ff-fd46-7f87d20b53e9@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <89ec010c-1b82-47ff-fd46-7f87d20b53e9@redhat.com> User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes X-SW-Source: 2018-12/txt/msg01426.txt.bz2 On Tue, Dec 18, 2018 at 10:27:56PM -0500, Jason Merrill wrote: > On 12/18/18 6:19 PM, Jakub Jelinek wrote: > > On Tue, Dec 18, 2018 at 05:40:03PM -0500, Jason Merrill wrote: > > > On 12/18/18 3:45 PM, Jakub Jelinek wrote: > > > > The following testcase FAILs, because parsing creates a TREE_CONSTANT > > > > CONSTRUCTOR that contains CONST_DECL elts. cp_fold_r can handle that, > > > > but constexpr evaluation doesn't touch those CONSTRUCTORs. > > > > > > > > Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for > > > > trunk? > > > > > > OK. I also wonder if store_init_value should use cp_fold_r rather than just > > > cp_fully_fold. > > > > I've been thinking about that already when working on the PR88410 bug. > > > > Do you mean something like following completely untested patch? > > Perhaps I could add a helper inline so that there is no code repetition > > between cp_fully_fold and this new function. > > Something like that, yes. The following does the job too (even the PR88410 ICE is gone with the cp-gimplify.c change from that patch reverted) and is shorter. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-12-19 Jakub Jelinek * cp-tree.h (cp_fully_fold_init): Declare. * cp-gimplify.c (cp_fully_fold_init): New function. * typeck2.c (split_nonconstant_init, store_init_value): Use it instead of cp_fully_fold. --- gcc/cp/cp-tree.h.jj 2018-12-19 09:09:28.251543416 +0100 +++ gcc/cp/cp-tree.h 2018-12-19 14:57:54.719812330 +0100 @@ -7542,6 +7542,7 @@ extern bool cxx_omp_privatize_by_referen extern bool cxx_omp_disregard_value_expr (tree, bool); extern void cp_fold_function (tree); extern tree cp_fully_fold (tree); +extern tree cp_fully_fold_init (tree); extern void clear_fold_cache (void); extern tree lookup_hotness_attribute (tree); extern tree process_stmt_hotness_attribute (tree); --- gcc/cp/cp-gimplify.c.jj 2018-12-19 09:09:28.335542037 +0100 +++ gcc/cp/cp-gimplify.c 2018-12-19 15:00:28.214293053 +0100 @@ -2171,6 +2171,20 @@ cp_fully_fold (tree x) return cp_fold_rvalue (x); } +/* Likewise, but also fold recursively, which cp_fully_fold doesn't perform + in some cases. */ + +tree +cp_fully_fold_init (tree x) +{ + if (processing_template_decl) + return x; + x = cp_fully_fold (x); + hash_set pset; + cp_walk_tree (&x, cp_fold_r, &pset, NULL); + return x; +} + /* c-common interface to cp_fold. If IN_INIT, this is in a static initializer and certain changes are made to the folding done. Or should be (FIXME). We never touch maybe_const, as it is only used for the C front-end --- gcc/cp/typeck2.c.jj 2018-12-19 09:09:28.401540956 +0100 +++ gcc/cp/typeck2.c 2018-12-19 14:57:54.736812061 +0100 @@ -750,7 +750,7 @@ split_nonconstant_init (tree dest, tree init = TARGET_EXPR_INITIAL (init); if (TREE_CODE (init) == CONSTRUCTOR) { - init = cp_fully_fold (init); + init = cp_fully_fold_init (init); code = push_stmt_list (); if (split_nonconstant_init_1 (dest, init)) init = NULL_TREE; @@ -858,7 +858,7 @@ store_init_value (tree decl, tree init, if (!const_init) value = oldval; } - value = cp_fully_fold (value); + value = cp_fully_fold_init (value); /* Handle aggregate NSDMI in non-constant initializers, too. */ value = replace_placeholders (value, decl); Jakub