https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88156

--- Comment #6 from rguenther at suse dot de <rguenther at suse dot de> ---
On Fri, 23 Nov 2018, xantares09 at hotmail dot com wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88156
> 
> --- Comment #2 from xantares09 at hotmail dot com ---
> Thanks for the quick reply.
> 
> On mingw __WCHAR_TYPE__ expands to short unsigned int:
> 
> $ x86_64-w64-mingw32-gcc -E main.c
> ...
> # 3 "main.cxx"
> int string_hash(const short unsigned int* data) {
> 
> 
> On x86_64-linux it expands to int:
> $ gcc -E main.c
> ...
> # 3 "main.c"
> int string_hash(const int* data) {

Ok, but then we have

        h = (h * 7) ^ *data;

which is on mingw

  h = (h * 7) ^ (int)*data

zero-extending *data.  This means the XOR can never change
the sign of h.  Likewise h * 7 can never make h negative
because h is initially zero and the operation would need to
overflow to become negative but that would invoke undefined
behavior.

Thus the bug is INVALID.

You can use -fwrapv or make h unsigned int to fix this
(and adjust the h < 0 test to (int)h < 0).

Reply via email to