<html>
<head>
<base href="https://bugs.freedesktop.org/" />
</head>
<body>
<p>
<div>
<b><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Undefined operation in tgsi_ureg.c left shift of 1 by 31 places cannot be represented in type 'int'"
href="https://bugs.freedesktop.org/show_bug.cgi?id=80266#c9">Comment # 9</a>
on <a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Undefined operation in tgsi_ureg.c left shift of 1 by 31 places cannot be represented in type 'int'"
href="https://bugs.freedesktop.org/show_bug.cgi?id=80266">bug 80266</a>
from <span class="vcard"><a class="email" href="mailto:zeccav@gmail.com" title="Vittorio <zeccav@gmail.com>"> <span class="fn">Vittorio</span></a>
</span></b>
<pre>(In reply to <a href="show_bug.cgi?id=80266#c6">comment #6</a>)
<span class="quote">> 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.</span >
Thanks for the appreciated explanation.
Maybe substituting 1<<31 with 1U<<31 clears any undefined behaviour on the many
architectures where mesa runs.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the assignee for the bug.</li>
</ul>
</body>
</html>