r248435 - Remove warning on over-wide bit-field of boolean type; there's no risk that

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 23 15:07:45 PDT 2015


Author: rsmith
Date: Wed Sep 23 17:07:44 2015
New Revision: 248435

URL: http://llvm.org/viewvc/llvm-project?rev=248435&view=rev
Log:
Remove warning on over-wide bit-field of boolean type; there's no risk that
someone thought all the bits would be value bits in this case.

Also fix the wording of the warning -- it claimed that the width of 'bool' is
8, which is not correct; the width is 1 bit, whereas the size is 8 bits in our
implementation.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CodeGenCXX/warn-padded-packed.cpp
    cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
    cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=248435&r1=248434&r2=248435&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep 23 17:07:44 2015
@@ -4320,10 +4320,11 @@ def err_anon_bitfield_has_negative_width
   "anonymous bit-field has negative width (%0)">;
 def err_bitfield_has_zero_width : Error<"named bit-field %0 has zero width">;
 def err_bitfield_width_exceeds_type_width : Error<
-  "width of bit-field %0 (%1 bits) exceeds width of its type (%2 bit%s2)">;
+  "width of bit-field %0 (%1 bits) exceeds %select{width|size}2 "
+  "of its type (%3 bit%s3)">;
 def err_anon_bitfield_width_exceeds_type_width : Error<
-  "width of anonymous bit-field (%0 bits) exceeds width of its type "
-  "(%1 bit%s1)">;
+  "width of anonymous bit-field (%0 bits) exceeds %select{width|size}1 "
+  "of its type (%2 bit%s2)">;
 def err_incorrect_number_of_vector_initializers : Error<
   "number of elements must be either one or match the size of the vector">;
 

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=248435&r1=248434&r2=248435&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Sep 23 17:07:44 2015
@@ -12660,13 +12660,18 @@ ExprResult Sema::VerifyBitField(SourceLo
           CStdConstraintViolation ? TypeWidth : TypeStorageSize;
       if (FieldName)
         return Diag(FieldLoc, diag::err_bitfield_width_exceeds_type_width)
-               << FieldName << (unsigned)Value.getZExtValue() << DiagWidth;
+               << FieldName << (unsigned)Value.getZExtValue()
+               << !CStdConstraintViolation << DiagWidth;
 
       return Diag(FieldLoc, diag::err_anon_bitfield_width_exceeds_type_width)
-             << (unsigned)Value.getZExtValue() << DiagWidth;
+             << (unsigned)Value.getZExtValue() << !CStdConstraintViolation
+             << DiagWidth;
     }
 
-    if (BitfieldIsOverwide) {
+    // Warn on types where the user might conceivably expect to get all
+    // specified bits as value bits: that's all integral types other than
+    // 'bool'.
+    if (BitfieldIsOverwide && !FieldTy->isBooleanType()) {
       if (FieldName)
         Diag(FieldLoc, diag::warn_bitfield_width_exceeds_type_width)
             << FieldName << (unsigned)Value.getZExtValue()

Modified: cfe/trunk/test/CodeGenCXX/warn-padded-packed.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/warn-padded-packed.cpp?rev=248435&r1=248434&r2=248435&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/warn-padded-packed.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/warn-padded-packed.cpp Wed Sep 23 17:07:44 2015
@@ -69,7 +69,7 @@ struct S12 {
 
 struct S13 { // expected-warning {{padding size of 'S13' with 6 bits to alignment boundary}}
   char c;
-  bool b : 10; // expected-warning {{width of bit-field 'b' (10 bits) exceeds the width of its type}}
+  bool b : 10;
 };
 
 // The warnings are emitted when the layout of the structs is computed, so we have to use them.

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=248435&r1=248434&r2=248435&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Wed Sep 23 17:07:44 2015
@@ -1801,7 +1801,7 @@ namespace Bitfields {
     bool b : 1;
     unsigned u : 5;
     int n : 5;
-    bool b2 : 3; // expected-warning {{exceeds the width of its type}}
+    bool b2 : 3;
     unsigned u2 : 74; // expected-warning {{exceeds the width of its type}}
     int n2 : 81; // expected-warning {{exceeds the width of its type}}
   };

Modified: cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp?rev=248435&r1=248434&r2=248435&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp (original)
+++ cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp Wed Sep 23 17:07:44 2015
@@ -1,10 +1,10 @@
 // RUN: %clang_cc1 -fno-rtti -emit-llvm-only -triple i686-pc-win32 -fdump-record-layouts -fsyntax-only -mms-bitfields -verify %s 2>&1
 
 struct A {
-  char a : 9; // expected-error{{width of bit-field 'a' (9 bits) exceeds width of its type (8 bits)}}
-  int b : 33; // expected-error{{width of bit-field 'b' (33 bits) exceeds width of its type (32 bits)}}
-  bool c : 9; // expected-error{{width of bit-field 'c' (9 bits) exceeds width of its type (8 bits)}}
-  bool d : 3; // expected-warning{{width of bit-field 'd' (3 bits) exceeds the width of its type; value will be truncated to 1 bit}}
+  char a : 9; // expected-error{{width of bit-field 'a' (9 bits) exceeds size of its type (8 bits)}}
+  int b : 33; // expected-error{{width of bit-field 'b' (33 bits) exceeds size of its type (32 bits)}}
+  bool c : 9; // expected-error{{width of bit-field 'c' (9 bits) exceeds size of its type (8 bits)}}
+  bool d : 3;
 };
 
 int a[sizeof(A) == 1 ? 1 : -1];




More information about the cfe-commits mailing list