<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Apr 20, 2017 at 2:27 AM, Liu Hao via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On 2017/4/20 10:28, Craig Topper via cfe-dev wrote:<br>
</span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">
On Wed, Apr 19, 2017 at 7:23 PM, Shiva Chen via llvm-dev<br></span><span class="gmail-">
<<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.or<wbr>g</a>>> wrote:<br>
<br>
    Hi,<br>
<br>
    I have a question about unsigned bitwise shift.<br>
<br>
    According the C99 6.5.7.4<br>
<br>
    The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated<br>
    bits are filled with zeros. If E1 has an unsigned type, the value of<br>
    the result is E1 × 2^E2, reduced modulo one more than the maximum<br>
    value representable in the result type.<br>
</span></blockquote>
Here `E1` is your bit field and is an lvalue, so it is converted to an rvalue of type `unsigned long long` (see N1256 <a href="http://6.3.2.1/1" rel="noreferrer" target="_blank">6.3.2.1/1</a>), 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 <a href="http://6.2.6.1/2" rel="noreferrer" target="_blank">6.2.6.1/2</a>), its value ranges from 0 to (2^40-1). So you are right, the result is stored modulo 2^40, yielding zero (see N1256 <a href="http://6.3.1.3/2" rel="noreferrer" target="_blank">6.3.1.3/2</a>).<span class="gmail-HOEnZb"><font color="#888888"><br></font></span></blockquote><div>It is hardly clear that the rvalue is of type unsigned long long (and not some special bit-field type).<br></div><div>See <a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1260.htm">http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1260.htm</a>.<br></div><div>I have been unable to find further discussion of the issue after <a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1270.pdf">http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1270.pdf</a>.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-HOEnZb"><font color="#888888">
<br>
-- <br>
Best regards,<br>
LH_Mouse</font></span><div class="gmail-HOEnZb"><div class="gmail-h5"><br>
<br>
______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
</div></div></blockquote></div><br></div></div>