diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -3949,11 +3949,20 @@ /// A simple holder for various uncommon bits which do not fit in /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the /// alignment of subsequent objects in TrailingObjects. - struct alignas(void *) FunctionTypeExtraBitfields { + class alignas(void *) FunctionTypeExtraBitfields { /// The number of types in the exception specification. /// A whole unsigned is not needed here and according to /// [implimits] 8 bits would be enough here. - unsigned NumExceptionType = 0; + unsigned NumExceptionType : 16; + + public: + FunctionTypeExtraBitfields() : NumExceptionType(0) {} + + void setNumExceptionType(unsigned N) { + assert(N < 65536 && "Not enough bits to encode exceptions"); + NumExceptionType = N; + } + unsigned getNumExceptionType() const { return NumExceptionType; } }; protected: @@ -4329,7 +4338,7 @@ unsigned getNumExceptions() const { return getExceptionSpecType() == EST_Dynamic ? getTrailingObjects() - ->NumExceptionType + ->getNumExceptionType() : 0; } diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -3371,7 +3371,7 @@ // Fill in the exception type array if present. if (getExceptionSpecType() == EST_Dynamic) { auto &ExtraBits = *getTrailingObjects(); - ExtraBits.NumExceptionType = epi.ExceptionSpec.Exceptions.size(); + ExtraBits.setNumExceptionType(epi.ExceptionSpec.Exceptions.size()); assert(hasExtraBitfields() && "missing trailing extra bitfields!"); auto *exnSlot =