On 08/08/2016 15:56, Pranith Kumar wrote: > Hi Paolo, > > On Mon, Aug 8, 2016 at 5:11 AM, Paolo Bonzini <pbonz...@redhat.com> wrote: >> >> >> On 07/08/2016 03:15, Pranith Kumar wrote: >>> With latest clang you get the following warning: >>> >>> warning: shifting a negative signed value is undefined >>> [-Wshift-negative-value] >>> >>> Fix the warning by changing negative shift to inverse 0 shift. >>> >> >> No, please no. >> >> clang is wrong in putting this under -Wall. >> > > Can you please explain why this warning is spurious? Isn't this what > the standard says?
Yes, but GCC promises to never exploit this kind of undefined behavior. Furthermore (though it's not the case for this patch) it's easy to get this "fix" wrong. For example if you change -1 << 3 to -1u << 3, and then the value is extended to 64-bit, the results will be different. Paolo