[clang] 7013a75 - [Clang] Limit FunctionTypeExtraBitfields::NumExceptionType to 16 bits.

Sander de Smalen via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 6 05:10:38 PDT 2023


Author: Sander de Smalen
Date: 2023-06-06T12:07:43Z
New Revision: 7013a751f170d829b35e7bb153d3334d144d5d54

URL: https://github.com/llvm/llvm-project/commit/7013a751f170d829b35e7bb153d3334d144d5d54
DIFF: https://github.com/llvm/llvm-project/commit/7013a751f170d829b35e7bb153d3334d144d5d54.diff

LOG: [Clang] Limit FunctionTypeExtraBitfields::NumExceptionType to 16 bits.

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

Added: 
    

Modified: 
    clang/include/clang/AST/Type.h
    clang/lib/AST/Type.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index e60438a2c0752..87e69bf61a8e0 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -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:

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 63a5159ba7035..82ac4aef0b721 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -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 =


        


More information about the cfe-commits mailing list