On Wed, Nov 16, 2016 at 04:26:36PM -0500, Jason Merrill wrote: > On Wed, Nov 16, 2016 at 4:00 PM, Jakub Jelinek <ja...@redhat.com> wrote: > > Jason's recent patch to turn reference vars initialized with invariant > > addresses broke the first testcase below, because &self->singleton > > is considered TREE_CONSTANT (because self is TREE_CONSTANT VAR_DECL and > > singleton field has constant offset), but after going into SSA form > > it is not supposed to be TREE_CONSTANT anymore (&self_2->singleton), > > because SSA_NAMEs don't have TREE_CONSTANT set on them. > > > > The following patch fixes it by gimplifying such vars into their > > DECL_INITIAL unless in OpenMP regions, where such folding is deferred > > until omplower pass finishes. > > Hmm, this seems like a workaround; why don't we see the same problem > with constant pointer variables?
Dunno, tried to construct a testcase, but it doesn't fail. If it is e.g. TREE_CONSTANT because of being constexpr, then the FE already replaces it by its initializer. > A simpler workaround would be to not set TREE_CONSTANT on references > in the first place, since the constexpr code doesn't need it. What do > you think? If the FE doesn't need it, indeed it would be simpler this way. > commit 6cdd28bb152fcb07a7eb6c9f053cd435cf719a20 > Author: Jason Merrill <ja...@redhat.com> > Date: Wed Nov 16 16:13:25 2016 -0500 > > ref > > diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c > index c54a2de..87db589 100644 > --- a/gcc/cp/decl.c > +++ b/gcc/cp/decl.c > @@ -6839,7 +6839,8 @@ cp_finish_decl (tree decl, tree init, bool > init_const_expr_p, > /* Set these flags now for templates. We'll update the flags in > store_init_value for instantiations. */ > DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1; > - if (decl_maybe_constant_var_p (decl)) > + if (decl_maybe_constant_var_p (decl) > + && TREE_CODE (type) != REFERENCE_TYPE) > TREE_CONSTANT (decl) = 1; > } > } > diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c > index 022a478..dcdb710 100644 > --- a/gcc/cp/typeck2.c > +++ b/gcc/cp/typeck2.c > @@ -824,7 +824,8 @@ store_init_value (tree decl, tree init, vec<tree, > va_gc>** cleanups, int flags) > const_init = (reduced_constant_expression_p (value) > || error_operand_p (value)); > DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = const_init; > - TREE_CONSTANT (decl) = const_init && decl_maybe_constant_var_p (decl); > + if (TREE_CODE (type) != REFERENCE_TYPE) > + TREE_CONSTANT (decl) = const_init && decl_maybe_constant_var_p (decl); > } > value = cp_fully_fold (value); > Jakub