gcc: Add `ll` and `L` length modifiers for `ms_printf`
authorLiu Hao <lh_mouse@126.com>
Thu, 12 Nov 2020 14:20:29 +0000 (22:20 +0800)
committerJonathan Yong <10walls@gmail.com>
Tue, 17 Nov 2020 10:34:05 +0000 (10:34 +0000)
commitc51f1e7427e6a5ae2a6d82b5a790df77a3adc99a
tree0865d2e375bc7c1f7e5bd81c3ac72734bf5639c5
parent200c9e865f49255ea32d4891b746d394d156a16f
gcc: Add `ll` and `L` length modifiers for `ms_printf`

Previous code abused `FMT_LEN_L` for the `I` modifier. As `L` is a
valid modifier for `f`, `e`, `g`, etc. and `I` has the same semantics
as the C99 `z` modifier, `FMT_LEN_z` is now used instead.

First, in the Microsoft ABI, type `long double` has the same layout as
type `double`, so `%Lg` behaves identically to `%g`. Users should pass
in `double`s instead of `long double`s, as GCC uses the 10-byte format.

Second, with a CRT that is recent enough (MSVCRT since Vista, MSVCR80,
UCRT, or mingw-w64 8.0), `printf`-family functions can handle the `ll`
length modifier correctly. This ability is assumed to be available
universally. A lot of libraries (such as libgomp) that use the
`format(printf, ...)` attribute used to suffer from warnings about
unknown format specifiers.

Reference: https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2008/tcxf1dw6(v=vs.90)
Reference: https://docs.microsoft.com/en-us/cpp/porting/visual-cpp-what-s-new-2003-through-2015#new-crt-features
Signed-off-by: Liu Hao <lh_mouse@126.com>
gcc/ChangeLog:
* config/i386/msformat-c.c: Add more length modifiers.

gcc/testsuite/ChangeLog:
* gcc.dg/format/ms_c99-printf-3.c: Update tests.
gcc/config/i386/msformat-c.c
gcc/testsuite/gcc.dg/format/ms_c99-printf-3.c