public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Martin Liška" <mliska@suse.cz>
To: Jason Merrill <jason@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] C++: target attribute - local decl
Date: Thu, 4 Mar 2021 09:19:37 +0100	[thread overview]
Message-ID: <752a6974-2069-eba1-faf0-03aa9689288d@suse.cz> (raw)
In-Reply-To: <bbf8e8cd-d017-a989-8b7a-522bd8e97d4b@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2190 bytes --]

On 3/2/21 6:57 PM, Jason Merrill wrote:
> On 3/2/21 5:34 AM, Martin Liška wrote:
>> On 3/1/21 8:58 PM, Jason Merrill wrote:
>>> On 3/1/21 11:59 AM, Martin Liška wrote:
>>>> On 3/1/21 5:36 PM, Jason Merrill wrote:
>>>>> On 3/1/21 7:43 AM, Martin Liška wrote:
>>>>>> On 2/22/21 11:53 PM, Jason Merrill wrote:
>>>>>>> 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.
>>>>>>
>>>>>> Ah, I see. Are you sure about the name 'maybe_function_versions'? I can't find it.
>>>>>
>>>>> Ah, it's maybe_version_functions, sorry.
>>>>
>>>> Thanks, I see the function now.
>>>> So about your guess:
>>>>
>>>>> I guess maybe_function_versions also needs to look through DECL_LOCAL_DECL_ALIAS.
>>>>
>>>> Do you mean maybe_version_functions's argument 'record' should depend on DECL_LOCAL_DECL_ALIAS of newdecl/oldddecl
>>>> (if present)? Or that DECL_FUNCTION_VERSIONED should be set for DECL_LOCAL_DECL_ALIASes of the newdecl/olddecl
>>>> function declarations?
>>>
>>> The latter.
>>
>> I see, but will not help us. Problem is that
>> #2  0x00000000015d8899 in ix86_get_function_versions_dispatcher (decl=0x7ffff7755000) at /home/marxin/Programming/gcc/gcc/config/i386/i386-features.c:2862
>>
>> is called for a declaration for which
>>
>> Breakpoint 5, maybe_version_functions (newdecl=<function_decl 0x7ffff7755000 f>, olddecl=<function_decl 0x7ffff7751f00 f>, record=false) at /home/marxin/Programming/gcc/gcc/cp/decl.c:1118
>>
>> is called with record=false. So that cgraph_node is not created for it.
>>
>> Or is a possible solution that get_function_version_dispatcher should look through the DECL_LOCAL_DECL_ALIAS?
> 
> Yes, I was thinking both that function and maybe_version_functions.
> 
> Jason
> 

All right, the following patch fixes that.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

[-- Attachment #2: 0001-c-support-target-attr-for-DECL_LOCAL_DECL_P-fns.patch --]
[-- Type: text/x-patch, Size: 3865 bytes --]

From ffff192a6ad5840c425a940ac724e27e0d25f7b0 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Wed, 3 Mar 2021 09:38:55 +0100
Subject: [PATCH] c++: support target attr for DECL_LOCAL_DECL_P fns

gcc/cp/ChangeLog:

	PR c++/99108
	* call.c (get_function_version_dispatcher): Understand
	DECL_LOCAL_DECL_ALIAS.
	* decl.c (record_function_versions): New.
	(maybe_version_functions): Call record_function_versions
	for both declarations and DECL_LOCAL_DECL_ALIAS aliases.

gcc/testsuite/ChangeLog:

	PR c++/99108
	* g++.target/i386/pr99108.C: New test.
---
 gcc/cp/call.c                           |  4 +++
 gcc/cp/decl.c                           | 40 +++++++++++++++----------
 gcc/testsuite/g++.target/i386/pr99108.C | 18 +++++++++++
 3 files changed, 47 insertions(+), 15 deletions(-)
 create mode 100644 gcc/testsuite/g++.target/i386/pr99108.C

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 123f06b1f2b..117f1755191 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -8467,6 +8467,10 @@ get_function_version_dispatcher (tree fn)
 {
   tree dispatcher_decl = NULL;
 
+  if (DECL_LOCAL_DECL_P (fn)
+      && DECL_LOCAL_DECL_ALIAS (fn) != NULL_TREE)
+    fn = DECL_LOCAL_DECL_ALIAS (fn);
+
   gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
 	      && DECL_FUNCTION_VERSIONED (fn));
 
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 1742e286d9f..69bf3011a5a 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -1108,6 +1108,23 @@ decls_match (tree newdecl, tree olddecl, bool record_versions /* = true */)
   return types_match;
 }
 
+/* Register function version for DECL that would point to VERSION.
+   If RECORD set to true, register function version in call graph.  */
+
+static void
+record_function_versions (tree decl, tree version, bool record)
+{
+  if (!DECL_FUNCTION_VERSIONED (version))
+    {
+      DECL_FUNCTION_VERSIONED (version) = 1;
+      if (DECL_ASSEMBLER_NAME_SET_P (version))
+	mangle_decl (version);
+    }
+
+  if (record && decl != version)
+    cgraph_node::record_function_versions (decl, version);
+}
+
 /* NEWDECL and OLDDECL have identical signatures.  If they are
    different versions adjust them and return true.
    If RECORD is set to true, record function versions.  */
@@ -1118,22 +1135,15 @@ maybe_version_functions (tree newdecl, tree olddecl, bool record)
   if (!targetm.target_option.function_versions (newdecl, olddecl))
     return false;
 
-  if (!DECL_FUNCTION_VERSIONED (olddecl))
-    {
-      DECL_FUNCTION_VERSIONED (olddecl) = 1;
-      if (DECL_ASSEMBLER_NAME_SET_P (olddecl))
-	mangle_decl (olddecl);
-    }
-
-  if (!DECL_FUNCTION_VERSIONED (newdecl))
-    {
-      DECL_FUNCTION_VERSIONED (newdecl) = 1;
-      if (DECL_ASSEMBLER_NAME_SET_P (newdecl))
-	mangle_decl (newdecl);
-    }
+  record_function_versions (olddecl, olddecl, record);
+  if (DECL_LOCAL_DECL_P (olddecl)
+      && DECL_LOCAL_DECL_ALIAS (olddecl) != NULL_TREE)
+    record_function_versions (olddecl, DECL_LOCAL_DECL_ALIAS (olddecl), true);
 
-  if (record)
-    cgraph_node::record_function_versions (olddecl, newdecl);
+  record_function_versions (olddecl, newdecl, record);
+  if (DECL_LOCAL_DECL_P (newdecl)
+      && DECL_LOCAL_DECL_ALIAS (newdecl) != NULL_TREE)
+    record_function_versions (olddecl, DECL_LOCAL_DECL_ALIAS (newdecl), true);
 
   return true;
 }
diff --git a/gcc/testsuite/g++.target/i386/pr99108.C b/gcc/testsuite/g++.target/i386/pr99108.C
new file mode 100644
index 00000000000..ad9409b8799
--- /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")));
+  int b = f();
+}
+void bar(void)
+{
+  A c;
+  c.foo(7);
+}
-- 
2.30.1


  reply	other threads:[~2021-03-04  8:19 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
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 [this message]
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=752a6974-2069-eba1-faf0-03aa9689288d@suse.cz \
    --to=mliska@suse.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@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).