Skip to content

Commit af1cfd9

Browse files
committed
fix x86_64/i386 gfunc_call, when arg is VT_STRUCT, need fetch cpu flag before generating any code
1 parent 34b7b2c commit af1cfd9

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

i386-gen.c

+3
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ ST_FUNC void gfunc_call(int nb_args)
409409
args_size = 0;
410410
for(i = 0;i < nb_args; i++) {
411411
if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) {
412+
/* fetch cpu flag before generating any code */
413+
if ((vtop->r & VT_VALMASK) == VT_CMP)
414+
gv(RC_INT);
412415
size = type_size(&vtop->type, &align);
413416
/* align to stack align size */
414417
size = (size + 3) & ~3;
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// https://lists.nongnu.org/archive/html/tinycc-devel/2024-12/msg00019.html
2+
// x86_64/i386 void gfunc_call(int nb_args), when push struct args, need fetch cpu flag before generating any code
3+
4+
#include <stdio.h>
5+
6+
struct string {
7+
char *str;
8+
int len;
9+
};
10+
11+
void dummy(struct string fpath, int dump_arg) {
12+
}
13+
14+
int main() {
15+
int a = 1;
16+
struct string x;
17+
x.str = "gg.v";
18+
x.len = 4;
19+
dummy(x, a == 0);
20+
printf("done\n");
21+
return 0;
22+
}
23+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
done

x86_64-gen.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,10 @@ void gfunc_call(int nb_args)
828828
continue; /* arguments smaller than 8 bytes passed in registers or on stack */
829829

830830
if (bt == VT_STRUCT) {
831-
/* align to stack align size */
831+
/* fetch cpu flag before generating any code */
832+
if ((vtop->r & VT_VALMASK) == VT_CMP)
833+
gv(RC_INT);
834+
/* align to stack align size */
832835
size = (size + 15) & ~15;
833836
/* generate structure store */
834837
r = get_reg(RC_INT);

0 commit comments

Comments
 (0)