> On Tue, Jan 26, 2021 at 10:03:16AM +0100, Richard Biener wrote: > > > In 4.8 and earlier we used to fold the following to 0 during GENERIC > > > folding, > > > but we don't do that anymore because ctor_for_folding etc. has been > > > turned into a > > > GIMPLE centric API, but as the testcase shows, it is invoked even during > > > GENERIC folding and there the automatic vars still should have meaningful > > > initializers. I've verified that the C++ FE drops TREE_READONLY on > > > automatic vars with const qualified types if they require non-constant > > > (runtime) initialization. > > > > --- gcc/varpool.c.jj 2021-01-26 08:57:36.184290279 +0100 > > > +++ gcc/varpool.c 2021-01-26 09:46:16.453619140 +0100 > > > @@ -412,6 +412,12 @@ ctor_for_folding (tree decl) > > > if (!TREE_STATIC (decl) && !DECL_EXTERNAL (decl)) > > > { > > > gcc_assert (!TREE_PUBLIC (decl)); > > > + /* Unless this is called during FE folding. */ > > > + if (!in_gimple_form > > > > Wouldn't it be better to use symtab->state == PARSING? Why isn't > > That would work for me too, in_gimple_form is just what is normally used > for the folding. And the routine is doing folding, but sits in a file where > symtab->state == PARSING check is more natural.
I think it is property of function to be in generic form. We allow functions to be constructed late and we could allow doing that using generic (even though as far as I know we generate them all as gimple - profiling code, collected ctors, offlining etc). So perhaps we don't need to tie that with symtab state. Honza > > > it safe to always return DECL_INITIAL (but demote NULL to > > error_mark_node and/or change the gimplifier to set it to > > I'm not sure if it is safe to look at DECL_INITIAL after gimplification for > automatic vars because the gimplifier is destructive and could have changed > the initializers in random ways. But I admit I haven't investigated whether > e.g. debug info cares about DECL_INITIAL for automatic vars or not. > > Looking at gimplify_decl_expr I see there: > if (init && init != error_mark_node) > { > if (!TREE_STATIC (decl)) > { > DECL_INITIAL (decl) = NULL_TREE; > init = build2 (INIT_EXPR, void_type_node, decl, init); > gimplify_and_add (init, seq_p); > ggc_free (init); > } > else > /* We must still examine initializers for static variables > as they may contain a label address. */ > walk_tree (&init, force_labels_r, NULL, NULL); > } > so perhaps we are usually fine. > gimplify_compound_literal_expr doesn't clear DECL_INITIAL when > optimizing non-addressable complit decls though (though perhaps those > decls shouldn't appear in the IL then). > > > error_mark_node for autos) for TREE_READONLY && !TREE_SIDE_EFFECTS > > decls (including autos)? Thus, why key on is_gimple_form at all? > > Perhaps it is not needed, I was just trying to be safe. Because > after gimplification it will generally not be useful anyway. > > Jakub >