diff options
author | Jakub Jelinek <jakub@redhat.com> | 2022-10-07 09:01:04 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2022-10-07 09:01:04 +0200 |
commit | 88f04e90f63f08620cc9cd2f059a1315b70bed3b (patch) | |
tree | 868dae2613d56d7f3cb26d24e62ff81a8d2d7745 /gcc/cp/cp-gimplify.cc | |
parent | 348e46fa8cba960c23170673bfc0c1b4fb384975 (diff) | |
download | gcc-88f04e90f63f08620cc9cd2f059a1315b70bed3b.zip gcc-88f04e90f63f08620cc9cd2f059a1315b70bed3b.tar.gz gcc-88f04e90f63f08620cc9cd2f059a1315b70bed3b.tar.bz2 |
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/cp/cp-gimplify.cc')
-rw-r--r-- | gcc/cp/cp-gimplify.cc | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index 5d26e59..cb8bbd8 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -3028,7 +3028,7 @@ cp_fold (tree x) return x; } -/* Look up either "hot" or "cold" in attribute list LIST. */ +/* Look up "hot", "cold", "likely" or "unlikely" in attribute list LIST. */ tree lookup_hotness_attribute (tree list) @@ -3036,24 +3036,36 @@ lookup_hotness_attribute (tree list) for (; list; list = TREE_CHAIN (list)) { tree name = get_attribute_name (list); - if (is_attribute_p ("hot", name) - || is_attribute_p ("cold", name) - || is_attribute_p ("likely", name) - || is_attribute_p ("unlikely", name)) + if ((is_attribute_p ("hot", name) + || is_attribute_p ("cold", name) + || is_attribute_p ("likely", name) + || is_attribute_p ("unlikely", name)) + && is_attribute_namespace_p ("", list)) break; } return list; } -/* Remove both "hot" and "cold" attributes from LIST. */ +/* Remove "hot", "cold", "likely" and "unlikely" attributes from LIST. */ static tree remove_hotness_attribute (tree list) { - list = remove_attribute ("hot", list); - list = remove_attribute ("cold", list); - list = remove_attribute ("likely", list); - list = remove_attribute ("unlikely", list); + for (tree *p = &list; *p; ) + { + tree l = *p; + tree name = get_attribute_name (l); + if ((is_attribute_p ("hot", name) + || is_attribute_p ("cold", name) + || is_attribute_p ("likely", name) + || is_attribute_p ("unlikely", name)) + && is_attribute_namespace_p ("", l)) + { + *p = TREE_CHAIN (l); + continue; + } + p = &TREE_CHAIN (l); + } return list; } |