aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2023-12-02 13:49:54 +0000
committerRichard Sandiford <richard.sandiford@arm.com>2023-12-02 13:49:54 +0000
commitf8135a5aefe7c9f79b7d6b416a2bb6cb5ac0b134 (patch)
tree4be90c9b72f9565fa7b6362d7a1bcbca3d96b1aa
parent3956f5146dc13aa72977c222cfe472ba1e92834c (diff)
downloadgcc-f8135a5aefe7c9f79b7d6b416a2bb6cb5ac0b134.zip
gcc-f8135a5aefe7c9f79b7d6b416a2bb6cb5ac0b134.tar.gz
gcc-f8135a5aefe7c9f79b7d6b416a2bb6cb5ac0b134.tar.bz2
attribs: Consider namespaces when comparing attributes
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. 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.
-rw-r--r--gcc/attribs.cc29
1 files changed, 23 insertions, 6 deletions
diff --git a/gcc/attribs.cc b/gcc/attribs.cc
index 95b0d0f..e2e0335 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
@@ -915,9 +932,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;
@@ -948,8 +965,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));
}
@@ -1462,7 +1479,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;
}
@@ -1476,7 +1493,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. */