public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Marek Polacek <mpolacek@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-8993] c-family: Fix ICE with -Wsuggest-attribute [PR98487]
Date: Mon, 19 Dec 2022 16:49:36 +0000 (GMT)	[thread overview]
Message-ID: <20221219164936.3192A3858C52@sourceware.org> (raw)

https://gcc.gnu.org/g:0e345504ec9349d9a3bf826c3e16b7e973739485

commit r12-8993-g0e345504ec9349d9a3bf826c3e16b7e973739485
Author: Marek Polacek <polacek@redhat.com>
Date:   Fri Dec 16 12:28:43 2022 -0500

    c-family: Fix ICE with -Wsuggest-attribute [PR98487]
    
    Here we crash because check_function_format was using TREE_PURPOSE
    directly rather than using get_attribute_name.
    
            PR c/98487
    
    gcc/c-family/ChangeLog:
    
            * c-format.cc (check_function_format): Use get_attribute_name.
    
    gcc/testsuite/ChangeLog:
    
            * c-c++-common/Wsuggest-attribute-1.c: New test.
    
    (cherry picked from commit 68e51bd0a85794cd437d3e740357dfef84dc560d)

Diff:
---
 gcc/c-family/c-format.cc                          |  2 +-
 gcc/testsuite/c-c++-common/Wsuggest-attribute-1.c | 36 +++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc
index d05e5acd063..fe5ed48b86b 100644
--- a/gcc/c-family/c-format.cc
+++ b/gcc/c-family/c-format.cc
@@ -1205,7 +1205,7 @@ check_function_format (const_tree fntype, tree attrs, int nargs,
 	      for (c = TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl));
 		   c;
 		   c = TREE_CHAIN (c))
-		if (is_attribute_p ("format", TREE_PURPOSE (c))
+		if (is_attribute_p ("format", get_attribute_name (c))
 		    && (decode_format_type (IDENTIFIER_POINTER
 					    (TREE_VALUE (TREE_VALUE (c))))
 			== info.format_type))
diff --git a/gcc/testsuite/c-c++-common/Wsuggest-attribute-1.c b/gcc/testsuite/c-c++-common/Wsuggest-attribute-1.c
new file mode 100644
index 00000000000..8b5b398fb78
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wsuggest-attribute-1.c
@@ -0,0 +1,36 @@
+/* PR c/98487 */
+/* { dg-do compile { target { c || c++11 } } } */
+/* { dg-options "-Wsuggest-attribute=format" } */
+
+#include <stdarg.h>
+
+[[gnu::__format__(__printf__, 1, 2)]]
+void
+do_printf(const char * const a0, ...)
+{
+  va_list ap;
+  va_start(ap, a0);
+  __builtin_vprintf(a0, ap);
+  va_end(ap);
+}
+
+[[gnu::__format__(__scanf__, 1, 2)]]
+void
+do_scanf(const char * const a0, ...)
+{
+  va_list ap;
+  va_start(ap, a0);
+  __builtin_vscanf(a0, ap);
+  va_end(ap);
+}
+
+struct tm;
+
+[[gnu::__format__(__strftime__, 1, 0)]]
+void
+do_strftime(const char * const a0, struct tm * a1)
+{
+  char buff[256];
+  __builtin_strftime(buff, sizeof(buff), a0, a1);
+  __builtin_puts(buff);
+}

                 reply	other threads:[~2022-12-19 16:49 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=20221219164936.3192A3858C52@sourceware.org \
    --to=mpolacek@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).