From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1026E3857722; Mon, 21 Aug 2023 12:50:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1026E3857722 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692622204; bh=z2SUVIuMxaEeeZTjDUispDLQMhAHYMC17XEcLc9KMF0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MiUADvhH/8vDr0x376uURWuJ5HEwuvWVpXSqFD0+9xyFq6MwNlvChqKhkP3xiofnf ZqeW2wb8VUDn+GQz6aThGN+gkjP+CEN2vH0wA4+/wgb0E046HrTurnYjT92abQuqri IxEphlUCfRa/EDGADDHAOMkKlg+D2CTJRIja1qbs= From: "tomas.kalibera at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/95130] GCC ignoring attribute(format(gnu_printf)) on printf in mingw Date: Mon, 21 Aug 2023 12:50:02 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed 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: tomas.kalibera at gmail dot com 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: Message-ID: In-Reply-To: References: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95130 --- Comment #22 from Tomas Kalibera --- (In reply to CVS Commits from comment #21) > The master branch has been updated by Jonathan Yong : >=20 > https://gcc.gnu.org/g:966f3c134bb4802ac7ba0517de4e8e3f6384cfa3 >=20 > commit r14-3334-g966f3c134bb4802ac7ba0517de4e8e3f6384cfa3 > Author: Tomas Kalibera > Date: Sun Aug 20 02:16:16 2023 +0000 >=20 > Fix format attribute for printf >=20=20=20=20=20 > 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. >=20=20=20=20=20 > 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. >=20=20=20=20=20 > A reproducible example of the problem: >=20=20=20=20=20 > $ cat format.c > __attribute__((__format__ (gnu_printf, 1, 2))) int printf (const char > *__format, ...); > __attribute__((__format__ (gnu_printf, 1, 2))) int othername (const c= har > *__format, ...); >=20=20=20=20=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 > format.c: In function 'function': > format.c:7:15: warning: unknown conversion type character 'l' in form= at > [-Wformat=3D] > 7 | printf("%llu\n", x); > | ^ > format.c:7:12: warning: too many arguments for format > [-Wformat-extra-args] > 7 | printf("%llu\n", x); > | ^~~~~~~~ >=20=20=20=20=20 > 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. >=20=20=20=20=20 > If the printf function declaration is changed into a static inline > function, the actual attribute used is honored though. >=20=20=20=20=20 > gcc/c-family/ChangeLog: >=20=20=20=20=20 > PR c/95130 > * c-format.cc: skip default format for printf symbol if > explicitly declared by prototype. >=20=20=20=20=20 > Signed-off-by: Tomas Kalibera > Signed-off-by: Jonathan Yong <10walls@gmail.com> Great, thanks a lot for finishing and adding this, Tomas=