[clang] [CIR] Correct union lowering behavior re-padding (PR #216349)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 14 17:10:04 PDT 2026


================
@@ -532,16 +588,25 @@ mlir::Type adjustGlobalTypeForInit(mlir::Type llvmType, mlir::Attribute init,
   // Structs can have a flexible array member, adjust that.
   if (mlir::isa<cir::StructType>(constRecord.getType()))
     return adjustGlobalStructTypeForInit(structTy, constRecord, converter,
-                                         dataLayout);
+                                         dataLayout, paddingAddedIndexes);
   if (mlir::isa<cir::UnionType>(constRecord.getType()))
     return adjustGlobalUnionTypeForInit(structTy, constRecord, converter,
                                         dataLayout);
   return llvmType;
 }
 
+mlir::Type adjustGlobalTypeForInit(mlir::Type llvmType, mlir::Attribute init,
+                                   const mlir::TypeConverter &converter,
+                                   const mlir::DataLayout &dataLayout) {
+  llvm::SmallVector<unsigned> ignoredAddedIndexes;
+  return adjustGlobalTypeForInit(llvmType, init, converter, dataLayout,
+                                 ignoredAddedIndexes);
----------------
erichkeane wrote:

Yeah, it is possible/expected for this to not be empty.  Only one of the uses actually cares about those added indexes, so use this version.  For example, when we lower the global, we don't care about these, but when we do the same call for the `ConstRecordAttr` we DO care about it (and is the only use of the 'other' version of this.

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


More information about the cfe-commits mailing list