aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-12-12 04:56:04 +0000
committerChris Lattner <sabre@nondot.org>2008-12-12 04:56:04 +0000
commitcd08707a960842223e4af9ab82c729ba179290c0 (patch)
treefe47e4483c81beac06ce48fe0d59a8e5b6b402aa /lib/Sema/SemaDecl.cpp
parentc9467cf4cff1bb09f38667b871268c47ed823f97 (diff)
Implement rdar://6138816 - [sema] named bitfields cannot have 0 width
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60920 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r--lib/Sema/SemaDecl.cpp21
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 43964f7cca..29d636fabd 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -2748,26 +2748,25 @@ static QualType TryToFixInvalidVariablyModifiedType(QualType T,
}
bool Sema::VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
- QualType FieldTy, const Expr *BitWidth)
-{
+ QualType FieldTy, const Expr *BitWidth) {
// FIXME: 6.7.2.1p4 - verify the field type.
llvm::APSInt Value;
if (VerifyIntegerConstantExpression(BitWidth, &Value))
return true;
- if (Value.isNegative()) {
- Diag(FieldLoc, diag::err_bitfield_has_negative_width) << FieldName;
- return true;
- }
+ // Zero-width bitfield is ok for anonymous field.
+ if (Value == 0 && FieldName)
+ return Diag(FieldLoc, diag::err_bitfield_has_zero_width) << FieldName;
+
+ if (Value.isNegative())
+ return Diag(FieldLoc, diag::err_bitfield_has_negative_width) << FieldName;
uint64_t TypeSize = Context.getTypeSize(FieldTy);
// FIXME: We won't need the 0 size once we check that the field type is valid.
- if (TypeSize && Value.getZExtValue() > TypeSize) {
- Diag(FieldLoc, diag::err_bitfield_width_exceeds_type_size) <<
- FieldName << (unsigned)TypeSize;
- return true;
- }
+ if (TypeSize && Value.getZExtValue() > TypeSize)
+ return Diag(FieldLoc, diag::err_bitfield_width_exceeds_type_size)
+ << FieldName << (unsigned)TypeSize;
return false;
}