[Nouveau] [Bug 80266] Undefined operation in tgsi_ureg.c left shift of 1 by 31 places cannot be represented in type 'int'

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Fri Jun 20 11:45:44 PDT 2014


https://bugs.freedesktop.org/show_bug.cgi?id=80266

--- Comment #6 from Patrick Baggett <baggett.patrick at gmail.com> ---
I'm sure that technically shifting any bits into the sign bit of a signed
number produces undefined behavior according to C99, so yes, (1<<31)
technically is undefined. As a matter of practicality, on basically any CPU,
1<<31 will produce a valid negative number, but the compiler sees it as trying
to assign the constant 2147483648 to a 32-bit signed container, which is
outside of the 2^31-1 range that it can accept.

In the C abstract machine, this would be a serious problem. Obviously you can
make such an assignment in hardware, but the result (when interpreted as
signed) is not a value of 2147483648, but a value of -2147483648, which is why
the compiler gives a warning. It's weird to read that (1<<31) is less than 0.
If you don't really mean to assign a value of -2147483648 or 2147483648 and
just want a bit pattern, using unsigned is almost always the way to go.

I know that Solaris Studio happens to give a warning for the same case, if that
means anything.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/nouveau/attachments/20140620/5f537d98/attachment-0001.html>


More information about the Nouveau mailing list