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 @@ -3953,7 +3953,7 @@ /// 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; + uint16_t NumExceptionType = 0; }; protected: 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,10 @@ // Fill in the exception type array if present. if (getExceptionSpecType() == EST_Dynamic) { auto &ExtraBits = *getTrailingObjects(); - ExtraBits.NumExceptionType = epi.ExceptionSpec.Exceptions.size(); + size_t NumExceptions = epi.ExceptionSpec.Exceptions.size(); + assert(NumExceptions <= UINT16_MAX && + "Not enough bits to encode exceptions"); + ExtraBits.NumExceptionType = NumExceptions; assert(hasExtraBitfields() && "missing trailing extra bitfields!"); auto *exnSlot =