ffi #foreign: C-variadic tail via args: ..T
Trailing `args: ..T` on a #foreign declaration now lowers to the C calling convention's `...` instead of sx-side slice-packing. Drops the per-arity #foreign-shim workaround for callers of variadic C APIs (__android_log_print, printf-family, etc.). Closes issue-0043. - IR: Function.is_variadic on inst.Function; declareFunction drops the variadic param from the IR signature for foreign+variadic decls. - emit_llvm: LLVMFunctionType receives is_var_arg=1 when the flag is set; call lowering passes extras through unchanged. - Lowering: packVariadicCallArgs early-outs for foreign+variadic (no slice-pack); new promoteCVariadicArgs applies C default argument promotion (bool/s8/s16/u8/u16 -> s32, f32 -> f64) to extras past the fixed param count. - Test: examples/ffi-foreign-cvariadic.sx + .c exercise s64/f64/s32 returns through C va_arg over s32/f64/*u8 element types. 134 host + 6 cross tests pass on the WIP-less baseline.
This commit is contained in:
@@ -478,6 +478,13 @@ pub const Function = struct {
|
||||
linkage: Linkage = .internal,
|
||||
call_conv: CallingConvention = .default,
|
||||
source_file: ?[]const u8 = null,
|
||||
/// Variadic tail at the IR signature level. Only `#foreign` decls reach
|
||||
/// IR with this set — sx-side `..T` params are slice-packed before
|
||||
/// lowering, so anything that survives is the C calling convention's
|
||||
/// `...`. emit_llvm passes `is_var_arg=1` to `LLVMFunctionType`; call
|
||||
/// sites apply the standard default argument promotions (s8/s16/bool →
|
||||
/// s32, f32 → f64) to extras past the fixed param count.
|
||||
is_variadic: bool = false,
|
||||
|
||||
pub const Param = struct {
|
||||
name: StringId,
|
||||
|
||||
Reference in New Issue
Block a user