2015-10-30 19:17:43 +01:00
|
|
|
/* Pass for parsing functions with multiple target attributes.
|
|
|
|
|
|
|
|
Contributed by Evgeny Stupachenko <evstupac@gmail.com>
|
|
|
|
|
2022-01-03 10:42:10 +01:00
|
|
|
Copyright (C) 2015-2022 Free Software Foundation, Inc.
|
2015-10-30 19:17:43 +01:00
|
|
|
|
|
|
|
This file is part of GCC.
|
|
|
|
|
|
|
|
GCC is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free
|
|
|
|
Software Foundation; either version 3, or (at your option) any later
|
|
|
|
version.
|
|
|
|
|
|
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GCC; see the file COPYING3. If not see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "coretypes.h"
|
|
|
|
#include "backend.h"
|
|
|
|
#include "tree.h"
|
|
|
|
#include "stringpool.h"
|
|
|
|
#include "gimple.h"
|
|
|
|
#include "diagnostic-core.h"
|
|
|
|
#include "gimple-ssa.h"
|
|
|
|
#include "cgraph.h"
|
|
|
|
#include "tree-pass.h"
|
|
|
|
#include "target.h"
|
|
|
|
#include "attribs.h"
|
|
|
|
#include "pretty-print.h"
|
2017-06-19 15:12:51 +02:00
|
|
|
#include "gimple-iterator.h"
|
|
|
|
#include "gimple-walk.h"
|
2018-03-07 10:16:07 +01:00
|
|
|
#include "tree-inline.h"
|
|
|
|
#include "intl.h"
|
2017-06-19 15:12:51 +02:00
|
|
|
|
|
|
|
/* Walker callback that replaces all FUNCTION_DECL of a function that's
|
|
|
|
going to be versioned. */
|
|
|
|
|
|
|
|
static tree
|
|
|
|
replace_function_decl (tree *op, int *walk_subtrees, void *data)
|
|
|
|
{
|
|
|
|
struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
|
|
|
|
cgraph_function_version_info *info = (cgraph_function_version_info *)wi->info;
|
|
|
|
|
|
|
|
if (TREE_CODE (*op) == FUNCTION_DECL
|
|
|
|
&& info->this_node->decl == *op)
|
|
|
|
{
|
|
|
|
*op = info->dispatcher_resolver;
|
|
|
|
*walk_subtrees = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-10-30 19:17:43 +01:00
|
|
|
|
|
|
|
/* If the call in NODE has multiple target attribute with multiple fields,
|
|
|
|
replace it with dispatcher call and create dispatcher (once). */
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_dispatcher_calls (struct cgraph_node *node)
|
|
|
|
{
|
2017-06-19 15:12:51 +02:00
|
|
|
ipa_ref *ref;
|
|
|
|
|
2017-06-23 20:08:31 +02:00
|
|
|
if (!DECL_FUNCTION_VERSIONED (node->decl)
|
|
|
|
|| !is_function_default_version (node->decl))
|
2017-06-19 15:12:51 +02:00
|
|
|
return;
|
|
|
|
|
2017-06-30 15:51:19 +02:00
|
|
|
if (!targetm.has_ifunc_p ())
|
|
|
|
{
|
|
|
|
error_at (DECL_SOURCE_LOCATION (node->decl),
|
2019-04-12 14:54:00 +02:00
|
|
|
"the call requires %<ifunc%>, which is not"
|
2017-06-30 15:51:19 +02:00
|
|
|
" supported by this target");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (!targetm.get_function_versions_dispatcher)
|
|
|
|
{
|
|
|
|
error_at (DECL_SOURCE_LOCATION (node->decl),
|
|
|
|
"target does not support function version dispatcher");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tree idecl = targetm.get_function_versions_dispatcher (node->decl);
|
|
|
|
if (!idecl)
|
|
|
|
{
|
|
|
|
error_at (DECL_SOURCE_LOCATION (node->decl),
|
2018-04-17 07:40:39 +02:00
|
|
|
"default %<target_clones%> attribute was not set");
|
2017-06-30 15:51:19 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cgraph_node *inode = cgraph_node::get (idecl);
|
|
|
|
gcc_assert (inode);
|
|
|
|
tree resolver_decl = targetm.generate_version_dispatcher_body (inode);
|
|
|
|
|
|
|
|
/* Update aliases. */
|
|
|
|
inode->alias = true;
|
|
|
|
inode->alias_target = resolver_decl;
|
|
|
|
if (!inode->analyzed)
|
|
|
|
inode->resolve_alias (cgraph_node::get (resolver_decl));
|
|
|
|
|
2017-06-19 15:12:51 +02:00
|
|
|
auto_vec<cgraph_edge *> edges_to_redirect;
|
2019-03-14 14:05:34 +01:00
|
|
|
/* We need to capture the references by value rather than just pointers to them
|
|
|
|
and remove them right away, as removing them later would invalidate what
|
|
|
|
some other reference pointers point to. */
|
|
|
|
auto_vec<ipa_ref> references_to_redirect;
|
2017-06-19 15:12:51 +02:00
|
|
|
|
2019-03-14 14:05:34 +01:00
|
|
|
while (node->iterate_referring (0, ref))
|
|
|
|
{
|
|
|
|
references_to_redirect.safe_push (*ref);
|
|
|
|
ref->remove_reference ();
|
|
|
|
}
|
2015-10-30 19:17:43 +01:00
|
|
|
|
|
|
|
/* We need to remember NEXT_CALLER as it could be modified in the loop. */
|
2017-06-19 15:12:51 +02:00
|
|
|
for (cgraph_edge *e = node->callers; e ; e = e->next_caller)
|
|
|
|
edges_to_redirect.safe_push (e);
|
2015-10-30 19:17:43 +01:00
|
|
|
|
2017-06-19 15:12:51 +02:00
|
|
|
if (!edges_to_redirect.is_empty () || !references_to_redirect.is_empty ())
|
|
|
|
{
|
|
|
|
/* Redirect edges. */
|
|
|
|
unsigned i;
|
|
|
|
cgraph_edge *e;
|
|
|
|
FOR_EACH_VEC_ELT (edges_to_redirect, i, e)
|
|
|
|
{
|
|
|
|
e->redirect_callee (inode);
|
2020-01-09 13:21:48 +01:00
|
|
|
cgraph_edge::redirect_call_stmt_to_callee (e);
|
2017-06-19 15:12:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Redirect references. */
|
|
|
|
FOR_EACH_VEC_ELT (references_to_redirect, i, ref)
|
|
|
|
{
|
|
|
|
if (ref->use == IPA_REF_ADDR)
|
|
|
|
{
|
|
|
|
struct walk_stmt_info wi;
|
|
|
|
memset (&wi, 0, sizeof (wi));
|
|
|
|
wi.info = (void *)node->function_version ();
|
|
|
|
|
|
|
|
if (dyn_cast<varpool_node *> (ref->referring))
|
|
|
|
{
|
|
|
|
hash_set<tree> visited_nodes;
|
|
|
|
walk_tree (&DECL_INITIAL (ref->referring->decl),
|
|
|
|
replace_function_decl, &wi, &visited_nodes);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimple_stmt_iterator it = gsi_for_stmt (ref->stmt);
|
|
|
|
if (ref->referring->decl != resolver_decl)
|
|
|
|
walk_gimple_stmt (&it, NULL, replace_function_decl, &wi);
|
|
|
|
}
|
2018-03-16 15:53:45 +01:00
|
|
|
|
|
|
|
symtab_node *source = ref->referring;
|
|
|
|
source->create_reference (inode, IPA_REF_ADDR);
|
2017-06-19 15:12:51 +02:00
|
|
|
}
|
2018-03-16 15:53:24 +01:00
|
|
|
else if (ref->use == IPA_REF_ALIAS)
|
|
|
|
{
|
|
|
|
symtab_node *source = ref->referring;
|
|
|
|
source->create_reference (inode, IPA_REF_ALIAS);
|
2019-07-03 10:31:35 +02:00
|
|
|
if (inode->get_comdat_group ())
|
|
|
|
source->add_to_same_comdat_group (inode);
|
2018-03-16 15:53:24 +01:00
|
|
|
}
|
2017-06-19 15:12:51 +02:00
|
|
|
else
|
|
|
|
gcc_unreachable ();
|
|
|
|
}
|
2015-10-30 19:17:43 +01:00
|
|
|
}
|
2017-06-19 15:12:51 +02:00
|
|
|
|
2021-08-20 16:35:18 +02:00
|
|
|
tree fname = clone_function_name (node->decl, "default");
|
|
|
|
symtab->change_decl_assembler_name (node->decl, fname);
|
2018-04-17 07:40:39 +02:00
|
|
|
|
2021-08-12 16:01:01 +02:00
|
|
|
if (node->definition)
|
|
|
|
{
|
|
|
|
/* FIXME: copy of cgraph_node::make_local that should be cleaned up
|
|
|
|
in next stage1. */
|
|
|
|
node->make_decl_local ();
|
|
|
|
node->set_section (NULL);
|
|
|
|
node->set_comdat_group (NULL);
|
|
|
|
node->externally_visible = false;
|
|
|
|
node->forced_by_abi = false;
|
|
|
|
node->set_section (NULL);
|
|
|
|
|
|
|
|
DECL_ARTIFICIAL (node->decl) = 1;
|
|
|
|
node->force_output = true;
|
|
|
|
}
|
2015-10-30 19:17:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Create string with attributes separated by comma.
|
|
|
|
Return number of attributes. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_attr_str (tree arglist, char *attr_str)
|
|
|
|
{
|
|
|
|
tree arg;
|
|
|
|
size_t str_len_sum = 0;
|
|
|
|
int argnum = 0;
|
|
|
|
|
|
|
|
for (arg = arglist; arg; arg = TREE_CHAIN (arg))
|
|
|
|
{
|
|
|
|
const char *str = TREE_STRING_POINTER (TREE_VALUE (arg));
|
|
|
|
size_t len = strlen (str);
|
2016-11-18 23:21:31 +01:00
|
|
|
for (const char *p = strchr (str, ','); p; p = strchr (p + 1, ','))
|
|
|
|
argnum++;
|
2015-10-30 19:17:43 +01:00
|
|
|
memcpy (attr_str + str_len_sum, str, len);
|
|
|
|
attr_str[str_len_sum + len] = TREE_CHAIN (arg) ? ',' : '\0';
|
|
|
|
str_len_sum += len + 1;
|
|
|
|
argnum++;
|
|
|
|
}
|
|
|
|
return argnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return number of attributes separated by comma and put them into ARGS.
|
2019-04-12 14:54:00 +02:00
|
|
|
If there is no DEFAULT attribute return -1.
|
|
|
|
If there is an empty string in attribute return -2.
|
|
|
|
If there are multiple DEFAULT attributes return -3.
|
|
|
|
*/
|
2015-10-30 19:17:43 +01:00
|
|
|
|
|
|
|
static int
|
2018-04-17 07:40:39 +02:00
|
|
|
separate_attrs (char *attr_str, char **attrs, int attrnum)
|
2015-10-30 19:17:43 +01:00
|
|
|
{
|
|
|
|
int i = 0;
|
2018-04-17 07:40:39 +02:00
|
|
|
int default_count = 0;
|
2015-10-30 19:17:43 +01:00
|
|
|
|
2016-11-18 23:21:31 +01:00
|
|
|
for (char *attr = strtok (attr_str, ",");
|
|
|
|
attr != NULL; attr = strtok (NULL, ","))
|
2015-10-30 19:17:43 +01:00
|
|
|
{
|
|
|
|
if (strcmp (attr, "default") == 0)
|
|
|
|
{
|
2018-04-17 07:40:39 +02:00
|
|
|
default_count++;
|
2015-10-30 19:17:43 +01:00
|
|
|
continue;
|
|
|
|
}
|
2016-11-18 23:21:31 +01:00
|
|
|
attrs[i++] = attr;
|
2015-10-30 19:17:43 +01:00
|
|
|
}
|
2018-04-17 07:40:39 +02:00
|
|
|
if (default_count == 0)
|
2015-10-30 19:17:43 +01:00
|
|
|
return -1;
|
2019-04-12 14:54:00 +02:00
|
|
|
else if (default_count > 1)
|
|
|
|
return -3;
|
2018-04-17 07:40:39 +02:00
|
|
|
else if (i + default_count < attrnum)
|
|
|
|
return -2;
|
|
|
|
|
2015-10-30 19:17:43 +01:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return true if symbol is valid in assembler name. */
|
|
|
|
|
|
|
|
static bool
|
|
|
|
is_valid_asm_symbol (char c)
|
|
|
|
{
|
|
|
|
if ('a' <= c && c <= 'z')
|
|
|
|
return true;
|
|
|
|
if ('A' <= c && c <= 'Z')
|
|
|
|
return true;
|
|
|
|
if ('0' <= c && c <= '9')
|
|
|
|
return true;
|
|
|
|
if (c == '_')
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Replace all not valid assembler symbols with '_'. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_new_asm_name (char *old_asm_name, char *new_asm_name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int old_name_len = strlen (old_asm_name);
|
|
|
|
|
|
|
|
/* Replace all not valid assembler symbols with '_'. */
|
|
|
|
for (i = 0; i < old_name_len; i++)
|
|
|
|
if (!is_valid_asm_symbol (old_asm_name[i]))
|
|
|
|
new_asm_name[i] = '_';
|
|
|
|
else
|
|
|
|
new_asm_name[i] = old_asm_name[i];
|
|
|
|
new_asm_name[old_name_len] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Creates target clone of NODE. */
|
|
|
|
|
|
|
|
static cgraph_node *
|
2019-01-18 08:41:05 +01:00
|
|
|
create_target_clone (cgraph_node *node, bool definition, char *name,
|
|
|
|
tree attributes)
|
2015-10-30 19:17:43 +01:00
|
|
|
{
|
|
|
|
cgraph_node *new_node;
|
|
|
|
|
|
|
|
if (definition)
|
|
|
|
{
|
2021-08-20 16:35:18 +02:00
|
|
|
new_node
|
|
|
|
= node->create_version_clone_with_body (vNULL, NULL, NULL, NULL, NULL,
|
|
|
|
name, attributes, false);
|
2019-01-18 08:41:05 +01:00
|
|
|
if (new_node == NULL)
|
|
|
|
return NULL;
|
2015-10-30 19:17:43 +01:00
|
|
|
new_node->force_output = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tree new_decl = copy_node (node->decl);
|
|
|
|
new_node = cgraph_node::get_create (new_decl);
|
2019-01-18 08:41:05 +01:00
|
|
|
DECL_ATTRIBUTES (new_decl) = attributes;
|
2015-11-03 13:02:53 +01:00
|
|
|
/* Generate a new name for the new version. */
|
2021-08-20 16:35:18 +02:00
|
|
|
tree fname = clone_function_name (node->decl, name);
|
|
|
|
symtab->change_decl_assembler_name (new_node->decl, fname);
|
2015-10-30 19:17:43 +01:00
|
|
|
}
|
|
|
|
return new_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the function in NODE has multiple target attributes
|
|
|
|
create the appropriate clone for each valid target attribute. */
|
|
|
|
|
|
|
|
static bool
|
2016-11-18 23:21:31 +01:00
|
|
|
expand_target_clones (struct cgraph_node *node, bool definition)
|
2015-10-30 19:17:43 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
/* Parsing target attributes separated by comma. */
|
|
|
|
tree attr_target = lookup_attribute ("target_clones",
|
|
|
|
DECL_ATTRIBUTES (node->decl));
|
|
|
|
/* No targets specified. */
|
|
|
|
if (!attr_target)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
tree arglist = TREE_VALUE (attr_target);
|
2022-02-28 13:27:22 +01:00
|
|
|
int attr_len = get_target_clone_attr_len (arglist);
|
2015-10-30 19:17:43 +01:00
|
|
|
|
|
|
|
/* No need to clone for 1 target attribute. */
|
|
|
|
if (attr_len == -1)
|
|
|
|
{
|
|
|
|
warning_at (DECL_SOURCE_LOCATION (node->decl),
|
2019-04-12 14:54:00 +02:00
|
|
|
0, "single %<target_clones%> attribute is ignored");
|
2015-10-30 19:17:43 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-07 10:16:07 +01:00
|
|
|
if (node->definition
|
2019-05-16 15:08:48 +02:00
|
|
|
&& (node->alias || !tree_versionable_function_p (node->decl)))
|
2018-03-07 10:16:07 +01:00
|
|
|
{
|
Add support for grouping of related diagnostics (PR other/84889)
We often emit logically-related groups of diagnostics.
A relatively simple case is this:
if (warning_at (body_loc, OPT_Wmultistatement_macros,
"macro expands to multiple statements"))
inform (guard_loc, "some parts of macro expansion are not guarded by "
"this %qs clause", guard_tinfo_to_string (keyword));
where the "note" diagnostic issued by the "inform" call
is guarded by the -Wmultistatement_macros warning.
More complicated examples can be seen in the C++ frontend,
where e.g. print_z_candidates can lead to numerous "note"
diagnostics being emitted.
I'm looking at various ways to improve how we handle such related
diagnostics, but, prior to this patch, there was no explicit
relationship between these diagnostics: the diagnostics subsystem
had no way of "knowing" that these were related.
This patch introduces a simple way to group the diagnostics:
an auto_diagnostic_group class: all diagnostics emitted within
the lifetime of an auto_diagnostic_group instance are logically
grouped.
Hence in the above example, the two diagnostics can be grouped
by simply adding an auto_diagnostic_group instance:
auto_diagnostic_group d;
if (warning_at (body_loc, OPT_Wmultistatement_macros,
"macro expands to multiple statements"))
inform (guard_loc, "some parts of macro expansion are not guarded by "
"this %qs clause", guard_tinfo_to_string (keyword));
Some more awkard cases are of the form:
if (some_condition
&& warning_at (...)
&& more_conditions)
inform (...);
which thus need restructuring to:
if (some_condition)
{
auto_diagnostic_group d;
warning_at (...);
if (more_conditions)
inform (...);
}
so that the lifetime of the auto_diagnostic_group groups the
warning_at and the inform call.
Nesting is handled by simply tracking a nesting depth within the
diagnostic_context.: all diagnostics are treated as grouped until the
final auto_diagnostic_group is popped.
diagnostic.c uses this internally, so that all diagnostics are part of
a group - those that are "by themselves" are treated as being part of
a group with one element.
The diagnostic_context gains optional callbacks for displaying the
start of a group (when the first diagnostic is emitted within it), and
the end of a group (for when the group was non-empty); these callbacks
are unused by default, but a test plugin demonstrates them (and verifies
that the machinery is working).
As noted above, I'm looking at various ways to use the grouping to
improve how we output the diagnostics.
FWIW, I experimented with a more involved implementation, of the form:
diagnostic_group d;
if (d.warning_at (body_loc, OPT_Wmultistatement_macros,
"macro expands to multiple statements"))
d.inform (guard_loc, "some parts of macro expansion are not guarded by "
"this %qs clause", guard_tinfo_to_string (keyword));
which had the advantage of allowing auto-detection of the places where
groups were needed (by converting ::warning_at's return type to bool),
but it was a much more invasive patch, especially when dealing with
the places in the C++ frontend that can emit numerous notes after
an error or warning (and thus having to pass the group around)
Hence I went with this simpler approach.
gcc/c-family/ChangeLog:
PR other/84889
* c-attribs.c (common_handle_aligned_attribute): Add
auto_diagnostic_group instance.
* c-indentation.c (warn_for_misleading_indentation): Likewise.
* c-opts.c (c_common_post_options): Likewise.
* c-warn.c (warn_logical_not_parentheses): Likewise.
(warn_duplicated_cond_add_or_warn): Likewise.
(warn_for_multistatement_macros): Likewise.
gcc/c/ChangeLog:
PR other/84889
* c-decl.c (pushtag): Add auto_diagnostic_group instance.
(diagnose_mismatched_decls): Likewise, in various places.
(warn_if_shadowing): Likewise.
(implicit_decl_warning): Likewise.
(implicitly_declare): Likewise.
(undeclared_variable): Likewise.
(declare_label): Likewise.
(grokdeclarator): Likewise.
(start_function): Likewise.
* c-parser.c (c_parser_declaration_or_fndef): Likewise.
(c_parser_parameter_declaration): Likewise.
(c_parser_binary_expression): Likewise.
* c-typeck.c (c_expr_sizeof_expr): Likewise.
(parser_build_binary_op): Likewise.
(build_unary_op): Likewise.
(error_init): Likewise.
(pedwarn_init): Likewise.
(warning_init): Likewise.
(convert_for_assignment): Likewise.
gcc/cp/ChangeLog:
PR other/84889
* call.c (build_user_type_conversion_1): Add auto_diagnostic_group
instance(s).
(print_error_for_call_failure): Likewise.
(build_op_call_1): Likewise.
(build_conditional_expr_1): Likewise.
(build_new_op_1): Likewise.
(build_op_delete_call): Likewise.
(convert_like_real): Likewise.
(build_over_call): Likewise.
(build_new_method_call_1): Likewise.
(joust): Likewise.
* class.c (check_tag): Likewise.
(finish_struct_anon_r): Likewise.
(one_inherited_ctor): Likewise.
(finalize_literal_type_property): Likewise.
(explain_non_literal_class): Likewise.
(find_flexarrays): Likewise.
(resolve_address_of_overloaded_function): Likewise.
* constexpr.c (ensure_literal_type_for_constexpr_object): Likewise.
(is_valid_constexpr_fn): Likewise.
(cx_check_missing_mem_inits): Likewise.
* cp-gimplify.c (cp_genericize_r): Likewise.
* cvt.c (maybe_warn_nodiscard): Likewise.
* decl.c (warn_extern_redeclared_static): Likewise.
(check_redeclaration_exception_specification): Likewise.
(check_no_redeclaration_friend_default_args): Likewise.
(duplicate_decls): Likewise.
(redeclaration_error_message): Likewise.
(warn_misplaced_attr_for_class_type): Likewise.
* decl2.c (finish_static_data_member_decl): Likewise.
(no_linkage_error): Likewise.
(cp_warn_deprecated_use): Likewise.
* error.c (qualified_name_lookup_error): Likewise.
* friend.c (make_friend_class): Likewise.
(do_friend): Likewise.
* init.c (perform_member_init): Likewise.
(build_new_1): Likewise.
(build_vec_delete_1): Likewise.
(build_delete): Likewise.
* lex.c (unqualified_name_lookup_error): Likewise.
* name-lookup.c (check_extern_c_conflict): Likewise.
(inform_shadowed): New function.
(check_local_shadow): Add auto_diagnostic_group instances,
replacing goto "inform_shadowed" label with call to subroutine.
(set_local_extern_decl_linkage): Add auto_diagnostic_group
instance(s).
* parser.c (cp_parser_diagnose_invalid_type_name): Likewise.
(cp_parser_namespace_name): Likewise.
* pt.c (check_specialization_namespace): Likewise.
(check_template_variable): Likewise.
(warn_spec_missing_attributes): Likewise.
(check_explicit_specialization): Likewise.
(process_partial_specialization): Likewise.
(lookup_template_class_1): Likewise.
(finish_template_variable): Likewise.
(do_auto_deduction): Likewise.
* search.c (check_final_overrider): Likewise.
(look_for_overrides_r): Likewise.
* tree.c (maybe_warn_parm_abi): Likewise.
* typeck.c (cxx_sizeof_expr): Likewise.
(cp_build_function_call_vec): Likewise.
(cp_build_binary_op): Likewise.
(convert_for_assignment): Likewise.
(maybe_warn_about_returning_address_of_local): Likewise.
* typeck2.c (abstract_virtuals_error_sfinae): Likewise.
(check_narrowing): Likewise.
gcc/ChangeLog:
PR other/84889
* attribs.c (diag_attr_exclusions): Add auto_diagnostic_group instance.
(decl_attributes): Likewise.
* calls.c (maybe_warn_nonstring_arg): Add auto_diagnostic_group
instance.
* cgraphunit.c (maybe_diag_incompatible_alias): Likewise.
* diagnostic-core.h (class auto_diagnostic_group): New class.
* diagnostic.c (diagnostic_initialize): Initialize the new fields.
(diagnostic_report_diagnostic): Handle the first diagnostics within
a group.
(emit_diagnostic): Add auto_diagnostic_group instance.
(inform): Likewise.
(inform_n): Likewise.
(warning): Likewise.
(warning_at): Likewise.
(warning_n): Likewise.
(pedwarn): Likewise.
(permerror): Likewise.
(error): Likewise.
(error_n): Likewise.
(error_at): Likewise.
(sorry): Likewise.
(fatal_error): Likewise.
(internal_error): Likewise.
(internal_error_no_backtrace): Likewise.
(auto_diagnostic_group::auto_diagnostic_group): New ctor.
(auto_diagnostic_group::~auto_diagnostic_group): New dtor.
* diagnostic.h (struct diagnostic_context): Add fields
"diagnostic_group_nesting_depth",
"diagnostic_group_emission_count", "begin_group_cb",
"end_group_cb".
* gimple-ssa-isolate-paths.c (find_implicit_erroneous_behavior):
Add auto_diagnostic_group instance(s).
(find_explicit_erroneous_behavior): Likewise.
* gimple-ssa-warn-alloca.c (pass_walloca::execute): Likewise.
* gimple-ssa-warn-restrict.c (maybe_diag_offset_bounds): Likewise.
* gimplify.c (warn_implicit_fallthrough_r): Likewise.
(gimplify_va_arg_expr): Likewise.
* hsa-gen.c (HSA_SORRY_ATV): Likewise.
(HSA_SORRY_AT): Likewise.
* ipa-devirt.c (compare_virtual_tables): Likewise.
(warn_odr): Likewise.
* multiple_target.c (expand_target_clones): Likewise.
* opts-common.c (cmdline_handle_error): Likewise.
* reginfo.c (globalize_reg): Likewise.
* substring-locations.c (format_warning_n_va): Likewise.
* tree-inline.c (expand_call_inline): Likewise.
* tree-ssa-ccp.c (pass_post_ipa_warn::execute): Likewise.
* tree-ssa-loop-niter.c
(do_warn_aggressive_loop_optimizations): Likewise.
* tree-ssa-uninit.c (warn_uninit): Likewise.
* tree.c (warn_deprecated_use): Likewise.
gcc/testsuite/ChangeLog:
PR other/84889
* gcc.dg/plugin/diagnostic-group-test-1.c: New test.
* gcc.dg/plugin/diagnostic_group_plugin.c: New test.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Add the new tests.
From-SVN: r263675
2018-08-20 23:06:46 +02:00
|
|
|
auto_diagnostic_group d;
|
2018-03-07 10:16:07 +01:00
|
|
|
error_at (DECL_SOURCE_LOCATION (node->decl),
|
|
|
|
"clones for %<target_clones%> 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 %<noclone%> attribute");
|
2019-05-16 15:08:48 +02:00
|
|
|
else if (node->alias)
|
|
|
|
reason
|
|
|
|
= "%<target_clones%> cannot be combined with %<alias%> attribute";
|
2018-03-07 10:16:07 +01:00
|
|
|
else
|
|
|
|
reason = copy_forbidden (DECL_STRUCT_FUNCTION (node->decl));
|
|
|
|
if (reason)
|
|
|
|
inform (DECL_SOURCE_LOCATION (node->decl), reason, node->decl);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-30 19:17:43 +01:00
|
|
|
char *attr_str = XNEWVEC (char, attr_len);
|
|
|
|
int attrnum = get_attr_str (arglist, attr_str);
|
|
|
|
char **attrs = XNEWVEC (char *, attrnum);
|
|
|
|
|
2018-04-17 07:40:39 +02:00
|
|
|
attrnum = separate_attrs (attr_str, attrs, attrnum);
|
2019-04-12 14:54:00 +02:00
|
|
|
switch (attrnum)
|
2015-10-30 19:17:43 +01:00
|
|
|
{
|
2019-04-12 14:54:00 +02:00
|
|
|
case -1:
|
2015-10-30 19:17:43 +01:00
|
|
|
error_at (DECL_SOURCE_LOCATION (node->decl),
|
2019-04-12 14:54:00 +02:00
|
|
|
"%<default%> target was not set");
|
|
|
|
break;
|
|
|
|
case -2:
|
2018-04-17 07:40:39 +02:00
|
|
|
error_at (DECL_SOURCE_LOCATION (node->decl),
|
|
|
|
"an empty string cannot be in %<target_clones%> attribute");
|
2019-04-12 14:54:00 +02:00
|
|
|
break;
|
|
|
|
case -3:
|
|
|
|
error_at (DECL_SOURCE_LOCATION (node->decl),
|
|
|
|
"multiple %<default%> targets were set");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attrnum < 0)
|
|
|
|
{
|
2018-04-17 07:40:39 +02:00
|
|
|
XDELETEVEC (attrs);
|
|
|
|
XDELETEVEC (attr_str);
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-30 19:17:43 +01:00
|
|
|
|
|
|
|
cgraph_function_version_info *decl1_v = NULL;
|
|
|
|
cgraph_function_version_info *decl2_v = NULL;
|
|
|
|
cgraph_function_version_info *before = NULL;
|
|
|
|
cgraph_function_version_info *after = NULL;
|
|
|
|
decl1_v = node->function_version ();
|
|
|
|
if (decl1_v == NULL)
|
|
|
|
decl1_v = node->insert_new_function_version ();
|
|
|
|
before = decl1_v;
|
|
|
|
DECL_FUNCTION_VERSIONED (node->decl) = 1;
|
|
|
|
|
|
|
|
for (i = 0; i < attrnum; i++)
|
|
|
|
{
|
|
|
|
char *attr = attrs[i];
|
|
|
|
char *suffix = XNEWVEC (char, strlen (attr) + 1);
|
|
|
|
|
|
|
|
create_new_asm_name (attr, suffix);
|
|
|
|
/* Create new target clone. */
|
|
|
|
tree attributes = make_attribute ("target", attr,
|
2019-01-18 08:41:05 +01:00
|
|
|
DECL_ATTRIBUTES (node->decl));
|
|
|
|
|
|
|
|
cgraph_node *new_node = create_target_clone (node, definition, suffix,
|
|
|
|
attributes);
|
|
|
|
if (new_node == NULL)
|
2017-03-14 15:24:49 +01:00
|
|
|
return false;
|
2019-10-30 08:56:22 +01:00
|
|
|
new_node->local = false;
|
2019-01-18 08:41:05 +01:00
|
|
|
XDELETEVEC (suffix);
|
2015-10-30 19:17:43 +01:00
|
|
|
|
|
|
|
decl2_v = new_node->function_version ();
|
|
|
|
if (decl2_v != NULL)
|
|
|
|
continue;
|
|
|
|
decl2_v = new_node->insert_new_function_version ();
|
|
|
|
|
|
|
|
/* Chain decl2_v and decl1_v. All semantically identical versions
|
|
|
|
will be chained together. */
|
|
|
|
after = decl2_v;
|
|
|
|
while (before->next != NULL)
|
|
|
|
before = before->next;
|
|
|
|
while (after->prev != NULL)
|
|
|
|
after = after->prev;
|
|
|
|
|
|
|
|
before->next = after;
|
|
|
|
after->prev = before;
|
|
|
|
DECL_FUNCTION_VERSIONED (new_node->decl) = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
XDELETEVEC (attrs);
|
|
|
|
XDELETEVEC (attr_str);
|
2016-11-18 23:21:31 +01:00
|
|
|
|
|
|
|
/* Setting new attribute to initial function. */
|
|
|
|
tree attributes = make_attribute ("target", "default",
|
|
|
|
DECL_ATTRIBUTES (node->decl));
|
|
|
|
DECL_ATTRIBUTES (node->decl) = attributes;
|
2019-10-30 08:56:22 +01:00
|
|
|
node->local = false;
|
2019-01-18 08:41:05 +01:00
|
|
|
return true;
|
2015-10-30 19:17:43 +01:00
|
|
|
}
|
|
|
|
|
2018-10-04 16:36:55 +02:00
|
|
|
/* When NODE is a target clone, consider all callees and redirect
|
|
|
|
to a clone with equal target attributes. That prevents multiple
|
|
|
|
multi-versioning dispatches and a call-chain can be optimized. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
redirect_to_specific_clone (cgraph_node *node)
|
|
|
|
{
|
|
|
|
cgraph_function_version_info *fv = node->function_version ();
|
|
|
|
if (fv == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tree attr_target = lookup_attribute ("target", DECL_ATTRIBUTES (node->decl));
|
|
|
|
if (attr_target == NULL_TREE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* We need to remember NEXT_CALLER as it could be modified in the loop. */
|
|
|
|
for (cgraph_edge *e = node->callees; e ; e = e->next_callee)
|
|
|
|
{
|
|
|
|
cgraph_function_version_info *fv2 = e->callee->function_version ();
|
|
|
|
if (!fv2)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
tree attr_target2 = lookup_attribute ("target",
|
|
|
|
DECL_ATTRIBUTES (e->callee->decl));
|
|
|
|
|
|
|
|
/* Function is not calling proper target clone. */
|
2020-06-26 23:46:15 +02:00
|
|
|
if (attr_target2 == NULL_TREE
|
|
|
|
|| !attribute_value_equal (attr_target, attr_target2))
|
2018-10-04 16:36:55 +02:00
|
|
|
{
|
|
|
|
while (fv2->prev != NULL)
|
|
|
|
fv2 = fv2->prev;
|
|
|
|
|
|
|
|
/* Try to find a clone with equal target attribute. */
|
|
|
|
for (; fv2 != NULL; fv2 = fv2->next)
|
|
|
|
{
|
|
|
|
cgraph_node *callee = fv2->this_node;
|
|
|
|
attr_target2 = lookup_attribute ("target",
|
|
|
|
DECL_ATTRIBUTES (callee->decl));
|
2020-06-26 23:46:15 +02:00
|
|
|
if (attr_target2 != NULL_TREE
|
|
|
|
&& attribute_value_equal (attr_target, attr_target2))
|
2018-10-04 16:36:55 +02:00
|
|
|
{
|
|
|
|
e->redirect_callee (callee);
|
2020-01-09 13:21:48 +01:00
|
|
|
cgraph_edge::redirect_call_stmt_to_callee (e);
|
2018-10-04 16:36:55 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-30 19:17:43 +01:00
|
|
|
static unsigned int
|
|
|
|
ipa_target_clone (void)
|
|
|
|
{
|
|
|
|
struct cgraph_node *node;
|
2018-04-17 07:40:39 +02:00
|
|
|
auto_vec<cgraph_node *> to_dispatch;
|
2015-10-30 19:17:43 +01:00
|
|
|
|
|
|
|
FOR_EACH_FUNCTION (node)
|
2018-04-17 07:40:39 +02:00
|
|
|
if (expand_target_clones (node, node->definition))
|
|
|
|
to_dispatch.safe_push (node);
|
2017-02-03 16:22:47 +01:00
|
|
|
|
2018-04-17 07:40:39 +02:00
|
|
|
for (unsigned i = 0; i < to_dispatch.length (); i++)
|
|
|
|
create_dispatcher_calls (to_dispatch[i]);
|
2017-02-03 16:22:47 +01:00
|
|
|
|
2018-10-04 16:36:55 +02:00
|
|
|
FOR_EACH_FUNCTION (node)
|
|
|
|
redirect_to_specific_clone (node);
|
|
|
|
|
2015-10-30 19:17:43 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
const pass_data pass_data_target_clone =
|
|
|
|
{
|
|
|
|
SIMPLE_IPA_PASS, /* type */
|
|
|
|
"targetclone", /* name */
|
|
|
|
OPTGROUP_NONE, /* optinfo_flags */
|
|
|
|
TV_NONE, /* tv_id */
|
|
|
|
( PROP_ssa | PROP_cfg ), /* properties_required */
|
|
|
|
0, /* properties_provided */
|
|
|
|
0, /* properties_destroyed */
|
|
|
|
0, /* todo_flags_start */
|
2017-02-03 16:22:47 +01:00
|
|
|
TODO_update_ssa /* todo_flags_finish */
|
2015-10-30 19:17:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class pass_target_clone : public simple_ipa_opt_pass
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
pass_target_clone (gcc::context *ctxt)
|
|
|
|
: simple_ipa_opt_pass (pass_data_target_clone, ctxt)
|
|
|
|
{}
|
|
|
|
|
|
|
|
/* opt_pass methods: */
|
|
|
|
virtual bool gate (function *);
|
|
|
|
virtual unsigned int execute (function *) { return ipa_target_clone (); }
|
|
|
|
};
|
|
|
|
|
|
|
|
bool
|
|
|
|
pass_target_clone::gate (function *)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anon namespace
|
|
|
|
|
|
|
|
simple_ipa_opt_pass *
|
|
|
|
make_pass_target_clone (gcc::context *ctxt)
|
|
|
|
{
|
|
|
|
return new pass_target_clone (ctxt);
|
|
|
|
}
|