From: Jonathan Wakely <jwakely@redhat.com>
To: Richard Biener <rguenther@suse.de>
Cc: Jakub Jelinek <jakub@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] tree: Add 3 argument fndecl_built_in_p
Date: Wed, 22 Feb 2023 12:16:07 +0000 [thread overview]
Message-ID: <CACb0b4n1_febUuxa0AsaPiQkeUjLNK_E=yKAH78dvQKV=rJwJg@mail.gmail.com> (raw)
In-Reply-To: <nycvar.YFH.7.77.849.2302221141320.27913@jbgna.fhfr.qr>
On Wed, 22 Feb 2023 at 11:49, Richard Biener <rguenther@suse.de> wrote:
>
> On Wed, 22 Feb 2023, Jakub Jelinek wrote:
>
> > On Wed, Feb 22, 2023 at 09:52:06AM +0000, Richard Biener wrote:
> > > > The following testcase ICEs because we still have some spots that
> > > > treat BUILT_IN_UNREACHABLE specially but not BUILT_IN_UNREACHABLE_TRAP
> > > > the same.
> >
> > This patch uses (fndecl_built_in_p (node, BUILT_IN_UNREACHABLE)
> > || fndecl_built_in_p (node, BUILT_IN_UNREACHABLE_TRAP))
> > a lot and from grepping around, we do something like that in lots of
> > other places, or in some spots instead as
> > (fndecl_built_in_p (node, BUILT_IN_NORMAL)
> > && (DECL_FUNCTION_CODE (node) == BUILT_IN_WHATEVER1
> > || DECL_FUNCTION_CODE (node) == BUILT_IN_WHATEVER2))
> > The following patch adds an overload for this case, so we can write
> > it in a shorter way. It isn't worth for 3+, code in that case
> > typically uses the fndecl_built_in_p (node, BUILT_IN_NORMAL)
> > + switch in DECL_FUNCTION_CODE.
> >
> > If this isn't appropriate for GCC 13 (or not at all), I think we'll
> > need to change at least ipa-prop.cc because it suffers from the same
> > problem as the previous patch was fixing.
>
> Is it possible to use C++ (template) magic to expand the > 1 argument
> case to
>
> if (fndecl_built_in_p (BUILT_IN_NORMA)
> && (... || ... || ...
>
> lispy we'd expand to the head check and then recursively on the
> first and the remaining args.
In C++17 yes, there are fold expressions, so you'd write it as literally:
if (fndecl_built_in_p (BUILT_IN_NORMA)
&& (DECL_FUNCTION_CODE (node) == name || ...)
Where "name" is a parameter pack, and the "..." is literally what the
code would contain, not an abbreviation for the example :-)
For C++11 you can write it recursively. Something like:
// Single argument case terminates recursion.
inline bool
fndecl_built_in_matches_name_p (const_tree node, built_in_function name1)
{
return DECL_FUNCTION_CODE (node) == name1;
}
// Recursive case. If names... is an empty pack then the overload above
// is a better match.
template<typename... Functions>
inline bool
fndecl_built_in_matches_name_p (const_tree node, built_in_function name1,
Functions... names)
{
return DECL_FUNCTION_CODE (node) == name1
|| fndecl_built_in_matches_name_p (node, names...);
}
// Call with one or more names.
template<typename... Functions>
inline bool
fndecl_built_in_p (const_tree node, built_in_function name1,
Functions names...)
{
return (fndecl_built_in_p (node, BUILT_IN_NORMAL)
&& fndecl_built_in_matches_name_p (node, name1, names...);
}
I think the "is a better match" comment is the status of C++ after a
DR, so might not actually be true in C++11 with GCC 4.8, I can check
that (and if needed, rewrite the recursive case to avoid the problem).
next prev parent reply other threads:[~2023-02-22 12:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-22 9:12 [PATCH] cgraph: Handle BUILT_IN_UNREACHABLE_TRAP like BUILT_IN_UNREACHABLE in more spots [PR106258] Jakub Jelinek
2023-02-22 9:52 ` Richard Biener
2023-02-22 11:04 ` [PATCH] tree: Add 3 argument fndecl_built_in_p Jakub Jelinek
2023-02-22 11:43 ` Richard Biener
2023-02-22 12:16 ` Jonathan Wakely [this message]
2023-02-22 12:35 ` Jonathan Wakely
2023-02-22 18:33 ` [PATCH] tree, v2: " Jakub Jelinek
2023-02-22 18:46 ` Richard Biener
2023-02-23 6:56 ` [PATCH] ipa-prop: Fix another case of missing BUILT_IN_UNREACHABLE_TRAP handling [PR106258] Jakub Jelinek
2023-02-23 10:33 ` Richard Biener
2023-02-22 12:49 ` [PATCH] tree: Add 3 argument fndecl_built_in_p Richard Biener
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='CACb0b4n1_febUuxa0AsaPiQkeUjLNK_E=yKAH78dvQKV=rJwJg@mail.gmail.com' \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=rguenther@suse.de \
/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).