Author: rnk Date: Wed Jul 17 15:46:03 2013 New Revision: 186536 URL: http://llvm.org/viewvc/llvm-project?rev=186536&view=rev Log: MS wide bitfield error check in Sema
cl.exe treats wide bitfields as an error. This patch causes them to be an error if IsMsStruct is true, as it is in straight C. Patch by Warren Hunt! Reviewers: eli.friedman Differential Revision: http://llvm-reviews.chandlerc.com/D1125 Added: cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp Modified: cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/Sema/SemaDecl.cpp Modified: cfe/trunk/include/clang/Sema/Sema.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=186536&r1=186535&r2=186536&view=diff ============================================================================== --- cfe/trunk/include/clang/Sema/Sema.h (original) +++ cfe/trunk/include/clang/Sema/Sema.h Wed Jul 17 15:46:03 2013 @@ -7286,8 +7286,8 @@ public: /// Returns false on success. /// Can optionally return whether the bit-field is of width 0 ExprResult VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, - QualType FieldTy, Expr *BitWidth, - bool *ZeroWidth = 0); + QualType FieldTy, bool IsMsStruct, + Expr *BitWidth, bool *ZeroWidth = 0); enum CUDAFunctionTarget { CFT_Device, Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=186536&r1=186535&r2=186536&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Jul 17 15:46:03 2013 @@ -10575,8 +10575,8 @@ void Sema::ActOnTagDefinitionError(Scope // Note that FieldName may be null for anonymous bitfields. ExprResult Sema::VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, - QualType FieldTy, Expr *BitWidth, - bool *ZeroWidth) { + QualType FieldTy, bool IsMsStruct, + Expr *BitWidth, bool *ZeroWidth) { // Default to true; that shouldn't confuse checks for emptiness if (ZeroWidth) *ZeroWidth = true; @@ -10625,7 +10625,7 @@ ExprResult Sema::VerifyBitField(SourceLo if (!FieldTy->isDependentType()) { uint64_t TypeSize = Context.getTypeSize(FieldTy); if (Value.getZExtValue() > TypeSize) { - if (!getLangOpts().CPlusPlus) { + if (!getLangOpts().CPlusPlus || IsMsStruct) { if (FieldName) return Diag(FieldLoc, diag::err_bitfield_width_exceeds_type_size) << FieldName << (unsigned)Value.getZExtValue() @@ -10843,7 +10843,8 @@ FieldDecl *Sema::CheckFieldDecl(Declarat bool ZeroWidth = false; // If this is declared as a bit-field, check the bit-field. if (!InvalidDecl && BitWidth) { - BitWidth = VerifyBitField(Loc, II, T, BitWidth, &ZeroWidth).take(); + BitWidth = VerifyBitField(Loc, II, T, Record->isMsStruct(Context), BitWidth, + &ZeroWidth).take(); if (!BitWidth) { InvalidDecl = true; BitWidth = 0; @@ -11024,7 +11025,8 @@ Decl *Sema::ActOnIvar(Scope *S, if (BitWidth) { // 6.7.2.1p3, 6.7.2.1p4 - BitWidth = VerifyBitField(Loc, II, T, BitWidth).take(); + BitWidth = + VerifyBitField(Loc, II, T, /*IsMsStruct=*/false, BitWidth).take(); if (!BitWidth) D.setInvalidType(); } else { Added: cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp?rev=186536&view=auto ============================================================================== --- cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp (added) +++ cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp Wed Jul 17 15:46:03 2013 @@ -0,0 +1,9 @@ +// 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{{size of bit-field 'a' (9 bits) exceeds size of its type (8 bits)}} + int b : 33; // expected-error{{size of bit-field 'b' (33 bits) exceeds size of its type (32 bits)}} + bool c : 9; // expected-error{{size of bit-field 'c' (9 bits) exceeds size of its type (8 bits)}} +}; + +int a[sizeof(A) == 1 ? 1 : -1]; _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
