[llvm-dev] undef value

Anastasiya Ruzhanskaya via llvm-dev llvm-dev at lists.llvm.org
Tue Jul 25 06:00:47 PDT 2017


Ok, thank you for the clarification.

2017-07-25 14:29 GMT+02:00 Bruce Hoult <bruce at hoult.org>:

> 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/be456d04/attachment.html>


More information about the llvm-dev mailing list