[PATCH] D152429: [Clang][Type] Add static assertion to guard future expansion for BuiltinType numbering

Yueh-Ting (eop) Chen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 8 09:32:13 PDT 2023


eopXD updated this revision to Diff 529634.
eopXD added a comment.

Address comment from Aaron.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152429/new/

https://reviews.llvm.org/D152429

Files:
  clang/include/clang/AST/Type.h


Index: clang/include/clang/AST/Type.h
===================================================================
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -1649,7 +1649,8 @@
     unsigned : NumTypeBits;
 
     /// The kind (BuiltinType::Kind) of builtin type this is.
-    unsigned Kind : 8;
+    static constexpr unsigned NumOfBuiltinTypeBits = 8;
+    unsigned Kind : NumOfBuiltinTypeBits;
   };
 
   /// FunctionTypeBitfields store various bits belonging to FunctionProtoType.
@@ -2677,6 +2678,10 @@
       : Type(Builtin, QualType(),
              K == Dependent ? TypeDependence::DependentInstantiation
                             : TypeDependence::None) {
+    static_assert(Kind::LastKind <
+                      (1 << BuiltinTypeBitfields::NumOfBuiltinTypeBits) &&
+                  "Defined builtin type exceeds the allocated space for serial "
+                  "numbering");
     BuiltinTypeBits.Kind = K;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152429.529634.patch
Type: text/x-patch
Size: 952 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230608/8ccb9f1d/attachment.bin>


More information about the cfe-commits mailing list