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>,
	GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] c++: Fix ICE in reshape_init with init-list [PR95164]
Date: Mon, 7 Sep 2020 18:23:01 -0400	[thread overview]
Message-ID: <966f88ec-b6d8-0803-ef1a-fbff81583cc9@redhat.com> (raw)
In-Reply-To: <20200904213922.2543048-1-polacek@redhat.com>

On 9/4/20 5:39 PM, Marek Polacek wrote:
> This patch fixes a long-standing bug in reshape_init_r.  Since r209314
> we implement DR 1467 which handles list-initialization with a single
> initializer of the same type as the target.  In this test this causes
> a crash in reshape_init_r when we're processing a constructor that has
> undergone the DR 1467 transformation.
> 
> Take e.g. the
> 
>    foo({{1, {H{k}}}});
> 
> line in the attached test.  {H{k}} initializes the field b of H in I.
> H{k} is a functional cast, so has TREE_HAS_CONSTRUCTOR set, so is
> COMPOUND_LITERAL_P.  We perform the DR 1467 transformation and turn
> {H{k}} into H{k}.  Then we attempt to reshape H{k} again and since
> first_initializer_p is null and it's COMPOUND_LITERAL_P, we go here:
> 
>             else if (COMPOUND_LITERAL_P (stripped_init))
>               gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (stripped_init));

It looks to me like the bug is here:

>   /* [dcl.init.aggr]                                                                                           
>                                                                                                                
>      All implicit type conversions (clause _conv_) are considered when                                         
>      initializing the aggregate member with an initializer from an                                             
>      initializer-list.  If the initializer can initialize a member,                                            
>      the member is initialized.  Otherwise, if the member is itself a                                          
>      non-empty subaggregate, brace elision is assumed and the                                                  
>      initializer is considered for the initialization of the first                                             
>      member of the subaggregate.  */
>   if (TREE_CODE (init) != CONSTRUCTOR
>       /* But don't try this for the first initializer, since that would be                                     
>          looking through the outermost braces; A a2 = { a1 }; is not a                                         
>          valid aggregate initialization.  */
>       && !first_initializer_p
>       && (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (init))
>           || can_convert_arg (type, TREE_TYPE (init), init, LOOKUP_NORMAL,
>                               complain)))
>     {
>       d->cur++;
>       return init;
>     }

We ought to handle H{k} here, treat it as the initializer for the 
member, and not get as far as the code you quote above.

Jason


  reply	other threads:[~2020-09-07 22:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-04 21:39 Marek Polacek
2020-09-07 22:23 ` Jason Merrill [this message]
2020-09-09 19:33   ` [PATCH v2] " Marek Polacek
2020-09-09 21:03     ` Jason Merrill

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=966f88ec-b6d8-0803-ef1a-fbff81583cc9@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).