On Mon, Jul 9, 2018 at 9:32 AM, Dominique Pellé
<[email protected]> wrote:
> 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

In this particular case, since incrementation starts at 0 and proceeds
in steps of +1, and the condition is "less than", not "(not) greater
than", overflow can never happen in this loop anyway, not even if
debug_backtrace_level happened (as unlikely as it might seem to me) to
be the maximum possible positive value for its type (assuming i has
the same type): the loop exit will be triggered when i becomes equal
to debug_backtrace_level, or immediately if for some reason
debug_backtrace_level were negative.

On Linux64, where I neither modify the makefiles (my configure
arguments are set by means of environment variables) nor bother with
optimization levels, the src/Makefile calls gcc with -O2 and IIUC
that's why I never got this warning.


Best regards,
Tony.

-- 
-- 
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