[clang] [CIR] Compute union base subobject for tail-padding reuse (PR #201428)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 4 10:49:40 PDT 2026


================
@@ -870,8 +888,20 @@ void CIRRecordLowering::lowerUnion() {
 
   if (layoutSize < getSize(storageType))
     storageType = getByteArrayType(layoutSize);
-  else
+
+  if (nonVirtualBaseType) {
----------------
adams381 wrote:

The divergence is caused by our `appendPaddingBytes` override (lines 198–209): for unions it routes tail padding into `unionPadding` rather than `fieldTypes`, because the complete-union path needs padding tracked separately from field types. Calling `appendPaddingBytes` in the `nonVirtualBaseType=true` path would silently stash the padding into `unionPadding` instead of `fieldTypes`, corrupting the base-subobject record layout. So the base path pushes the padding directly into `fieldTypes` — what `appendPaddingBytes` does in the non-union case — rather than calling the override, which would redirect it into `unionPadding`.

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


More information about the cfe-commits mailing list