Re: [PATCH][RFC] Make mingw-w64 printf/scanf attribute alias to ms_printf/ms_scanf only for C89
On 11/16/20 5:40 AM, Jonathan Yong wrote: On 11/14/20 12:29 PM, Liu Hao via Gcc-patches wrote: This is the third revision of my patch: 1. Two typos in the commit message have been fixed. 2. Support for `%a` and `%A` has been added. Documentation can be found on the same page in the commit message. 3. GCC will no longer warn about 'ISO C does not support the ‘L’ ms_printf length modifier'. This was caused by mistaken array indices in `TARGET_OVERRIDES_FORMAT_INIT`. I'll be pushing this soon if there aren't any more complaints. Pushed to master, thanks all for contributing and reviewing. OpenPGP_0x713B5FE29C145D45_and_old_rev.asc Description: application/pgp-keys OpenPGP_signature Description: OpenPGP digital signature
Re: [PATCH][RFC] Make mingw-w64 printf/scanf attribute alias to ms_printf/ms_scanf only for C89
On 11/14/20 12:29 PM, Liu Hao via Gcc-patches wrote: This is the third revision of my patch: 1. Two typos in the commit message have been fixed. 2. Support for `%a` and `%A` has been added. Documentation can be found on the same page in the commit message. 3. GCC will no longer warn about 'ISO C does not support the ‘L’ ms_printf length modifier'. This was caused by mistaken array indices in `TARGET_OVERRIDES_FORMAT_INIT`. I'll be pushing this soon if there aren't any more complaints. OpenPGP_0x713B5FE29C145D45_and_old_rev.asc Description: application/pgp-keys OpenPGP_signature Description: OpenPGP digital signature
Re: [PATCH][RFC] Make mingw-w64 printf/scanf attribute alias to ms_printf/ms_scanf only for C89
This is the third revision of my patch: 1. Two typos in the commit message have been fixed. 2. Support for `%a` and `%A` has been added. Documentation can be found on the same page in the commit message. 3. GCC will no longer warn about 'ISO C does not support the ‘L’ ms_printf length modifier'. This was caused by mistaken array indices in `TARGET_OVERRIDES_FORMAT_INIT`. -- Best regards, LH_Mouse From f73d5dcdc61a5da1a4265b144739067b4ec40ec2 Mon Sep 17 00:00:00 2001 From: Liu Hao Date: Thu, 12 Nov 2020 22:20:29 +0800 Subject: [PATCH] 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 gcc/: * config/i386/msformat-c.c: Add more length modifiers --- gcc/config/i386/msformat-c.c | 53 ++- gcc/testsuite/gcc.dg/format/ms_c99-printf-3.c | 22 +++- 2 files changed, 49 insertions(+), 26 deletions(-) diff --git a/gcc/config/i386/msformat-c.c b/gcc/config/i386/msformat-c.c index 4ceec633a6e..085ac88789a 100644 --- a/gcc/config/i386/msformat-c.c +++ b/gcc/config/i386/msformat-c.c @@ -32,10 +32,11 @@ along with GCC; see the file COPYING3. If not see static format_length_info ms_printf_length_specs[] = { { "h", FMT_LEN_h, STD_C89, NULL, FMT_LEN_none, STD_C89, 0 }, - { "l", FMT_LEN_l, STD_C89, NULL, FMT_LEN_none, STD_C89, 0 }, + { "l", FMT_LEN_l, STD_C89, "ll", FMT_LEN_ll, STD_C89, 0 }, + { "L", FMT_LEN_L, STD_C89, NULL, FMT_LEN_none, STD_C89, 1 }, { "I32", FMT_LEN_l, STD_EXT, NULL, FMT_LEN_none, STD_C89, 1 }, { "I64", FMT_LEN_ll, STD_EXT, NULL, FMT_LEN_none, STD_C89, 1 }, - { "I", FMT_LEN_L, STD_EXT, NULL, FMT_LEN_none, STD_C89, 1 }, + { "I", FMT_LEN_z, STD_EXT, NULL, FMT_LEN_none, STD_C89, 1 }, { NULL, FMT_LEN_none, STD_C89, NULL, FMT_LEN_none, STD_C89, 0 } }; @@ -90,33 +91,35 @@ static const format_flag_pair ms_strftime_flag_pairs[] = static const format_char_info ms_print_char_table[] = { /* C89 conversion specifiers. */ - { "di", 0, STD_C89, { T89_I, BADLEN, T89_S, T89_L, T9L_LL, T99_SST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0 +'", "i", NULL }, - { "oxX", 0, STD_C89, { T89_UI, BADLEN, T89_US, T89_UL, T9L_ULL, T99_ST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0#", "i", NULL }, - { "u", 0, STD_C89, { T89_UI, BADLEN, T89_US, T89_UL, T9L_ULL, T99_ST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0'","i", NULL }, - { "fgG", 0, STD_C89, { T89_D, BADLEN, BADLEN, T99_D, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0 +#'", "", NULL }, - { "eE", 0, STD_C89, { T89_D, BADLEN, BADLEN, T99_D, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0 +#", "", NULL }, - { "c", 0, STD_C89, { T89_I, BADLEN, T89_S, T94_WI, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-w","", NULL }, - { "s", 1, STD_C89, { T89_C, BADLEN, T89_S, T94_W, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp", "cR", NULL }, - { "p", 1, STD_C89, { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-w","c", NULL }, - { "n", 1, STD_C89, { T89_I, BADLEN, T89_S, T89_L, T9L_LL, BADLEN, BADLEN, BADLEN, T99_IM, BADLEN, BADLEN, BADLEN }, "", "W", NULL }, + { "di", 0, STD_C89, { T89_I, BADLEN, T89_S, T89_L, T9L_LL, BADLEN, T99_SST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0 +'", "i", NULL }, + { "oxX", 0, STD_C89, { T89_UI, BADLEN, T89_US, T89_UL, T9L_ULL, BADLEN, T99_ST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0#","i", NULL }, + { "u", 0, STD_C89, { T89_UI, BADLEN, T89_US, T89_UL, T9L_ULL, BADLEN, T99_ST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0'","i", NULL }, + { "fgG", 0, STD_C89, { T89_D, BADLEN, BADLEN, T99_D, BADLEN, T89_D, BADLEN,
Re: [PATCH][RFC] Make mingw-w64 printf/scanf attribute alias to ms_printf/ms_scanf only for C89
在 2020/11/14 上午8:12, Joseph Myers 写道: > On Fri, 13 Nov 2020, Liu Hao via Gcc-patches wrote: > >> 在 2020/11/13 2:46, Joseph Myers 写道: >>> I'd expect these patches to include updates to the gcc.dg/format/ms_*.c >>> tests to reflect the changed semantics (or new tests there if some of the >>> changes don't result in any failures in the existing tests). >>> >> >> Does the attached patch suffice? > > This is testing the sort of thing I'd expect tests for regarding 'L' and > 'll'. What about the changes for 'I' - do those result in changes to how > the compiler behaves, which should also have tests? > There is already a test for `%Ix` in 'ms_c99-printf-2.c', but there is no test (in all 'ms_*printf*' files) which checks for absence of warnings. -- Best regards, LH_Mouse signature.asc Description: OpenPGP digital signature
Re: [PATCH][RFC] Make mingw-w64 printf/scanf attribute alias to ms_printf/ms_scanf only for C89
On Fri, 13 Nov 2020, Liu Hao via Gcc-patches wrote: > 在 2020/11/13 2:46, Joseph Myers 写道: > > I'd expect these patches to include updates to the gcc.dg/format/ms_*.c > > tests to reflect the changed semantics (or new tests there if some of the > > changes don't result in any failures in the existing tests). > > > > Does the attached patch suffice? This is testing the sort of thing I'd expect tests for regarding 'L' and 'll'. What about the changes for 'I' - do those result in changes to how the compiler behaves, which should also have tests? -- Joseph S. Myers jos...@codesourcery.com
Re: [PATCH][RFC] Make mingw-w64 printf/scanf attribute alias to ms_printf/ms_scanf only for C89
在 2020/11/13 2:46, Joseph Myers 写道: > I'd expect these patches to include updates to the gcc.dg/format/ms_*.c > tests to reflect the changed semantics (or new tests there if some of the > changes don't result in any failures in the existing tests). > Does the attached patch suffice? I know very little about Deja GNU. I only tried compiling the function in that test and verified that lines without `dg-warning` didn't result in any warnings with my bootstrapped GCC last night, both on i686 and x86_64. -- Best regards, LH_Mouse From 3f58912fb369fd1f645d880a3d967e6523b87507 Mon Sep 17 00:00:00 2001 From: Liu Hao Date: Thu, 12 Nov 2020 22:20:29 +0800 Subject: [PATCH] gcc: Add `ll` and `L` length modifiers for `ms_printf` Previous code abuse `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. 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 as `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 gcc/: * config/i386/msformat-c.c: Add more length modifiers --- gcc/config/i386/msformat-c.c | 45 ++- gcc/testsuite/gcc.dg/format/ms_c99-printf-3.c | 22 - 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/gcc/config/i386/msformat-c.c b/gcc/config/i386/msformat-c.c index 4ceec633a6e..1902b3c73d0 100644 --- a/gcc/config/i386/msformat-c.c +++ b/gcc/config/i386/msformat-c.c @@ -32,10 +32,11 @@ along with GCC; see the file COPYING3. If not see static format_length_info ms_printf_length_specs[] = { { "h", FMT_LEN_h, STD_C89, NULL, FMT_LEN_none, STD_C89, 0 }, - { "l", FMT_LEN_l, STD_C89, NULL, FMT_LEN_none, STD_C89, 0 }, + { "l", FMT_LEN_l, STD_C89, "ll", FMT_LEN_ll, STD_C89, 0 }, + { "L", FMT_LEN_L, STD_C89, NULL, FMT_LEN_none, STD_C89, 1 }, { "I32", FMT_LEN_l, STD_EXT, NULL, FMT_LEN_none, STD_C89, 1 }, { "I64", FMT_LEN_ll, STD_EXT, NULL, FMT_LEN_none, STD_C89, 1 }, - { "I", FMT_LEN_L, STD_EXT, NULL, FMT_LEN_none, STD_C89, 1 }, + { "I", FMT_LEN_z, STD_EXT, NULL, FMT_LEN_none, STD_C89, 1 }, { NULL, FMT_LEN_none, STD_C89, NULL, FMT_LEN_none, STD_C89, 0 } }; @@ -90,33 +91,33 @@ static const format_flag_pair ms_strftime_flag_pairs[] = static const format_char_info ms_print_char_table[] = { /* C89 conversion specifiers. */ - { "di", 0, STD_C89, { T89_I, BADLEN, T89_S, T89_L, T9L_LL, T99_SST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0 +'", "i", NULL }, - { "oxX", 0, STD_C89, { T89_UI, BADLEN, T89_US, T89_UL, T9L_ULL, T99_ST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0#", "i", NULL }, - { "u", 0, STD_C89, { T89_UI, BADLEN, T89_US, T89_UL, T9L_ULL, T99_ST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0'","i", NULL }, - { "fgG", 0, STD_C89, { T89_D, BADLEN, BADLEN, T99_D, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0 +#'", "", NULL }, - { "eE", 0, STD_C89, { T89_D, BADLEN, BADLEN, T99_D, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0 +#", "", NULL }, - { "c", 0, STD_C89, { T89_I, BADLEN, T89_S, T94_WI, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-w","", NULL }, - { "s", 1, STD_C89, { T89_C, BADLEN, T89_S, T94_W, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp", "cR", NULL }, - { "p", 1, STD_C89, { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-w","c", NULL }, - { "n", 1, STD_C89, { T89_I, BADLEN, T89_S, T89_L, T9L_LL, BADLEN, BADLEN, BADLEN, T99_IM, BADLEN, BADLEN, BADLEN }, "", "W", NULL }, + { "di", 0, STD_C89, { T89_I, BADLEN, T89_S, T89_L, T9L_LL, BADLEN, T99_SST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0 +'", "i", NULL }, + { "oxX", 0, STD_C89, { T89_UI, BADLEN, T89_US, T89_UL, T9L_ULL, BADLEN, T99_ST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0#","i", NULL }, + { "u", 0, STD_C89, { T89_UI, BADLEN, T89_US, T89_UL, T9L_ULL, BADLEN, T99_ST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN },
Re: [PATCH][RFC] Make mingw-w64 printf/scanf attribute alias to ms_printf/ms_scanf only for C89
I'd expect these patches to include updates to the gcc.dg/format/ms_*.c tests to reflect the changed semantics (or new tests there if some of the changes don't result in any failures in the existing tests). -- Joseph S. Myers jos...@codesourcery.com
Re: [PATCH][RFC] Make mingw-w64 printf/scanf attribute alias to ms_printf/ms_scanf only for C89
在 2020/11/12 23:12, Liu Hao 写道: > > My humble opinion is that people should have gotten used to the `ll` > specifier so I propose a > different patch that enables it unconditionally. As Jonathan Yong pointed > out, GCC is impossible to The previous patch missed a `double_name` field. A revised version has been attached. -- Best regards, LH_Mouse From 1d61adae0695e7067e35f36e607a754a7cf12796 Mon Sep 17 00:00:00 2001 From: Liu Hao Date: Thu, 12 Nov 2020 22:20:29 +0800 Subject: [PATCH] gcc: Add `ll` and `L` length modifiers for `ms_printf` Previous code abuse `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. 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 as `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 gcc/: * config/i386/msformat-c.c: Add more length modifiers --- gcc/config/i386/msformat-c.c | 45 ++-- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/gcc/config/i386/msformat-c.c b/gcc/config/i386/msformat-c.c index 4ceec633a6e..1629b866976 100644 --- a/gcc/config/i386/msformat-c.c +++ b/gcc/config/i386/msformat-c.c @@ -32,10 +32,11 @@ along with GCC; see the file COPYING3. If not see static format_length_info ms_printf_length_specs[] = { { "h", FMT_LEN_h, STD_C89, NULL, FMT_LEN_none, STD_C89, 0 }, - { "l", FMT_LEN_l, STD_C89, NULL, FMT_LEN_none, STD_C89, 0 }, + { "l", FMT_LEN_l, STD_C89, "ll", FMT_LEN_ll, STD_C89, 0 }, + { "L", FMT_LEN_L, STD_C89, NULL, FMT_LEN_none, STD_C89, 1 }, { "I32", FMT_LEN_l, STD_EXT, NULL, FMT_LEN_none, STD_C89, 1 }, { "I64", FMT_LEN_ll, STD_EXT, NULL, FMT_LEN_none, STD_C89, 1 }, - { "I", FMT_LEN_L, STD_EXT, NULL, FMT_LEN_none, STD_C89, 1 }, + { "I", FMT_LEN_z, STD_EXT, NULL, FMT_LEN_none, STD_C89, 1 }, { NULL, FMT_LEN_none, STD_C89, NULL, FMT_LEN_none, STD_C89, 0 } }; @@ -90,33 +91,33 @@ static const format_flag_pair ms_strftime_flag_pairs[] = static const format_char_info ms_print_char_table[] = { /* C89 conversion specifiers. */ - { "di", 0, STD_C89, { T89_I, BADLEN, T89_S, T89_L, T9L_LL, T99_SST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0 +'", "i", NULL }, - { "oxX", 0, STD_C89, { T89_UI, BADLEN, T89_US, T89_UL, T9L_ULL, T99_ST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0#", "i", NULL }, - { "u", 0, STD_C89, { T89_UI, BADLEN, T89_US, T89_UL, T9L_ULL, T99_ST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0'","i", NULL }, - { "fgG", 0, STD_C89, { T89_D, BADLEN, BADLEN, T99_D, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0 +#'", "", NULL }, - { "eE", 0, STD_C89, { T89_D, BADLEN, BADLEN, T99_D, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0 +#", "", NULL }, - { "c", 0, STD_C89, { T89_I, BADLEN, T89_S, T94_WI, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-w","", NULL }, - { "s", 1, STD_C89, { T89_C, BADLEN, T89_S, T94_W, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp", "cR", NULL }, - { "p", 1, STD_C89, { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-w","c", NULL }, - { "n", 1, STD_C89, { T89_I, BADLEN, T89_S, T89_L, T9L_LL, BADLEN, BADLEN, BADLEN, T99_IM, BADLEN, BADLEN, BADLEN }, "", "W", NULL }, + { "di", 0, STD_C89, { T89_I, BADLEN, T89_S, T89_L, T9L_LL, BADLEN, T99_SST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0 +'", "i", NULL }, + { "oxX", 0, STD_C89, { T89_UI, BADLEN, T89_US, T89_UL, T9L_ULL, BADLEN, T99_ST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0#","i", NULL }, + { "u", 0, STD_C89, { T89_UI, BADLEN, T89_US, T89_UL, T9L_ULL, BADLEN, T99_ST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0'","i", NULL }, + { "fgG", 0, STD_C89, { T89_D, BADLEN, BADLEN, T99_D, BADLEN, T89_D, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0 +#'", "", NULL }, + { "eE", 0, STD_C89, { T89_D, BADLEN, BADLEN, T99_D,
Re: [PATCH][RFC] Make mingw-w64 printf/scanf attribute alias to ms_printf/ms_scanf only for C89
在 2020/11/12 18:18, Jonathan Yong 写道: > libgomp build fails because of the false -Wformat error, even though: > 1. Correct C99 inttypes.h macros are used. > 2. __mingw_* C99 wrappers are used. > 3. The printf attribute is used, but it was aliased to ms_printf > > The attached patch makes mingw-w64 printf attribute equivalent to other > platforms on C99 or later. > This allows libgomp to build again with -Werror on. This patch should not > affect the original > mingw.org distribution in any way. > According to the conversation on IRC, I personally consider this inappropriate. Although the `ll` modifier is specified by C99 for `long long`, there are many more that don't conform to C99 without UCRT: 1. The `z` modifier for `size_t` is unrecognized. 2. The `t` modifier for `ptrdiff_t` is unrecognized. 3. The `L` modifier for `long double` is accepted but ignored due to the fact that MSABI uses an 8-byte type. > For C99 or later, the mingw-w64 headers already wrap printf/scanf properly, > and inttypes.h also > gives the correct C99 specifiers, so it makes sense to treat the printf > attribute as C99 compliant. > Under C89 mode, the headers would produce MS specific specifiers, so the > printf attribute under C89 > reverts to the old behavior of being aliased to ms_printf. > > This might break other code that assumes differently however. I don't think > there is a solution to > satisfy everyone, but at least this allows C99/C++11 compliant code to build > again with -Werror. > Comments? My humble opinion is that people should have gotten used to the `ll` specifier so I propose a different patch that enables it unconditionally. As Jonathan Yong pointed out, GCC is impossible to predict where the target executable will run. It may be reasonable to expect Vista+ instead of an ancient one. Users who still code for XP- should probably handle such differentiation themselves. In comparison, MSVC does not have such format checks at all. I started bootstrapping GCC a few minutes ago. It's not gonna finish very soon so I send this patch for your comments. -- Best regards, LH_Mouse From 1d61adae0695e7067e35f36e607a754a7cf12796 Mon Sep 17 00:00:00 2001 From: Liu Hao Date: Thu, 12 Nov 2020 22:20:29 +0800 Subject: [PATCH] gcc: Add `ll` and `L` length modifiers for `ms_printf` Previous code abuse `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. 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 as `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 gcc/: * config/i386/msformat-c.c: Add more length modifiers --- gcc/config/i386/msformat-c.c | 45 ++-- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/gcc/config/i386/msformat-c.c b/gcc/config/i386/msformat-c.c index 4ceec633a6e..1629b866976 100644 --- a/gcc/config/i386/msformat-c.c +++ b/gcc/config/i386/msformat-c.c @@ -32,10 +32,11 @@ along with GCC; see the file COPYING3. If not see static format_length_info ms_printf_length_specs[] = { { "h", FMT_LEN_h, STD_C89, NULL, FMT_LEN_none, STD_C89, 0 }, - { "l", FMT_LEN_l, STD_C89, NULL, FMT_LEN_none, STD_C89, 0 }, + { "l", FMT_LEN_l, STD_C89, NULL, FMT_LEN_ll, STD_C9L, 0 }, + { "L", FMT_LEN_L, STD_C89, NULL, FMT_LEN_none, STD_C89, 1 }, { "I32", FMT_LEN_l, STD_EXT, NULL, FMT_LEN_none, STD_C89, 1 }, { "I64", FMT_LEN_ll, STD_EXT, NULL, FMT_LEN_none, STD_C89, 1 }, - { "I", FMT_LEN_L, STD_EXT, NULL, FMT_LEN_none, STD_C89, 1 }, + { "I", FMT_LEN_z, STD_EXT, NULL, FMT_LEN_none, STD_C89, 1 }, { NULL, FMT_LEN_none, STD_C89, NULL, FMT_LEN_none, STD_C89, 0 } }; @@ -90,33 +91,33 @@ static const format_flag_pair ms_strftime_flag_pairs[] = static const format_char_info ms_print_char_table[] = { /* C89 conversion specifiers. */ - { "di", 0, STD_C89, { T89_I, BADLEN, T89_S, T89_L, T9L_LL, T99_SST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0 +'", "i", NULL }, - { "oxX", 0, STD_C89, { T89_UI, BADLEN, T89_US, T89_UL, T9L_ULL, T99_ST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0#", "i", NULL }, - { "u", 0, STD_C89, { T89_UI, BADLEN, T89_US, T89_UL,
[PATCH][RFC] Make mingw-w64 printf/scanf attribute alias to ms_printf/ms_scanf only for C89
libgomp build fails because of the false -Wformat error, even though: 1. Correct C99 inttypes.h macros are used. 2. __mingw_* C99 wrappers are used. 3. The printf attribute is used, but it was aliased to ms_printf The attached patch makes mingw-w64 printf attribute equivalent to other platforms on C99 or later. This allows libgomp to build again with -Werror on. This patch should not affect the original mingw.org distribution in any way. For C99 or later, the mingw-w64 headers already wrap printf/scanf properly, and inttypes.h also gives the correct C99 specifiers, so it makes sense to treat the printf attribute as C99 compliant. Under C89 mode, the headers would produce MS specific specifiers, so the printf attribute under C89 reverts to the old behavior of being aliased to ms_printf. This might break other code that assumes differently however. I don't think there is a solution to satisfy everyone, but at least this allows C99/C++11 compliant code to build again with -Werror. Comments? From 397097aba5a098f18da92704e9ca7560adb4f29c Mon Sep 17 00:00:00 2001 From: Jonathan Yong <10wa...@gmail.com> Date: Thu, 12 Nov 2020 06:45:00 + Subject: [PATCH] gcc: make mingw-w64 printf/scanf attribute gnu equivalents in C99 Makes printf/scanf attribute equivalent to gnu_printf and gnu_scanf in C99 mode. Fixes false positive warnings for functions with printf attribute, even when correct C99 style printf specifiers are used. 12-11-2020 Jonathan Yong <10wa...@gmail.com> gcc/ChangeLog: * c-family/c-format.c (convert_format_name_to_system_name): Turn TARGET_OVERRIDES_FORMAT_ATTRIBUTES into a callback that returns a list of attribute aliases. * config/i386/mingw-w64.h (TARGET_OVERRIDES_FORMAT_C89): Define. Tell GCC to use ms_printf and ms_scanf in C89. * config/i386/mingw32.h: (TARGET_OVERRIDES_FORMAT_ATTRIBUTES): Point to wrapper function and update description. (TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT): remove. * config/i386/msformat-c.c: (mingw_format_attribute_overrides): New callback. (mingw_format_attribute_overrides_table): make null terminated. --- gcc/c-family/c-format.c | 28 gcc/config/i386/mingw-w64.h | 4 gcc/config/i386/mingw32.h| 8 ++-- gcc/config/i386/msformat-c.c | 23 --- 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c index 77d24ad94e4..4edf4c64f79 100644 --- a/gcc/c-family/c-format.c +++ b/gcc/c-family/c-format.c @@ -5077,7 +5077,7 @@ extern const format_kind_info TARGET_FORMAT_TYPES[]; #endif #ifdef TARGET_OVERRIDES_FORMAT_ATTRIBUTES -extern const target_ovr_attr TARGET_OVERRIDES_FORMAT_ATTRIBUTES[]; +extern const target_ovr_attr* TARGET_OVERRIDES_FORMAT_ATTRIBUTES (int format_std_version); #endif #ifdef TARGET_OVERRIDES_FORMAT_INIT extern void TARGET_OVERRIDES_FORMAT_INIT (void); @@ -5102,6 +5102,9 @@ static const char * convert_format_name_to_system_name (const char *attr_name) { int i; +#ifdef TARGET_OVERRIDES_FORMAT_ATTRIBUTES + const target_ovr_attr* override_attributes; +#endif if (attr_name == NULL || *attr_name == 0 || strncmp (attr_name, "gcc_", 4) == 0) @@ -5112,18 +5115,19 @@ convert_format_name_to_system_name (const char *attr_name) #ifdef TARGET_OVERRIDES_FORMAT_ATTRIBUTES /* Check if format attribute is overridden by target. */ - if (TARGET_OVERRIDES_FORMAT_ATTRIBUTES != NULL - && TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT > 0) + override_attributes = TARGET_OVERRIDES_FORMAT_ATTRIBUTES(C_STD_VER); + if (override_attributes != NULL) { - for (i = 0; i < TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT; ++i) -{ - if (cmp_attribs (TARGET_OVERRIDES_FORMAT_ATTRIBUTES[i].named_attr_src, - attr_name)) -return attr_name; - if (cmp_attribs (TARGET_OVERRIDES_FORMAT_ATTRIBUTES[i].named_attr_dst, - attr_name)) -return TARGET_OVERRIDES_FORMAT_ATTRIBUTES[i].named_attr_src; -} + for (i = 0; + override_attributes[i].named_attr_src != NULL + && override_attributes[i].named_attr_dst != NULL; + ++i) + { + if (cmp_attribs (override_attributes[i].named_attr_src, attr_name)) + return attr_name; + if (cmp_attribs (override_attributes[i].named_attr_dst, attr_name)) + return override_attributes[i].named_attr_src; + } } #endif /* Otherwise default to gnu format. */ diff --git a/gcc/config/i386/mingw-w64.h b/gcc/config/i386/mingw-w64.h index 0d0aa939996..586d151a082 100644 --- a/gcc/config/i386/mingw-w64.h +++ b/gcc/config/i386/mingw-w64.h @@ -104,3 +104,7 @@ along with GCC; see the file COPYING3. If not see original mingw32. */ #undef TARGET_LIBC_HAS_FUNCTION #define TARGET_LIBC_HAS_FUNCTION gnu_libc_has_function + +/* alias printf/scanf attributes to MS variants when in C89 */ +#undef TARGET_OVERRIDES_FORMAT_C89 +#define TARGET_OVERRIDES_FORMAT_C89 diff --git a/gcc/config/i386/mingw32.h