From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1734) id 14B1F3858D32; Mon, 19 Dec 2022 16:43:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 14B1F3858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671468233; bh=vHj++qpsZbL5tDykLxf8No8Jny8Yw5Zz0b7cSFO0v7M=; h=From:To:Subject:Date:From; b=hQ9ERjDkcivYKCHZDbQD1hQhMvoVxX2a1fxLTwgGsc570GSdQoAVJFfEz771tfKzi uMoBJqfIXo6KbLqcsV4EimbK5OzQn86iOyuY1V7U2A3zXel2hr5qnAkhKqb6f8Vumb u+V40geZ82BFpRyW6LEaWnu2c78J00fIIdKLorFs= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marek Polacek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4796] c-family: Fix ICE with -Wsuggest-attribute [PR98487] X-Act-Checkin: gcc X-Git-Author: Marek Polacek X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 263c22a95bc9a0d80c4873c0291b0f938cea7310 X-Git-Newrev: 68e51bd0a85794cd437d3e740357dfef84dc560d Message-Id: <20221219164353.14B1F3858D32@sourceware.org> Date: Mon, 19 Dec 2022 16:43:53 +0000 (GMT) List-Id: https://gcc.gnu.org/g:68e51bd0a85794cd437d3e740357dfef84dc560d commit r13-4796-g68e51bd0a85794cd437d3e740357dfef84dc560d Author: Marek Polacek 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. 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 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 + +[[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); +}