public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Marek Polacek <polacek@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH v3] c++: ICE with temporary of class type in array DMI [PR109966]
Date: Fri, 12 Apr 2024 16:15:45 -0400	[thread overview]
Message-ID: <5fd063a8-9406-4b16-8d8d-3c4b3d364abd@redhat.com> (raw)
In-Reply-To: <ZfNro5HtgOJTEE4R@redhat.com>

On 3/14/24 17:26, Marek Polacek wrote:
> 
> In the following patch, I'm taking a different tack.  I believe
> we ought to use TARGET_EXPR_ELIDING_P.  The gimplify_arg bit I'm
> talking about below is this:
> 
>        /* Also strip a TARGET_EXPR that would force an extra copy.  */
>        if (TREE_CODE (*arg_p) == TARGET_EXPR)
>          {
>            tree init = TARGET_EXPR_INITIAL (*arg_p);
>            if (init
>                && !VOID_TYPE_P (TREE_TYPE (init)))
>              *arg_p = init;
>          }
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/13?
> 
> -- >8 --
> This ICE started with the fairly complicated r13-765.  We crash in
> gimplify_var_or_parm_decl because a stray VAR_DECL leaked there.
> The problem is ultimately that potential_prvalue_result_of wasn't
> correctly handling arrays and replace_placeholders_for_class_temp_r
> replaced a PLACEHOLDER_EXPR in a TARGET_EXPR which is used in the
> context of copy elision.  If I have
> 
>    M m[2] = { M{""}, M{""} };
> 
> then we don't invoke the M(const M&) copy-ctor.
> 
> One part of the fix is to use TARGET_EXPR_ELIDING_P rather than
> potential_prvalue_result_of.  That unfortunately doesn't handle the
> case like
> 
>    struct N { N(M); };
>    N arr[2] = { M{""}, M{""} };
> 
> because TARGET_EXPRs that initialize a function argument are not
> marked TARGET_EXPR_ELIDING_P even though gimplify_arg drops such
> TARGET_EXPRs on the floor.  We can use a pset to avoid replacing
> placeholders in them.
> 
> I made an attempt to use set_target_expr_eliding in
> convert_for_arg_passing but that regressed constexpr-diag1.C, and does
> not seem like a prudent change in stage 4 anyway.

I tried the same thing to see what you mean, and that doesn't look like 
a regression to me, just a different (and more accurate) diagnostic.

But you're right that this patch is safer, and the other approach can 
wait for stage 1.  Will you queue that up?  In the mean time, this patch 
is OK.

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

...with this change.

Jason


  parent reply	other threads:[~2024-04-12 20:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-11 23:27 [PATCH] " Marek Polacek
2024-03-12 13:57 ` Jason Merrill
2024-03-12 15:56   ` [PATCH v2] " Marek Polacek
2024-03-12 22:26     ` Jason Merrill
2024-03-14 21:26       ` [PATCH v3] " Marek Polacek
2024-03-19 19:47         ` Marek Polacek
2024-04-12 20:15         ` Jason Merrill [this message]
2024-04-12 21:41           ` Marek Polacek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5fd063a8-9406-4b16-8d8d-3c4b3d364abd@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=polacek@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).