[clang] [NFC] Refactor ConstantArrayType size storage (PR #85716)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 25 14:58:35 PDT 2024


================
@@ -3182,34 +3182,100 @@ class ArrayType : public Type, public llvm::FoldingSetNode {
 /// For example, the canonical type for 'int A[4 + 4*100]' is a
 /// ConstantArrayType where the element type is 'int' and the size is 404.
 class ConstantArrayType final
-    : public ArrayType,
-      private llvm::TrailingObjects<ConstantArrayType, const Expr *> {
+    : public ArrayType {
   friend class ASTContext; // ASTContext creates these.
-  friend TrailingObjects;
 
-  llvm::APInt Size; // Allows us to unique the type.
+  struct ExternalSize {
+    ExternalSize(const llvm::APInt &Sz, const Expr *SE)
+        : Size(Sz), SizeExpr(SE) {}
+    llvm::APInt Size; // Allows us to unique the type.
+    const Expr *SizeExpr;
+  };
+  struct InlineSize {
+    InlineSize(uint64_t TSz, uint64_t Sz) : ByteWidth(TSz), Size(Sz) {}
+    uint64_t ByteWidth : 4;
----------------
efriedma-quic wrote:

Do we actually need to store the ByteWidth here?  It's always just Target->getMaxPointerWidth().  Granted, it might be inconvenient to change the API... in which case, I guess we can store it here.

Maybe consider sticking the ByteWidth in ConstantArrayTypeBitfields; there should be a few spare bits available there.

https://github.com/llvm/llvm-project/pull/85716


More information about the cfe-commits mailing list