diff options
author | David Majnemer <david.majnemer@gmail.com> | 2015-09-15 02:36:41 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2015-09-15 02:36:41 +0000 |
commit | 1cbe80408d1e24126b4eb1ee19466fd23f9ec255 (patch) | |
tree | 84c474cd8c4f8a1f0e90eacd79e3f3cfbb6f94b6 /clang/lib/Sema/SemaDecl.cpp | |
parent | bde7e4563efdf8a0ef6504c44d94915bf0481d32 (diff) | |
download | bcm5719-llvm-1cbe80408d1e24126b4eb1ee19466fd23f9ec255.tar.gz bcm5719-llvm-1cbe80408d1e24126b4eb1ee19466fd23f9ec255.zip |
[MS ABI] Restore our warning for overwide bitfields using the MS ABI
This restores a diagnostic lost in r247651.
llvm-svn: 247659
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 9c641ddbb65..2ed4a61aaba 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -12626,29 +12626,36 @@ ExprResult Sema::VerifyBitField(SourceLocation FieldLoc, } if (!FieldTy->isDependentType()) { - bool UseMSBitfieldSemantics = - IsMsStruct || Context.getTargetInfo().getCXXABI().isMicrosoft(); - bool UseStorageSize = getLangOpts().CPlusPlus && UseMSBitfieldSemantics; - uint64_t TypeWidth = UseStorageSize ? Context.getTypeSize(FieldTy) - : Context.getIntWidth(FieldTy); - if (Value.ugt(TypeWidth)) { - if (!getLangOpts().CPlusPlus || UseMSBitfieldSemantics) { - if (FieldName) - return Diag(FieldLoc, diag::err_bitfield_width_exceeds_type_width) - << FieldName << (unsigned)Value.getZExtValue() - << (unsigned)TypeWidth; - - return Diag(FieldLoc, diag::err_anon_bitfield_width_exceeds_type_width) - << (unsigned)Value.getZExtValue() << (unsigned)TypeWidth; - } - + uint64_t TypeStorageSize = Context.getTypeSize(FieldTy); + uint64_t TypeWidth = Context.getIntWidth(FieldTy); + bool BitfieldIsOverwide = Value.ugt(TypeWidth); + + // Over-wide bitfields are an error in C or when using the MSVC bitfield + // ABI. + bool CStdConstraintViolation = + BitfieldIsOverwide && !getLangOpts().CPlusPlus; + bool MSBitfieldViolation = + Value.ugt(TypeStorageSize) && + (IsMsStruct || Context.getTargetInfo().getCXXABI().isMicrosoft()); + if (CStdConstraintViolation || MSBitfieldViolation) { + unsigned DiagWidth = + CStdConstraintViolation ? TypeWidth : TypeStorageSize; + if (FieldName) + return Diag(FieldLoc, diag::err_bitfield_width_exceeds_type_width) + << FieldName << (unsigned)Value.getZExtValue() << DiagWidth; + + return Diag(FieldLoc, diag::err_anon_bitfield_width_exceeds_type_width) + << (unsigned)Value.getZExtValue() << DiagWidth; + } + + if (BitfieldIsOverwide) { if (FieldName) Diag(FieldLoc, diag::warn_bitfield_width_exceeds_type_width) - << FieldName << (unsigned)Value.getZExtValue() - << (unsigned)TypeWidth; + << FieldName << (unsigned)Value.getZExtValue() + << (unsigned)TypeWidth; else Diag(FieldLoc, diag::warn_anon_bitfield_width_exceeds_type_width) - << (unsigned)Value.getZExtValue() << (unsigned)TypeWidth; + << (unsigned)Value.getZExtValue() << (unsigned)TypeWidth; } } |