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
>From ffff192a6ad5840c425a940ac724e27e0d25f7b0 Mon Sep 17 00:00:00 2001
From: Martin Liska <mli...@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