bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Warning from count-leading-zeros.h


From: Paul Eggert
Subject: Re: Warning from count-leading-zeros.h
Date: Fri, 14 Dec 2018 17:31:22 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1

On 12/14/18 4:09 AM, Reuben Thomas wrote:
As far as I can tell, the following warning is not dependent on my code, as it's inside a function in count-leading-zeros.h. Warning obtained with GCC 7.3.0:

bits_util.c: In function ‘smite_find_msbit’:
../lib/count-leading-zeros.h:39:26: warning: assuming signed overflow does not occur when simplifying conditional to constant [-Wstrict-overflow]
   return x ? BUILTIN (x) : CHAR_BIT * sizeof x;
          ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
../lib/count-leading-zeros.h:100:3: note: in expansion of macro ‘COUNT_LEADING_ZEROS’    COUNT_LEADING_ZEROS (__builtin_clzl, _BitScanReverse, unsigned long int);
   ^~~~~~~~~~~~~~~~~~~

The warning could stem from your code, if your code calls count_leading_zeros (E) where E's value depends on a computation that could involve signed integer overflow (which means behavior is undefined so GCC can optimize the if-then-else away and pretend it yields 0 or whatever else it likes). The warning almost surely does not stem from the underlined expression (CHAR_BIT * sizeof x), as that expression should evaluate to 32 or 64 on current platforms and this doesn't involve integer overflow.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]