Skip to content

Commit

Permalink
[Clang] Limit FunctionTypeExtraBitfields::NumExceptionType to 16 bits.
Browse files Browse the repository at this point in the history
In https://reviews.llvm.org/D127762#4102578 @erichkeane suggested to
limit size of this field to 16bits, such that the field that encodes the
SME attributes for a function fall within the alignment of the struct for
32bit platforms.

Standard implimits defines the minimum handlers per try block to 256,
which suggests that 16bits should be more than sufficient for most
programs. Erich also pointed out that exception specs are being
deprecated and are rarely used, so hopefully this change is safe to make.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D152140
  • Loading branch information
sdesmalen-arm committed Jun 6, 2023
1 parent b2817d2 commit 7013a75
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/AST/Type.h
Expand Up @@ -3953,7 +3953,7 @@ class FunctionType : public Type {
/// 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:
Expand Down
5 changes: 4 additions & 1 deletion clang/lib/AST/Type.cpp
Expand Up @@ -3371,7 +3371,10 @@ FunctionProtoType::FunctionProtoType(QualType result, ArrayRef<QualType> params,
// Fill in the exception type array if present.
if (getExceptionSpecType() == EST_Dynamic) {
auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
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 =
Expand Down

0 comments on commit 7013a75

Please sign in to comment.