public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-8940] attribs: Don't canonicalize lookup_scoped_attribute_spec argument [PR113674]
Date: Mon, 12 Feb 2024 19:45:40 +0000 (GMT)	[thread overview]
Message-ID: <20240212194540.E4EC83858419@sourceware.org> (raw)

https://gcc.gnu.org/g:b42e978f29b33071addff6d7bb8bcdb11d176606

commit r14-8940-gb42e978f29b33071addff6d7bb8bcdb11d176606
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Mon Feb 12 20:45:01 2024 +0100

    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.

Diff:
---
 gcc/attribs.cc                             | 10 ----------
 gcc/testsuite/c-c++-common/Wattributes-3.c | 13 +++++++++++++
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/gcc/attribs.cc b/gcc/attribs.cc
index 4df5d2410dad..fc7459c3850a 100644
--- a/gcc/attribs.cc
+++ b/gcc/attribs.cc
@@ -116,15 +116,6 @@ get_gnu_namespace ()
   return gnu_namespace_cache;
 }
 
-/* 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 SPECS into its namespace.  IGNORED_P is true iff all unknown
    attributes in this namespace should be ignored for the purposes of
    -Wattributes.  The function returns the namespace into which the
@@ -398,7 +389,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 000000000000..a1a6d9a58955
--- /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;
+}

                 reply	other threads:[~2024-02-12 19:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240212194540.E4EC83858419@sourceware.org \
    --to=jakub@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).