aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-02-12 20:45:01 +0100
committerJakub Jelinek <jakub@redhat.com>2024-06-11 12:35:31 +0200
commitfda7a897d037ff1c59630f0a741eb20e68f45848 (patch)
treed15a0e8d3875a16d4c94e406d0343b90c16e27da
parente6976013c0910a1043b82a820180f01f356ffd3d (diff)
downloadgcc-fda7a897d037ff1c59630f0a741eb20e68f45848.zip
gcc-fda7a897d037ff1c59630f0a741eb20e68f45848.tar.gz
gcc-fda7a897d037ff1c59630f0a741eb20e68f45848.tar.bz2
attribs: Don't canonicalize lookup_scoped_attribute_spec argument [PR113674]
The C and C++ FEs when parsing attributes already canonicalize them (i.e. if they start with __ and end with __ substrings, we remove those). lookup_attribute already verifies in gcc_assert that the first character of name is not an underscore, and even lookup_scoped_attribute_spec doesn't attempt to canonicalize the namespace it is passed. But for some historic reason it was canonicalizing the name argument, which misbehaves when an attribute starts with ____ and ends with ____. I believe it is just wrong to try to canonicalize lookup_scope_attribute_spec name attribute, it should have been canonicalized already, in other spots where it is called it is already canonicalized before. 2024-02-12 Jakub Jelinek <jakub@redhat.com> PR c++/113674 * attribs.cc (extract_attribute_substring): Remove. (lookup_scoped_attribute_spec): Don't call it. * c-c++-common/Wattributes-3.c: New test. (cherry picked from commit b42e978f29b33071addff6d7bb8bcdb11d176606)
-rw-r--r--gcc/attribs.cc10
-rw-r--r--gcc/testsuite/c-c++-common/Wattributes-3.c13
2 files changed, 13 insertions, 10 deletions
diff --git a/gcc/attribs.cc b/gcc/attribs.cc
index 876277d..f73e00b 100644
--- a/gcc/attribs.cc
+++ b/gcc/attribs.cc
@@ -109,15 +109,6 @@ static const struct attribute_spec empty_attribute_table[] =
{ NULL, 0, 0, false, false, false, false, NULL, NULL }
};
-/* Return base name of the attribute. Ie '__attr__' is turned into 'attr'.
- To avoid need for copying, we simply return length of the string. */
-
-static void
-extract_attribute_substring (struct substring *str)
-{
- canonicalize_attr_name (str->str, str->length);
-}
-
/* Insert an array of attributes ATTRIBUTES into a namespace. This
array must be NULL terminated. NS is the name of attribute
namespace. IGNORED_P is true iff all unknown attributes in this
@@ -409,7 +400,6 @@ lookup_scoped_attribute_spec (const_tree ns, const_tree name)
attr.str = IDENTIFIER_POINTER (name);
attr.length = IDENTIFIER_LENGTH (name);
- extract_attribute_substring (&attr);
return attrs->attribute_hash->find_with_hash (&attr,
substring_hash (attr.str,
attr.length));
diff --git a/gcc/testsuite/c-c++-common/Wattributes-3.c b/gcc/testsuite/c-c++-common/Wattributes-3.c
new file mode 100644
index 0000000..a1a6d9a
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wattributes-3.c
@@ -0,0 +1,13 @@
+/* PR c++/113674 */
+/* { dg-do compile { target { c || c++11 } } } */
+/* { dg-options "" } */
+
+[[____noreturn____]] int foo (int i) /* { dg-warning "'__noreturn__' attribute (directive )?ignored" } */
+{
+ return i;
+}
+
+[[____maybe_unused____]] int bar (int i) /* { dg-warning "'__maybe_unused__' attribute (directive )?ignored" } */
+{
+ return i;
+}