public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: "Martin Liška" <mliska@suse.cz>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] C++: target attribute - local decl
Date: Mon, 22 Feb 2021 17:53:27 -0500	[thread overview]
Message-ID: <43c9c10d-077a-633d-92d4-d769c5838e6f@redhat.com> (raw)
In-Reply-To: <15035626-d39b-cb2a-f9b6-272503b16ba5@suse.cz>

On 2/18/21 7:15 AM, Martin Liška wrote:
> We crash when target attribute get_function_versions_dispatcher is called
> for a function that is not registered in call graph. This fixes that
> by emitting a new error.
> 
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> 
> Ready to be installed?
> Thanks,
> Martin
> 
> gcc/cp/ChangeLog:
> 
>      PR c++/99108
>      * call.c (get_function_version_dispatcher): Do not parse
>      target attribute for a function with a missing declaration.
> 
> gcc/testsuite/ChangeLog:
> 
>      PR c++/99108
>      * g++.target/i386/pr99108.C: New test.
> ---
>   gcc/cp/call.c                           |  8 +++++++-
>   gcc/testsuite/g++.target/i386/pr99108.C | 18 ++++++++++++++++++
>   2 files changed, 25 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.target/i386/pr99108.C
> 
> diff --git a/gcc/cp/call.c b/gcc/cp/call.c
> index 186feef6fe3..844853e504e 100644
> --- a/gcc/cp/call.c
> +++ b/gcc/cp/call.c
> @@ -8386,8 +8386,14 @@ get_function_version_dispatcher (tree fn)
>             && DECL_FUNCTION_VERSIONED (fn));
> 
>     gcc_assert (targetm.get_function_versions_dispatcher);
> -  dispatcher_decl = targetm.get_function_versions_dispatcher (fn);
> +  if (cgraph_node::get (fn) == NULL)
> +    {
> +      error_at (DECL_SOURCE_LOCATION (fn), "missing declaration "
> +        "for a multiversioned function");

This seems like the wrong message.  The declaration isn't missing, 
you're using its source location for the error.  Do you mean 
"definition"?  But adding definitions earlier in the file doesn't help. 
And having file-scope declarations without definitions is fine.

The problem seems to be with the handling of local decls.  If 
DECL_LOCAL_DECL_P, you need to look at DECL_LOCAL_DECL_ALIAS to find the 
namespace-scope decl.  But then if there is no preceding namespace-scope 
declaration, the new decl created by push_local_extern_decl_alias 
doesn't have a cgraph node, either.  I guess maybe_function_versions 
also needs to look through DECL_LOCAL_DECL_ALIAS.

> +      return NULL;
> +    }
> 
> +  dispatcher_decl = targetm.get_function_versions_dispatcher (fn);
>     if (dispatcher_decl == NULL)
>       {
>         error_at (input_location, "use of multiversioned function "
> diff --git a/gcc/testsuite/g++.target/i386/pr99108.C 
> b/gcc/testsuite/g++.target/i386/pr99108.C
> new file mode 100644
> index 00000000000..b0c4ffa2688
> --- /dev/null
> +++ b/gcc/testsuite/g++.target/i386/pr99108.C
> @@ -0,0 +1,18 @@
> +/* PR c++/99108 */
> +/* { dg-do compile { target c++20 } } */
> +/* { dg-require-ifunc "" }  */
> +
> +struct A {
> +  void foo(auto);
> +};
> +void A::foo(auto)
> +{
> +  int f(void) __attribute__((target("default")));
> +  int f(void) __attribute__((target("arch=atom"))); /* { dg-error 
> "missing declaration for a multiversioned function" } */
> +  int b = f();
> +}
> +void bar(void)
> +{
> +  A c;
> +  c.foo(7);
> +}


  reply	other threads:[~2021-02-22 22:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-18 12:15 Martin Liška
2021-02-22 22:53 ` Jason Merrill [this message]
2021-03-01 12:43   ` Martin Liška
2021-03-01 16:36     ` Jason Merrill
2021-03-01 16:59       ` Martin Liška
2021-03-01 19:58         ` Jason Merrill
2021-03-02 10:34           ` Martin Liška
2021-03-02 17:57             ` Jason Merrill
2021-03-04  8:19               ` Martin Liška
2021-03-04 15:03                 ` Jason Merrill
2021-03-04 15:39                   ` Martin Liška
2021-03-04 15:45                     ` Jason Merrill
2021-03-04 15:52                       ` Martin Liška
2021-03-04 20:54                         ` Jason Merrill
2021-03-08  9:33                           ` Martin Liška
2021-03-16 20:12                             ` 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=43c9c10d-077a-633d-92d4-d769c5838e6f@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mliska@suse.cz \
    /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).