[cfe-dev] [llvm-dev] Unsigned Bitwise Shift for Bit-field Structure

Hubert Tong via cfe-dev cfe-dev at lists.llvm.org
Thu Apr 20 04:20:28 PDT 2017


On Thu, Apr 20, 2017 at 2:27 AM, Liu Hao via cfe-dev <cfe-dev at lists.llvm.org
> wrote:

> On 2017/4/20 10:28, Craig Topper via cfe-dev wrote:
>
>> On Wed, Apr 19, 2017 at 7:23 PM, Shiva Chen via llvm-dev
>> <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote:
>>
>>     Hi,
>>
>>     I have a question about unsigned bitwise shift.
>>
>>     According the C99 6.5.7.4
>>
>>     The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated
>>     bits are filled with zeros. If E1 has an unsigned type, the value of
>>     the result is E1 × 2^E2, reduced modulo one more than the maximum
>>     value representable in the result type.
>>
> Here `E1` is your bit field and is an lvalue, so it is converted to an
> rvalue of type `unsigned long long` (see N1256 6.3.2.1/1), and
> left-shifting it by one yields an rvalue with the value `0x10000000000` and
> the type `unsigned long long`. The rvalue is then converted and stored in
> the bit field. Since the bit field is unsigned and said to have a 'pure
> binary notation' (see N1256 6.2.6.1/2), its value ranges from 0 to
> (2^40-1). So you are right, the result is stored modulo 2^40, yielding zero
> (see N1256 6.3.1.3/2).
>
It is hardly clear that the rvalue is of type unsigned long long (and not
some special bit-field type).
See http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1260.htm.
I have been unable to find further discussion of the issue after
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1270.pdf.


>
> --
> Best regards,
> LH_Mouse
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170420/c83376f4/attachment.html>


More information about the cfe-dev mailing list