public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/95130] New: GCC ignoring attribute(format(gnu_printf)) on printf in mingw
@ 2020-05-14 11:37 martin at martin dot st
  2020-05-14 17:27 ` [Bug c/95130] " joseph at codesourcery dot com
                   ` (27 more replies)
  0 siblings, 28 replies; 29+ messages in thread
From: martin at martin dot st @ 2020-05-14 11:37 UTC (permalink / raw)
  To: gcc-bugs

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.

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

end of thread, other threads:[~2024-04-19  7:27 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-14 11:37 [Bug c/95130] New: GCC ignoring attribute(format(gnu_printf)) on printf in mingw martin at martin dot st
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

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