<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Apr 19, 2017 at 10:35 PM, Craig Topper via cfe-dev <span dir="ltr"><<a target="_blank" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div>This test program prints 0. <br></div></blockquote><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div dir="ltr"><div><br></div><div><div>#include <stdio.h></div><span class="gmail-"><div><br></div><div>struct foo</div><div>{</div><div> unsigned long long b:40;</div><div>} x;</div><div><br></div></span><div>int main() {</div><div> foo f;</div><div> f.b = 0x8000000000ULL;</div><div> f.b <<= 1;</div><div> printf("%llx\n", f.b);</div><div> return 0;</div><div>}</div></div></div></blockquote><div>Which does not answer the question. The question is whether (f.b << 1) is 0.<br><br>Test:<br>int printf(const char *, ...);<br>int main(void) {<br> struct F { unsigned long long b : 40; } f;<br> f.b = 0x8000000000ull;<br> printf("0x%016llx\n", (unsigned long long)(f.b << 1));<br>}<br><br></div><div>GCC says 0. Clang says otherwise.<br></div><div>Online compiler: <a href="https://wandbox.org/permlink/MNTBbjv2F96N4boA">https://wandbox.org/permlink/MNTBbjv2F96N4boA</a><br><br></div><div>Now, the use of unsigned long long is itself a bit of an extension; however, yes, the wording does make it so that (f.b << 1) does not perform promotion of the bitfield type to unsigned long long.<br></div><div> </div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div class="gmail_extra"><span class="gmail-HOEnZb"><font color="#888888"><br clear="all"><div><div class="gmail-m_5455829473405972643gmail_signature">~Craig</div></div></font></span><div><div class="gmail-h5">
<br><div class="gmail_quote">On Wed, Apr 19, 2017 at 7:28 PM, Craig Topper <span dir="ltr"><<a target="_blank" href="mailto:craig.topper@gmail.com">craig.topper@gmail.com</a>></span> wrote:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div dir="ltr">Adding the clang developer list and removing the llvm developer list. Clang folks would be better for asking a C++ question such as this.</div><div class="gmail_extra"><span class="gmail-m_5455829473405972643HOEnZb"><font color="#888888"><br clear="all"><div><div class="gmail-m_5455829473405972643m_-7464533048109059033gmail_signature">~Craig</div></div></font></span><div><div class="gmail-m_5455829473405972643h5">
<br><div class="gmail_quote">On Wed, Apr 19, 2017 at 7:23 PM, Shiva Chen via llvm-dev <span dir="ltr"><<a target="_blank" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">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>
<br>
So if<br>
<br>
unsigned b = 0x80000000;<br>
unsigned a = b << 1;<br>
a will equal to 0 because a = (b << 1) mod (1<<32);<br>
(1<< 32) is UINT_MAX+1<br>
<br>
For the bit-field structure defined as<br>
struct foo<br>
{<br>
unsigned long long b:40;<br>
} x;<br>
<br>
According to C99 6.7.2.1<br>
A bit-field is interpreted as a signed or unsigned integer type<br>
consisting of the specified number of bits.<br>
So the x.b will treat as 40 bit unsigned integer and it should follow 6.5.7.4.<br>
<br>
if x.b = 0x80000000 00;<br>
x.b << 1 = (x.b << 1) mod (1<<40)<br>
So x.b << 1 should be 0, right ?<br>
<br>
Please correct me if I miss understanding something.<br>
<br>
Thanks,<br>
Shiva<br>
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a target="_blank" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a target="_blank" rel="noreferrer" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br></div></div></div>
</blockquote></div><br></div></div></div>
<br>______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a target="_blank" rel="noreferrer" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>