[llvm-dev] Unsigned Bitwise Shift for Bit-field Structure
Shiva Chen via llvm-dev
llvm-dev at lists.llvm.org
Wed Apr 19 19:23:13 PDT 2017
I have a question about unsigned bitwise shift.
According the C99 22.214.171.124
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.
unsigned b = 0x80000000;
unsigned a = b << 1;
a will equal to 0 because a = (b << 1) mod (1<<32);
(1<< 32) is UINT_MAX+1
For the bit-field structure defined as
unsigned long long b:40;
According to C99 126.96.36.199
A bit-field is interpreted as a signed or unsigned integer type
consisting of the specified number of bits.
So the x.b will treat as 40 bit unsigned integer and it should follow 188.8.131.52.
if x.b = 0x80000000 00;
x.b << 1 = (x.b << 1) mod (1<<40)
So x.b << 1 should be 0, right ?
Please correct me if I miss understanding something.
More information about the llvm-dev