Skip to content

codegen(win64): fix indirect-closure spurious sret arg; un-skip 3 #806 tests - #818

Merged
ropoctl merged 2 commits into
mainfrom
windows-806-closure-sret
Aug 17, 2026
Merged

ropoctl merged 2 commits into
mainfrom
windows-806-closure-sret

Conversation

@ropoctl

@ropoctl ropoctl commented Aug 17, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #817 (windows-codegen-806).

Codegen fix

The generic sret path in mir_emit_call_term appended an sret argument
whenever the destination local needed win64 sret and call_ft had one
more param than the call had 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 to
void(env) (Never collapses to void, 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.

Now the sret slot is only added when param_count exceeds args plus
the 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, and
object 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 its
sret result), a distinct data-flow bug that stays skipped until fixed.

Base automatically changed from windows-codegen-806 to main August 17, 2026 21:36
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
ropoctl force-pushed the windows-806-closure-sret branch from e87cda5 to 4102f1e Compare August 17, 2026 21:36
@ropoctl
ropoctl merged commit 0a0a90b into main Aug 17, 2026
3 checks passed
@ehartford
ehartford deleted the windows-806-closure-sret branch September 24, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant