From: Jason Merrill <jason@redhat.com>
To: Marek Polacek <polacek@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH v2] c++: Fix crash in gimplifier with paren init of aggregates [PR94155]
Date: Fri, 3 Apr 2020 22:39:49 -0400 [thread overview]
Message-ID: <79f201f2-3932-b10c-7f78-afda837c93e4@redhat.com> (raw)
In-Reply-To: <20200404010813.GV2929@redhat.com>
On 4/3/20 9:08 PM, Marek Polacek wrote:
> On Fri, Apr 03, 2020 at 03:01:37PM -0400, Jason Merrill via Gcc-patches wrote:
>> On 3/30/20 4:28 PM, Marek Polacek wrote:
>>> Here we crash in the gimplifier because gimplify_init_ctor_eval doesn't
>>> expect null indexes for a constructor:
>>>
>>> /* ??? Here's to hoping the front end fills in all of the indices,
>>> so we don't have to figure out what's missing ourselves. */
>>> gcc_assert (purpose);
>>>
>>> The indexes weren't filled because we never called reshape_init: for
>>> a constructor that represents parenthesized initialization of an
>>> aggregate we don't allow brace elision or designated initializers. So
>>> fill in the indexes manually, here we have an array, and we can simply
>>> assign indexes starting from 0.
>>>
>>> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>>
>> Shouldn't digest_init fill in the indexes? In
>> process_init_constructor_array I see
>>
>> if (!ce->index)
>> ce->index = size_int (i);
>
> Yes, that works too. Thus:
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> -- >8 --
> Here we crash in the gimplifier because gimplify_init_ctor_eval doesn't
> expect null indexes for a constructor:
>
> /* ??? Here's to hoping the front end fills in all of the indices,
> so we don't have to figure out what's missing ourselves. */
> gcc_assert (purpose);
>
> The indexes weren't filled because we never called reshape_init: for
> a constructor that represents parenthesized initialization of an
> aggregate we don't allow brace elision or designated initializers. So
> call digest_init to fill in the indexes.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> PR c++/94155 - crash in gimplifier with paren init of aggregates.
> * decl.c (check_initializer): Call digest_init.
>
> * g++.dg/cpp2a/paren-init22.C: New test.
> ---
> gcc/cp/decl.c | 5 +++++
> gcc/testsuite/g++.dg/cpp2a/paren-init22.C | 15 +++++++++++++++
> 2 files changed, 20 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/cpp2a/paren-init22.C
>
> diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
> index 69a238997b4..63e7bda09f5 100644
> --- a/gcc/cp/decl.c
> +++ b/gcc/cp/decl.c
> @@ -6754,6 +6754,11 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
> init = build_constructor_from_list (init_list_type_node, init);
> CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
> CONSTRUCTOR_IS_PAREN_INIT (init) = true;
> + /* The gimplifier expects that the front end fills in all of the
> + indices. Normally, reshape_init_array fills these in, but we
> + don't call reshape_init because that does nothing when it gets
> + CONSTRUCTOR_IS_PAREN_INIT. */
> + init = digest_init (type, init, tf_warning_or_error);
But why weren't we already calling digest_init in store_init_value? Was
the CONSTRUCTOR making it all the way to gimplification still having
init_list_type_node?
> }
> }
> else if (TREE_CODE (init) == TREE_LIST
> diff --git a/gcc/testsuite/g++.dg/cpp2a/paren-init22.C b/gcc/testsuite/g++.dg/cpp2a/paren-init22.C
> new file mode 100644
> index 00000000000..1b2959e7731
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/paren-init22.C
> @@ -0,0 +1,15 @@
> +// PR c++/94155 - crash in gimplifier with paren init of aggregates.
> +// { dg-do compile { target c++2a } }
> +
> +struct S { int i, j; };
> +
> +struct A {
> + S s;
> + constexpr A(S e) : s(e) {}
> +};
> +
> +void
> +f()
> +{
> + A g[1]({{1, 1}});
> +}
>
> base-commit: 0c809f727cd2a6c70c307d9dd53d26dc84bf292a
>
next prev parent reply other threads:[~2020-04-04 2:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-30 20:28 [PATCH] " Marek Polacek
2020-04-03 19:01 ` Jason Merrill
2020-04-04 1:08 ` [PATCH v2] " Marek Polacek
2020-04-04 2:39 ` Jason Merrill [this message]
2020-04-04 17:56 ` Marek Polacek
2020-04-06 14:47 ` Jason Merrill
2020-04-06 15:57 ` [PATCH v3] " Marek Polacek
2020-04-06 16:35 ` 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=79f201f2-3932-b10c-7f78-afda837c93e4@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).