From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 783E7395C06B; Thu, 14 May 2020 11:37:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 783E7395C06B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1589456269; bh=koC9BnX+uc1BrIOBV6bQ6SNF26O3876GlzGbi/nKrgs=; h=From:To:Subject:Date:From; b=OeiP2nDduZk0kddqrZmii89+VAtZQ39ZXDuKtniXLXRI17+/qMX6gl1BG00wHm+1L xCWof/FHKeSUVjQP9RKve9C1w9rp3qFLoqY04E1LLCeENx5D53rXUEJGAeeoFrx3B3 GF5KmkZynGOpjHagPvN9gZ87SXaXdCWod1t9vqXo= From: "martin at martin dot st" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 9.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: martin at martin dot st X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 May 2020 11:37:49 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95130 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 eit= her 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, ...);=20 void function(void) { long long unsigned x =3D 42; othername("%llu\n", x); printf("%llu\n", x); } $ x86_64-w64-mingw32-gcc -c -Wformat format.c=20 format.c: In function 'function': format.c:7:15: warning: unknown conversion type character 'l' in format [-Wformat=3D]=20 7 | printf("%llu\n", x);=20 | ^ 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 "otherna= me" 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.=