decl_attributes and comp_type_attributes both had code that
iterated over one list of attributes and looked for coresponding
attributes in another list.  This patch makes those lookups
namespace-aware.

Tested on aarch64-linux-gnu & x86_64-linux-gnu.  OK to install?

Richard


gcc/
        * attribs.cc (find_same_attribute): New function.
        (decl_attributes, comp_type_attributes): Use it when looking
        up one list's attributes in another list.
---
 gcc/attribs.cc | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/gcc/attribs.cc b/gcc/attribs.cc
index 6c70110e350..c23ed3bac91 100644
--- a/gcc/attribs.cc
+++ b/gcc/attribs.cc
@@ -583,6 +583,23 @@ attribute_ignored_p (const attribute_spec *const as)
   return as->max_length == -2;
 }
 
+/* See whether LIST contains at least one instance of attribute ATTR
+   (possibly with different arguments).  Return the first such attribute
+   if so, otherwise return null.  */
+
+static tree
+find_same_attribute (const_tree attr, tree list)
+{
+  if (list == NULL_TREE)
+    return NULL_TREE;
+  tree ns = get_attribute_namespace (attr);
+  tree name = get_attribute_name (attr);
+  return private_lookup_attribute (ns ? IDENTIFIER_POINTER (ns) : nullptr,
+                                  IDENTIFIER_POINTER (name),
+                                  ns ? IDENTIFIER_LENGTH (ns) : 0,
+                                  IDENTIFIER_LENGTH (name), list);
+}
+
 /* Process the attributes listed in ATTRIBUTES and install them in *NODE,
    which is either a DECL (including a TYPE_DECL) or a TYPE.  If a DECL,
    it should be modified in place; if a TYPE, a copy should be created
@@ -912,9 +929,9 @@ decl_attributes (tree *node, tree attributes, int flags,
          else
            old_attrs = TYPE_ATTRIBUTES (*anode);
 
-         for (a = lookup_attribute (spec->name, old_attrs);
+         for (a = find_same_attribute (attr, old_attrs);
               a != NULL_TREE;
-              a = lookup_attribute (spec->name, TREE_CHAIN (a)))
+              a = find_same_attribute (attr, TREE_CHAIN (a)))
            {
              if (simple_cst_equal (TREE_VALUE (a), args) == 1)
                break;
@@ -945,8 +962,8 @@ decl_attributes (tree *node, tree attributes, int flags,
                          if (TYPE_ATTRIBUTES (variant) == old_attrs)
                            TYPE_ATTRIBUTES (variant)
                              = TYPE_ATTRIBUTES (*anode);
-                         else if (!lookup_attribute
-                                  (spec->name, TYPE_ATTRIBUTES (variant)))
+                         else if (!find_same_attribute
+                                  (attr, TYPE_ATTRIBUTES (variant)))
                            TYPE_ATTRIBUTES (variant) = tree_cons
                              (name, args, TYPE_ATTRIBUTES (variant));
                        }
@@ -1459,7 +1476,7 @@ comp_type_attributes (const_tree type1, const_tree type2)
       if (!as || as->affects_type_identity == false)
        continue;
 
-      attr = lookup_attribute (as->name, CONST_CAST_TREE (a2));
+      attr = find_same_attribute (a, CONST_CAST_TREE (a2));
       if (!attr || !attribute_value_equal (a, attr))
        break;
     }
@@ -1473,7 +1490,7 @@ comp_type_attributes (const_tree type1, const_tree type2)
          if (!as || as->affects_type_identity == false)
            continue;
 
-         if (!lookup_attribute (as->name, CONST_CAST_TREE (a1)))
+         if (!find_same_attribute (a, CONST_CAST_TREE (a1)))
            break;
          /* We don't need to compare trees again, as we did this
             already in first loop.  */
-- 
2.25.1

Reply via email to