sdesmalen created this revision.
sdesmalen added reviewers: erichkeane, aaron.ballman.
Herald added a project: All.
sdesmalen requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152140

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


Index: clang/lib/AST/Type.cpp
===================================================================
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -3371,7 +3371,7 @@
   // Fill in the exception type array if present.
   if (getExceptionSpecType() == EST_Dynamic) {
     auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
-    ExtraBits.NumExceptionType = epi.ExceptionSpec.Exceptions.size();
+    ExtraBits.setNumExceptionType(epi.ExceptionSpec.Exceptions.size());
 
     assert(hasExtraBitfields() && "missing trailing extra bitfields!");
     auto *exnSlot =
Index: clang/include/clang/AST/Type.h
===================================================================
--- clang/include/clang/AST/Type.h
+++ 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<FunctionTypeExtraBitfields>()
-                     ->NumExceptionType
+                     ->getNumExceptionType()
                : 0;
   }
 


Index: clang/lib/AST/Type.cpp
===================================================================
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -3371,7 +3371,7 @@
   // Fill in the exception type array if present.
   if (getExceptionSpecType() == EST_Dynamic) {
     auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
-    ExtraBits.NumExceptionType = epi.ExceptionSpec.Exceptions.size();
+    ExtraBits.setNumExceptionType(epi.ExceptionSpec.Exceptions.size());
 
     assert(hasExtraBitfields() && "missing trailing extra bitfields!");
     auto *exnSlot =
Index: clang/include/clang/AST/Type.h
===================================================================
--- clang/include/clang/AST/Type.h
+++ 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<FunctionTypeExtraBitfields>()
-                     ->NumExceptionType
+                     ->getNumExceptionType()
                : 0;
   }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to