gcc 10.1 warnings

52 views
Skip to first unread message

John Marriott

unread,
May 9, 2020, 3:30:42 AM5/9/20
to vim...@googlegroups.com
Hi All,

After cleaning my vim source repo and rebuilding with the brand new gcc
10.1 (mingw64), I get these warnings:
<snip>
gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
-DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -DFEAT_GUI_MSWIN
-DFEAT_CLIPBOARD -pipe -march=native -Wall -O3 -fomit-frame-pointer
-freg-struct-return main.c -o gobjnative/main.o
In file included from main.c:11:
main.c: In function 'early_arg_scan':
vim.h:343:33: warning: 'I' flag used with '%x' gnu_scanf format [-Wformat=]
  343 | # define SCANF_HEX_LONG_U "%Ix"
      | ^~~~~
vim.h:343:33: note: in definition of macro 'SCANF_HEX_LONG_U'
  343 | # define SCANF_HEX_LONG_U "%Ix"
      | ^~~~~
vim.h:343:36: note: format string is defined here
  343 | # define SCANF_HEX_LONG_U "%Ix"
      | ^
vim.h:343:33: warning: format '%x' expects argument of type 'unsigned
int *', but argument 3 has type 'long_u *' {aka 'long lo
ng unsigned int *'} [-Wformat=]
  343 | # define SCANF_HEX_LONG_U "%Ix"
      | ^~~~~
vim.h:343:33: note: in definition of macro 'SCANF_HEX_LONG_U'
  343 | # define SCANF_HEX_LONG_U "%Ix"
      | ^~~~~
vim.h:343:36: note: format string is defined here
  343 | # define SCANF_HEX_LONG_U "%Ix"
      | ~~^
      | |
      |                                    unsigned int *
      | %Illx
vim.h:344:33: warning: format '%u' expects argument of type 'unsigned
int *', but argument 3 has type 'long_u *' {aka 'long lo
ng unsigned int *'} [-Wformat=]
  344 | # define SCANF_DECIMAL_LONG_U "%Iu"
      | ^~~~~
vim.h:344:33: note: in definition of macro 'SCANF_DECIMAL_LONG_U'
  344 | # define SCANF_DECIMAL_LONG_U "%Iu"
      | ^~~~~
vim.h:344:36: note: format string is defined here
  344 | # define SCANF_DECIMAL_LONG_U "%Iu"
      | ~~^
      | |
      |                                    unsigned int *
      | %Illu

gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
-DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -DFEAT_GUI_MSWIN
-DFEAT_CLIPBOARD -pipe -march=native -Wall -O3 -fomit-frame-pointer
-freg-struct-return dict.c -o gobjnative/dict.o
In file included from dict.c:14:
In function 'dictitem_copy',
    inlined from 'dict_extend' at dict.c:936:9:
vim.h:1591:26: warning: 'strcpy' offset 0 from the object at '<unknown>'
is out of the bounds of referenced subobject 'di_key'
 with type 'char_u[1]' {aka 'unsigned char[1]'} at offset 0
[-Warray-bounds]
 1591 | #define STRCPY(d, s)     strcpy((char *)(d), (char *)(s))
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim.h:1591:26: note: in definition of macro 'STRCPY'
 1591 | #define STRCPY(d, s)     strcpy((char *)(d), (char *)(s))
      | ^~~~~~
In file included from vim.h:1815,
                 from dict.c:14:
dict.c: In function 'dict_extend':
structs.h:1466:12: note: subobject 'di_key' declared here
 1466 |     char_u di_key[1]; // key (actually longer!)
      | ^~~~~~

gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
-DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -DFEAT_GUI_MSWIN
-DFEAT_CLIPBOARD -pipe -march=native -Wall -O3 -fomit-frame-pointer
-freg-struct-return evalvars.c -o gobjnative/evalvars.o
evalvars.c: In function 'lookup_scriptvar':
cc1.exe: warning: function may return address of local variable
[-Wreturn-local-addr]
evalvars.c:2504:12: note: declared here
 2504 |     char_u buffer[30];
      | ^~~~~~

gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
-DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -DFEAT_GUI_MSWIN
-DFEAT_CLIPBOARD -pipe -march=native -Wall -O3 -fomit-frame-pointer
-freg-struct-return userfunc.c -o gobjnative/userfunc.o
In file included from userfunc.c:14:
In function 'cat_func_name',
    inlined from 'get_user_func_name' at userfunc.c:3425:2:
vim.h:1591:26: warning: 'strcpy' offset 0 from the object at '<unknown>'
is out of the bounds of referenced subobject 'uf_name
' with type 'char_u[1]' {aka 'unsigned char[1]'} at offset 0
[-Warray-bounds]
 1591 | #define STRCPY(d, s)     strcpy((char *)(d), (char *)(s))
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim.h:1591:26: note: in definition of macro 'STRCPY'
 1591 | #define STRCPY(d, s)     strcpy((char *)(d), (char *)(s))
      | ^~~~~~
In file included from vim.h:1815,
                 from userfunc.c:14:
userfunc.c: In function 'get_user_func_name':
structs.h:1569:12: note: subobject 'uf_name' declared here
 1569 |     char_u uf_name[1]; // name of function (actually longer); can
      | ^~~~~~~
</snip>

I've had a look at the vim.h warning (the one from main.c). From what I
can gather the "I" in the "%Ix" and "%Iu" scan format strings is a
MS-specific thing. Anyhow, replacing the "I" with "z" in the format
strings (lines 343 to 345 in vim.h) makes the warnings go away (see the
attached patch).

Not sure about the others at the moment.

Cheers
John
vim.h.patch

Ken Takata

unread,
May 9, 2020, 7:06:48 AM5/9/20
to vim_dev
Hi John,
Unfortunately, older MSVC (e.g. VC 2010) doesn't support "z" specifier.
Do the warnings disappear if you change "%I" to "%I64"?

Regards,
Ken Takata

Ken Takata

unread,
May 9, 2020, 7:33:20 AM5/9/20
to vim_dev
Hi,
We used "I" specifier for very old compilers like MSVC6 which doesn't support "long long".
But, we dropped support for such old compilers a few years ago. So now we can use
"long long" and "ll" specifier. So, how about changing "%I" to "%ll"?

Regards,
Ken Takata

Bram Moolenaar

unread,
May 9, 2020, 7:41:59 AM5/9/20
to vim...@googlegroups.com, John Marriott

John Marriott wrote:

> After cleaning my vim source repo and rebuilding with the brand new gcc
> 10.1 (mingw64), I get these warnings:
> <snip>
> gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
> -DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -DFEAT_GUI_MSWIN
> -DFEAT_CLIPBOARD -pipe -march=native -Wall -O3 -fomit-frame-pointer
> -freg-struct-return main.c -o gobjnative/main.o
> In file included from main.c:11:
> main.c: In function 'early_arg_scan':
> vim.h:343:33: warning: 'I' flag used with '%x' gnu_scanf format [-Wformat=]
>   343 | # define SCANF_HEX_LONG_U "%Ix"
>       | ^~~~~

[...]

> gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
> -DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -DFEAT_GUI_MSWIN
> -DFEAT_CLIPBOARD -pipe -march=native -Wall -O3 -fomit-frame-pointer
> -freg-struct-return dict.c -o gobjnative/dict.o
> In file included from dict.c:14:
> In function 'dictitem_copy',
>     inlined from 'dict_extend' at dict.c:936:9:
> vim.h:1591:26: warning: 'strcpy' offset 0 from the object at '<unknown>'
> is out of the bounds of referenced subobject 'di_key'
>  with type 'char_u[1]' {aka 'unsigned char[1]'} at offset 0
> [-Warray-bounds]
>  1591 | #define STRCPY(d, s)     strcpy((char *)(d), (char *)(s))
>       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> vim.h:1591:26: note: in definition of macro 'STRCPY'
>  1591 | #define STRCPY(d, s)     strcpy((char *)(d), (char *)(s))
>       | ^~~~~~
> In file included from vim.h:1815,
>                  from dict.c:14:
> dict.c: In function 'dict_extend':
> structs.h:1466:12: note: subobject 'di_key' declared here
>  1466 |     char_u di_key[1]; // key (actually longer!)
>       | ^~~~~~

This probably can't be avoided, the compiler doesn't see the "actually
longer" remark. Perhaps GCC has an annotation to suppress the warning?

> gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
> -DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -DFEAT_GUI_MSWIN
> -DFEAT_CLIPBOARD -pipe -march=native -Wall -O3 -fomit-frame-pointer
> -freg-struct-return evalvars.c -o gobjnative/evalvars.o
> evalvars.c: In function 'lookup_scriptvar':
> cc1.exe: warning: function may return address of local variable
> [-Wreturn-local-addr]
> evalvars.c:2504:12: note: declared here
>  2504 |     char_u buffer[30];
>       | ^~~~~~

I'll fix this one.

> gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
> -DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -DFEAT_GUI_MSWIN
> -DFEAT_CLIPBOARD -pipe -march=native -Wall -O3 -fomit-frame-pointer
> -freg-struct-return userfunc.c -o gobjnative/userfunc.o
> In file included from userfunc.c:14:
> In function 'cat_func_name',
>     inlined from 'get_user_func_name' at userfunc.c:3425:2:
> vim.h:1591:26: warning: 'strcpy' offset 0 from the object at '<unknown>'
> is out of the bounds of referenced subobject 'uf_name
> ' with type 'char_u[1]' {aka 'unsigned char[1]'} at offset 0
> [-Warray-bounds]
>  1591 | #define STRCPY(d, s)     strcpy((char *)(d), (char *)(s))
>       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> vim.h:1591:26: note: in definition of macro 'STRCPY'
>  1591 | #define STRCPY(d, s)     strcpy((char *)(d), (char *)(s))
>       | ^~~~~~
> In file included from vim.h:1815,
>                  from userfunc.c:14:
> userfunc.c: In function 'get_user_func_name':
> structs.h:1569:12: note: subobject 'uf_name' declared here
>  1569 |     char_u uf_name[1]; // name of function (actually longer); can
>       | ^~~~~~~
> </snip>

Same reason, uf_name is used as the key in the function hashtable.

> I've had a look at the vim.h warning (the one from main.c). From what I
> can gather the "I" in the "%Ix" and "%Iu" scan format strings is a
> MS-specific thing. Anyhow, replacing the "I" with "z" in the format
> strings (lines 343 to 345 in vim.h) makes the warnings go away (see the
> attached patch).

This probably causes problems for other compilers, the format was like
this for a reason. Is there an #ifdef we can use for gcc?

--
Proof techniques #2: Proof by Oddity.
SAMPLE: To prove that horses have an infinite number of legs.
(1) Horses have an even number of legs.
(2) They have two legs in back and fore legs in front.
(3) This makes a total of six legs, which certainly is an odd number of
legs for a horse.
(4) But the only number that is both odd and even is infinity.
(5) Therefore, horses must have an infinite number of legs.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

John Marriott

unread,
May 9, 2020, 4:15:26 PM5/9/20
to vim...@googlegroups.com
> Unfortunately, older MSVC (e.g. VC 2010) doesn't support "z" specifier.
> Do the warnings disappear if you change "%I" to "%I64"?
>
>
Hi Ken,

Changing them to "%I64" doesn't help:
<snip>
gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
-DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -DFEAT_GUI_MSWIN
 -DFEAT_CLIPBOARD -pipe -march=native -Wall -O3 -fomit-frame-pointer
-freg-struct-return main.c -o gobjnative/main.o
In file included from main.c:11:
main.c: In function 'early_arg_scan':
vim.h:343:33: warning: 'I' flag used with '%x' gnu_scanf format [-Wformat=]
  343 | # define SCANF_HEX_LONG_U "%I64x"
      | ^~~~~~~
vim.h:343:33: note: in definition of macro 'SCANF_HEX_LONG_U'
  343 | # define SCANF_HEX_LONG_U "%I64x"
      | ^~~~~~~
vim.h:343:38: note: format string is defined here
  343 | # define SCANF_HEX_LONG_U "%I64x"
      | ^
vim.h:343:33: warning: format '%x' expects argument of type 'unsigned
int *', but argument 3 has type 'long_u *' {aka 'long lo
ng unsigned int *'} [-Wformat=]
  343 | # define SCANF_HEX_LONG_U "%I64x"
      | ^~~~~~~
vim.h:343:33: note: in definition of macro 'SCANF_HEX_LONG_U'
  343 | # define SCANF_HEX_LONG_U "%I64x"
      | ^~~~~~~
vim.h:343:38: note: format string is defined here
  343 | # define SCANF_HEX_LONG_U "%I64x"
      | ~~~~^
      | |
      |                                      unsigned int *
      | %I64llx
vim.h:344:33: warning: unknown conversion type character 'I' in format
[-Wformat=]
  344 | # define SCANF_DECIMAL_LONG_U "%I64Iu"
      | ^~~~~~~~
vim.h:344:33: note: in definition of macro 'SCANF_DECIMAL_LONG_U'
  344 | # define SCANF_DECIMAL_LONG_U "%I64Iu"
      | ^~~~~~~~
vim.h:344:38: note: format string is defined here
  344 | # define SCANF_DECIMAL_LONG_U "%I64Iu"
      | ^
vim.h:344:33: warning: too many arguments for format [-Wformat-extra-args]
  344 | # define SCANF_DECIMAL_LONG_U "%I64Iu"
      | ^~~~~~~~
vim.h:344:33: note: in definition of macro 'SCANF_DECIMAL_LONG_U'
  344 | # define SCANF_DECIMAL_LONG_U "%I64Iu"
      | ^~~~~~~~
</snip>

However, putting the definitions around some ifdefs works for me, like
so (see attached):
<snip>
#ifdef _WIN64
typedef unsigned __int64    long_u;
typedef         __int64    long_i;
# if defined(__GNUC__) && !defined(__clang__)
    # define SCANF_HEX_LONG_U       "%zx"
    # define SCANF_DECIMAL_LONG_U   "%zu"
    # define PRINTF_HEX_LONG_U      "0x%zx"
# else
    # define SCANF_HEX_LONG_U       "%Ix"
    # define SCANF_DECIMAL_LONG_U   "%Iu"
    # define PRINTF_HEX_LONG_U      "0x%Ix"
# endif
#else
  // Microsoft-specific. The __w64 keyword should be specified on any
typedefs
  // that change size between 32-bit and 64-bit platforms.  For any
such type,
  // __w64 should appear only on the 32-bit definition of the typedef.
  // Define __w64 as an empty token for everything but MSVC 7.x or later.
# if !defined(_MSC_VER)    || (_MSC_VER < 1300)
#  define __w64
# endif
typedef unsigned long __w64    long_u;
typedef         long __w64     long_i;
# define SCANF_HEX_LONG_U       "%lx"
# define SCANF_DECIMAL_LONG_U   "%lu"
# define PRINTF_HEX_LONG_U      "0x%lx"
#endif
#define PRINTF_DECIMAL_LONG_U SCANF_DECIMAL_LONG_U
</snip>

Cheers
John



vim.h.patch

Bram Moolenaar

unread,
May 9, 2020, 5:11:13 PM5/9/20
to vim...@googlegroups.com, John Marriott

John Marriott wrote:

> However, putting the definitions around some ifdefs works for me, like
> so (see attached):
> <snip>
> #ifdef _WIN64
> typedef unsigned __int64    long_u;
> typedef         __int64    long_i;
> # if defined(__GNUC__) && !defined(__clang__)

Any specified reason you exclude clang here? I thought it was using the
same runtime library.

>     # define SCANF_HEX_LONG_U       "%zx"
>     # define SCANF_DECIMAL_LONG_U   "%zu"
>     # define PRINTF_HEX_LONG_U      "0x%zx"
> # else
>     # define SCANF_HEX_LONG_U       "%Ix"
>     # define SCANF_DECIMAL_LONG_U   "%Iu"
>     # define PRINTF_HEX_LONG_U      "0x%Ix"
> # endif

--
hundred-and-one symptoms of being an internet addict:
84. Books in your bookcase bear the names Bongo, WinSock and Inside OLE

John Marriott

unread,
May 9, 2020, 5:38:41 PM5/9/20
to vim...@googlegroups.com

On 10-May-2020 07:11, Bram Moolenaar wrote:
> Any specified reason you exclude clang here? I thought it was using the
> same runtime library.
>
>
Ah no. It looks like I pinched too much from stackoverflow. Whoops sorry :-)

Ken Takata

unread,
May 9, 2020, 10:27:16 PM5/9/20
to vim_dev
Hi,
 I don't think we need to use #if here.
Attached patch should be enough.

Additionally, at least Windows 7's msvcrt.dll doesn't support the "z" specifier.

Regards,
Ken Takata
mingw-warning.diff

Bram Moolenaar

unread,
May 10, 2020, 7:45:07 AM5/10/20
to vim...@googlegroups.com, John Marriott
I included Ken's patch, because it is the simplest. Please check that
it works.

--
Ed's Radiator Shop: The Best Place in Town to Take a Leak.

John Marriott

unread,
May 10, 2020, 3:19:07 PM5/10/20
to Bram Moolenaar, vim...@googlegroups.com

On 10-May-2020 21:44, Bram Moolenaar wrote:
> I included Ken's patch, because it is the simplest. Please check that
> it works.
>
Hi Bram,

Ken's patch works for me.

Cheers
John
Reply all
Reply to author
Forward
0 new messages