From 0f1de8d013d92e2996f6936ecb25b2561e48ca56 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 7 Mar 2018 10:16:07 +0100 Subject: [PATCH] re PR middle-end/84723 (ICE in create_target_clone, at multiple_target.c:275) PR middle-end/84723 * multiple_target.c: Include tree-inline.h and intl.h. (expand_target_clones): Diagnose and fail if node->definition and !tree_versionable_function_p (node->decl). * gcc.target/i386/pr84723-1.c: New test. * gcc.target/i386/pr84723-2.c: New test. * gcc.target/i386/pr84723-3.c: New test. * gcc.target/i386/pr84723-4.c: New test. * gcc.target/i386/pr84723-5.c: New test. From-SVN: r258316 --- gcc/ChangeLog | 7 +++++++ gcc/multiple_target.c | 18 ++++++++++++++++++ gcc/testsuite/ChangeLog | 9 +++++++++ gcc/testsuite/gcc.target/i386/pr84723-1.c | 11 +++++++++++ gcc/testsuite/gcc.target/i386/pr84723-2.c | 13 +++++++++++++ gcc/testsuite/gcc.target/i386/pr84723-3.c | 17 +++++++++++++++++ gcc/testsuite/gcc.target/i386/pr84723-4.c | 11 +++++++++++ gcc/testsuite/gcc.target/i386/pr84723-5.c | 11 +++++++++++ 8 files changed, 97 insertions(+) create mode 100644 gcc/testsuite/gcc.target/i386/pr84723-1.c create mode 100644 gcc/testsuite/gcc.target/i386/pr84723-2.c create mode 100644 gcc/testsuite/gcc.target/i386/pr84723-3.c create mode 100644 gcc/testsuite/gcc.target/i386/pr84723-4.c create mode 100644 gcc/testsuite/gcc.target/i386/pr84723-5.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 442b60bd1aa..078a9091b36 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2018-03-07 Jakub Jelinek + + PR middle-end/84723 + * multiple_target.c: Include tree-inline.h and intl.h. + (expand_target_clones): Diagnose and fail if node->definition and + !tree_versionable_function_p (node->decl). + 2018-03-06 John David Anglin * config/pa/pa.h (ASM_GENERATE_INTERNAL_LABEL): Revise to use diff --git a/gcc/multiple_target.c b/gcc/multiple_target.c index ecf69fc2124..a6767985774 100644 --- a/gcc/multiple_target.c +++ b/gcc/multiple_target.c @@ -36,6 +36,8 @@ along with GCC; see the file COPYING3. If not see #include "pretty-print.h" #include "gimple-iterator.h" #include "gimple-walk.h" +#include "tree-inline.h" +#include "intl.h" /* Walker callback that replaces all FUNCTION_DECL of a function that's going to be versioned. */ @@ -312,6 +314,22 @@ expand_target_clones (struct cgraph_node *node, bool definition) return false; } + if (node->definition + && !tree_versionable_function_p (node->decl)) + { + error_at (DECL_SOURCE_LOCATION (node->decl), + "clones for % attribute cannot be created"); + const char *reason = NULL; + if (lookup_attribute ("noclone", DECL_ATTRIBUTES (node->decl))) + reason = G_("function %q+F can never be copied " + "because it has % attribute"); + else + reason = copy_forbidden (DECL_STRUCT_FUNCTION (node->decl)); + if (reason) + inform (DECL_SOURCE_LOCATION (node->decl), reason, node->decl); + return false; + } + char *attr_str = XNEWVEC (char, attr_len); int attrnum = get_attr_str (arglist, attr_str); char **attrs = XNEWVEC (char *, attrnum); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0440f02a696..a2be76bf2dc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2018-03-07 Jakub Jelinek + + PR middle-end/84723 + * gcc.target/i386/pr84723-1.c: New test. + * gcc.target/i386/pr84723-2.c: New test. + * gcc.target/i386/pr84723-3.c: New test. + * gcc.target/i386/pr84723-4.c: New test. + * gcc.target/i386/pr84723-5.c: New test. + 2018-03-06 Steven G. Kargl PR fortran/64107 diff --git a/gcc/testsuite/gcc.target/i386/pr84723-1.c b/gcc/testsuite/gcc.target/i386/pr84723-1.c new file mode 100644 index 00000000000..0264ecb1159 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr84723-1.c @@ -0,0 +1,11 @@ +/* PR middle-end/84723 */ +/* { dg-do compile } */ +/* { dg-require-ifunc } */ +/* { dg-options "-O2" } */ + +__attribute__((target_clones ("avx", "default"))) +__attribute__((noclone)) +void +foo (void) /* { dg-error "clones for .target_clones. attribute cannot be created" } */ +{ /* { dg-message "function .foo. can never be copied because it has .noclone. attribute" "" { target *-*-* } .-1 } */ +} diff --git a/gcc/testsuite/gcc.target/i386/pr84723-2.c b/gcc/testsuite/gcc.target/i386/pr84723-2.c new file mode 100644 index 00000000000..6456d6d256f --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr84723-2.c @@ -0,0 +1,13 @@ +/* PR middle-end/84723 */ +/* { dg-do compile } */ +/* { dg-require-ifunc } */ +/* { dg-options "-O2" } */ + +__attribute__((target_clones ("avx", "default"))) +void +foo (void) /* { dg-error "clones for .target_clones. attribute cannot be created" } */ +{ /* { dg-message "function .foo. can never be copied because it saves address of local label in a static variable" "" { target *-*-* } .-1 } */ + static void *p = &&lab; + asm volatile ("" : "+m" (p) : : "memory"); +lab:; +} diff --git a/gcc/testsuite/gcc.target/i386/pr84723-3.c b/gcc/testsuite/gcc.target/i386/pr84723-3.c new file mode 100644 index 00000000000..bb8e7cabc88 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr84723-3.c @@ -0,0 +1,17 @@ +/* PR middle-end/84723 */ +/* { dg-do compile } */ +/* { dg-require-ifunc } */ +/* { dg-options "-O2" } */ + +__attribute__((target_clones ("avx", "default"))) +int +foo (int x) /* { dg-error "clones for .target_clones. attribute cannot be created" } */ +{ /* { dg-message "function .foo. can never be copied because it receives a non-local goto" "" { target *-*-* } .-1 } */ + __label__ lab; + __attribute__((noinline)) void bar () { goto lab; } + if (x == 5) + bar (); + x++; +lab:; + return x; +} diff --git a/gcc/testsuite/gcc.target/i386/pr84723-4.c b/gcc/testsuite/gcc.target/i386/pr84723-4.c new file mode 100644 index 00000000000..9df1008497c --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr84723-4.c @@ -0,0 +1,11 @@ +/* PR middle-end/84723 */ +/* { dg-do compile } */ +/* { dg-require-ifunc } */ +/* { dg-options "-O2" } */ + +__attribute__((target_clones ("avx", "default"))) +__attribute__((naked)) +void +foo (void) /* { dg-error "clones for .target_clones. attribute cannot be created" } */ +{ /* { dg-message "function .foo. can never be copied because it has .noclone. attribute" "" { target *-*-* } .-1 } */ +} diff --git a/gcc/testsuite/gcc.target/i386/pr84723-5.c b/gcc/testsuite/gcc.target/i386/pr84723-5.c new file mode 100644 index 00000000000..c7aa92804fa --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr84723-5.c @@ -0,0 +1,11 @@ +/* PR middle-end/84723 */ +/* { dg-do compile } */ +/* { dg-require-ifunc } */ +/* { dg-options "-O2" } */ + +__attribute__((target_clones ("avx", "default"))) +__attribute__((noipa)) +void +foo (void) /* { dg-error "clones for .target_clones. attribute cannot be created" } */ +{ /* { dg-message "function .foo. can never be copied because it has .noclone. attribute" "" { target *-*-* } .-1 } */ +} -- 2.30.2