[clang] [CIR][NFC] Factor StructType and UnionType into CIR_RecordTypeBase (PR #248692)

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 4 15:19:42 PST 2026


https://github.com/bcardosolopes updated https://github.com/llvm/llvm-project/pull/248692

>From 3d2f9e012bca2fc92d69df472d7e3d3c2815f9bc Mon Sep 17 00:00:00 2001
From: Bruno Cardoso Lopes <bruno.cardoso at gmail.com>
Date: Wed, 2 Dec 2026 13:32:49 -0800
Subject: [PATCH 1/3] [CIR][NFC] Factor StructType and UnionType into
 CIR_RecordTypeBase

StructType and UnionType repeat the same traits, storage setup, leading
parameters, declarations, and hand-written accessors. Move them into one
tablegen base class; each record adds its own declarations through
`extraRecordDeclaration`, and the shared out-of-line definitions come from
`extraClassDefinition`. Follow-up to review feedback on #247883.

Assisted-by: Claude Opus 5.5
---
 .../include/clang/CIR/Dialect/IR/CIRTypes.td  | 226 +++++++++---------
 clang/lib/CIR/Dialect/IR/CIRTypes.cpp         |  61 +----
 2 files changed, 117 insertions(+), 170 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
index af0dabbcb0a64..4e909f556e4b0 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
@@ -1012,17 +1012,120 @@ def CIR_RecordMemberKind : CIR_I32Enum<
   }];
 }
 
+//===----------------------------------------------------------------------===//
+// CIR_RecordTypeBase
+//
+// What StructType and UnionType share. Their storage classes are written in
+// C++ for mutability, so the accessors are written by hand too. A record adds
+// its own declarations through `extraRecordDeclaration`.
+//===----------------------------------------------------------------------===//
+
+class CIR_RecordTypeBase<string name, string typeMnemonic>
+    : CIR_Type<name, typeMnemonic, [
+        DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
+        DeclareTypeInterfaceMethods<CIR_SizedTypeInterface>,
+        MutableType,
+      ]> {
+  // The parameters every record starts with.
+  dag recordParameters = (ins
+    OptionalArrayRefParameter<"mlir::Type">:$members,
+    OptionalParameter<"mlir::StringAttr">:$name,
+    "bool":$incomplete,
+    "bool":$packed
+  );
+
+  let storageClass = name # "TypeStorage";
+  let genStorageClass = 0;
+
+  let skipDefaultBuilders = 1;
+  let genVerifyDecl = 1;
+  let hasCustomAssemblyFormat = 1;
+
+  code extraRecordDeclaration = [{}];
+
+  let extraClassDeclaration = [{
+    bool isComplete() const { return !isIncomplete(); }
+    bool isIncomplete() const;
+
+    size_t getNumElements() const { return getMembers().size(); }
+    mlir::Type getElementType(size_t idx) const {
+      return getMembers()[idx];
+    }
+    std::string getPrefixedName() const {
+      return getKindAsStr() + "." + getName().getValue().str();
+    }
+
+    // The completion shared by both record kinds needs mutate().
+    template <typename RecordTy>
+    friend llvm::LogicalResult
+    completeRecord(RecordTy record,
+                   llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
+                   llvm::ArrayRef<mlir::Type> members, bool packed,
+                   mlir::Type padding,
+                   llvm::ArrayRef<cir::RecordMemberKind> memberKinds);
+
+    // Checks the name of this record to check if it is a 'after' (or during)
+    // ABI conversion.
+    bool isABIConvertedRecord() const;
+
+    // Get the version of this record's name for use during cxx-abi conversion.
+    mlir::StringAttr getABIConvertedName() const;
+
+    // This function should only be called after the CXXABILowering pass. It is
+    // intended to do a 'fixup' of the name so that we don't end up with messy
+    // looking CIR after CXXABI lowering. This should only be called if all uses
+    // of the pre-CXXABILowering version have been removed, otherwise we'll have
+    // a conflict in RecordStorage because two types will have the same hash.
+    void removeABIConversionNamePrefix();
+
+    bool isSized() const { return isComplete(); }
+
+  private:
+    static constexpr char abi_conversion_prefix[] = "__post_abi_";
+  public:
+  }] # extraRecordDeclaration;
+
+  let extraClassDefinition = [{
+    llvm::ArrayRef<mlir::Type> $cppClass::getMembers() const {
+      return getImpl()->members;
+    }
+    mlir::StringAttr $cppClass::getName() const { return getImpl()->name; }
+    bool $cppClass::isIncomplete() const { return getImpl()->incomplete; }
+    bool $cppClass::getIncomplete() const { return getImpl()->incomplete; }
+    bool $cppClass::getPacked() const { return getImpl()->packed; }
+    llvm::ArrayRef<cir::RecordMemberKind> $cppClass::getMemberKinds() const {
+      return getImpl()->member_kinds;
+    }
+
+    bool $cppClass::isABIConvertedRecord() const {
+      return getName() &&
+             getName().getValue().starts_with(abi_conversion_prefix);
+    }
+
+    mlir::StringAttr $cppClass::getABIConvertedName() const {
+      assert(!isABIConvertedRecord());
+      return mlir::StringAttr::get(getContext(),
+                                   abi_conversion_prefix + getName().getValue());
+    }
+
+    void $cppClass::removeABIConversionNamePrefix() {
+      mlir::StringAttr recordName = getName();
+      if (recordName &&
+          recordName.getValue().starts_with(abi_conversion_prefix))
+        getImpl()->name = mlir::StringAttr::get(
+            recordName.getValue().drop_front(sizeof(abi_conversion_prefix) - 1),
+            recordName.getType());
+    }
+  }];
+}
+
 //===----------------------------------------------------------------------===//
 // StructType
 //
 // The CIR type for C/C++ struct and class declarations.
 //===----------------------------------------------------------------------===//
 
-def CIR_StructType : CIR_Type<"Struct", "struct", [
-    DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
-    DeclareTypeInterfaceMethods<CIR_SizedTypeInterface>,
-    MutableType,
-]> {
+def CIR_StructType : CIR_RecordTypeBase<"Struct", "struct"> {
   let summary = "CIR struct/class type";
   let description = [{
     Each unique clang::RecordDecl with struct or class kind is mapped to a
@@ -1070,21 +1173,10 @@ def CIR_StructType : CIR_Type<"Struct", "struct", [
     ```
   }];
 
-  let parameters = (ins
-    OptionalArrayRefParameter<"mlir::Type">:$members,
-    OptionalParameter<"mlir::StringAttr">:$name,
-    "bool":$incomplete,
-    "bool":$packed,
+  let parameters = !con(recordParameters, (ins
     ArrayRefParameter<"cir::RecordMemberKind">:$member_kinds,
     "bool":$is_class
-  );
-
-  // StorageClass is defined in C++ for mutability.
-  let storageClass = "StructTypeStorage";
-  let genStorageClass = 0;
-
-  let skipDefaultBuilders = 1;
-  let genVerifyDecl = 1;
+  ));
 
   let builders = [
     // Create an identified and complete struct/class type.
@@ -1122,7 +1214,7 @@ def CIR_StructType : CIR_Type<"Struct", "struct", [
     }]>
   ];
 
-  let extraClassDeclaration = [{
+  let extraRecordDeclaration = [{
     /// Verifies a storage key, as sub-element replacement rebuilds from one.
     /// It is a template because the storage class is incomplete here.
     template <typename StorageKey>
@@ -1135,19 +1227,10 @@ def CIR_StructType : CIR_Type<"Struct", "struct", [
 
     bool isClass() const { return getIsClass(); }
     bool isStruct() const { return !getIsClass(); }
-    bool isComplete() const { return !isIncomplete(); }
-    bool isIncomplete() const;
 
-    size_t getNumElements() const { return getMembers().size(); }
     std::string getKindAsStr() const {
       return getIsClass() ? "class" : "struct";
     }
-    mlir::Type getElementType(size_t idx) const {
-      return getMembers()[idx];
-    }
-    std::string getPrefixedName() const {
-      return getKindAsStr() + "." + getName().getValue().str();
-    }
 
     void complete(llvm::ArrayRef<mlir::Type> members, bool packed,
                   llvm::ArrayRef<cir::RecordMemberKind> memberKinds);
@@ -1160,15 +1243,6 @@ def CIR_StructType : CIR_Type<"Struct", "struct", [
                     llvm::ArrayRef<mlir::Type> members, bool packed,
                     llvm::ArrayRef<cir::RecordMemberKind> memberKinds);
 
-    // The completion shared with the other record kind needs mutate().
-    template <typename RecordTy>
-    friend llvm::LogicalResult
-    completeRecord(RecordTy record,
-                   llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
-                   llvm::ArrayRef<mlir::Type> members, bool packed,
-                   mlir::Type padding,
-                   llvm::ArrayRef<cir::RecordMemberKind> memberKinds);
-
     /// Whether any member is marked pad.
     bool getPadded() const;
 
@@ -1184,35 +1258,16 @@ def CIR_StructType : CIR_Type<"Struct", "struct", [
     /// only in how their members were produced are layout-identical.
     bool isLayoutIdentical(const StructType &other);
 
-    // Checks the name of this record to check if it is a 'after' (or during)
-    // ABI conversion.
-    bool isABIConvertedRecord() const;
-
-    // Get the version of this record's name for use during cxx-abi conversion.
-    mlir::StringAttr getABIConvertedName() const;
-
-    // This function should only be called after the CXXABILowering pass. It is
-    // intended to do a 'fixup' of the name so that we don't end up with messy
-    // looking CIR after CXXABI lowering. This should only be called if all uses
-    // of the pre-CXXABILowering version have been removed, otherwise we'll have
-    // a conflict in RecordStorage because two types will have the same hash.
-    void removeABIConversionNamePrefix();
-
-    bool isSized() const { return isComplete(); }
-
     /// Returns the data size for this struct type.  Tail padding is the
     /// trailing run of pad members, so interior padding and a trailing member
     /// of any other kind stay inside the data size.
     unsigned computeStructDataSize(const mlir::DataLayout &dataLayout) const;
 
   private:
-    static constexpr char abi_conversion_prefix[] = "__post_abi_";
     unsigned computeStructSize(const mlir::DataLayout &dataLayout) const;
     uint64_t computeStructAlignment(const mlir::DataLayout &dataLayout) const;
   public:
   }];
-
-  let hasCustomAssemblyFormat = 1;
 }
 
 //===----------------------------------------------------------------------===//
@@ -1221,11 +1276,7 @@ def CIR_StructType : CIR_Type<"Struct", "struct", [
 // The CIR type for C/C++ union declarations.
 //===----------------------------------------------------------------------===//
 
-def CIR_UnionType : CIR_Type<"Union", "union", [
-    DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
-    DeclareTypeInterfaceMethods<CIR_SizedTypeInterface>,
-    MutableType,
-]> {
+def CIR_UnionType : CIR_RecordTypeBase<"Union", "union"> {
   let summary = "CIR union type";
   let description = [{
     Each unique clang::RecordDecl with union kind is mapped to a `cir.union`
@@ -1261,21 +1312,10 @@ def CIR_UnionType : CIR_Type<"Union", "union", [
     ```
   }];
 
-  let parameters = (ins
-    OptionalArrayRefParameter<"mlir::Type">:$members,
-    OptionalParameter<"mlir::StringAttr">:$name,
-    "bool":$incomplete,
-    "bool":$packed,
+  let parameters = !con(recordParameters, (ins
     OptionalParameter<"mlir::Type">:$padding,
     ArrayRefParameter<"cir::RecordMemberKind">:$member_kinds
-  );
-
-  // StorageClass is defined in C++ for mutability.
-  let storageClass = "UnionTypeStorage";
-  let genStorageClass = 0;
-
-  let skipDefaultBuilders = 1;
-  let genVerifyDecl = 1;
+  ));
 
   let builders = [
     // Create an identified and complete union type.
@@ -1310,7 +1350,7 @@ def CIR_UnionType : CIR_Type<"Union", "union", [
     }]>
   ];
 
-  let extraClassDeclaration = [{
+  let extraRecordDeclaration = [{
     /// Verifies a storage key, as sub-element replacement rebuilds from one.
     /// It is a template because the storage class is incomplete here.
     template <typename StorageKey>
@@ -1322,20 +1362,11 @@ def CIR_UnionType : CIR_Type<"Union", "union", [
     }
 
     bool isUnion() const { return true; }
-    bool isComplete() const { return !isIncomplete(); }
-    bool isIncomplete() const;
 
     /// Whether this union carries a tail-padding type.
     bool getPadded() const;
 
-    size_t getNumElements() const { return getMembers().size(); }
     std::string getKindAsStr() const { return "union"; }
-    mlir::Type getElementType(size_t idx) const {
-      return getMembers()[idx];
-    }
-    std::string getPrefixedName() const {
-      return "union." + getName().getValue().str();
-    }
 
     /// Returns the highest-alignment variant of the union (the member used as
     /// the storage type when lowering to LLVM IR).  Returns a null type for
@@ -1357,15 +1388,6 @@ def CIR_UnionType : CIR_Type<"Union", "union", [
                     mlir::Type padding,
                     llvm::ArrayRef<cir::RecordMemberKind> memberKinds);
 
-    // The completion shared with the other record kind needs mutate().
-    template <typename RecordTy>
-    friend llvm::LogicalResult
-    completeRecord(RecordTy record,
-                   llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
-                   llvm::ArrayRef<mlir::Type> members, bool packed,
-                   mlir::Type padding,
-                   llvm::ArrayRef<cir::RecordMemberKind> memberKinds);
-
     uint64_t getElementOffset(const mlir::DataLayout &, unsigned) const {
       return 0;
     }
@@ -1373,25 +1395,7 @@ def CIR_UnionType : CIR_Type<"Union", "union", [
     /// Marks are provenance rather than layout, so two unions that differ only
     /// in how their members were produced are layout-identical.
     bool isLayoutIdentical(const UnionType &other);
-
-    // Checks the name of this record to check if it is a 'after' (or during)
-    // ABI conversion.
-    bool isABIConvertedRecord() const;
-
-    // Get the version of this record's name for use during cxx-abi conversion.
-    mlir::StringAttr getABIConvertedName() const;
-
-    // This function should only be called after the CXXABILowering pass.
-    void removeABIConversionNamePrefix();
-
-    bool isSized() const { return isComplete(); }
-
-  private:
-    static constexpr char abi_conversion_prefix[] = "__post_abi_";
-  public:
   }];
-
-  let hasCustomAssemblyFormat = 1;
 }
 
 // CIRRecordType: tablegen constraint matching either !cir.struct or !cir.union.
diff --git a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
index 70ce72db2dded..8a52a990ec231 100644
--- a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
@@ -377,42 +377,13 @@ mlir::LogicalResult StructType::verify(
   return verifyRecordMemberKinds(emitError, members.size(), member_kinds);
 }
 
-// Accessors are hand-written because genStorageClass = 0 suppresses generated
-// implementations.
-llvm::ArrayRef<mlir::Type> StructType::getMembers() const {
-  return getImpl()->members;
-}
-mlir::StringAttr StructType::getName() const { return getImpl()->name; }
-bool StructType::isIncomplete() const { return getImpl()->incomplete; }
-bool StructType::getIncomplete() const { return getImpl()->incomplete; }
-bool StructType::getPacked() const { return getImpl()->packed; }
-llvm::ArrayRef<RecordMemberKind> StructType::getMemberKinds() const {
-  return getImpl()->member_kinds;
-}
+// The accessors shared with UnionType are in CIR_RecordTypeBase.
 bool StructType::getIsClass() const { return getImpl()->is_class; }
 
 bool StructType::getPadded() const {
   return llvm::is_contained(getMemberKinds(), RecordMemberKind::Pad);
 }
 
-bool StructType::isABIConvertedRecord() const {
-  return getName() && getName().getValue().starts_with(abi_conversion_prefix);
-}
-
-mlir::StringAttr StructType::getABIConvertedName() const {
-  assert(!isABIConvertedRecord());
-  return StringAttr::get(getContext(),
-                         abi_conversion_prefix + getName().getValue());
-}
-
-void StructType::removeABIConversionNamePrefix() {
-  mlir::StringAttr recordName = getName();
-  if (recordName && recordName.getValue().starts_with(abi_conversion_prefix))
-    getImpl()->name = mlir::StringAttr::get(
-        recordName.getValue().drop_front(sizeof(abi_conversion_prefix) - 1),
-        recordName.getType());
-}
-
 namespace cir {
 /// Completes a named struct or union. \p padding is only used by unions.
 template <typename RecordTy>
@@ -618,37 +589,9 @@ UnionType::verify(function_ref<mlir::InFlightDiagnostic()> emitError,
   return verifyRecordMemberKinds(emitError, members.size(), member_kinds);
 }
 
-// Accessors.
-llvm::ArrayRef<mlir::Type> UnionType::getMembers() const {
-  return getImpl()->members;
-}
-mlir::StringAttr UnionType::getName() const { return getImpl()->name; }
-bool UnionType::isIncomplete() const { return getImpl()->incomplete; }
-bool UnionType::getIncomplete() const { return getImpl()->incomplete; }
-bool UnionType::getPacked() const { return getImpl()->packed; }
+// The accessors shared with StructType are in CIR_RecordTypeBase.
 bool UnionType::getPadded() const { return getPadding() ? true : false; }
 mlir::Type UnionType::getPadding() const { return getImpl()->padding; }
-llvm::ArrayRef<RecordMemberKind> UnionType::getMemberKinds() const {
-  return getImpl()->member_kinds;
-}
-
-bool UnionType::isABIConvertedRecord() const {
-  return getName() && getName().getValue().starts_with(abi_conversion_prefix);
-}
-
-mlir::StringAttr UnionType::getABIConvertedName() const {
-  assert(!isABIConvertedRecord());
-  return StringAttr::get(getContext(),
-                         abi_conversion_prefix + getName().getValue());
-}
-
-void UnionType::removeABIConversionNamePrefix() {
-  mlir::StringAttr recordName = getName();
-  if (recordName && recordName.getValue().starts_with(abi_conversion_prefix))
-    getImpl()->name = mlir::StringAttr::get(
-        recordName.getValue().drop_front(sizeof(abi_conversion_prefix) - 1),
-        recordName.getType());
-}
 
 void UnionType::complete(ArrayRef<Type> members, bool packed,
                          mlir::Type padding,

>From 56d7ed2be4306535cf41760356f277eab3019bfc Mon Sep 17 00:00:00 2001
From: Bruno Cardoso Lopes <bruno.cardoso at gmail.com>
Date: Thu, 3 Dec 2026 15:00:42 -0800
Subject: [PATCH 2/3] [CIR] Name the shared record declarations instead of
 appending a hook

Each record now writes one extraClassDeclaration that starts with the
base's recordDeclarations. The generated code is unchanged.
---
 clang/include/clang/CIR/Dialect/IR/CIRTypes.td | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
index 4e909f556e4b0..8d208331b7604 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
@@ -1016,8 +1016,7 @@ def CIR_RecordMemberKind : CIR_I32Enum<
 // CIR_RecordTypeBase
 //
 // What StructType and UnionType share. Their storage classes are written in
-// C++ for mutability, so the accessors are written by hand too. A record adds
-// its own declarations through `extraRecordDeclaration`.
+// C++ for mutability, so the accessors are written by hand too.
 //===----------------------------------------------------------------------===//
 
 class CIR_RecordTypeBase<string name, string typeMnemonic>
@@ -1041,9 +1040,9 @@ class CIR_RecordTypeBase<string name, string typeMnemonic>
   let genVerifyDecl = 1;
   let hasCustomAssemblyFormat = 1;
 
-  code extraRecordDeclaration = [{}];
-
-  let extraClassDeclaration = [{
+  // The declarations both records share. Each record starts its
+  // extraClassDeclaration with them.
+  code recordDeclarations = [{
     bool isComplete() const { return !isIncomplete(); }
     bool isIncomplete() const;
 
@@ -1083,7 +1082,7 @@ class CIR_RecordTypeBase<string name, string typeMnemonic>
   private:
     static constexpr char abi_conversion_prefix[] = "__post_abi_";
   public:
-  }] # extraRecordDeclaration;
+  }];
 
   let extraClassDefinition = [{
     llvm::ArrayRef<mlir::Type> $cppClass::getMembers() const {
@@ -1214,7 +1213,7 @@ def CIR_StructType : CIR_RecordTypeBase<"Struct", "struct"> {
     }]>
   ];
 
-  let extraRecordDeclaration = [{
+  let extraClassDeclaration = recordDeclarations # [{
     /// Verifies a storage key, as sub-element replacement rebuilds from one.
     /// It is a template because the storage class is incomplete here.
     template <typename StorageKey>
@@ -1350,7 +1349,7 @@ def CIR_UnionType : CIR_RecordTypeBase<"Union", "union"> {
     }]>
   ];
 
-  let extraRecordDeclaration = [{
+  let extraClassDeclaration = recordDeclarations # [{
     /// Verifies a storage key, as sub-element replacement rebuilds from one.
     /// It is a template because the storage class is incomplete here.
     template <typename StorageKey>

>From 71d0e2d0e0f56b987f69a00af1ade0993d51c939 Mon Sep 17 00:00:00 2001
From: Bruno Cardoso Lopes <bruno.cardoso at gmail.com>
Date: Fri, 4 Dec 2026 11:25:50 -0800
Subject: [PATCH 3/3] [CIR] Append record declarations and accessors to the
 base's

Each record appends to the base's extraClassDeclaration and
extraClassDefinition, so getIsClass and getPadding move into the .td
next to the shared accessors.
---
 clang/include/clang/CIR/Dialect/IR/CIRTypes.td | 16 +++++++++++-----
 clang/lib/CIR/Dialect/IR/CIRTypes.cpp          |  5 -----
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
index 8d208331b7604..bd672f84d95f4 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
@@ -1040,9 +1040,7 @@ class CIR_RecordTypeBase<string name, string typeMnemonic>
   let genVerifyDecl = 1;
   let hasCustomAssemblyFormat = 1;
 
-  // The declarations both records share. Each record starts its
-  // extraClassDeclaration with them.
-  code recordDeclarations = [{
+  let extraClassDeclaration = [{
     bool isComplete() const { return !isIncomplete(); }
     bool isIncomplete() const;
 
@@ -1213,7 +1211,7 @@ def CIR_StructType : CIR_RecordTypeBase<"Struct", "struct"> {
     }]>
   ];
 
-  let extraClassDeclaration = recordDeclarations # [{
+  let append extraClassDeclaration = [{
     /// Verifies a storage key, as sub-element replacement rebuilds from one.
     /// It is a template because the storage class is incomplete here.
     template <typename StorageKey>
@@ -1267,6 +1265,10 @@ def CIR_StructType : CIR_RecordTypeBase<"Struct", "struct"> {
     uint64_t computeStructAlignment(const mlir::DataLayout &dataLayout) const;
   public:
   }];
+
+  let append extraClassDefinition = [{
+    bool $cppClass::getIsClass() const { return getImpl()->is_class; }
+  }];
 }
 
 //===----------------------------------------------------------------------===//
@@ -1349,7 +1351,7 @@ def CIR_UnionType : CIR_RecordTypeBase<"Union", "union"> {
     }]>
   ];
 
-  let extraClassDeclaration = recordDeclarations # [{
+  let append extraClassDeclaration = [{
     /// Verifies a storage key, as sub-element replacement rebuilds from one.
     /// It is a template because the storage class is incomplete here.
     template <typename StorageKey>
@@ -1395,6 +1397,10 @@ def CIR_UnionType : CIR_RecordTypeBase<"Union", "union"> {
     /// in how their members were produced are layout-identical.
     bool isLayoutIdentical(const UnionType &other);
   }];
+
+  let append extraClassDefinition = [{
+    mlir::Type $cppClass::getPadding() const { return getImpl()->padding; }
+  }];
 }
 
 // CIRRecordType: tablegen constraint matching either !cir.struct or !cir.union.
diff --git a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
index 8a52a990ec231..361986965b98a 100644
--- a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
@@ -377,9 +377,6 @@ mlir::LogicalResult StructType::verify(
   return verifyRecordMemberKinds(emitError, members.size(), member_kinds);
 }
 
-// The accessors shared with UnionType are in CIR_RecordTypeBase.
-bool StructType::getIsClass() const { return getImpl()->is_class; }
-
 bool StructType::getPadded() const {
   return llvm::is_contained(getMemberKinds(), RecordMemberKind::Pad);
 }
@@ -589,9 +586,7 @@ UnionType::verify(function_ref<mlir::InFlightDiagnostic()> emitError,
   return verifyRecordMemberKinds(emitError, members.size(), member_kinds);
 }
 
-// The accessors shared with StructType are in CIR_RecordTypeBase.
 bool UnionType::getPadded() const { return getPadding() ? true : false; }
-mlir::Type UnionType::getPadding() const { return getImpl()->padding; }
 
 void UnionType::complete(ArrayRef<Type> members, bool packed,
                          mlir::Type padding,



More information about the cfe-commits mailing list