[llvm-dev] undef value

Bruce Hoult via llvm-dev llvm-dev at lists.llvm.org
Tue Jul 25 05:29:29 PDT 2017


This seems like a misunderstanding of the standard.

For unsigned a, a << b is equal to (a * pow(2,b)) % (MAXUINT+1), *except*
if b is greater than or equal to the word size, in which case the result is
undefined.

For the particular case of 1 << 33, many machines will give 0 and many will
give 2. Some many give other values. As far as the C standard, the result
is undefined and llvm is correct.

On Tue, Jul 25, 2017 at 3:15 PM, Anastasiya Ruzhanskaya via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> I have also tested and found out, that however in this example:
>   unsigned a = 1;
>   unsigned b = a << 33;
>   for (int i = 0; i < 32; i++)
>     printf("%d ", ((b >> i) & 1));
>   return b;
>  I get the undef value at the end:
>  * ret i32 undef*
> he bits are printed correctly - shifted by the modulo, as is defined in
> the standard. What is the explanation?
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170725/aeec5d34/attachment.html>


More information about the llvm-dev mailing list