forked from M-Labs/nac3
1
0
Fork 0

core/codegen: Handle vararg in function generation

This commit is contained in:
David Mak 2024-07-16 19:36:08 +08:00
parent 466c2bbd3a
commit 967ef0e7dd
1 changed files with 18 additions and 3 deletions

View File

@ -726,6 +726,19 @@ pub fn gen_func_impl<
let mut params = args
.iter()
.map(|arg| {
let base_ty = if arg.is_vararg {
let TypeEnum::TTuple { ty, is_vararg_ctx: true, .. } =
&*unifier.get_ty_immutable(arg.ty)
else {
unreachable!()
};
debug_assert_eq!(ty.len(), 1);
ty[0]
} else {
arg.ty
};
get_llvm_abi_type(
context,
&module,
@ -734,7 +747,7 @@ pub fn gen_func_impl<
top_level_ctx.as_ref(),
&mut type_cache,
&primitives,
arg.ty,
base_ty,
)
.into()
})
@ -744,9 +757,11 @@ pub fn gen_func_impl<
params.insert(0, ret_type.unwrap().ptr_type(AddressSpace::default()).into());
}
let is_vararg = args.iter().any(|arg| arg.is_vararg);
let fn_type = match ret_type {
Some(ret_type) if !has_sret => ret_type.fn_type(&params, false),
_ => context.void_type().fn_type(&params, false),
Some(ret_type) if !has_sret => ret_type.fn_type(&params, is_vararg),
_ => context.void_type().fn_type(&params, is_vararg),
};
let symbol = &task.symbol_name;