Repository navigation
codegen(win64): fix indirect-closure spurious sret arg; un-skip 3 #806 tests - #818
Merged
Merged
Conversation
The generic sret path in mir_emit_call_term appends an sret argument when
the destination local's type needs win64 sret and call_ft has one more
param than the call has args. For an indirect closure/fn-pointer call,
call_ft already reserves param 0 for the environment pointer, so that
extra param is the env slot, not an sret slot.
A Never-returning closure (`() => unreachable(...)`) lowers its body to
`void(env)` — Never collapses to void, so there is no sret param. The old
guard counted the env slot as sret room and appended a spurious sret arg,
emitting `call void %fn(env, sret)`: two args against a one-param type.
LLVM verify rejected it ("Incorrect number of arguments") and win64
codegen aborted for any program with such a closure.
Only add the sret slot when param_count exceeds args plus the env slot.
Gated behind internal_abi_needs_sret, which is false off win64, so
linux/mac IR is byte-identical.
With the win64 closure/vtable sret ABI now consistent, the pure trait-object spec tests produce correct output on Windows: Box[dyn] coercion, implicit trait-object coercion, and object safety. Cross-built and run under wine (exit 0, matching the linux baseline). The remaining seven #806 skips still fail at runtime on win64 — they exercise fat-fn/closure value returns (str-returning closures corrupt their sret result) and stay skipped until that data-flow bug is fixed.
ropoctl
force-pushed
the
windows-806-closure-sret
branch
from
August 17, 2026 21:36
e87cda5 to
4102f1e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #817 (
windows-codegen-806).Codegen fix
The generic sret path in
mir_emit_call_termappended an sret argumentwhenever the destination local needed win64 sret and
call_fthad onemore param than the call had args. For an indirect closure/fn-pointer
call,
call_ftalready reserves param 0 for the environment pointer, sothat extra param is the env slot — not an sret slot.
A
Never-returning closure (() => unreachable(...)) lowers tovoid(env)(Never collapses to void, no sret param). The old guardcounted the env slot as sret room and appended a spurious sret arg,
emitting
call void %fn(env, sret): two args against a one-param type.LLVM verify rejected it ("Incorrect number of arguments") and win64
codegen aborted for any program with such a closure.
Now the sret slot is only added when
param_countexceeds args plusthe env slot. Gated behind
internal_abi_needs_sret(false off win64),so linux/mac IR is byte-identical.
Test un-skips
With the win64 closure/vtable sret ABI consistent, three pure
trait-object spec tests produce correct output on Windows and are
un-skipped:
Box[dyn]coercion, implicit trait-object coercion, andobject safety (cross-built, run under wine, exit 0 matching the linux
baseline).
The other seven #806 skips still fail at runtime on win64 — they exercise
fat-fn/closure value returns (a
str-returning closure corrupts itssret result), a distinct data-flow bug that stays skipped until fixed.