fix x86_64/i386 gfunc_call, when arg is VT_STRUCT, need fetch cpu flag before generating any code

This commit is contained in:
kbkpbot 2024-12-26 12:30:07 +08:00
parent 34b7b2cef5
commit af1cfd9e82
4 changed files with 31 additions and 1 deletions

View file

@ -409,6 +409,9 @@ ST_FUNC void gfunc_call(int nb_args)
args_size = 0; args_size = 0;
for(i = 0;i < nb_args; i++) { for(i = 0;i < nb_args; i++) {
if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) { 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); size = type_size(&vtop->type, &align);
/* align to stack align size */ /* align to stack align size */
size = (size + 3) & ~3; size = (size + 3) & ~3;

View file

@ -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 <stdio.h>
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;
}

View file

@ -0,0 +1 @@
done

View file

@ -828,7 +828,10 @@ void gfunc_call(int nb_args)
continue; /* arguments smaller than 8 bytes passed in registers or on stack */ continue; /* arguments smaller than 8 bytes passed in registers or on stack */
if (bt == VT_STRUCT) { 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; size = (size + 15) & ~15;
/* generate structure store */ /* generate structure store */
r = get_reg(RC_INT); r = get_reg(RC_INT);