]> granicus.if.org Git - clang/commitdiff
Remove warning on over-wide bit-field of boolean type; there's no risk that
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 23 Sep 2015 22:07:44 +0000 (22:07 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 23 Sep 2015 22:07:44 +0000 (22:07 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248435 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 5e4e711492df86da03b8f9459dbd4fbd95887896..5b03968609effb01f2d38716cd17930c2c7b69e0 100644 (file)
@@ -4320,10 +4320,11 @@ def err_anon_bitfield_has_negative_width : Error<
   "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">;
 
index 9195a060dbfd98427c99192a802c108d5df094e1..592f393d464c5596190d6d0595cbc6803f3fa69e 100644 (file)
@@ -12660,13 +12660,18 @@ ExprResult Sema::VerifyBitField(SourceLocation FieldLoc,
           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()
index f15373e5b5e9f2dbba6f4be264f9809a01eeff54..f2af60865e05a5d250eb5859ebc0e009399224d2 100644 (file)
@@ -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.
index ead69faa9188b2eeec84b41f25e133bfb2bde723..794932df40956d7315a2ee75cba95eaa5aa0400d 100644 (file)
@@ -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}}
   };
index 3e6a16579c8e7371e9f788be7f39071aba04e100..b634e78c70ce54e2ef2fba61361c0cb4c8313f77 100644 (file)
@@ -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];