summaryrefslogtreecommitdiff
path: root/gcc/attribs.h
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2022-10-07 09:01:04 +0200
committerJakub Jelinek <jakub@redhat.com>2022-10-07 09:01:04 +0200
commit88f04e90f63f08620cc9cd2f059a1315b70bed3b (patch)
tree868dae2613d56d7f3cb26d24e62ff81a8d2d7745 /gcc/attribs.h
parent348e46fa8cba960c23170673bfc0c1b4fb384975 (diff)
downloadgcc-88f04e90f63f08620cc9cd2f059a1315b70bed3b.tar.gz
c++: Improve handling of foreigner namespace attributes
In some cases we want to look up or remove both standard attributes and attributes from gnu namespace but not others. This patch arranges for ATTR_NS of "" to stand for ATTR_NS NULL or "gnu", so that we don't need 2 separate calls, and introduces is_attribute_namespace_p function which allows testing the namespace of an attribute similar way. The patch also uses the new lookup_attribute overload and extra tests to avoid emitting weird warnings on foreign namespace attributes which we should just ignore (perhaps with a warning), but shouldn't imply any meaning to them just because they have a name matching some standard or gnu attribute name. 2022-10-07 Jakub Jelinek <jakub@redhat.com> gcc/ * attribs.h (is_attribute_namespace_p): New inline function. (lookup_attribute): Document meaning of ATTR_NS equal to "". * attribs.cc (remove_attribute): Use is_attribute_namespace_p. (private_lookup_attribute): For ATTR_NS "" match either standard attribute or "gnu" namespace one. gcc/c-family/ * c-common.cc (attribute_fallthrough_p): Lookup fallthrough attribute only in gnu namespace or as standard attribute, treat fallthrough attributes in other namespaces like any other unknown attribute. gcc/cp/ * parser.cc (cp_parser_check_std_attribute): Only do checks if attribute is a standard attribute or in gnu namespace and only lookup other attributes in those namespaces. * cp-gimplify.cc (lookup_hotness_attribute): Adjust function comment. Only return true for standard attribute or gnu namespace attribute. (remove_hotness_attribute): Only remove hotness attributes when they are standard or in gnu namespace, implement it in a single loop rather than former 4 now 8 remove_attribute calls. gcc/testsuite/ * g++.dg/cpp1z/fallthrough2.C: New test. * g++.dg/cpp2a/attr-likely7.C: New test.
Diffstat (limited to 'gcc/attribs.h')
-rw-r--r--gcc/attribs.h19
1 files changed, 18 insertions, 1 deletions
diff --git a/gcc/attribs.h b/gcc/attribs.h
index 121b9ebbc39..1dc16e4bc4e 100644
--- a/gcc/attribs.h
+++ b/gcc/attribs.h
@@ -188,6 +188,22 @@ is_attribute_p (const char *attr_name, const_tree ident)
IDENTIFIER_POINTER (ident), IDENTIFIER_LENGTH (ident));
}
+/* Given an attribute ATTR and a string ATTR_NS, return true
+ if the attribute namespace is valid for the string. ATTR_NS "" stands
+ for standard attribute (NULL get_attribute_namespace) or "gnu"
+ namespace. */
+
+static inline bool
+is_attribute_namespace_p (const char *attr_ns, const_tree attr)
+{
+ tree ident = get_attribute_namespace (attr);
+ if (attr_ns == NULL)
+ return ident == NULL_TREE;
+ if (attr_ns[0])
+ return ident && is_attribute_p (attr_ns, ident);
+ return ident == NULL_TREE || is_attribute_p ("gnu", ident);
+}
+
/* Given an attribute name ATTR_NAME and a list of attributes LIST,
return a pointer to the attribute's list element if the attribute
is part of the list, or NULL_TREE if not found. If the attribute
@@ -217,7 +233,8 @@ lookup_attribute (const char *attr_name, tree list)
}
}
-/* Similar to lookup_attribute, but also match the attribute namespace. */
+/* Similar to lookup_attribute, but also match the attribute namespace.
+ ATTR_NS "" stands for either standard attribute or "gnu" namespace. */
static inline tree
lookup_attribute (const char *attr_ns, const char *attr_name, tree list)