[clang] [WIP][clang][SPARC] Don't flatten or pad zero-size struct arguments in the stack (PR #217065)
Sergei Barannikov via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 6 18:46:06 PDT 2026
================
@@ -371,17 +371,25 @@ ABIArgInfo SparcV9ABIInfo::classifyType(QualType Ty, unsigned SizeLimit,
CoerceBuilder CB(VMContext, getDataLayout());
CB.addStruct(0, StrTy);
- // All structs, even empty ones, should take up a register argument slot,
- // so pin the minimum struct size to one bit.
- CB.pad(llvm::alignTo(
- std::max(CB.DL.getTypeSizeInBits(StrTy).getKnownMinValue(), uint64_t(1)),
- 64));
+
+ // All structs, even empty ones, should take up a register argument slot, so
+ // pin the minimum struct size to one bit. However, empty structs don't take
+ // up any stack slot, so only do it on register arguments (i.e. the first
+ // six).
+ bool IsStackArgument = RegOffset > 5;
+ uint64_t ActualSize = CB.DL.getTypeSizeInBits(StrTy).getKnownMinValue();
+ uint64_t ExpandedSize = std::max(ActualSize, uint64_t(1));
+ if (IsStackArgument)
+ ExpandedSize = ActualSize;
+
+ CB.pad(llvm::alignTo(ExpandedSize, 64));
RegOffset += PaddingSlots + CB.Size / 64;
// Try to use the original type for coercion.
llvm::Type *CoerceTy = CB.isUsableType(StrTy) ? StrTy : CB.getType();
- ABIArgInfo AAI = ABIArgInfo::getDirect(CoerceTy, 0, Padding);
+ ABIArgInfo AAI = ABIArgInfo::getDirect(CoerceTy, 0, Padding,
+ !IsStackArgument && ExpandedSize == 0);
----------------
s-barannikov wrote:
If an argument should completely disappear from IR (an argument passed on the stack?), use `ABIArgInfo::getIgnore()`. I'm not sure what happens if one tries to take an address of a removed argument, but other targets seem to be fine with it.
Beware that "zero-sized structs" and "empty structs" are not always equivalent. See `CodeGen::isEmptyRecord()` if it can be a better fit.
https://github.com/llvm/llvm-project/pull/217065
More information about the cfe-commits
mailing list