On Wed, Mar 29, 2017 at 12:38 PM, Marek Polacek <pola...@redhat.com> wrote: > Here we have a reference initialization with NSDMI and *this. We are crashing > because a PLACEHOLDER_EXPR crept into the gimplifier. > > This happens since r218653 where set_up_extended_ref_temp was changed to > use split_nonconstant_init. As a consequence, cp_gimplify_init_expr might > now be receiving > > D.2051.p = (void *) &<PLACEHOLDER_EXPR struct A> > > instead of > > D.2051 = {.p = (void *) &<PLACEHOLDER_EXPR struct A>} > > where the RHS was a CONSTRUCTOR. It no longer is, so replace_placeholders is > not called anymore. It occurred to me that we should use the same check as in > store_init_value (i.e. check that the object to be used in the substitution is > a class), but given what split_nonconstant_init might produce, handle > COMPONENT_REFs specially. > > Bootstrapped/regtested on x86_64-linux, ok for trunk and 6? > > 2017-03-29 Marek Polacek <pola...@redhat.com> > > PR c++/80095 - ICE with this pointer in NSDMI. > * cp-gimplify.c (cp_gimplify_init_expr): Call replace_placeholders > when TO is a class. > > * g++.dg/cpp1y/nsdmi-aggr8.C: New test. > > diff --git gcc/cp/cp-gimplify.c gcc/cp/cp-gimplify.c > index 354ae1a..e530daf 100644 > --- gcc/cp/cp-gimplify.c > +++ gcc/cp/cp-gimplify.c > @@ -496,7 +496,16 @@ cp_gimplify_init_expr (tree *expr_p) > TREE_TYPE (from) = void_type_node; > } > > - if (cxx_dialect >= cxx14 && TREE_CODE (sub) == CONSTRUCTOR) > + /* split_nonconstant_init might've produced something like > + D.2051.p = (void *) &<PLACEHOLDER_EXPR struct A> > + in which case we want to substitute the placeholder with > + D.2051. */ > + tree op0 = to; > + while (TREE_CODE (op0) == COMPONENT_REF) > + op0 = TREE_OPERAND (op0, 0); > + tree type = TREE_TYPE (op0); > + > + if (cxx_dialect >= cxx14 && CLASS_TYPE_P (strip_array_types (type)))
How about doing this checking in replace_placeholders, instead? That is, if the object isn't a (member of a) class, just return. Jason