From 3a6eb921b50e191468d29c233718657f9f85d68e Mon Sep 17 00:00:00 2001 From: _ov4 Date: Thu, 22 Oct 2026 13:45:36 +0000 Subject: feat(codegen): pass C-struct records by value EXTERN parameters may now be C-struct records by value. clang's arrangement decides the passing: coerced through memory, flattened into elements, or indirect as byval or a pointer to a copy. Returning a record by value stays rejected for now. Co-Authored-By: Claude Opus 5.5 --- tests/i/extern-c-struct-value/lib.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/i/extern-c-struct-value/lib.c (limited to 'tests/i/extern-c-struct-value/lib.c') diff --git a/tests/i/extern-c-struct-value/lib.c b/tests/i/extern-c-struct-value/lib.c new file mode 100644 index 0000000..d6abe01 --- /dev/null +++ b/tests/i/extern-c-struct-value/lib.c @@ -0,0 +1,16 @@ +/* Each struct is passed by value; the host C ABI decides how. */ +struct Pair { int a, b; }; +struct Vec2 { double x, y; }; +struct Mixed { char tag; double value; int count; }; +struct Vec3f { float x, y, z; }; +struct Wide { long long lo, hi; }; + +int pair_sum(struct Pair p) { return p.a + p.b; } +double vec2_dot(struct Vec2 u, struct Vec2 v) { return u.x * v.x + u.y * v.y; } +double mixed_score(short bias, struct Mixed m, int k) { + return bias + m.value * k + m.count + (m.tag == 'M'); +} +double vec3f_sum(struct Vec3f v) { return v.x + v.y + v.z; } +long long wide_after_five(int a, int b, int c, int d, int e, struct Wide w) { + return a + b + c + d + e + w.lo + w.hi; +} -- cgit v1.3.1-4-g156e