diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-22 13:45:36 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-22 13:45:36 +0000 |
| commit | 3a6eb921b50e191468d29c233718657f9f85d68e (patch) | |
| tree | ebf411667c1a4360f6e78e0ac971f9df924511d1 /tests/i/extern-c-struct-value/lib.c | |
| parent | 06538905915b15bde6364459929fe89cf0b8de5c (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'tests/i/extern-c-struct-value/lib.c')
| -rw-r--r-- | tests/i/extern-c-struct-value/lib.c | 16 |
1 files changed, 16 insertions, 0 deletions
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; +} |
