Axel Bender <[email protected]> wrote:

> Compiling gVim 8.1 (latest) on Windows 7 64-bit with MinGW gcc 7.30 64-bit I 
> receive the following compiler warning in file userfunc.c:
>
> gcc -c -Iproto -DWIN32 -DWINVER=0x0600 -D_WIN32_WINNT=0x0600 -DHAVE_PATHDEF 
> -DFEAT_BIG -DHAVE_STDINT_H -DMS_WIN64 -DHAVE_GETTEXT -DHAVE_LOCALE_H 
> -DDYNAMIC_GETTEXT -DFEAT_CSCOPE -DFEAT_MBYTE
> -DFEAT_MBYTE_IME -DDYNAMIC_IME -DDYNAMIC_ICONV -pipe -march=x86-64 -Wall 
> -DFEAT_PYTHON3 -DDYNAMIC_PYTHON3 -DDYNAMIC_PYTHON3_DLL=\"python36.dll\" -O3 
> -fomit-frame-pointer -freg-struct-return
> -s userfunc.c -o objx86-64/userfunc.o
> userfunc.c: In function 'get_funccal_local_ht':
> userfunc.c:3609:2: warning: assuming signed overflow does not occur when 
> assuming that (X + c) < X is always false [-Wstrict-overflow]
>   for (i = 0; i < debug_backtrace_level; i++)
>   ^~~
> userfunc.c: In function 'get_funccal_local_var':
> userfunc.c:3609:2: warning: assuming signed overflow does not occur when 
> assuming that (X + c) < X is always false [-Wstrict-overflow]
>   for (i = 0; i < debug_backtrace_level; i++)
>   ^~~
> userfunc.c: In function 'get_funccal_args_ht':
> userfunc.c:3609:2: warning: assuming signed overflow does not occur when 
> assuming that (X + c) < X is always false [-Wstrict-overflow]
>   for (i = 0; i < debug_backtrace_level; i++)
>   ^~~
> userfunc.c: In function 'get_funccal_args_var':
> userfunc.c:3609:2: warning: assuming signed overflow does not occur when 
> assuming that (X + c) < X is always false [-Wstrict-overflow]
>   for (i = 0; i < debug_backtrace_level; i++)
>   ^~~


I don't think we can do much about this warning.
I consider more as an information from the compiler
rather than a warning caused by Vim code.

It happens when building with -O3 if I recall.
It's telling you that the compiler is statically making the
assumption that a signed integer addition is never overflowing. It's
allowed to do that, because signed int overflows are undefined
behavior in C, so the compiler can do whatever it wants in
case of overflow. When optimizing with -O3, that can cause
changes to the generated code, such as removing 'if' conditions
that are deemed useless because code would be undefined
behavior anyway.

In above cases, Vim code looks fine. You could add
-Wno-strict-overflow to avoid those warnings.

We could also silence such warnings by using unsigned
int (since signed int overflow are well defined in C, but I
don't think it's worth.

We can detect signed integer overflows at runtime by
using ubsan (= undefined behavior sanitizer), to be assured
that they don't happen, at least when running all Vim tests,
and when fuzzing vim.

Dominique

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui