Skip to content

Windows: win64 indirect-aggregate call-arg ABI fix (#798 codegen prerequisite) - #812

Merged
ropoctl merged 1 commit into
mainfrom
windows-regex-fnarg-abi-798
Aug 17, 2026
Merged

ropoctl merged 1 commit into
mainfrom
windows-regex-fnarg-abi-798

Conversation

@ropoctl

@ropoctl ropoctl commented Aug 17, 2026 •

Copy link
Copy Markdown
Collaborator

Windows: win64 indirect-aggregate call-arg ABI fix (#798)

Lands the codegen fix for the native-Windows 0xC0000005 fault that any
regex literal triggered.

Root cause

The win64 internal-ABI indirect-aggregate call path decided the aggregate
LLVM type from the argument's sema type rather than the callee's
declared parameter
type. A bare fn item lowers to a fat {ptr, ptr}
16-byte closure; when passed to a parameter declared *const fn (a thin
pointer), the caller spilled the fat closure to a stack alloca and passed
its address where the callee reads a thin function pointer. The callee
then called through a pointer into stack data — faulting 0xC0000005 the
moment any regex literal reached pcre2_general_context_create_8.

Fix (src/CodegenDispatch.w)

Key the indirect-aggregate decision on the callee's declared parameter
type (expected_sema_ty), falling back to the argument's sema type only
for unsignatured indirect closure calls. A *const fn param now passes a
plain pointer and no longer spills. This follows the FnAbi single-source
doctrine: the passing shape comes from the signature, computed once, read
at the call site.

Verified natively on the Windows VM: the six regex exes, linked against a
regex_runtime.o rebuilt with this fix, print ok (RC=0).

Why the 6 regex behavior tests stay skip-windows: #798

The faulting call sites live in the compiler-internal rt/regex_runtime.w
(pcre2_general_context_create_8), which build.w compiles into the
embedded regex_runtime.o using the fetched seed compiler — which
predates this fix. So the linked runtime object still contains the buggy
lowering until the seed is refreshed with a compiler that carries this
fix. Un-skipping the six tests is therefore blocked on a reseed (or a
build.w change that builds the runtime objects with the freshly-staged
compiler instead of the seed) — tracked in #798 / #60. Un-skipping here
would red the battery on a fix that is present in source but absent from
the embedded runtime.

This PR lands the correct codegen prerequisite; the un-skip follows once
the runtime object is rebuilt with it.

@ropoctl
ropoctl force-pushed the windows-regex-fnarg-abi-798 branch from f91ca09 to 39646a0 Compare August 17, 2026 02:27
@ropoctl
ropoctl force-pushed the windows-regex-fnarg-abi-798 branch 2 times, most recently from 29a3e5c to c841f15 Compare August 17, 2026 04:03
@ropoctl ropoctl changed the title Windows: fix regex-literal codegen crash, un-skip 6 regex behavior tests (#798) Windows: win64 indirect-aggregate call-arg ABI fix (#798 codegen prerequisite) Aug 17, 2026
Base automatically changed from windows-map-closure-sret-802 to main August 17, 2026 05:18
… not arg (#798)

The win64 internal-ABI indirect-aggregate call-argument path decided
whether to spill an argument to an alloca and pass its address by
inspecting the ARGUMENT's sema type. For a bare function item passed to a
`*const fn(...)` parameter that is wrong: the argument's type is TY_FN,
which mir_sema_type_to_llvm lowers to a fat {ptr,ptr} closure (16 bytes),
so internal_abi_needs_indirect_param said "indirect" and the caller
spilled the fat value and passed its stack address. The callee, however,
declares a thin `ptr` parameter and `call`s through it directly —
executing stack data. On native win64 that is a 0xC0000005 access
violation, which is the regex crash (#798): pcre2_general_context_create_8
takes `*const fn` malloc/free pointers and regex_runtime.w passes bare
fns.

Fix: mirror the CALLEE's own ABI decision, per the FnAbi doctrine — one
ABI decision per signature, computed from the parameter and read by both
the callee prologue and this call site. Key the aggregate LLVM type on
the callee's declared param sema type (expected_sema_ty, already computed
from the signature above), which lowers a `*const fn` param to a thin
`ptr` (not indirect → no spill, falls through to normal pointer passing)
and a genuine by-value aggregate param to its struct type (indirect →
spill, unchanged). Fall back to the argument's type only for an
unsignatured indirect closure call, where no callee signature exists.

Proven at IR level for the minimal /tmp/fnptr.w repro and all three
rt/regex_runtime.w create_8 call sites. Un-skip of the #798 regex tests
and the windows regex-runtime rebuild follow once the isolation battery
(build/fixpoint/audits/test/drop-audit/move-audit) blesses it.
@ropoctl
ropoctl force-pushed the windows-regex-fnarg-abi-798 branch from c841f15 to 7ca6952 Compare August 17, 2026 05:18
@ropoctl
ropoctl merged commit d31ec7c into main Aug 17, 2026
3 checks passed
@ehartford
ehartford deleted the windows-regex-fnarg-abi-798 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