[flang-commits] [flang] [flang] Preserve the alignment attribute across stack/heap conversions (PR #234898)
Eugene Epshteyn via flang-commits
flang-commits at lists.llvm.org
Mon Oct 26 06:52:38 PDT 2026
================
@@ -215,9 +215,15 @@ void AllocationPlacementPass::runOnOperation() {
? placementHook(info, basePolicy, stackBytesUsed)
: fir::decideAllocationPlacement(info, basePolicy, stackBytesUsed);
- // Account for the decision in the running stack budget.
- if (endsUpOnStack(placement, info.isCurrentlyOnStack) && info.byteSize)
+ // Account for the decision in the running stack budget, including the
+ // worst-case padding a requested alignment may need.
+ if (endsUpOnStack(placement, info.isCurrentlyOnStack) && info.byteSize) {
stackBytesUsed += static_cast<std::size_t>(*info.byteSize);
+ std::optional<std::int64_t> alignment =
+ alloca ? alloca.getAlignment() : allocmem.getAlignment();
+ if (alignment && *alignment > 1)
+ stackBytesUsed += static_cast<std::size_t>(*alignment - 1);
----------------
eugeneepshteyn wrote:
Indeed: as written the first aligned temporary always slipped in under the limit. Done: the requested alignment is now part of `PendingAllocationInfo`, and `stackBytesNeeded()` (size plus worst-case padding) is what `shouldAllocateOnStack` compares against the limit and what the pass charges afterwards, so the two agree.
https://github.com/llvm/llvm-project/pull/234898
More information about the flang-commits
mailing list