From 5eccd90b47b327917ad0e5858c79ca8fab27cd74 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Thu, 22 Oct 2026 13:51:44 +0000 Subject: feat(codegen): pass C-struct records by value as variadic arguments A variadic EXTERN call is now arranged by clang per call, from the fixed parameter count and the promoted argument types. C-struct records pass unchanged in variadic positions, as C11 6.5.2.2p6-7 and 7.16.1.1p2 allow; a record that is not a C struct names the offending field. Co-Authored-By: Claude Opus 5.5 --- tests/i/extern-c-struct-value/program.cps | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tests/i/extern-c-struct-value/program.cps') diff --git a/tests/i/extern-c-struct-value/program.cps b/tests/i/extern-c-struct-value/program.cps index 6b2cb8e..c8b3a1f 100644 --- a/tests/i/extern-c-struct-value/program.cps +++ b/tests/i/extern-c-struct-value/program.cps @@ -1,4 +1,5 @@ -// Records whose fields are C types pass to and return from C functions by value. +// Records whose fields are C types pass to and return from C functions by +// value, also as variadic arguments. INCLUDE_OBJ "lib.o" TYPE CShort = C_TYPE("short") TYPE CFloat = C_TYPE("float") @@ -34,10 +35,13 @@ EXTERN "C" EXTERN_FUNCTION make_pair(C_INT, C_INT) RETURNS Pair EXTERN "C" EXTERN_FUNCTION make_vec2(C_DOUBLE, C_DOUBLE) RETURNS Vec2 EXTERN "C" EXTERN_FUNCTION make_mixed(C_CHAR, C_DOUBLE, C_INT) RETURNS Mixed EXTERN "C" EXTERN_FUNCTION make_vec3f(CFloat, CFloat, CFloat) RETURNS Vec3f +EXTERN "C" EXTERN_FUNCTION sum_vec2(C_INT, ...) RETURNS C_DOUBLE +EXTERN "C" EXTERN_FUNCTION mixed_counts(C_INT, ...) RETURNS C_INT DECLARE P : Pair DECLARE U : Vec2 DECLARE V : Vec2 DECLARE M : Mixed +DECLARE N : Mixed DECLARE F : Vec3f DECLARE W : Wide P.A <- (C_INT)3 @@ -68,3 +72,6 @@ M <- make_mixed((C_CHAR)'Q', (C_DOUBLE)0.25, (C_INT)9) OUTPUT M.Tag, " ", M.Value, " ", M.Count F <- make_vec3f((CFloat)0.5, (CFloat)1.25, (CFloat)2) OUTPUT F.X, " ", F.Y, " ", F.Z +OUTPUT sum_vec2((C_INT)2, U, V) +N <- make_mixed((C_CHAR)'R', (C_DOUBLE)1, (C_INT)5) +OUTPUT mixed_counts((C_INT)2, M, N) -- cgit v1.3.1-4-g156e