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++: ICE with template code in constexpr [PR104284]
Date: Thu, 24 Mar 2022 11:40:11 -0400 [thread overview]
Message-ID: <4bc3f576-c238-2559-197e-3a51b3722505@redhat.com> (raw)
In-Reply-To: <YjT/2vcFRIYNVWgD@redhat.com>
On 3/18/22 17:55, Marek Polacek wrote:
> On Fri, Mar 11, 2022 at 06:46:42PM -0500, Jason Merrill wrote:
>> On 3/10/22 18:04, Marek Polacek wrote:
>>> Since r9-6073 cxx_eval_store_expression preevaluates the value to
>>> be stored, and that revealed a crash where a template code (here,
>>> code=IMPLICIT_CONV_EXPR) leaks into cxx_eval*.
>>>
>>> It happens because we're performing build_vec_init while processing
>>> a template
>>
>> Hmm, that seems like the bug. Where's that call coming from?
>
> From build_aggr_init. So we're handling e.g.
>
> template<class>
> constexpr void g () {
> constexpr S s2[]{{'a'}};
> }
>
> cp_finish_decl (decl=s2, init={{'a'}}) sees we're in processing_template_decl,
> but also that we have a constexpr var which is not dependent, nor is its
> initializer:
>
> else if (init
> && (init_const_expr_p || DECL_DECLARED_CONSTEXPR_P (decl))
> && !TYPE_REF_P (type)
> && decl_maybe_constant_var_p (decl)
> && !(dep_init = value_dependent_init_p (init)))
> {
> /* This variable seems to be a non-dependent constant, so process
> its initializer. If check_initializer returns non-null the
> initialization wasn't constant after all. */
> tree init_code;
> cleanups = make_tree_vector ();
> init_code = check_initializer (decl, init, flags, &cleanups);
>
> so we call check_initializer, where we go down this path:
>
> init_code = build_aggr_init_full_exprs (decl, init, flags);
>
> build_aggr_init sees that the type of 's2' is ARRAY_TYPE, so it calls
> build_vec_init.
>
> I now recall that we've discussed build_vec_init in a template in the
> past, for example in the context of c++/93676. So I agree we ought to
> make an effort to avoid calling build_vec_init in a template. Perhaps
> like this: use an INIT_EXPR. With that, we should call build_vec_init
> if needed while instantiating. Does that make any sense?
Hmm. If we do that, then we get back to
> if (TREE_CODE (init_code) == INIT_EXPR)
in check_initializer, and pull out the same init again, and set
LOOKUP_ALREADY_DIGESTED. But I think that's wrong, we haven't digested
it yet.
Maybe we could avoid entering the below block of check_initializer at
all in this situation?
> if (((type_build_ctor_call (type) || CLASS_TYPE_P (type))
> && !(flags & LOOKUP_ALREADY_DIGESTED)
> && !(init && BRACE_ENCLOSED_INITIALIZER_P (init)
> && CP_AGGREGATE_TYPE_P (type)
> && (CLASS_TYPE_P (type)
Maybe by adding || processing_template_decl here?
> || !TYPE_NEEDS_CONSTRUCTING (type)
> || type_has_extended_temps (type))))
> || (DECL_DECOMPOSITION_P (decl) && TREE_CODE (type) == ARRAY_TYPE))
Jason
next prev parent reply other threads:[~2022-03-24 15:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-10 22:04 [PATCH] " Marek Polacek
2022-03-10 22:27 ` Marek Polacek
2022-03-11 23:46 ` Jason Merrill
2022-03-18 21:55 ` [PATCH v2] " Marek Polacek
2022-03-24 15:40 ` Jason Merrill [this message]
2022-03-24 21:53 ` [PATCH v3] " Marek Polacek
2022-03-24 22:14 ` 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=4bc3f576-c238-2559-197e-3a51b3722505@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).