public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Jonathan Wakely <jwakely@redhat.com>
Cc: Richard Biener <rguenther@suse.de>,
	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 13:49:06 +0100	[thread overview]
Message-ID: <CAFiYyc2SKwmMF=oXTstg3DpjVuryZCEN2s7SH7zUa-2rCZr1cQ@mail.gmail.com> (raw)
In-Reply-To: <CACb0b4n1_febUuxa0AsaPiQkeUjLNK_E=yKAH78dvQKV=rJwJg@mail.gmail.com>

On Wed, Feb 22, 2023 at 1:17 PM Jonathan Wakely via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> 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 :-)

Ah, that's nice.  But then I'd need to replace each arg with
DECL_FUNCTION_CODE (node) == arg, fold expressions seem to
only support literal replacement here?

> For C++11 you can write it recursively. Something like:

But sure, we're C++11 only ...

>
> // 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).
>

      parent reply	other threads:[~2023-02-22 12:49 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
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         ` Richard Biener [this message]

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='CAFiYyc2SKwmMF=oXTstg3DpjVuryZCEN2s7SH7zUa-2rCZr1cQ@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jwakely@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).