public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] C++: target attribute - local decl
@ 2021-02-18 12:15 Martin Liška
  2021-02-22 22:53 ` Jason Merrill
  0 siblings, 1 reply; 16+ messages in thread
From: Martin Liška @ 2021-02-18 12:15 UTC (permalink / raw)
  To: gcc-patches

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");
+      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);
+}
-- 
2.30.0


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-03-16 20:12 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-18 12:15 [PATCH] C++: target attribute - local decl 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
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

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