public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/37768] New: bogus warnings on x86_64-mingw32 due to attribute((format(printf))) breakage
@ 2008-10-08 9:31 mikpe at it dot uu dot se
2008-10-08 16:16 ` [Bug c/37768] " joseph at codesourcery dot com
2008-10-09 7:05 ` mikpe at it dot uu dot se
0 siblings, 2 replies; 3+ messages in thread
From: mikpe at it dot uu dot se @ 2008-10-08 9:31 UTC (permalink / raw)
To: gcc-bugs
When gcc is configured to generate code for x86_64-pc-mingw32, that is MinGW
for 64-bit Windows, attribute((format(printf))) is redefined by the backend to
be compatible with MSVC's runtime library, which differs significantly from
C99.
This is fine for calls that link to MSVC's library, but it breaks code that
uses private implementations of C99-compliant formatting routines, because the
backend redefines ALL uses of attribute((format(printf))) to mean MSVC's printf
not C99. The result is that C99-compliant code gets stray warnings and
inadequate printf format checking on x86_64-pc-mingw32.
The program below illustrates the issue. It declares a private C99-compliant
snprintf() implementation and invokes it with "%zu" and "%llx" formats. This
triggers the following bogus warnings on x86_64-pc-mingw32:
> x86_64-pc-mingw32-gcc -std=c99 -O -Wall -c badwarning.c
badwarning.c: In function 'main':
badwarning.c:16: warning: unknown conversion type character 'z' in format
badwarning.c:16: warning: unknown conversion type character 'l' in format
badwarning.c:16: warning: too many arguments for format
What I think the backend should do is to implement an "msprintf" format type,
and then Mingw-w64 should declare printf() et al using that not plain "printf".
/* badwarning.c */
#include <stddef.h>
#include <stdarg.h>
int __attribute__((format(printf, 3, 4)))
my_snprintf(char *buf, size_t n, const char *fmt, ...)
{
/* invoke C99 compliant private vsnprintf() here */
return 0;
}
int main(void)
{
char buf[64];
return my_snprintf(buf, sizeof buf, "%zu %llx",
sizeof buf, 0ULL);
}
--
Summary: bogus warnings on x86_64-mingw32 due to
attribute((format(printf))) breakage
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mikpe at it dot uu dot se
GCC target triplet: x86_64-pc-mingw32
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37768
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/37768] bogus warnings on x86_64-mingw32 due to attribute((format(printf))) breakage
2008-10-08 9:31 [Bug c/37768] New: bogus warnings on x86_64-mingw32 due to attribute((format(printf))) breakage mikpe at it dot uu dot se
@ 2008-10-08 16:16 ` joseph at codesourcery dot com
2008-10-09 7:05 ` mikpe at it dot uu dot se
1 sibling, 0 replies; 3+ messages in thread
From: joseph at codesourcery dot com @ 2008-10-08 16:16 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from joseph at codesourcery dot com 2008-10-08 16:15 -------
Subject: Re: New: bogus warnings on x86_64-mingw32 due to
attribute((format(printf))) breakage
On Wed, 8 Oct 2008, mikpe at it dot uu dot se wrote:
> When gcc is configured to generate code for x86_64-pc-mingw32, that is MinGW
> for 64-bit Windows, attribute((format(printf))) is redefined by the backend to
> be compatible with MSVC's runtime library, which differs significantly from
> C99.
Correct. This is the conclusion we eventually reached, that "printf"
would be for the system formats (e.g. for a function wrapping a call to a
system function), that "gnu_printf" would be for the formats accepted by
the GNU C Library (including GNU extensions) on all platforms and that
"ms_printf" would be for the MSVC formats, on Windows platforms only.
> The program below illustrates the issue. It declares a private C99-compliant
> snprintf() implementation and invokes it with "%zu" and "%llx" formats. This
> triggers the following bogus warnings on x86_64-pc-mingw32:
Use gnu_printf for such an implementation.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37768
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/37768] bogus warnings on x86_64-mingw32 due to attribute((format(printf))) breakage
2008-10-08 9:31 [Bug c/37768] New: bogus warnings on x86_64-mingw32 due to attribute((format(printf))) breakage mikpe at it dot uu dot se
2008-10-08 16:16 ` [Bug c/37768] " joseph at codesourcery dot com
@ 2008-10-09 7:05 ` mikpe at it dot uu dot se
1 sibling, 0 replies; 3+ messages in thread
From: mikpe at it dot uu dot se @ 2008-10-09 7:05 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from mikpe at it dot uu dot se 2008-10-09 07:04 -------
> > The program below illustrates the issue. It declares a private C99-compliant
> > snprintf() implementation and invokes it with "%zu" and "%llx" formats. This
> > triggers the following bogus warnings on x86_64-pc-mingw32:
>
> Use gnu_printf for such an implementation.
Thanks. Using gnu_printf (new in 4.4) solves the issues I had.
--
mikpe at it dot uu dot se changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37768
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-10-09 7:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-08 9:31 [Bug c/37768] New: bogus warnings on x86_64-mingw32 due to attribute((format(printf))) breakage mikpe at it dot uu dot se
2008-10-08 16:16 ` [Bug c/37768] " joseph at codesourcery dot com
2008-10-09 7:05 ` mikpe at it dot uu dot se
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).