Skip to content

Commit 157819e

Browse files
committed
Fix va_list handling for Windows Arm64 ABI
1 parent a591924 commit 157819e

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

gcc/config/aarch64/aarch64.cc

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21584,6 +21584,17 @@ aarch64_expand_builtin_va_start (tree valist, rtx nextarg ATTRIBUTE_UNUSED)
2158421584
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2158521585
}
2158621586

21587+
#ifdef TARGET_AARCH64_MS_ABI
21588+
21589+
static void
21590+
aarch64_ms_abi_expand_builtin_va_start (tree valist, rtx nextarg)
21591+
{
21592+
nextarg = plus_constant (Pmode, nextarg, cfun->machine->frame.first_vararg_offset, true);
21593+
std_expand_builtin_va_start (valist, nextarg);
21594+
}
21595+
21596+
#endif
21597+
2158721598
/* Implement TARGET_GIMPLIFY_VA_ARG_EXPR. */
2158821599

2158921600
static tree
@@ -21962,6 +21973,10 @@ aarch64_setup_incoming_varargs (cumulative_args_t cum_v,
2196221973
= (ROUND_UP (gr_saved * UNITS_PER_WORD,
2196321974
STACK_BOUNDARY / BITS_PER_UNIT)
2196421975
+ vr_saved * UNITS_PER_VREG);
21976+
21977+
#ifdef TARGET_AARCH64_MS_ABI
21978+
cfun->machine->frame.first_vararg_offset = -gr_saved * UNITS_PER_WORD;
21979+
#endif
2196521980
}
2196621981

2196721982
static void
@@ -22744,9 +22759,12 @@ static const char *
2274422759
aarch64_mangle_type (const_tree type)
2274522760
{
2274622761
/* The AArch64 ABI documents say that "__va_list" has to be
22747-
mangled as if it is in the "std" namespace. */
22762+
mangled as if it is in the "std" namespace.
22763+
The Windows Arm64 ABI uses just an address of the first variadict argument. */
22764+
#ifndef TARGET_AARCH64_MS_ABI
2274822765
if (lang_hooks.types_compatible_p (CONST_CAST_TREE (type), va_list_type))
2274922766
return "St9__va_list";
22767+
#endif
2275022768

2275122769
/* Half-precision floating point types. */
2275222770
if (SCALAR_FLOAT_TYPE_P (type) && TYPE_PRECISION (type) == 16)
@@ -31266,8 +31284,10 @@ aarch64_run_selftests (void)
3126631284
#undef TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY
3126731285
#define TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY aarch64_print_patchable_function_entry
3126831286

31287+
#ifndef TARGET_AARCH64_MS_ABI
3126931288
#undef TARGET_BUILD_BUILTIN_VA_LIST
3127031289
#define TARGET_BUILD_BUILTIN_VA_LIST aarch64_build_builtin_va_list
31290+
#endif
3127131291

3127231292
#undef TARGET_CALLEE_COPIES
3127331293
#define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_arg_info_false
@@ -31338,7 +31358,11 @@ aarch64_run_selftests (void)
3133831358
#define TARGET_EXPAND_BUILTIN aarch64_expand_builtin
3133931359

3134031360
#undef TARGET_EXPAND_BUILTIN_VA_START
31361+
#ifdef TARGET_AARCH64_MS_ABI
31362+
#define TARGET_EXPAND_BUILTIN_VA_START aarch64_ms_abi_expand_builtin_va_start
31363+
#else
3134131364
#define TARGET_EXPAND_BUILTIN_VA_START aarch64_expand_builtin_va_start
31365+
#endif
3134231366

3134331367
#undef TARGET_FOLD_BUILTIN
3134431368
#define TARGET_FOLD_BUILTIN aarch64_fold_builtin
@@ -31378,8 +31402,10 @@ aarch64_run_selftests (void)
3137831402
#undef TARGET_GIMPLE_FOLD_BUILTIN
3137931403
#define TARGET_GIMPLE_FOLD_BUILTIN aarch64_gimple_fold_builtin
3138031404

31405+
#ifndef TARGET_AARCH64_MS_ABI
3138131406
#undef TARGET_GIMPLIFY_VA_ARG_EXPR
3138231407
#define TARGET_GIMPLIFY_VA_ARG_EXPR aarch64_gimplify_va_arg_expr
31408+
#endif
3138331409

3138431410
#undef TARGET_INIT_BUILTINS
3138531411
#define TARGET_INIT_BUILTINS aarch64_init_builtins

gcc/config/aarch64/aarch64.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,11 @@ struct GTY (()) aarch64_frame
10111011
STACK_BOUNDARY. */
10121012
HOST_WIDE_INT saved_varargs_size;
10131013

1014+
#ifdef TARGET_AARCH64_MS_ABI
1015+
/* Offset to the first variadict argument on the stack. */
1016+
HOST_WIDE_INT first_vararg_offset;
1017+
#endif
1018+
10141019
/* The number of bytes between the bottom of the static frame (the bottom
10151020
of the outgoing arguments) and the bottom of the register save area.
10161021
This value is always a multiple of STACK_BOUNDARY. */

0 commit comments

Comments
 (0)