From: Jason Merrill <jason@redhat.com>
To: Patrick Palka <ppalka@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: non-dependent .* folding [PR112427]
Date: Fri, 10 Nov 2023 16:36:38 -0500 [thread overview]
Message-ID: <8fd05dbf-f08d-441f-90c0-10ac6fe5f7a8@redhat.com> (raw)
In-Reply-To: <2fb218a2-713a-1a09-3c18-0f37ab359631@idea>
On 11/10/23 10:28, Patrick Palka wrote:
> On Fri, 10 Nov 2023, Patrick Palka wrote:
>
>> On Thu, 9 Nov 2023, Jason Merrill wrote:
>>
>>> On 11/8/23 16:59, Patrick Palka wrote:
>>>> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
>>>> trunk?
>>>>
>>>> -- >8 --
>>>>
>>>> Here when building up the non-dependent .* expression, we crash from
>>>> fold_convert on 'b.a' due to this (templated) COMPONENT_REF having an
>>>> IDENTIFIER_NODE instead of FIELD_DECL operand that middle-end routines
>>>> expect. Like in r14-4899-gd80a26cca02587, this patch fixes this by
>>>> replacing the problematic piecemeal folding with a single call to
>>>> cp_fully_fold.
>>>>
>>>> PR c++/112427
>>>>
>>>> gcc/cp/ChangeLog:
>>>>
>>>> * typeck2.cc (build_m_component_ref): Use cp_convert, build2 and
>>>> cp_fully_fold instead of fold_build_pointer_plus and fold_convert.
>>>
>>>> gcc/testsuite/ChangeLog:
>>>>
>>>> * g++.dg/template/non-dependent29.C: New test.
>>>> ---
>>>> gcc/cp/typeck2.cc | 5 ++++-
>>>> gcc/testsuite/g++.dg/template/non-dependent29.C | 13 +++++++++++++
>>>> 2 files changed, 17 insertions(+), 1 deletion(-)
>>>> create mode 100644 gcc/testsuite/g++.dg/template/non-dependent29.C
>>>>
>>>> diff --git a/gcc/cp/typeck2.cc b/gcc/cp/typeck2.cc
>>>> index 309903afed8..208004221da 100644
>>>> --- a/gcc/cp/typeck2.cc
>>>> +++ b/gcc/cp/typeck2.cc
>>>> @@ -2378,7 +2378,10 @@ build_m_component_ref (tree datum, tree component,
>>>> tsubst_flags_t complain)
>>>> /* Build an expression for "object + offset" where offset is the
>>>> value stored in the pointer-to-data-member. */
>>>> ptype = build_pointer_type (type);
>>>> - datum = fold_build_pointer_plus (fold_convert (ptype, datum),
>>>> component);
>>>> + datum = cp_convert (ptype, datum, complain);
>>>> + datum = build2 (POINTER_PLUS_EXPR, ptype,
>>>> + datum, convert_to_ptrofftype (component));
>>>
>>> We shouldn't need to build the POINTER_PLUS_EXPR at all in template context.
>>> OK with that change.
>>
>> Hmm, that seems harmless at first glance, but I noticed
>> build_min_non_dep (called from build_x_binary_op in this case) is
>> careful to propagate TREE_SIDE_EFFECTS of the given tree, and so eliding
>> POINTER_PLUS_EXPR here could potentially mean that the tree we
>> ultimately return from build_x_binary_op when in a template context has
>> TREE_SIDE_EFFECTS not set when it used to. Shall we still elide the
>> POINTER_PLUS_EXPR in a template context despite this?
True, we would need build_min_non_dep to also get TREE_SIDE_EFFECTS from
the operands. That might be useful in general for similar situations?
I also note that convert_to_ptrofftype uses fold_convert, so the new
code could have the same problem if the pointer to member operand is
also a COMPONENT_REF.
Jason
next prev parent reply other threads:[~2023-11-10 21:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-08 21:59 Patrick Palka
2023-11-10 0:28 ` Jason Merrill
2023-11-10 15:12 ` Patrick Palka
2023-11-10 15:28 ` Patrick Palka
2023-11-10 21:36 ` Jason Merrill [this message]
2023-11-14 15:43 ` Patrick Palka
2023-11-14 22:29 ` 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=8fd05dbf-f08d-441f-90c0-10ac6fe5f7a8@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=ppalka@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).