public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c-family: Fix ICE with -Wsuggest-attribute [PR98487]
@ 2022-12-16 18:28 Marek Polacek
  2022-12-17  0:15 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2022-12-16 18:28 UTC (permalink / raw)
  To: GCC Patches; +Cc: Joseph Myers, Jason Merrill, Jakub Jelinek

Here we crash because check_function_format was using TREE_PURPOSE
directly rather than using get_attribute_name.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

	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.
---
 gcc/c-family/c-format.cc                      |  2 +-
 .../c-c++-common/Wsuggest-attribute-1.c       | 36 +++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/c-c++-common/Wsuggest-attribute-1.c

diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc
index 01adea4ff41..08643c5da7a 100644
--- a/gcc/c-family/c-format.cc
+++ b/gcc/c-family/c-format.cc
@@ -1215,7 +1215,7 @@ check_function_format (const_tree fn, 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);
+}

base-commit: b50fe16a3b2214c418ecc5febc0bb21bc17912b7
-- 
2.38.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c-family: Fix ICE with -Wsuggest-attribute [PR98487]
  2022-12-16 18:28 [PATCH] c-family: Fix ICE with -Wsuggest-attribute [PR98487] Marek Polacek
@ 2022-12-17  0:15 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2022-12-17  0:15 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches; +Cc: Joseph Myers, Jakub Jelinek

On 12/16/22 13:28, Marek Polacek wrote:
> Here we crash because check_function_format was using TREE_PURPOSE
> directly rather than using get_attribute_name.
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

OK.

> 	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.
> ---
>   gcc/c-family/c-format.cc                      |  2 +-
>   .../c-c++-common/Wsuggest-attribute-1.c       | 36 +++++++++++++++++++
>   2 files changed, 37 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/c-c++-common/Wsuggest-attribute-1.c
> 
> diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc
> index 01adea4ff41..08643c5da7a 100644
> --- a/gcc/c-family/c-format.cc
> +++ b/gcc/c-family/c-format.cc
> @@ -1215,7 +1215,7 @@ check_function_format (const_tree fn, 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);
> +}
> 
> base-commit: b50fe16a3b2214c418ecc5febc0bb21bc17912b7


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-17  0:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-16 18:28 [PATCH] c-family: Fix ICE with -Wsuggest-attribute [PR98487] Marek Polacek
2022-12-17  0:15 ` Jason Merrill

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).