]> granicus.if.org Git - clang/commitdiff
[MS ABI] Overwide bool bitfields should be permitted
authorDavid Majnemer <david.majnemer@gmail.com>
Tue, 15 Sep 2015 01:00:55 +0000 (01:00 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Tue, 15 Sep 2015 01:00:55 +0000 (01:00 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@247651 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/ms_wide_bitfield.cpp

index 8501bc5b2242cbfb2d465ee6ee3c40c51f5812f7..9c641ddbb65d93fb9e6824607e0fb8123182e89f 100644 (file)
@@ -12626,11 +12626,14 @@ ExprResult Sema::VerifyBitField(SourceLocation FieldLoc,
   }
 
   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;
index 2b11579a5cd2ff67178d30f82310b32b2bb6783d..022d604ec1199f95d4ec8c777429c4407cad6358 100644 (file)
@@ -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];