]> granicus.if.org Git - clang/commitdiff
[AST] Update/correct the static_asserts for the bit-fields in Type
authorBruno Ricci <riccibrun@gmail.com>
Mon, 13 Aug 2018 16:40:57 +0000 (16:40 +0000)
committerBruno Ricci <riccibrun@gmail.com>
Mon, 13 Aug 2018 16:40:57 +0000 (16:40 +0000)
The current static_assert only checks that ObjCObjectTypeBitfields
fits into an unsigned. However it turns out that FunctionTypeBitfields
do not currently fits into an unsigned. Therefore the anonymous
union containing the bit-fields always use 8 bytes instead of 4.

This patch removes the lone misguided static_assert and systematically
checks the size of each bit-field.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D50630

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

include/clang/AST/Type.h

index cda84b19fa9bbd72cb3e00442ebb46afedd67100..93dafc47dd0172045473c8fa0bcce35a7bcb5baa 100644 (file)
@@ -1539,8 +1539,6 @@ protected:
     unsigned IsKindOf : 1;
   };
 
-  static_assert(NumTypeBits + 7 + 6 + 1 <= 32, "Does not fit in an unsigned");
-
   class ReferenceTypeBitfields {
     friend class ReferenceType;
 
@@ -1619,6 +1617,27 @@ protected:
     ReferenceTypeBitfields ReferenceTypeBits;
     TypeWithKeywordBitfields TypeWithKeywordBits;
     VectorTypeBitfields VectorTypeBits;
+
+    static_assert(sizeof(TypeBitfields) <= 8,
+                  "TypeBitfields is larger than 8 bytes!");
+    static_assert(sizeof(ArrayTypeBitfields) <= 8,
+                  "ArrayTypeBitfields is larger than 8 bytes!");
+    static_assert(sizeof(AttributedTypeBitfields) <= 8,
+                  "AttributedTypeBitfields is larger than 8 bytes!");
+    static_assert(sizeof(AutoTypeBitfields) <= 8,
+                  "AutoTypeBitfields is larger than 8 bytes!");
+    static_assert(sizeof(BuiltinTypeBitfields) <= 8,
+                  "BuiltinTypeBitfields is larger than 8 bytes!");
+    static_assert(sizeof(FunctionTypeBitfields) <= 8,
+                  "FunctionTypeBitfields is larger than 8 bytes!");
+    static_assert(sizeof(ObjCObjectTypeBitfields) <= 8,
+                  "ObjCObjectTypeBitfields is larger than 8 bytes!");
+    static_assert(sizeof(ReferenceTypeBitfields) <= 8,
+                  "ReferenceTypeBitfields is larger than 8 bytes!");
+    static_assert(sizeof(TypeWithKeywordBitfields) <= 8,
+                  "TypeWithKeywordBitfields is larger than 8 bytes!");
+    static_assert(sizeof(VectorTypeBitfields) <= 8,
+                  "VectorTypeBitfields is larger than 8 bytes!");
   };
 
 private: