<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Sep 21, 2015 at 3:21 PM, Alexey Samsonov <span dir="ltr"><<a href="mailto:vonosmas@gmail.com" target="_blank">vonosmas@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Do you plan to fix diagnostic emission for cases like "bool b : 4" in the near future, or it makes sense to revert this change until we reach consensus on the rules, and implementation?</div></blockquote><div><br></div><div>Fixed in r<span style="color:rgb(0,0,0)">248435.</span></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="gmail_extra"><div><div><div class="gmail_quote">On Fri, Sep 18, 2015 at 11:17 PM, Nico Weber via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div>On Fri, Sep 18, 2015 at 10:19 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div>On Fri, Sep 18, 2015 at 8:49 PM, Nico Weber <span dir="ltr"><<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div>On Fri, Sep 18, 2015 at 5:06 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div>On Wed, Sep 16, 2015 at 5:33 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div>On Wed, Sep 16, 2015 at 5:27 PM, Nico Weber via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>On Tue, Sep 15, 2015 at 5:50 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>On Tue, Sep 15, 2015 at 12:38 PM, Nico Weber <span dir="ltr"><<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">With this patch, we warn on `bool a : 4;`, yet we don't warn on `bool b` (which has 8 bits storage, 1 bit value). Warning on `bool b` is silly of course, but why is warning on `bool a : 4` useful? That's like 50% more storage efficient than `bool b` ;-)<div><br></div><div>It's possible that this is a good warning for some reason, but I don't quite see why yet.</div></div></blockquote><div><br></div></span><div>Why would we warn on "unsigned n : 57;"? The bit-field is wider than necessary, and we have no idea what the programmer was trying to do</div></div></div></div></blockquote><div><br></div></span><div>Warning on this kind of makes sense to me, as the field is wider than the default width of int. (Not warning on that doesn't seem terrible to me either though.)</div><div><br></div><div>I'm only confused about the bool case with bitfield sizes < 8 I think. We warn that the bitfield is wider than the value size, even though it's smaller than the default storage size, and we don't warn on regular bools.</div><div><br></div><div>To get an idea how often this warning fires, I ran it on a large-ish open source codebase I had flying around. The only place it fired on is one header in protobuf (extension_set.h). I looked at the history of that file, and it had a struct that used to look like</div><div><br></div><div>  struct Extension {</div><div>    SomeEnum e;</div><div>    bool a;</div><div>    bool b;<br></div><div>    bool c;</div><div>    int d;</div><div>    // ...some more stuff...</div><div>  };</div><div><br></div><div>Someone then added another field to this and for some reason decided to do it like so:</div><div><br></div><div><div>  struct Extension {</div><div>    SomeEnum e;</div><div>    bool a;</div><div>    bool b1 : 4;</div><div>    bool b2 : 4;</div><div>    bool c;</div><div>    int d;</div><div>    // ...some more stuff...</div><div>  };</div></div><div><br></div><div>Neither the commit message nor the review discussion mention the bitfield at all as far as I can tell. Now, given that this isn't a small struct and it has a bunch of normal bools, I don't know why they added the new field as bitfield while this wasn't deemed necessary for the existing bools. My best guess is that that they didn't want to add 3 bytes of padding (due to the int field), which seems like a decent reason.</div><div><br></div><div>Had the warning been in place when this code got written, I suppose they had used ": 1" instead. Does this make this code much better? It doesn't seem like it to me. So after doing a warning quality eval, I'd suggest to not emit the warning for bool bitfields if the bitfield size is < 8. (But since the warning fires only very rarely, I don't feel very strongly about this.)</div></div></div></div></blockquote><div><br></div></div></div><div>I agree it doesn't make the code /much/ better. But if I were reading that, I would certainly pause for a few moments wondering what the author was thinking. I also don't feel especially strongly about this, but I don't see a good rationale for warning on 'bool : 9' but not on 'bool : 5'.</div></div></div></div></blockquote><div><br></div></div></div><div>I'm coming around to the opinion that we shouldn't give this warning on bool at all -- the point of the warning is to point out that an 'unsigned : 40;' bitfield can't hold 2**40 - 1, and values of that size will be truncated. There is no corresponding problematic case for bool, so we have a much weaker justification for warning in this case -- we have no idea what the user was trying to achieve, but we do not have a signal that their code is wrong.</div><div><br></div><div>Thoughts?</div></div></div></div></blockquote><div><br></div></div></div><div>Makes sense to me :-) What about `bool : 16`?</div></div></div></div></blockquote><div><br></div></div></div><div>I don't think it makes sense to treat bool : 3 and bool : 16 differently. The fact that an unadorned bool would occupy 8 bits doesn't seem relevant to whether we should warn. Either we warn that there are padding bits, or we don't.</div></div></div></div></blockquote><div><br></div></div></div><div>Yup, makes sense.</div><div><div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>, but it doesn't seem likely they got that effect. Would you be more convinced if we amended the diagnostic to provide a fixit suggesting using an anonymous bit-field to insert padding?</div></div></div></div></blockquote><div><br></div></span><div>Isn't the Right Fix (tm) to make bool bitfields 1 wide and rely on the compiler to figure out padding?</div></div></div></div></blockquote><div><br></div></span><div>It depends; maybe the intent is to be compatible with some on-disk format, and the explicit padding is important:</div><div><br></div><div>struct X {</div><div>  int n : 3;</div><div>  bool b : 3;</div><div>  int n : 2;</div><div>};</div><div><br></div><div>Changing the bool bit-field to 1 bit without inserting an anonymous bit-field would change the struct layout.</div><div><div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div><div class="gmail_extra"><div class="gmail_quote">On Mon, Sep 14, 2015 at 11:06 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>On Mon, Sep 14, 2015 at 7:07 PM, Rachel Craik <span dir="ltr"><<a href="mailto:rcraik@ca.ibm.com" target="_blank">rcraik@ca.ibm.com</a>></span> wrote:<br></span><span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>
<p><font size="2" face="sans-serif">As of DR262, the C standard clarified that the width of a bit-field can not exceed that of the specified type, and this change was primarily to ensure that Clang correctly enforced this part of the standard. Looking at the C++11 standard again, it states that although the specified width of a bit-field may exceed the number of bits in the </font><font size="2" face="sans-serif"><i>object representation</i></font><font size="2" face="sans-serif"> (which includes padding bits) of the specified type, the extra bits will not take any part in the bit-field's </font><font size="2" face="sans-serif"><i>value representation</i></font><font size="2" face="sans-serif">.</font><br>
<br>
<font size="2" face="sans-serif">Taking this into account, it seems that the correct way to validate the width of a bit-field (ignoring the special case of MS in C mode) would be to use getIntWidth in C mode, and getTypeSize in C++ mode.</font><br>
<br>
<font size="2" face="sans-serif">I would be happy create a patch to make this change tomorrow if people are in agreement.</font></p></div></blockquote></span><div>David Majnemer has already landed a couple of changes to fix this up, so hopefully that won't be necessary. Thanks for working on this!</div><div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><p>
<font size="2" face="sans-serif">Rachel<br>
</font><br>
<br>
<img width="16" height="16" src="cid:1__=0ABBF452DF98CF3A8f9e8a93df938@ca.ibm.com" border="0" alt="Inactive hide details for Nico Weber ---09/14/2015 09:53:25 PM---On Mon, Sep 14, 2015 at 5:28 PM, Richard Smith <richard@metafo"><font size="2" color="#424282" face="sans-serif">Nico Weber ---09/14/2015 09:53:25 PM---On Mon, Sep 14, 2015 at 5:28 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>> wrote:</font><br>
<br>
<font size="1" color="#5F5F5F" face="sans-serif">From:      </font><font size="1" face="sans-serif">Nico Weber <<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>></font><br>
<font size="1" color="#5F5F5F" face="sans-serif">To:        </font><font size="1" face="sans-serif">Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></font><br>
<font size="1" color="#5F5F5F" face="sans-serif">Cc:        </font><font size="1" face="sans-serif">Rachel Craik/Toronto/IBM@IBMCA, cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></font><br>
<font size="1" color="#5F5F5F" face="sans-serif">Date:      </font><font size="1" face="sans-serif">09/14/2015 09:53 PM</font><br>
<font size="1" color="#5F5F5F" face="sans-serif">Subject:   </font><font size="1" face="sans-serif">Re: r247618 - C11 _Bool bitfield diagnostic</font><br>
<font size="1" color="#5F5F5F" face="sans-serif">Sent by:   </font><font size="1" face="sans-serif"><a href="mailto:thakis@google.com" target="_blank">thakis@google.com</a></font><br>
</p><hr width="100%" size="2" align="left" noshade style="color:rgb(128,145,165)"><div><div><br>
<br>
<br>
<font size="3" face="serif">On Mon, Sep 14, 2015 at 5:28 PM, Richard Smith <</font><a href="mailto:richard@metafoo.co.uk" target="_blank"><font size="3" color="#0000FF" face="serif"><u>richard@metafoo.co.uk</u></font></a><font size="3" face="serif">> wrote:</font>
<ul style="padding-left:9pt"><font size="3" face="serif">On Mon, Sep 14, 2015 at 5:18 PM, Nico Weber via cfe-commits <</font><a href="mailto:cfe-commits@lists.llvm.org" target="_blank"><font size="3" color="#0000FF" face="serif"><u>cfe-commits@lists.llvm.org</u></font></a><font size="3" face="serif">> wrote:</font>
<ul style="padding-left:9pt"><font size="3" face="serif">This also fires for bool in C++ files, even though the commit message saying C11 and _Bool. Given the test changes, I suppose that's intentional? This fires a lot on existing code, for example protobuf:</font><br>
<br>
<font size="3" face="serif">../../third_party/protobuf/src/google/protobuf/extension_set.h:465:10: error: width of bit-field 'is_cleared' (4 bits) exceeds the width of its type; value will be truncated to 1 bit [-Werror,-Wbitfield-width]</font><br>
<font size="3" face="serif">    bool is_cleared : 4;</font><br>
<font size="3" face="serif">         ^</font><br>
<font size="3" face="serif">../../third_party/protobuf/src/google/protobuf/extension_set.h:472:10: error: width of bit-field 'is_lazy' (4 bits) exceeds the width of its type; value will be truncated to 1 bit [-Werror,-Wbitfield-width]</font><br>
<font size="3" face="serif">    bool is_lazy : 4;</font><br>
<font size="3" face="serif">         ^</font><br>
<br>
<font size="3" face="serif">Is this expected? Is this a behavior change, or did the truncation happen previously and it's now just getting warned on?</font></ul>
<br>
<font size="3" face="serif">The code previously assumed that MSVC used the C rules here; it appears that's not true in all cases.</font></ul>
<br>
<font size="3" face="serif">This was on a Mac bot…</font><br>
<font size="3" face="serif"> </font>
<ul style="padding-left:9pt"><br>
<font size="3" face="serif">Can we just remove the "</font><font size="1" face="serif"> || IsMsStruct || Context.getTargetInfo().getCXXABI().isMicrosoft()"? Is there some reason we need to prohibit overwide bitfields for MS bitfield layout, rather than just warning on them? (Does record layout fail somehow?)</font><br>

<ul style="padding-left:9pt"><font size="3" face="serif">On Mon, Sep 14, 2015 at 2:27 PM, Rachel Craik via cfe-commits <</font><a href="mailto:cfe-commits@lists.llvm.org" target="_blank"><font size="3" color="#0000FF" face="serif"><u>cfe-commits@lists.llvm.org</u></font></a><font size="3" face="serif">> wrote:</font>
<ul style="padding-left:9pt"><font size="3" face="serif">Author: rcraik<br>
Date: Mon Sep 14 16:27:36 2015<br>
New Revision: 247618<br>
<br>
URL: </font><a href="http://llvm.org/viewvc/llvm-project?rev=247618&view=rev" target="_blank"><font size="3" color="#0000FF" face="serif"><u>http://llvm.org/viewvc/llvm-project?rev=247618&view=rev</u></font></a><font size="3" face="serif"><br>
Log:<br>
C11 _Bool bitfield diagnostic<br>
<br>
Summary: Implement DR262 (for C). This patch will mainly affect bitfields of type _Bool<br>
<br>
Reviewers: fraggamuffin, rsmith<br>
<br>
Subscribers: hubert.reinterpretcast, cfe-commits<br>
<br>
Differential Revision: </font><a href="http://reviews.llvm.org/D10018" target="_blank"><font size="3" color="#0000FF" face="serif"><u>http://reviews.llvm.org/D10018</u></font></a><font size="3" face="serif"><br>
<br>
Modified:<br>
    cfe/trunk/include/clang/Basic/DiagnosticGroups.td<br>
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
    cfe/trunk/lib/Sema/SemaDecl.cpp<br>
    cfe/trunk/test/CodeGen/bitfield-2.c<br>
    cfe/trunk/test/CodeGenCXX/warn-padded-packed.cpp<br>
    cfe/trunk/test/Misc/warning-flags.c<br>
    cfe/trunk/test/Sema/bitfield.c<br>
    cfe/trunk/test/SemaCXX/bitfield-layout.cpp<br>
    cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp<br>
    cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp<br>
    cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp<br>
    cfe/trunk/test/SemaObjC/class-bitfield.m<br>
<br>
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td<br>
URL: </font><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=247618&r1=247617&r2=247618&view=diff" target="_blank"><font size="3" color="#0000FF" face="serif"><u>http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=247618&r1=247617&r2=247618&view=diff</u></font></a><font size="3" face="serif"><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)<br>
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Mon Sep 14 16:27:36 2015<br>
@@ -32,6 +32,7 @@ def AutoImport : DiagGroup<"auto-import"<br>
 def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;<br>
 def GNUCompoundLiteralInitializer : DiagGroup<"gnu-compound-literal-initializer">;<br>
 def BitFieldConstantConversion : DiagGroup<"bitfield-constant-conversion">;<br>
+def BitFieldWidth : DiagGroup<"bitfield-width">;<br>
 def ConstantConversion :<br>
   DiagGroup<"constant-conversion", [ BitFieldConstantConversion ] >;<br>
 def LiteralConversion : DiagGroup<"literal-conversion">;<br>
<br>
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
URL: </font><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=247618&r1=247617&r2=247618&view=diff" target="_blank"><font size="3" color="#0000FF" face="serif"><u>http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=247618&r1=247617&r2=247618&view=diff</u></font></a><font size="3" face="serif"><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Sep 14 16:27:36 2015<br>
@@ -4314,20 +4314,21 @@ def err_bitfield_has_negative_width : Er<br>
 def err_anon_bitfield_has_negative_width : Error<<br>
   "anonymous bit-field has negative width (%0)">;<br>
 def err_bitfield_has_zero_width : Error<"named bit-field %0 has zero width">;<br>
-def err_bitfield_width_exceeds_type_size : Error<<br>
-  "size of bit-field %0 (%1 bits) exceeds size of its type (%2 bits)">;<br>
-def err_anon_bitfield_width_exceeds_type_size : Error<<br>
-  "size of anonymous bit-field (%0 bits) exceeds size of its type (%1 bits)">;<br>
+def err_bitfield_width_exceeds_type_width : Error<<br>
+  "width of bit-field %0 (%1 bits) exceeds width of its type (%2 bit%s2)">;<br>
+def err_anon_bitfield_width_exceeds_type_width : Error<<br>
+  "width of anonymous bit-field (%0 bits) exceeds width of its type "<br>
+  "(%1 bit%s1)">;<br>
 def err_incorrect_number_of_vector_initializers : Error<<br>
   "number of elements must be either one or match the size of the vector">;<br>
<br>
 // Used by C++ which allows bit-fields that are wider than the type.<br>
-def warn_bitfield_width_exceeds_type_size: Warning<<br>
-  "size of bit-field %0 (%1 bits) exceeds the size of its type; value will be "<br>
-  "truncated to %2 bits">;<br>
-def warn_anon_bitfield_width_exceeds_type_size : Warning<<br>
-  "size of anonymous bit-field (%0 bits) exceeds size of its type; value will "<br>
-  "be truncated to %1 bits">;<br>
+def warn_bitfield_width_exceeds_type_width: Warning<<br>
+  "width of bit-field %0 (%1 bits) exceeds the width of its type; value will "<br>
+  "be truncated to %2 bit%s2">, InGroup<BitFieldWidth>;<br>
+def warn_anon_bitfield_width_exceeds_type_width : Warning<<br>
+  "width of anonymous bit-field (%0 bits) exceeds width of its type; value "<br>
+  "will be truncated to %1 bit%s1">, InGroup<BitFieldWidth>;<br>
<br>
 def warn_missing_braces : Warning<<br>
   "suggest braces around initialization of subobject">,<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp<br>
URL: </font><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=247618&r1=247617&r2=247618&view=diff" target="_blank"><font size="3" color="#0000FF" face="serif"><u>http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=247618&r1=247617&r2=247618&view=diff</u></font></a><font size="3" face="serif"><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Sep 14 16:27:36 2015<br>
@@ -12625,26 +12625,26 @@ ExprResult Sema::VerifyBitField(SourceLo<br>
   }<br>
<br>
   if (!FieldTy->isDependentType()) {<br>
-    uint64_t TypeSize = Context.getTypeSize(FieldTy);<br>
-    if (Value.getZExtValue() > TypeSize) {<br>
+    uint64_t TypeWidth = Context.getIntWidth(FieldTy);<br>
+    if (Value.ugt(TypeWidth)) {<br>
       if (!getLangOpts().CPlusPlus || IsMsStruct ||<br>
           Context.getTargetInfo().getCXXABI().isMicrosoft()) {<br>
         if (FieldName)<br>
-          return Diag(FieldLoc, diag::err_bitfield_width_exceeds_type_size)<br>
+          return Diag(FieldLoc, diag::err_bitfield_width_exceeds_type_width)<br>
             << FieldName << (unsigned)Value.getZExtValue()<br>
-            << (unsigned)TypeSize;<br>
+            << (unsigned)TypeWidth;<br>
<br>
-        return Diag(FieldLoc, diag::err_anon_bitfield_width_exceeds_type_size)<br>
-          << (unsigned)Value.getZExtValue() << (unsigned)TypeSize;<br>
+        return Diag(FieldLoc, diag::err_anon_bitfield_width_exceeds_type_width)<br>
+          << (unsigned)Value.getZExtValue() << (unsigned)TypeWidth;<br>
       }<br>
<br>
       if (FieldName)<br>
-        Diag(FieldLoc, diag::warn_bitfield_width_exceeds_type_size)<br>
+        Diag(FieldLoc, diag::warn_bitfield_width_exceeds_type_width)<br>
           << FieldName << (unsigned)Value.getZExtValue()<br>
-          << (unsigned)TypeSize;<br>
+          << (unsigned)TypeWidth;<br>
       else<br>
-        Diag(FieldLoc, diag::warn_anon_bitfield_width_exceeds_type_size)<br>
-          << (unsigned)Value.getZExtValue() << (unsigned)TypeSize;<br>
+        Diag(FieldLoc, diag::warn_anon_bitfield_width_exceeds_type_width)<br>
+          << (unsigned)Value.getZExtValue() << (unsigned)TypeWidth;<br>
     }<br>
   }<br>
<br>
<br>
Modified: cfe/trunk/test/CodeGen/bitfield-2.c<br>
URL: </font><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/bitfield-2.c?rev=247618&r1=247617&r2=247618&view=diff" target="_blank"><font size="3" color="#0000FF" face="serif"><u>http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/bitfield-2.c?rev=247618&r1=247617&r2=247618&view=diff</u></font></a><font size="3" face="serif"><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGen/bitfield-2.c (original)<br>
+++ cfe/trunk/test/CodeGen/bitfield-2.c Mon Sep 14 16:27:36 2015<br>
@@ -237,7 +237,7 @@ unsigned long long test_5() {<br>
 /***/<br>
<br>
 struct s6 {<br>
-  _Bool f0 : 2;<br>
+  unsigned f0 : 2;<br>
 };<br>
<br>
 struct s6 g6 = { 0xF };<br>
<br>
Modified: cfe/trunk/test/CodeGenCXX/warn-padded-packed.cpp<br>
URL: </font><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/warn-padded-packed.cpp?rev=247618&r1=247617&r2=247618&view=diff" target="_blank"><font size="3" color="#0000FF" face="serif"><u>http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/warn-padded-packed.cpp?rev=247618&r1=247617&r2=247618&view=diff</u></font></a><font size="3" face="serif"><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/warn-padded-packed.cpp (original)<br>
+++ cfe/trunk/test/CodeGenCXX/warn-padded-packed.cpp Mon Sep 14 16:27:36 2015<br>
@@ -69,7 +69,7 @@ struct S12 {<br>
<br>
 struct S13 { // expected-warning {{padding size of 'S13' with 6 bits to alignment boundary}}<br>
   char c;<br>
-  bool b : 10; // expected-warning {{size of bit-field 'b' (10 bits) exceeds the size of its type}}<br>
+  bool b : 10; // expected-warning {{width of bit-field 'b' (10 bits) exceeds the width of its type}}<br>
 };<br>
<br>
 // The warnings are emitted when the layout of the structs is computed, so we have to use them.<br>
<br>
Modified: cfe/trunk/test/Misc/warning-flags.c<br>
URL: </font><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/warning-flags.c?rev=247618&r1=247617&r2=247618&view=diff" target="_blank"><font size="3" color="#0000FF" face="serif"><u>http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/warning-flags.c?rev=247618&r1=247617&r2=247618&view=diff</u></font></a><font size="3" face="serif"><br>
==============================================================================<br>
--- cfe/trunk/test/Misc/warning-flags.c (original)<br>
+++ cfe/trunk/test/Misc/warning-flags.c Mon Sep 14 16:27:36 2015<br>
@@ -18,7 +18,7 @@ This test serves two purposes:<br>
<br>
 The list of warnings below should NEVER grow.  It should gradually shrink to 0.<br>
<br>
-CHECK: Warnings without flags (92):<br>
+CHECK: Warnings without flags (90):<br>
 CHECK-NEXT:   ext_excess_initializers<br>
 CHECK-NEXT:   ext_excess_initializers_in_char_array_initializer<br>
 CHECK-NEXT:   ext_expected_semi_decl_list<br>
@@ -44,10 +44,8 @@ CHECK-NEXT:   pp_pragma_once_in_main_fil<br>
 CHECK-NEXT:   pp_pragma_sysheader_in_main_file<br>
 CHECK-NEXT:   w_asm_qualifier_ignored<br>
 CHECK-NEXT:   warn_accessor_property_type_mismatch<br>
-CHECK-NEXT:   warn_anon_bitfield_width_exceeds_type_size<br>
 CHECK-NEXT:   warn_arcmt_nsalloc_realloc<br>
 CHECK-NEXT:   warn_asm_label_on_auto_decl<br>
-CHECK-NEXT:   warn_bitfield_width_exceeds_type_size<br>
 CHECK-NEXT:   warn_c_kext<br>
 CHECK-NEXT:   warn_call_to_pure_virtual_member_function_from_ctor_dtor<br>
 CHECK-NEXT:   warn_call_wrong_number_of_arguments<br>
<br>
Modified: cfe/trunk/test/Sema/bitfield.c<br>
URL: </font><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/bitfield.c?rev=247618&r1=247617&r2=247618&view=diff" target="_blank"><font size="3" color="#0000FF" face="serif"><u>http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/bitfield.c?rev=247618&r1=247617&r2=247618&view=diff</u></font></a><font size="3" face="serif"><br>
==============================================================================<br>
--- cfe/trunk/test/Sema/bitfield.c (original)<br>
+++ cfe/trunk/test/Sema/bitfield.c Mon Sep 14 16:27:36 2015<br>
@@ -6,7 +6,7 @@ struct a {<br>
   int a : -1; // expected-error{{bit-field 'a' has negative width}}<br>
<br>
   // rdar://6081627<br>
-  int b : 33; // expected-error{{size of bit-field 'b' (33 bits) exceeds size of its type (32 bits)}}<br>
+  int b : 33; // expected-error{{width of bit-field 'b' (33 bits) exceeds width of its type (32 bits)}}<br>
<br>
   int c : (1 + 0.25); // expected-error{{expression is not an integer constant expression}}<br>
   int d : (int)(1 + 0.25);<br>
@@ -22,9 +22,12 @@ struct a {<br>
   int g : (_Bool)1;<br>
<br>
   // PR4017<br>
-  char : 10;      // expected-error {{size of anonymous bit-field (10 bits) exceeds size of its type (8 bits)}}<br>
+  char : 10;      // expected-error {{width of anonymous bit-field (10 bits) exceeds width of its type (8 bits)}}<br>
   unsigned : -2;  // expected-error {{anonymous bit-field has negative width (-2)}}<br>
   float : 12;     // expected-error {{anonymous bit-field has non-integral type 'float'}}<br>
+<br>
+  _Bool : 2;   // expected-error {{width of anonymous bit-field (2 bits) exceeds width of its type (1 bit)}}<br>
+  _Bool h : 5; // expected-error {{width of bit-field 'h' (5 bits) exceeds width of its type (1 bit)}}<br>
 };<br>
<br>
 struct b {unsigned x : 2;} x;<br>
<br>
Modified: cfe/trunk/test/SemaCXX/bitfield-layout.cpp<br>
URL: </font><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/bitfield-layout.cpp?rev=247618&r1=247617&r2=247618&view=diff" target="_blank"><font size="3" color="#0000FF" face="serif"><u>http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/bitfield-layout.cpp?rev=247618&r1=247617&r2=247618&view=diff</u></font></a><font size="3" face="serif"><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/bitfield-layout.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/bitfield-layout.cpp Mon Sep 14 16:27:36 2015<br>
@@ -5,25 +5,25 @@<br>
<br>
 // Simple tests.<br>
 struct Test1 {<br>
-  char c : 9; // expected-warning {{size of bit-field 'c' (9 bits) exceeds the size of its type; value will be truncated to 8 bits}}<br>
+  char c : 9; // expected-warning {{width of bit-field 'c' (9 bits) exceeds the width of its type; value will be truncated to 8 bits}}<br>
 };<br>
 CHECK_SIZE(Test1, 2);<br>
 CHECK_ALIGN(Test1, 1);<br>
<br>
 struct Test2 {<br>
-  char c : 16; // expected-warning {{size of bit-field 'c' (16 bits) exceeds the size of its type; value will be truncated to 8 bits}}<br>
+  char c : 16; // expected-warning {{width of bit-field 'c' (16 bits) exceeds the width of its type; value will be truncated to 8 bits}}<br>
 };<br>
 CHECK_SIZE(Test2, 2);<br>
 CHECK_ALIGN(Test2, 2);<br>
<br>
 struct Test3 {<br>
-  char c : 32; // expected-warning {{size of bit-field 'c' (32 bits) exceeds the size of its type; value will be truncated to 8 bits}}<br>
+  char c : 32; // expected-warning {{width of bit-field 'c' (32 bits) exceeds the width of its type; value will be truncated to 8 bits}}<br>
 };<br>
 CHECK_SIZE(Test3, 4);<br>
 CHECK_ALIGN(Test3, 4);<br>
<br>
 struct Test4 {<br>
-  char c : 64; // expected-warning {{size of bit-field 'c' (64 bits) exceeds the size of its type; value will be truncated to 8 bits}}<br>
+  char c : 64; // expected-warning {{width of bit-field 'c' (64 bits) exceeds the width of its type; value will be truncated to 8 bits}}<br>
 };<br>
 CHECK_SIZE(Test4, 8);<br>
 CHECK_ALIGN(Test4, 8);<br>
<br>
Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp<br>
URL: </font><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=247618&r1=247617&r2=247618&view=diff" target="_blank"><font size="3" color="#0000FF" face="serif"><u>http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=247618&r1=247617&r2=247618&view=diff</u></font></a><font size="3" face="serif"><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Mon Sep 14 16:27:36 2015<br>
@@ -1801,9 +1801,9 @@ namespace Bitfields {<br>
     bool b : 1;<br>
     unsigned u : 5;<br>
     int n : 5;<br>
-    bool b2 : 3;<br>
-    unsigned u2 : 74; // expected-warning {{exceeds the size of its type}}<br>
-    int n2 : 81; // expected-warning {{exceeds the size of its type}}<br>
+    bool b2 : 3; // expected-warning {{exceeds the width of its type}}<br>
+    unsigned u2 : 74; // expected-warning {{exceeds the width of its type}}<br>
+    int n2 : 81; // expected-warning {{exceeds the width of its type}}<br>
   };<br>
<br>
   constexpr A a = { false, 33, 31, false, 0xffffffff, 0x7fffffff }; // expected-warning 2{{truncation}}<br>
<br>
Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp<br>
URL: </font><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp?rev=247618&r1=247617&r2=247618&view=diff" target="_blank"><font size="3" color="#0000FF" face="serif"><u>http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp?rev=247618&r1=247617&r2=247618&view=diff</u></font></a><font size="3" face="serif"><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp Mon Sep 14 16:27:36 2015<br>
@@ -872,7 +872,7 @@ namespace Lifetime {<br>
<br>
 namespace Bitfields {<br>
   struct A {<br>
-    bool b : 3;<br>
+    bool b : 1;<br>
     int n : 4;<br>
     unsigned u : 5;<br>
   };<br>
<br>
Modified: cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp<br>
URL: </font><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp?rev=247618&r1=247617&r2=247618&view=diff" target="_blank"><font size="3" color="#0000FF" face="serif"><u>http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp?rev=247618&r1=247617&r2=247618&view=diff</u></font></a><font size="3" face="serif"><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp Mon Sep 14 16:27:36 2015<br>
@@ -1,9 +1,10 @@<br>
 // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fdump-record-layouts -fsyntax-only -mms-bitfields -verify %s 2>&1<br>
<br>
 struct A {<br>
-  char a : 9; // expected-error{{size of bit-field 'a' (9 bits) exceeds size of its type (8 bits)}}<br>
-  int b : 33; // expected-error{{size of bit-field 'b' (33 bits) exceeds size of its type (32 bits)}}<br>
-  bool c : 9; // expected-error{{size of bit-field 'c' (9 bits) exceeds size of its type (8 bits)}}<br>
+  char a : 9; // expected-error{{width of bit-field 'a' (9 bits) exceeds width of its type (8 bits)}}<br>
+  int b : 33; // expected-error{{width of bit-field 'b' (33 bits) exceeds width of its type (32 bits)}}<br>
+  bool c : 9; // expected-error{{width of bit-field 'c' (9 bits) exceeds width of its type (1 bit)}}<br>
+  bool d : 3; // expected-error{{width of bit-field 'd' (3 bits) exceeds width of its type (1 bit)}}<br>
 };<br>
<br>
 int a[sizeof(A) == 1 ? 1 : -1];<br>
<br>
Modified: cfe/trunk/test/SemaObjC/class-bitfield.m<br>
URL: </font><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/class-bitfield.m?rev=247618&r1=247617&r2=247618&view=diff" target="_blank"><font size="3" color="#0000FF" face="serif"><u>http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/class-bitfield.m?rev=247618&r1=247617&r2=247618&view=diff</u></font></a><font size="3" face="serif"><br>
==============================================================================<br>
--- cfe/trunk/test/SemaObjC/class-bitfield.m (original)<br>
+++ cfe/trunk/test/SemaObjC/class-bitfield.m Mon Sep 14 16:27:36 2015<br>
@@ -5,7 +5,7 @@<br>
   int a : -1; // expected-error{{bit-field 'a' has negative width}}<br>
<br>
   // rdar://6081627<br>
-  int b : 33; // expected-error{{size of bit-field 'b' (33 bits) exceeds size of its type (32 bits)}}<br>
+  int b : 33; // expected-error{{width of bit-field 'b' (33 bits) exceeds width of its type (32 bits)}}<br>
<br>
   int c : (1 + 0.25); // expected-error{{expression is not an integer constant expression}}<br>
   int d : (int)(1 + 0.25);<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list</font><font size="3" color="#0000FF" face="serif"><u><br>
</u></font><a href="mailto:cfe-commits@lists.llvm.org" target="_blank"><font size="3" color="#0000FF" face="serif"><u>cfe-commits@lists.llvm.org</u></font></a><font size="3" color="#0000FF" face="serif"><u><br>
</u></font><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" target="_blank"><font size="3" color="#0000FF" face="serif"><u>http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</u></font></a></ul>
<br>
<font size="3" face="serif"><br>
_______________________________________________<br>
cfe-commits mailing list</font><font size="3" color="#0000FF" face="serif"><u><br>
</u></font><a href="mailto:cfe-commits@lists.llvm.org" target="_blank"><font size="3" color="#0000FF" face="serif"><u>cfe-commits@lists.llvm.org</u></font></a><font size="3" color="#0000FF" face="serif"><u><br>
</u></font><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" target="_blank"><font size="3" color="#0000FF" face="serif"><u>http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</u></font></a><font size="3" face="serif"><br>
</font></ul>
</ul>
<br>
</div></div><p></p></div>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div></div></div><br></div></div>
</blockquote></div></div></div><br></div></div>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div></div></div><br></div></div>
</blockquote></div></div></div><br></div></div>
</blockquote></div></div></div><br></div></div>
</blockquote></div></div></div><br></div></div>
</blockquote></div></div></div><br></div></div>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div></div></div><span><font color="#888888">-- <br><div><div dir="ltr">Alexey Samsonov<br><a href="mailto:vonosmas@gmail.com" target="_blank">vonosmas@gmail.com</a></div></div>
</font></span></div>
</blockquote></div><br></div></div>