diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-09-23 22:07:44 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-09-23 22:07:44 +0000 |
commit | d209967a68dc11e255c9794d77340dce080a84e6 (patch) | |
tree | 127ddce4ffe1463e4a5e6ae9ab776f08c0e478dc | |
parent | d93aa1060a66d4d58b72918cc5c1a9ff762e81ef (diff) | |
download | bcm5719-llvm-d209967a68dc11e255c9794d77340dce080a84e6.tar.gz bcm5719-llvm-d209967a68dc11e255c9794d77340dce080a84e6.zip |
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.
llvm-svn: 248435
-rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 7 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 11 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/warn-padded-packed.cpp | 2 | ||||
-rw-r--r-- | clang/test/SemaCXX/constant-expression-cxx11.cpp | 2 | ||||
-rw-r--r-- | clang/test/SemaCXX/ms_wide_bitfield.cpp | 8 |
5 files changed, 18 insertions, 12 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 5e4e711492d..5b03968609e 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -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">; diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 9195a060dbf..592f393d464 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -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() diff --git a/clang/test/CodeGenCXX/warn-padded-packed.cpp b/clang/test/CodeGenCXX/warn-padded-packed.cpp index f15373e5b5e..f2af60865e0 100644 --- a/clang/test/CodeGenCXX/warn-padded-packed.cpp +++ b/clang/test/CodeGenCXX/warn-padded-packed.cpp @@ -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. diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp index ead69faa918..794932df409 100644 --- a/clang/test/SemaCXX/constant-expression-cxx11.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp @@ -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}} }; diff --git a/clang/test/SemaCXX/ms_wide_bitfield.cpp b/clang/test/SemaCXX/ms_wide_bitfield.cpp index 3e6a16579c8..b634e78c70c 100644 --- a/clang/test/SemaCXX/ms_wide_bitfield.cpp +++ b/clang/test/SemaCXX/ms_wide_bitfield.cpp @@ -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]; |