@@ -278,7 +278,6 @@ static int arm64_type_size(int t)
278278 case VT_DOUBLE : return 3 ;
279279 case VT_LDOUBLE : return 4 ;
280280 case VT_BOOL : return 0 ;
281- case VT_VOID : return 0 ;
282281 }
283282 assert (0 );
284283 return 0 ;
@@ -832,11 +831,10 @@ static unsigned long arm64_pcs_aux(int variadic, int n, CType **type, unsigned l
832831
833832 for (i = 0 ; i < n ; i ++ ) {
834833 int hfa = arm64_hfa (type [i ], 0 );
835- int win_vararg_float = 0 ;
836- int size , align ;
834+ int size , align , bt ;
837835
838- if (( type [i ]-> t & VT_ARRAY ) ||
839- ( type [ i ] -> t & VT_BTYPE ) == VT_FUNC )
836+ bt = type [i ]-> t & VT_BTYPE ;
837+ if ( bt == VT_PTR || bt == VT_FUNC )
840838 size = align = 8 ;
841839 else
842840 size = type_size (type [i ], & align );
@@ -848,13 +846,10 @@ static unsigned long arm64_pcs_aux(int variadic, int n, CType **type, unsigned l
848846 }
849847
850848#elif defined(TCC_TARGET_PE )
851- if (variadic && i >= variadic && ( hfa || is_float ( type [ i ] -> t )) ) {
849+ if (variadic && i >= variadic ) {
852850 hfa = 0 ;
853- if (is_float (type [i ]-> t )) {
854- win_vararg_float = 1 ;
855- size = 8 ;
856- align = 8 ;
857- }
851+ if (is_float (bt ))
852+ bt = VT_INT , size = align = 8 ;
858853 }
859854#endif
860855 if (hfa )
@@ -871,12 +866,12 @@ static unsigned long arm64_pcs_aux(int variadic, int n, CType **type, unsigned l
871866 }
872867 continue ;
873868 }
874- else if (( type [ i ] -> t & VT_BTYPE ) == VT_STRUCT )
869+ else if (bt == VT_STRUCT )
875870 // B.4
876871 size = (size + 7 ) & ~7 ;
877872
878873 // C.1
879- if (! win_vararg_float && is_float (type [ i ] -> t ) && nv < 8 ) {
874+ if (is_float (bt ) && nv < 8 ) {
880875 a [i ] = 16 + (nv ++ << 1 );
881876 continue ;
882877 }
@@ -895,24 +890,24 @@ static unsigned long arm64_pcs_aux(int variadic, int n, CType **type, unsigned l
895890 }
896891
897892 // C.4
898- if (hfa || ( type [ i ] -> t & VT_BTYPE ) == VT_LDOUBLE ) {
893+ if (hfa || bt == VT_LDOUBLE ) {
899894 ns = (ns + 7 ) & ~7 ;
900895 ns = (ns + align - 1 ) & - align ;
901896 }
902897
903898 // C.5
904- if (( type [ i ] -> t & VT_BTYPE ) == VT_FLOAT )
899+ if (bt == VT_FLOAT )
905900 size = 8 ;
906901
907902 // C.6
908- if (! win_vararg_float && ( hfa || is_float (type [ i ] -> t ) )) {
903+ if (hfa || is_float (bt )) {
909904 a [i ] = ns ;
910905 ns += size ;
911906 continue ;
912907 }
913908
914909 // C.7
915- if (( type [ i ] -> t & VT_BTYPE ) != VT_STRUCT && size <= 8 && nx < 8 ) {
910+ if (bt != VT_STRUCT && size <= 8 && nx < 8 ) {
916911 a [i ] = nx ++ << 1 ;
917912 continue ;
918913 }
@@ -922,14 +917,14 @@ static unsigned long arm64_pcs_aux(int variadic, int n, CType **type, unsigned l
922917 nx = (nx + 1 ) & ~1 ;
923918
924919 // C.9
925- if (( type [ i ] -> t & VT_BTYPE ) != VT_STRUCT && size == 16 && nx < 7 ) {
920+ if (bt != VT_STRUCT && size == 16 && nx < 7 ) {
926921 a [i ] = nx << 1 ;
927922 nx += 2 ;
928923 continue ;
929924 }
930925
931926 // C.10
932- if (( type [ i ] -> t & VT_BTYPE ) == VT_STRUCT && size <= (8 - nx ) * 8 ) {
927+ if (bt == VT_STRUCT && size <= (8 - nx ) * 8 ) {
933928 a [i ] = nx << 1 ;
934929 nx += (size + 7 ) >> 3 ;
935930 continue ;
@@ -943,7 +938,7 @@ static unsigned long arm64_pcs_aux(int variadic, int n, CType **type, unsigned l
943938 ns = (ns + align - 1 ) & - align ;
944939
945940 // C.13
946- if (( type [ i ] -> t & VT_BTYPE ) == VT_STRUCT ) {
941+ if (bt == VT_STRUCT ) {
947942 a [i ] = ns ;
948943 ns += size ;
949944 continue ;
@@ -974,11 +969,11 @@ static unsigned long arm64_pcs(int variadic, int n, CType **type, unsigned long
974969 }
975970
976971 // Argument types:
977- stack = arm64_pcs_aux (variadic , n , type + 1 , a + 1 );
972+ stack = arm64_pcs_aux (variadic , n - 1 , type + 1 , a + 1 );
978973
979974 if (0 ) {
980975 int i ;
981- for (i = 0 ; i <= n ; i ++ ) {
976+ for (i = 0 ; i < n ; i ++ ) {
982977 if (!i )
983978 printf ("arm64_pcs return: " );
984979 else
@@ -1076,9 +1071,9 @@ ST_FUNC void gfunc_call(int nb_args)
10761071
10771072 stack = arm64_pcs (
10781073#ifdef TCC_TARGET_PE
1079- old_style ? -1 :
1074+ old_style ? /* all args like varargs in K&R style */ -1 :
10801075#endif
1081- var_nb_arg , nb_args , t , a );
1076+ var_nb_arg , nb_args + 1 , t , a );
10821077
10831078 // Allocate space for structs replaced by pointer:
10841079 for (i = nb_args ; i ; i -- )
@@ -1258,43 +1253,39 @@ ST_FUNC void gfunc_prolog(Sym *func_sym)
12581253 CType * func_type = & func_sym -> type ;
12591254 int n = 0 ;
12601255 int i = 0 ;
1261- int pcs_n ;
12621256 Sym * sym ;
12631257 CType * * t ;
12641258 unsigned long * a ;
12651259 int use_x8 = 0 ;
12661260 int last_int = 0 ;
12671261 int last_float = 0 ;
12681262 int variadic = func_sym -> type .ref -> f .func_type == FUNC_ELLIPSIS ;
1269- int var_nb_arg = n_func_args (& func_sym -> type );
1270- int c ;
1263+ int var_nb_arg = variadic ? n_func_args (& func_sym -> type ) : 0 ;
12711264
12721265 func_vc = 144 ; // offset of where x8 is stored
12731266
12741267 for (sym = func_type -> ref ; sym ; sym = sym -> next )
12751268 ++ n ;
12761269
1277- pcs_n = n - 1 ;
1278- c = n + variadic ;
1279- t = tcc_malloc (c * sizeof (* t ));
1280- a = tcc_malloc (c * sizeof (* a ));
1270+ #ifdef TCC_TARGET_PE
1271+ n += variadic ;
1272+ #endif
12811273
1274+ t = tcc_malloc (n * sizeof (* t ));
1275+ a = tcc_malloc (n * sizeof (* a ));
12821276 for (sym = func_type -> ref ; sym ; sym = sym -> next )
12831277 t [i ++ ] = & sym -> type ;
12841278
12851279#ifdef TCC_TARGET_PE
1286- if (variadic ) {
1287- t [i ++ ] = & int_type ;
1288- ++ pcs_n ;
1289- }
1280+ if (variadic )
1281+ t [i ] = & int_type ;
12901282#endif
12911283
1292- arm64_func_va_list_stack = arm64_pcs (variadic ? var_nb_arg : 0 ,
1293- pcs_n , t , a );
1284+ arm64_func_va_list_stack = arm64_pcs (var_nb_arg , n , t , a );
12941285
12951286#ifdef TCC_TARGET_PE
12961287 if (variadic )
1297- arm64_func_va_list_stack = arm64_pe_param_off (a [n ]);
1288+ arm64_func_va_list_stack = arm64_pe_param_off (a [n - 1 ]);
12981289#endif
12991290
13001291#if !defined(TCC_TARGET_MACHO )
@@ -1304,6 +1295,7 @@ ST_FUNC void gfunc_prolog(Sym *func_sym)
13041295 last_float = 4 ;
13051296 }
13061297#endif
1298+
13071299 if (a && a [0 ] == 1 )
13081300 use_x8 = 1 ;
13091301 for (i = 1 , sym = func_type -> ref -> next ; sym ; i ++ , sym = sym -> next ) {
@@ -1563,7 +1555,8 @@ ST_FUNC void gfunc_return(CType *func_type)
15631555 CType * t = func_type ;
15641556 unsigned long a ;
15651557
1566- arm64_pcs (0 , 0 , & t , & a );
1558+ arm64_pcs (0 , 1 , & t , & a );
1559+
15671560 switch (a ) {
15681561 case -1 :
15691562 break ;
0 commit comments