This patch changes the handling of mutual exclusions involving the target and target_clones attributes to use the generic attribute exclusion lists. Additionally, the duplicate handling for the always_inline and noinline attribute exclusion is removed.
The only change in functionality is the choice of warning message displayed - due to either a change in the wording for mutual exclusion warnings, or a change in the order in which different checks occur. Ok for master? gcc/c-family/ChangeLog: * c-attribs.cc (attr_always_inline_exclusions): New. (attr_target_exclusions): Ditto. (attr_target_clones_exclusions): Ditto. (c_common_attribute_table): Add new exclusion lists. (handle_noinline_attribute): Remove custom exclusion handling. (handle_always_inline_attribute): Ditto. (handle_target_attribute): Ditto. (handle_target_clones_attribute): Ditto. gcc/testsuite/ChangeLog: * g++.target/i386/mvc2.C: * g++.target/i386/mvc3.C: diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 461732f60f7c4031cc6692000fbdddb9f726a035..b3b41ef123a0f171f57acb1b7f7fdde716428c00 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -214,6 +214,13 @@ static const struct attribute_spec::exclusions attr_inline_exclusions[] = ATTR_EXCL (NULL, false, false, false), }; +static const struct attribute_spec::exclusions attr_always_inline_exclusions[] = +{ + ATTR_EXCL ("noinline", true, true, true), + ATTR_EXCL ("target_clones", true, true, true), + ATTR_EXCL (NULL, false, false, false), +}; + static const struct attribute_spec::exclusions attr_noinline_exclusions[] = { ATTR_EXCL ("always_inline", true, true, true), @@ -221,6 +228,19 @@ static const struct attribute_spec::exclusions attr_noinline_exclusions[] = ATTR_EXCL (NULL, false, false, false), }; +static const struct attribute_spec::exclusions attr_target_exclusions[] = +{ + ATTR_EXCL ("target_clones", true, true, true), + ATTR_EXCL (NULL, false, false, false), +}; + +static const struct attribute_spec::exclusions attr_target_clones_exclusions[] = +{ + ATTR_EXCL ("always_inline", true, true, true), + ATTR_EXCL ("target", true, true, true), + ATTR_EXCL (NULL, false, false, false), +}; + extern const struct attribute_spec::exclusions attr_noreturn_exclusions[] = { ATTR_EXCL ("alloc_align", true, true, true), @@ -332,7 +352,7 @@ const struct attribute_spec c_common_attribute_table[] = handle_leaf_attribute, NULL }, { "always_inline", 0, 0, true, false, false, false, handle_always_inline_attribute, - attr_inline_exclusions }, + attr_always_inline_exclusions }, { "gnu_inline", 0, 0, true, false, false, false, handle_gnu_inline_attribute, attr_inline_exclusions }, @@ -483,9 +503,11 @@ const struct attribute_spec c_common_attribute_table[] = { "error", 1, 1, true, false, false, false, handle_error_attribute, NULL }, { "target", 1, -1, true, false, false, false, - handle_target_attribute, NULL }, + handle_target_attribute, + attr_target_exclusions }, { "target_clones", 1, -1, true, false, false, false, - handle_target_clones_attribute, NULL }, + handle_target_clones_attribute, + attr_target_clones_exclusions }, { "optimize", 1, -1, true, false, false, false, handle_optimize_attribute, NULL }, /* For internal use only. The leading '*' both prevents its usage in @@ -1397,16 +1419,7 @@ handle_noinline_attribute (tree *node, tree name, int ARG_UNUSED (flags), bool *no_add_attrs) { if (TREE_CODE (*node) == FUNCTION_DECL) - { - if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node))) - { - warning (OPT_Wattributes, "%qE attribute ignored due to conflict " - "with attribute %qs", name, "always_inline"); - *no_add_attrs = true; - } - else - DECL_UNINLINABLE (*node) = 1; - } + DECL_UNINLINABLE (*node) = 1; else { warning (OPT_Wattributes, "%qE attribute ignored", name); @@ -1487,22 +1500,9 @@ handle_always_inline_attribute (tree *node, tree name, { if (TREE_CODE (*node) == FUNCTION_DECL) { - if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node))) - { - warning (OPT_Wattributes, "%qE attribute ignored due to conflict " - "with %qs attribute", name, "noinline"); - *no_add_attrs = true; - } - else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node))) - { - warning (OPT_Wattributes, "%qE attribute ignored due to conflict " - "with %qs attribute", name, "target_clones"); - *no_add_attrs = true; - } - else - /* Set the attribute and mark it for disregarding inline - limits. */ - DECL_DISREGARD_INLINE_LIMITS (*node) = 1; + /* Set the attribute and mark it for disregarding inline + limits. */ + DECL_DISREGARD_INLINE_LIMITS (*node) = 1; } else { @@ -5650,12 +5650,6 @@ handle_target_attribute (tree *node, tree name, tree args, int flags, warning (OPT_Wattributes, "%qE attribute ignored", name); *no_add_attrs = true; } - else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node))) - { - warning (OPT_Wattributes, "%qE attribute ignored due to conflict " - "with %qs attribute", name, "target_clones"); - *no_add_attrs = true; - } else if (! targetm.target_option.valid_attribute_p (*node, name, args, flags)) *no_add_attrs = true; @@ -5696,19 +5690,7 @@ handle_target_clones_attribute (tree *node, tree name, tree ARG_UNUSED (args), } } - if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node))) - { - warning (OPT_Wattributes, "%qE attribute ignored due to conflict " - "with %qs attribute", name, "always_inline"); - *no_add_attrs = true; - } - else if (lookup_attribute ("target", DECL_ATTRIBUTES (*node))) - { - warning (OPT_Wattributes, "%qE attribute ignored due to conflict " - "with %qs attribute", name, "target"); - *no_add_attrs = true; - } - else if (get_target_clone_attr_len (args) == -1) + if (get_target_clone_attr_len (args) == -1) { warning (OPT_Wattributes, "single %<target_clones%> attribute is ignored"); diff --git a/gcc/testsuite/g++.target/i386/mvc2.C b/gcc/testsuite/g++.target/i386/mvc2.C index 7c1fb6518d04f404123086660c32853dcd9f65ba..04ee0573d607f6de2e7ea382e891f62884c18ea7 100644 --- a/gcc/testsuite/g++.target/i386/mvc2.C +++ b/gcc/testsuite/g++.target/i386/mvc2.C @@ -3,7 +3,7 @@ __attribute__((target_clones("avx","arch=slm","default"))) __attribute__((target("avx"))) -int foo (); /* { dg-warning "'target' attribute ignored due to conflict with 'target_clones' attribute" } */ +int foo (); /* { dg-warning "ignoring attribute 'target' because it conflicts with attribute 'target_clones'" } */ __attribute__((target_clones("avx","arch=slm","default"),always_inline)) -int bar (); /* { dg-warning "'always_inline' attribute ignored due to conflict with 'target_clones' attribute" } */ +int bar (); /* { dg-warning "ignoring attribute 'always_inline' because it conflicts with attribute 'target_clones'" } */ diff --git a/gcc/testsuite/g++.target/i386/mvc3.C b/gcc/testsuite/g++.target/i386/mvc3.C index 5d634fd7ea68b905a0e93ca1c25f6907bc9d2858..5ad1f88fd2d7da74fafcafcff24b77cb2d12a5a0 100644 --- a/gcc/testsuite/g++.target/i386/mvc3.C +++ b/gcc/testsuite/g++.target/i386/mvc3.C @@ -3,7 +3,7 @@ __attribute__((target("avx"))) __attribute__((target_clones("avx","arch=slm","default"))) -int foo (); /* { dg-warning "'target_clones' attribute ignored due to conflict with 'target' attribute" } */ +int foo (); /* { dg-warning "ignoring attribute 'target_clones' because it conflicts with attribute 'target'" } */ __attribute__((always_inline,target_clones("avx","arch=slm","default"))) -int bar (); /* { dg-warning "'target_clones' attribute ignored due to conflict with 'always_inline' attribute" } */ +int bar (); /* { dg-warning "ignoring attribute 'target_clones' because it conflicts with attribute 'always_inline'" } */