From af1cfd9e821fde20ad5bc486ca401f3fcd640c9f Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Thu, 26 Dec 2024 12:30:07 +0800 Subject: [PATCH] fix x86_64/i386 gfunc_call, when arg is VT_STRUCT, need fetch cpu flag before generating any code --- i386-gen.c | 3 +++ tests/tests2/135_func_arg_struct_compare.c | 23 +++++++++++++++++++ .../tests2/135_func_arg_struct_compare.expect | 1 + x86_64-gen.c | 5 +++- 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/tests2/135_func_arg_struct_compare.c create mode 100644 tests/tests2/135_func_arg_struct_compare.expect diff --git a/i386-gen.c b/i386-gen.c index 5814a398f..ad71c301e 100644 --- a/i386-gen.c +++ b/i386-gen.c @@ -409,6 +409,9 @@ ST_FUNC void gfunc_call(int nb_args) args_size = 0; for(i = 0;i < nb_args; i++) { if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) { + /* fetch cpu flag before generating any code */ + if ((vtop->r & VT_VALMASK) == VT_CMP) + gv(RC_INT); size = type_size(&vtop->type, &align); /* align to stack align size */ size = (size + 3) & ~3; diff --git a/tests/tests2/135_func_arg_struct_compare.c b/tests/tests2/135_func_arg_struct_compare.c new file mode 100644 index 000000000..62f0a964d --- /dev/null +++ b/tests/tests2/135_func_arg_struct_compare.c @@ -0,0 +1,23 @@ +// https://lists.nongnu.org/archive/html/tinycc-devel/2024-12/msg00019.html +// x86_64/i386 void gfunc_call(int nb_args), when push struct args, need fetch cpu flag before generating any code + +#include + +struct string { + char *str; + int len; +}; + +void dummy(struct string fpath, int dump_arg) { +} + +int main() { + int a = 1; + struct string x; + x.str = "gg.v"; + x.len = 4; + dummy(x, a == 0); + printf("done\n"); + return 0; +} + diff --git a/tests/tests2/135_func_arg_struct_compare.expect b/tests/tests2/135_func_arg_struct_compare.expect new file mode 100644 index 000000000..19f86f493 --- /dev/null +++ b/tests/tests2/135_func_arg_struct_compare.expect @@ -0,0 +1 @@ +done diff --git a/x86_64-gen.c b/x86_64-gen.c index e02f6cc24..fe239273c 100644 --- a/x86_64-gen.c +++ b/x86_64-gen.c @@ -828,7 +828,10 @@ void gfunc_call(int nb_args) continue; /* arguments smaller than 8 bytes passed in registers or on stack */ if (bt == VT_STRUCT) { - /* align to stack align size */ + /* fetch cpu flag before generating any code */ + if ((vtop->r & VT_VALMASK) == VT_CMP) + gv(RC_INT); + /* align to stack align size */ size = (size + 15) & ~15; /* generate structure store */ r = get_reg(RC_INT);