From: Jason Merrill <jason@redhat.com>
To: Marek Polacek <polacek@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH v5] c++: implement P2564, consteval needs to propagate up [PR107687]
Date: Thu, 30 Nov 2023 18:34:01 -0500 [thread overview]
Message-ID: <1d9a1b66-c1ba-4aa1-80e3-09c5e1840845@redhat.com> (raw)
In-Reply-To: <ZV+B5aYQheJ347xT@redhat.com>
On 11/23/23 11:46, Marek Polacek wrote:
> v5 greatly simplifies the code.
Indeed, it's much cleaner now.
> I still need a new ff_ flag to signal that we can return immediately
> after seeing an i-e expr.
That's still not clear to me:
> + /* In turn, maybe promote the function we find ourselves in... */
> + if ((data->flags & ff_find_escalating_expr)
> + && DECL_IMMEDIATE_FUNCTION_P (decl)
> + /* ...but not if the call to DECL was constant; that is the
> + "an immediate invocation that is not a constant expression"
> + case. */
> + && (e = cxx_constant_value (stmt, tf_none), e == error_mark_node))
> + {
> + /* Since we had to set DECL_ESCALATION_CHECKED_P before the walk,
> + we call promote_function_to_consteval directly which doesn't
> + check unchecked_immediate_escalating_function_p. */
> + if (current_function_decl)
> + promote_function_to_consteval (current_function_decl);
> + *walk_subtrees = 0;
> + return stmt;
> + }
This is the one use of ff_find_escalating_expr, and it seems redundant
with the code immediately below, where we use complain (derived from
ff_mce_false) to decide whether to return immediately. Can we remove
this hunk and the flag, and merge find_escalating_expr with
cp_fold_immediate?
I think you want to walk the function body for three-ish reasons:
1) at EOF, to check for escalation
2) at EOF, to check for errors
3) at error time, to explain escalation
It's not clear to me that we need a flag to distinguish between them.
When we encounter an immediate-escalating expression E:
A) if we're in an immediate-escalating function, escalate and return E
(#1, #3).
B) otherwise, if we're diagnosing, error and continue (#2).
C) otherwise, return E (individual expression mce_unknown walk from
constexpr.cc).
> @@ -1178,11 +1388,19 @@ cp_fold_r (tree *stmt_p, int *walk_subtrees, void *data_
> )
> *walk_subtrees = 0;
> /* Don't return yet, still need the cp_fold below. */
> }
> - cp_fold_immediate_r (stmt_p, walk_subtrees, data);
> + else
> + cp_fold_immediate_r (stmt_p, walk_subtrees, data);
> }
>
> *stmt_p = stmt = cp_fold (*stmt_p, data->flags);
>
> + /* For certain trees, like +foo(), the cp_fold below will remove the +,
s/below/above/?
> +/* We've stashed immediate-escalating functions. Now see if they indeed
> + ought to be promoted to consteval. */
> +
> +void
> +process_pending_immediate_escalating_fns ()
> +{
> + /* This will be null for -fno-immediate-escalation. */
> + if (!deferred_escalating_exprs)
> + return;
> +
> + for (auto e : *deferred_escalating_exprs)
> + if (TREE_CODE (e) == FUNCTION_DECL && !DECL_ESCALATION_CHECKED_P (e))
> + cp_fold_immediate (&DECL_SAVED_TREE (e), mce_false, e);
> +}
> +
> +/* We've escalated every function that could have been promoted to
> + consteval. Check that we are not taking the address of a consteval
> + function. */
> +
> +void
> +check_immediate_escalating_refs ()
> +{
> + /* This will be null for -fno-immediate-escalation. */
> + if (!deferred_escalating_exprs)
> + return;
> +
> + for (auto ref : *deferred_escalating_exprs)
> + {
> + if (TREE_CODE (ref) == FUNCTION_DECL)
> + continue;
> + tree decl = (TREE_CODE (ref) == PTRMEM_CST
> + ? PTRMEM_CST_MEMBER (ref)
> + : TREE_OPERAND (ref, 0));
> + if (DECL_IMMEDIATE_FUNCTION_P (decl))
> + taking_address_of_imm_fn_error (ref, decl);
> + }
> +
> + deferred_escalating_exprs = nullptr;
> }
Could these be merged, so you do a single loop of cp_fold_immediate over
function bodies or non-function expressions? I'd expect that to work.
Jason
next prev parent reply other threads:[~2023-11-30 23:34 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-23 19:49 [PATCH] " Marek Polacek
2023-08-29 19:26 ` Jason Merrill
2023-10-10 17:20 ` [PATCH v2] " Marek Polacek
2023-10-11 20:42 ` Marek Polacek
2023-10-14 4:56 ` Jason Merrill
2023-11-02 15:28 ` [PATCH v3] " Marek Polacek
2023-11-02 15:32 ` Marek Polacek
2023-11-03 17:51 ` Jason Merrill
2023-11-06 22:34 ` [PATCH v4] " Marek Polacek
2023-11-14 2:06 ` Jason Merrill
2023-11-23 16:46 ` [PATCH v5] " Marek Polacek
2023-11-30 23:34 ` Jason Merrill [this message]
2023-12-01 23:37 ` [PATCH v6] " Marek Polacek
2023-12-02 0:43 ` Jason Merrill
2023-12-04 20:23 ` [PATCH v7] " Marek Polacek
2023-12-04 21:49 ` Jason Merrill
2023-12-05 0:44 ` [PATCH v8] " Marek Polacek
2023-12-06 11:39 ` Prathamesh Kulkarni
2023-12-06 14:34 ` Marek Polacek
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=1d9a1b66-c1ba-4aa1-80e3-09c5e1840845@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).