[flang-commits] [flang] [flang] Fix `getTypeSizeAndAlignment` for packed/tail-padded `RecordType` and `TRANSFER` gate (PR #220377)

Daniel Chen via flang-commits flang-commits at lists.llvm.org
Thu Sep 3 05:55:49 PDT 2026


================
@@ -8904,10 +8904,15 @@ IntrinsicLibrary::genTransfer(mlir::Type resultType,
         (fir::isa_trivial(sourceType) ||
          mlir::isa<fir::RecordType>(sourceType)) &&
         fir::isa_trivial(moldType)) {
+      // Use storeSizeOnly=true so that tail padding in RecordType sources is
+      // excluded: TRANSFER reinterprets raw data bits, so the comparison must
+      // be against the store size (data bytes), not the allocation size.
       auto sourceSizeAndAlign = fir::getTypeSizeAndAlignment(
-          loc, sourceType, builder.getDataLayout(), builder.getKindMap());
+          loc, sourceType, builder.getDataLayout(), builder.getKindMap(),
+          /*storeSizeOnly=*/true);
----------------
DanielCChen wrote:

The store-size comparison is kept: `dl.getTypeSize` already returns the store size for trivial scalars, so `storeSizeOnly` only affects `RecordType` sources, where it correctly reflects Fortran's STORAGE_SIZE data-bit definition rather than the compiler's allocation size. The comment has been updated to make the two concerns explicit — store-size equality gates path selection; alignment is handled separately by the alloca-copy path added in the previous fix.

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


More information about the flang-commits mailing list