[clang] [CIR] Fix union layout calculations- remove getLargestMember (PR #199292)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Fri May 22 16:09:05 PDT 2026


================
@@ -322,36 +322,26 @@ void RecordType::complete(ArrayRef<Type> members, bool packed, bool padded) {
     llvm_unreachable("failed to complete record");
 }
 
-/// Return the largest member of in the type.
-///
-/// Recurses into union members never returning a union as the largest member.
-Type RecordType::getLargestMember(const ::mlir::DataLayout &dataLayout) const {
-  assert(isUnion() && "Only call getLargestMember on unions");
+/// Return the 'storage' type of the union, that is, without padding,
+/// the type that is used to convert to the 'storage' for LLVM-IR.
+Type RecordType::getUnionStorageType(
+    const ::mlir::DataLayout &dataLayout) const {
+  assert(isUnion() && "Only call getUnionStorageType on unions");
   llvm::ArrayRef<Type> members = getMembers();
-  if (members.empty())
+  if (members.empty() || (getPadded() && members.size() == 1))
----------------
andykaylor wrote:

This is in conflict with https://github.com/llvm/llvm-project/pull/198423

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


More information about the cfe-commits mailing list