From a037fc8da13c5bfc53a322efb0f4349b9f04a1d1 Mon Sep 17 00:00:00 2001 From: v420v Date: Mon, 28 Oct 2024 00:23:05 +0900 Subject: [PATCH] codegen: fix variadic argument handling --- src/codegen/codegen.ibu | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/codegen/codegen.ibu b/src/codegen/codegen.ibu index 5aff5cc..09daca3 100644 --- a/src/codegen/codegen.ibu +++ b/src/codegen/codegen.ibu @@ -139,14 +139,14 @@ func func_call_args_to_stack(g *Gen, args *Vec, ty *Type) i32 { gen_push(g, "%rax"); stack = stack + 8; - if ty.is_variadic && i-1 == (ty.params.len - 2 - 1) { + if ty.is_variadic && i == (ty.params.len - 2) { let argc i32 = 0; if args.len > (ty.params.len - 2) { argc = args.len - (ty.params.len - 2); } - printf("\tleaq (%%rsp), %%rax\n"); + printf("\tleaq (%%rsp), %%rax\n"); // push argv gen_push(g, "%rax"); - gen_push_num(g, argc); + gen_push_num(g, argc); // push argc stack = stack + 16; }