c++: Improve handling of foreigner namespace attributes
authorJakub Jelinek <jakub@redhat.com>
Fri, 7 Oct 2022 07:01:04 +0000 (09:01 +0200)
committerJakub Jelinek <jakub@redhat.com>
Fri, 7 Oct 2022 07:01:04 +0000 (09:01 +0200)
commit88f04e90f63f08620cc9cd2f059a1315b70bed3b
tree868dae2613d56d7f3cb26d24e62ff81a8d2d7745
parent348e46fa8cba960c23170673bfc0c1b4fb384975
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.
gcc/attribs.cc
gcc/attribs.h
gcc/c-family/c-common.cc
gcc/cp/cp-gimplify.cc
gcc/cp/parser.cc
gcc/testsuite/g++.dg/cpp1z/fallthrough2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/attr-likely7.C [new file with mode: 0644]