public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "martin at martin dot st" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/95130] New: GCC ignoring attribute(format(gnu_printf)) on printf in mingw Date: Thu, 14 May 2020 11:37:49 +0000 [thread overview] Message-ID: <bug-95130-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95130 Bug ID: 95130 Summary: GCC ignoring attribute(format(gnu_printf)) on printf in mingw Product: gcc Version: 9.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: martin at martin dot st Target Milestone: --- Since a long time (GCC 4.4?) GCC does support annotating functions with either the format attribute "gnu_printf" or "ms_printf" to distinguish between different format string interpretations. However, it seems like the attribute is ignored for the "printf" symbol; regardless what the function declaration says, GCC treats it as "ms_printf". This has become an issue now that mingw-w64 supports using the UCRT instead of msvcrt.dll, and in this case the stdio functions are declared with the gnu_printf attribute, and inttypes.h uses the same format specifiers as in GNU mode. A reproducible example of the problem: $ cat format.c __attribute__((__format__ (gnu_printf, 1, 2))) int printf (const char *__format, ...); __attribute__((__format__ (gnu_printf, 1, 2))) int othername (const char *__format, ...); void function(void) { long long unsigned x = 42; othername("%llu\n", x); printf("%llu\n", x); } $ x86_64-w64-mingw32-gcc -c -Wformat format.c format.c: In function 'function': format.c:7:15: warning: unknown conversion type character 'l' in format [-Wformat=] 7 | printf("%llu\n", x); | ^ format.c:7:12: warning: too many arguments for format [-Wformat-extra-args] 7 | printf("%llu\n", x); | ^~~~~~~~ Note how both functions, printf and othername, are declare with identical gnu_printf format attributes - GCC does take this into account for "othername" and doesn't produce a warning, but GCC seems to disregard the attribute in the printf declaration and behave as if it was declared as ms_printf. If the printf function declaration is changed into a static inline function, the actual attribute used is honored though.
next reply other threads:[~2020-05-14 11:37 UTC|newest] Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-05-14 11:37 martin at martin dot st [this message] 2020-05-14 17:27 ` [Bug c/95130] " joseph at codesourcery dot com 2021-11-22 21:21 ` tomas.kalibera at gmail dot com 2021-12-15 17:27 ` tomas.kalibera at gmail dot com 2021-12-15 17:29 ` tomas.kalibera at gmail dot com 2021-12-15 17:45 ` tomas.kalibera at gmail dot com 2022-10-25 7:10 ` lh_mouse at 126 dot com 2022-10-25 16:46 ` tomas.kalibera at gmail dot com 2022-10-25 19:40 ` martin at martin dot st 2022-10-26 7:03 ` tomas.kalibera at gmail dot com 2022-10-26 10:09 ` lh_mouse at 126 dot com 2022-10-26 12:04 ` tomas.kalibera at gmail dot com 2022-10-26 15:27 ` tomas.kalibera at gmail dot com 2022-12-15 15:42 ` tomas.kalibera at gmail dot com 2023-01-29 18:20 ` alvinhochun at gmail dot com 2023-08-02 2:06 ` tanksherman27 at gmail dot com 2023-08-02 13:15 ` tomas.kalibera at gmail dot com 2023-08-03 16:33 ` tomas.kalibera at gmail dot com 2023-08-17 6:11 ` tanksherman27 at gmail dot com 2023-08-19 10:18 ` tanksherman27 at gmail dot com 2023-08-19 19:11 ` tomas.kalibera at gmail dot com 2023-08-20 2:22 ` cvs-commit at gcc dot gnu.org 2023-08-21 12:50 ` tomas.kalibera at gmail dot com 2024-04-19 2:53 ` pinskia at gcc dot gnu.org 2024-04-19 3:28 ` lh_mouse at 126 dot com 2024-04-19 7:04 ` martin at martin dot st 2024-04-19 7:12 ` lh_mouse at 126 dot com 2024-04-19 7:13 ` pinskia at gcc dot gnu.org 2024-04-19 7:27 ` lh_mouse at 126 dot com
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=bug-95130-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@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: linkBe 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).