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 v6] c++: Move consteval folding to cp_fold_r
Date: Sat, 16 Sep 2023 16:22:44 -0400	[thread overview]
Message-ID: <d23afef7-55e9-d3c1-d821-3fad4bac52cf@redhat.com> (raw)
In-Reply-To: <ZQS/ddll2R/hjMIp@redhat.com>

On 9/15/23 16:32, Marek Polacek wrote:
> On Fri, Sep 15, 2023 at 02:08:46PM -0400, Jason Merrill wrote:
>> On 9/13/23 20:02, Marek Polacek wrote:
>>> On Wed, Sep 13, 2023 at 05:57:47PM -0400, Jason Merrill wrote:
>>>> On 9/13/23 16:56, Marek Polacek wrote:
>>>>> On Tue, Sep 12, 2023 at 05:26:25PM -0400, Jason Merrill wrote:
>>>>>> On 9/8/23 14:24, Marek Polacek wrote:
>>>>>>> +  switch (TREE_CODE (stmt))
>>>>>>> +    {
>>>>>>> +    /* Unfortunately we must handle code like
>>>>>>> +	 false ? bar () : 42
>>>>>>> +       where we have to check bar too.  */
>>>>>>> +    case COND_EXPR:
>>>>>>> +      if (cp_fold_immediate_r (&TREE_OPERAND (stmt, 1), walk_subtrees, data))
>>>>>>> +	return error_mark_node;
>>>>>>> +      if (TREE_OPERAND (stmt, 2)
>>>>>>> +	  && cp_fold_immediate_r (&TREE_OPERAND (stmt, 2), walk_subtrees, data))
>>>>>>> +	return error_mark_node;
>>>>>>
>>>>>> Is this necessary?  Doesn't walk_tree already walk into the arms of
>>>>>> COND_EXPR?
>>>>>
>>>>> Unfortunately yes.  The cp_fold call in cp_fold_r could fold the ?: into
>>>>> a constant before we see it here.  I've added a comment saying just that.
>>>>
>>>> Ah.  But in that case I guess we need to walk into the arms, not just check
>>>> the top-level expression in them.
>>> Arg, of course.  I was fooled into thinking that it would recurse, but
>>> you're right.  Fixed by using cp_walk_tree as I intended.  Tested in
>>> consteval34.C.
>>>
>>>> But maybe cp_fold_r should do that before the cp_fold, instead of this
>>>> function?
>>>
>>> I...am not sure how that would be better than what I did.
>>
>> Callers of cp_fold_immediate don't need this because cp_fold_r isn't
>> involved, so it isn't folding anything.
> 
> This is true.
>   
>> cp_fold_r can walk the arms with cp_fold_r and then clear *walk_subtrees to
>> avoid walking the arms again normally.
> 
> I didn't think we wanted to do everything cp_fold_r does even in dead
> branches, but ok.

Ah, that's a good point.  With the recursive walk in 
cp_fold_immediate_r, I suppose we could suppress it when called from 
cp_fold_immediate with a new fold_flag?  That would still allow for 
cp_walk_tree_without_duplicates.

Incidentally, I notice you check for null op2 of COND_EXPR, should 
probably also check op1.

Jason


  reply	other threads:[~2023-09-16 20:22 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-01 17:23 [PATCH] " Marek Polacek
2023-09-01 17:36 ` Marek Polacek
2023-09-05 14:52 ` Jason Merrill
2023-09-05 19:59   ` Marek Polacek
2023-09-05 20:36     ` Jason Merrill
2023-09-07 15:23       ` [PATCH v2] " Marek Polacek
2023-09-07 18:32         ` Jason Merrill
2023-09-08 18:24           ` [PATCH v3] " Marek Polacek
2023-09-12 21:26             ` Jason Merrill
2023-09-13 20:56               ` [PATCH v4] " Marek Polacek
2023-09-13 21:57                 ` Jason Merrill
2023-09-14  0:02                   ` [PATCH v5] " Marek Polacek
2023-09-15 18:08                     ` Jason Merrill
2023-09-15 20:32                       ` [PATCH v6] " Marek Polacek
2023-09-16 20:22                         ` Jason Merrill [this message]
2023-09-18 21:42                           ` [PATCH v7] " Marek Polacek
2023-09-19  1:36                             ` Jason Merrill
2023-09-19 13:01                               ` Marek Polacek
2023-09-19 13:20                                 ` 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=d23afef7-55e9-d3c1-d821-3fad4bac52cf@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).