Author: majnemer
Date: Mon Sep 14 20:00:55 2015
New Revision: 247651
URL: http://llvm.org/viewvc/llvm-project?rev=247651&view=rev
Log:
[MS ABI] Overwide bool bitfields should be permitted
Overwide bool bitfields have eight bits of storage size, make sure we
take the padding into account when determining whether or not they are
problematic.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=247651&r1=247650&r2=247651&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Sep 14 20:00:55 2015
@@ -12626,11 +12626,14 @@ ExprResult Sema::VerifyBitField(SourceLo
}
if (!FieldTy->isDependentType()) {
- uint64_t TypeWidth = Context.getIntWidth(FieldTy);
+ 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 || IsMsStruct ||
- Context.getTargetInfo().getCXXABI().isMicrosoft()) {
- if (FieldName)
+ if (!getLangOpts().CPlusPlus || UseMSBitfieldSemantics) {
+ if (FieldName)
return Diag(FieldLoc, diag::err_bitfield_width_exceeds_type_width)
<< FieldName << (unsigned)Value.getZExtValue()
<< (unsigned)TypeWidth;
Modified: cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp?rev=247651&r1=247650&r2=247651&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp (original)
+++ cfe/trunk/test/SemaCXX/ms_wide_bitfield.cpp Mon Sep 14 20:00:55 2015
@@ -3,8 +3,8 @@
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 (1 bit)}}
- bool d : 3; // expected-error{{width of bit-field 'd' (3 bits) exceeds width
of its type (1 bit)}}
+ bool c : 9; // expected-error{{width of bit-field 'c' (9 bits) exceeds width
of its type (8 bits)}}
+ bool d : 3;
};
int a[sizeof(A) == 1 ? 1 : -1];
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits