Files
sx/examples/ffi/1203-ffi-callconv-c-fnptr-large-aggregate.sx
agra 66bdc70bf1 test: group examples into per-category folders
Move examples/*.sx and their expected/ snapshots into per-category
subfolders (examples/<category>/...). Folder = leading filename token,
with ffi-objc/ffi-jni kept whole; filenames are unchanged. The corpus
runner and LSP sweep now discover each category's expected/ dir, while
issues/ stays flat. Example 1058's repo-root-relative companion import
is made file-relative. Path strings embedded in 164 snapshots were
regenerated (path-only changes). Test-layout docs in CLAUDE.md updated.
2026-06-21 14:41:34 +03:00

38 lines
1.2 KiB
Plaintext

// Regression test for issue-0025 path B.
//
// When a fn-pointer's type is spelled with `abi(.c)`, the indirect
// call must apply the same C-ABI byval coercion that direct C-ABI calls
// do at the call site (path A): >16-byte non-HFA aggregates are passed
// as `ptr byval(<T>)`. Without the fix, the indirect call site builds
// an LLVM function type whose param slot is the raw struct, which the
// AArch64/x86_64 backend tries to lay out across registers + stack in
// ways that don't match the byval-attributed callee signature — the
// callee then reads garbage out of the wrong machine-state slots.
//
// The opt-in is the `abi(.c)` on the fn-pointer type spelling.
// Pure-sx fn-pointer casts (no abi suffix) keep their default
// calling convention — verified by examples/87-fnptr-cast-large-aggregate.sx.
#import "modules/std.sx";
Wide :: struct {
a: i64;
b: i64;
c: i64;
d: i64;
}
accept_c :: (w: Wide) -> i64 abi(.c) {
w.a + w.b + w.c + w.d
}
main :: () -> i32 {
w := Wide.{ a = 1, b = 10, c = 100, d = 1000 };
if accept_c(w) != 1111 { return 1; }
fn_ptr : (Wide) -> i64 abi(.c) = xx accept_c;
if fn_ptr(w) != 1111 { return 2; }
0
}