History

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

kbkpbot committed 1 year ago

Commit af1cfd91 parent 34b7b2c4 files · +31 −1Browse files

Unified · Split

4 files
  1. i386-gen.c +3 −0
  2. tests/tests2/135_func_arg_struct_compare.c +23 −0
  3. tests/tests2/135_func_arg_struct_compare.expect +1 −0
  4. x86_64-gen.c +4 −1
i386-gen.c+3−0
@@ -409,6 +409,9 @@ ST_FUNC void gfunc_call(int nb_args) · 408 unmodified lines
409 args_size = 0;409 args_size = 0;
410 for(i = 0;i < nb_args; i++) {410 for(i = 0;i < nb_args; i++) {
411 if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) {411 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);
412 size = type_size(&vtop->type, &align);415 size = type_size(&vtop->type, &align);
413 /* align to stack align size */416 /* align to stack align size */
414 size = (size + 3) & ~3;417 size = (size + 3) & ~3;
tests/tests2/135_func_arg_struct_compare.c+23−0
@@ -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
6struct string {
7 char *str;
8 int len;
9};
10
11void dummy(struct string fpath, int dump_arg) {
12}
13
14int 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
tests/tests2/135_func_arg_struct_compare.expect+1−0
@@ -0,0 +1 @@
1done
x86_64-gen.c+4−1
@@ -828,7 +828,10 @@ void gfunc_call(int nb_args) · 827 unmodified lines
828 continue; /* arguments smaller than 8 bytes passed in registers or on stack */828 continue; /* arguments smaller than 8 bytes passed in registers or on stack */
829 829
830 if (bt == VT_STRUCT) {830 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 */
832 size = (size + 15) & ~15;835 size = (size + 15) & ~15;
833 /* generate structure store */836 /* generate structure store */
834 r = get_reg(RC_INT);837 r = get_reg(RC_INT);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t