Skip to content

Commit

Permalink
fix x86_64/i386 gfunc_call, when arg is VT_STRUCT, need fetch cpu fla…
Browse files Browse the repository at this point in the history
…g before generating any code
  • Loading branch information
kbkpbot committed Dec 26, 2024
1 parent 34b7b2c commit af1cfd9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions i386-gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions tests/tests2/135_func_arg_struct_compare.c
Original file line number Diff line number Diff line change
@@ -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;
}

1 change: 1 addition & 0 deletions tests/tests2/135_func_arg_struct_compare.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
done
5 changes: 4 additions & 1 deletion x86_64-gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit af1cfd9

Please sign in to comment.