[clang] [CIR] Check union tail padding in CallConvLowering (PR #233897)
Henrich Lauko via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 20 23:05:09 PDT 2026
https://github.com/xlauko updated https://github.com/llvm/llvm-project/pull/233897
>From c2fdac58d08085e68399b3c9cf60abcd4f51aaca Mon Sep 17 00:00:00 2001
From: Henrich Lauko <hlauko at nvidia.com>
Date: Tue, 20 Oct 2026 09:43:38 +0000
Subject: [PATCH] [CIR] Check union tail padding in CallConvLowering
isSupportedType checked a union's members but not its tail padding,
which the union's size includes. Incomplete-record padding asserted in
computeStructSize, and scalable-vector padding was lowered as a byval
of meaningless size. Check the padding like a member, so both are
reported as NYI.
Assisted-by: Claude Code (Claude Opus 5.5)
---
.../lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp | 4 ++++
.../CIR/Transforms/abi-lowering/x86_64-aggregate-nyi.cir | 9 +++++++++
2 files changed, 13 insertions(+)
diff --git a/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp b/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp
index 3b9156ee95bb5b..9615fc16519176 100644
--- a/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp
@@ -241,6 +241,10 @@ static bool isSupportedType(mlir::Type ty, const DataLayout &dl) {
[&](mlir::Type m) { return isSupportedType(m, dl); }))
return false;
if (recTy.isUnion()) {
+ // The size query below reads the tail padding too.
+ if (mlir::Type padding = cast<cir::UnionType>(ty).getPadding();
+ padding && !isSupportedType(padding, dl))
+ return false;
llvm::ArrayRef<mlir::Type> members = recTy.getMembers();
uint64_t recordBits = dl.getTypeSizeInBits(recTy).getFixedValue();
// Refuse a union that could reach SSEUP at a size no coerce exists for.
diff --git a/clang/test/CIR/Transforms/abi-lowering/x86_64-aggregate-nyi.cir b/clang/test/CIR/Transforms/abi-lowering/x86_64-aggregate-nyi.cir
index c264b26e150416..d04f75cc2781a7 100644
--- a/clang/test/CIR/Transforms/abi-lowering/x86_64-aggregate-nyi.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/x86_64-aggregate-nyi.cir
@@ -39,6 +39,7 @@
!rec_AtomicWrapper = !cir.struct<{data !rec_S1, pad !cir.array<!s8i x 2>}>
!rec_HoldsAllPad = !cir.struct<"HoldsAllPad" {data !s32i, empty !rec_E}>
!rec_Incomplete = !cir.struct<"Incomplete" incomplete>
+!rec_UIncompletePad = !cir.union<"UIncompletePad" {data !s32i}, padding = {!rec_Incomplete}>
module attributes {
dlti.dl_spec = #dlti.dl_spec<
@@ -175,4 +176,12 @@ module attributes {
}
// CHECK: not yet implemented for type '!cir.struct<"Incomplete" incomplete>'
+
+ // A union's size includes its tail padding, so the padding is checked like
+ // a member.
+ cir.func @take_incomplete_padding(%arg0: !rec_UIncompletePad) {
+ cir.return
+ }
+
+ // CHECK: not yet implemented for type '!cir.union<"UIncompletePad"
}
More information about the cfe-commits
mailing list