eopXD created this revision. eopXD added reviewers: craig.topper, aaron.ballman, erichkeane. Herald added a project: All. eopXD requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Recent expansion D152070 <https://reviews.llvm.org/D152070> exceeds the limit and I had a hard time triaging the bug because the overflow just creates unexpected behaviors within the compiler. This patch adds a static assertionto keep an eye for overflows when we expand more types in the future. Repository: rG LLVM Github Monorepo 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 @@ -1539,6 +1539,8 @@ GNUAutoType }; +static const unsigned NumOfBuiltinTypeBits = 8; + /// The base class of the type hierarchy. /// /// A central concept with types is that each type always has a canonical @@ -1649,7 +1651,7 @@ unsigned : NumTypeBits; /// The kind (BuiltinType::Kind) of builtin type this is. - unsigned Kind : 8; + unsigned Kind : NumOfBuiltinTypeBits; }; /// FunctionTypeBitfields store various bits belonging to FunctionProtoType. @@ -2677,6 +2679,9 @@ : Type(Builtin, QualType(), K == Dependent ? TypeDependence::DependentInstantiation : TypeDependence::None) { + static_assert(Kind::LastKind < (1 << NumOfBuiltinTypeBits) && + "Defined builtin type exceeds the allocated space for serial " + "numbering"); BuiltinTypeBits.Kind = K; }
Index: clang/include/clang/AST/Type.h =================================================================== --- clang/include/clang/AST/Type.h +++ clang/include/clang/AST/Type.h @@ -1539,6 +1539,8 @@ GNUAutoType }; +static const unsigned NumOfBuiltinTypeBits = 8; + /// The base class of the type hierarchy. /// /// A central concept with types is that each type always has a canonical @@ -1649,7 +1651,7 @@ unsigned : NumTypeBits; /// The kind (BuiltinType::Kind) of builtin type this is. - unsigned Kind : 8; + unsigned Kind : NumOfBuiltinTypeBits; }; /// FunctionTypeBitfields store various bits belonging to FunctionProtoType. @@ -2677,6 +2679,9 @@ : Type(Builtin, QualType(), K == Dependent ? TypeDependence::DependentInstantiation : TypeDependence::None) { + static_assert(Kind::LastKind < (1 << NumOfBuiltinTypeBits) && + "Defined builtin type exceeds the allocated space for serial " + "numbering"); BuiltinTypeBits.Kind = K; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits