[clang] [CIR] Check union tail padding in CallConvLowering (PR #233897)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 20 23:10:29 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Henrich Lauko (xlauko)
<details>
<summary>Changes</summary>
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)
---
Full diff: https://github.com/llvm/llvm-project/pull/233897.diff
2 Files Affected:
- (modified) clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp (+4)
- (modified) clang/test/CIR/Transforms/abi-lowering/x86_64-aggregate-nyi.cir (+9)
``````````diff
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"
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/233897
More information about the cfe-commits
mailing list