]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-family: Simplify attribute exclusion handling
authorAndrew Carlotti <andrew.carlotti@arm.com>
Mon, 6 Nov 2023 16:10:55 +0000 (16:10 +0000)
committerAndrew Carlotti <andrew.carlotti@arm.com>
Sat, 16 Dec 2023 00:38:42 +0000 (00:38 +0000)
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.

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:

gcc/c-family/c-attribs.cc
gcc/testsuite/g++.target/i386/mvc2.C
gcc/testsuite/g++.target/i386/mvc3.C

index a3671fe3a572b71777aa5284f127e082a83dd4d9..9638848591fc82d3f7116cadf38b11237206ac0b 100644 (file)
@@ -217,6 +217,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),
@@ -224,6 +231,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),
@@ -339,7 +359,7 @@ const struct attribute_spec c_common_gnu_attributes[] =
                              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 },
@@ -490,9 +510,11 @@ const struct attribute_spec c_common_gnu_attributes[] =
   { "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
@@ -1580,16 +1602,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);
@@ -1671,22 +1684,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
     {
@@ -5836,12 +5836,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;
@@ -5882,19 +5876,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");
index 7c1fb6518d04f404123086660c32853dcd9f65ba..04ee0573d607f6de2e7ea382e891f62884c18ea7 100644 (file)
@@ -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'" } */
index 5d634fd7ea68b905a0e93ca1c25f6907bc9d2858..5ad1f88fd2d7da74fafcafcff24b77cb2d12a5a0 100644 (file)
@@ -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'" } */