On Thu, Mar 14, 2024 at 05:26:59PM -0400, Marek Polacek wrote:
> @@ -1441,11 +1406,13 @@ static tree
>  replace_placeholders_for_class_temp_r (tree *tp, int *, void *data)
>  {
>    tree t = *tp;
> -  tree full_expr = *static_cast<tree *>(data);
> +  auto pset = static_cast<hash_set<tree> *>(data);
>  
>    /* We're looking for a TARGET_EXPR nested in the whole expression.  */
>    if (TREE_CODE (t) == TARGET_EXPR
> -      && !potential_prvalue_result_of (t, full_expr))
> +      /* That serves as temporary materialization, not an initializer.  */
> +      && !TARGET_EXPR_ELIDING_P (t)
> +      && !pset->add (t))
>      {
>        tree init = TARGET_EXPR_INITIAL (t);
>        while (TREE_CODE (init) == COMPOUND_EXPR)
> @@ -1460,6 +1427,16 @@ replace_placeholders_for_class_temp_r (tree *tp, int 
> *, void *data)
>         gcc_checking_assert (!find_placeholders (init));
>       }
>      }
> +  /* TARGET_EXPRs initializing function arguments are not marked as eliding,
> +     even though gimplify_arg drops them on the floor.  Don't go replacing
> +     placeholders in them.  */
> +  else if (TREE_CODE (t) == CALL_EXPR || TREE_CODE (t) == AGGR_INIT_EXPR)
> +    for (int i = 0; i < call_expr_nargs (t); ++i)
> +      {
> +     tree arg = get_nth_callarg (t, i);
> +     if (TREE_CODE (arg) == TARGET_EXPR)

I just realized this could also check !TARGET_EXPR_ELIDING_P; there's no point
to adding an eliding TARGET_EXPR into the pset.

> +       pset->add (arg);
> +      }

Marek

Reply via email to