Skip to content

Commit 0321b24

Browse files
committed
Fix va_list handling for Windows Arm64 ABI
1 parent 266c7a4 commit 0321b24

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
@@ -21483,6 +21483,17 @@ aarch64_expand_builtin_va_start (tree valist, rtx nextarg ATTRIBUTE_UNUSED)
2148321483
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2148421484
}
2148521485

21486+
#ifdef TARGET_AARCH64_MS_ABI
21487+
21488+
static void
21489+
aarch64_ms_abi_expand_builtin_va_start (tree valist, rtx nextarg)
21490+
{
21491+
nextarg = plus_constant (Pmode, nextarg, cfun->machine->frame.first_vararg_offset, true);
21492+
std_expand_builtin_va_start (valist, nextarg);
21493+
}
21494+
21495+
#endif
21496+
2148621497
/* Implement TARGET_GIMPLIFY_VA_ARG_EXPR. */
2148721498

2148821499
static tree
@@ -21861,6 +21872,10 @@ aarch64_setup_incoming_varargs (cumulative_args_t cum_v,
2186121872
= (ROUND_UP (gr_saved * UNITS_PER_WORD,
2186221873
STACK_BOUNDARY / BITS_PER_UNIT)
2186321874
+ vr_saved * UNITS_PER_VREG);
21875+
21876+
#ifdef TARGET_AARCH64_MS_ABI
21877+
cfun->machine->frame.first_vararg_offset = -gr_saved * UNITS_PER_WORD;
21878+
#endif
2186421879
}
2186521880

2186621881
static void
@@ -22634,9 +22649,12 @@ static const char *
2263422649
aarch64_mangle_type (const_tree type)
2263522650
{
2263622651
/* The AArch64 ABI documents say that "__va_list" has to be
22637-
mangled as if it is in the "std" namespace. */
22652+
mangled as if it is in the "std" namespace.
22653+
The Windows Arm64 ABI uses just an address of the first variadict argument. */
22654+
#ifndef TARGET_AARCH64_MS_ABI
2263822655
if (lang_hooks.types_compatible_p (CONST_CAST_TREE (type), va_list_type))
2263922656
return "St9__va_list";
22657+
#endif
2264022658

2264122659
/* Half-precision floating point types. */
2264222660
if (SCALAR_FLOAT_TYPE_P (type) && TYPE_PRECISION (type) == 16)
@@ -30986,8 +31004,10 @@ aarch64_run_selftests (void)
3098631004
#undef TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY
3098731005
#define TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY aarch64_print_patchable_function_entry
3098831006

31007+
#ifndef TARGET_AARCH64_MS_ABI
3098931008
#undef TARGET_BUILD_BUILTIN_VA_LIST
3099031009
#define TARGET_BUILD_BUILTIN_VA_LIST aarch64_build_builtin_va_list
31010+
#endif
3099131011

3099231012
#undef TARGET_CALLEE_COPIES
3099331013
#define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_arg_info_false
@@ -31058,7 +31078,11 @@ aarch64_run_selftests (void)
3105831078
#define TARGET_EXPAND_BUILTIN aarch64_expand_builtin
3105931079

3106031080
#undef TARGET_EXPAND_BUILTIN_VA_START
31081+
#ifdef TARGET_AARCH64_MS_ABI
31082+
#define TARGET_EXPAND_BUILTIN_VA_START aarch64_ms_abi_expand_builtin_va_start
31083+
#else
3106131084
#define TARGET_EXPAND_BUILTIN_VA_START aarch64_expand_builtin_va_start
31085+
#endif
3106231086

3106331087
#undef TARGET_FOLD_BUILTIN
3106431088
#define TARGET_FOLD_BUILTIN aarch64_fold_builtin
@@ -31098,8 +31122,10 @@ aarch64_run_selftests (void)
3109831122
#undef TARGET_GIMPLE_FOLD_BUILTIN
3109931123
#define TARGET_GIMPLE_FOLD_BUILTIN aarch64_gimple_fold_builtin
3110031124

31125+
#ifndef TARGET_AARCH64_MS_ABI
3110131126
#undef TARGET_GIMPLIFY_VA_ARG_EXPR
3110231127
#define TARGET_GIMPLIFY_VA_ARG_EXPR aarch64_gimplify_va_arg_expr
31128+
#endif
3110331129

3110431130
#undef TARGET_INIT_BUILTINS
3110531131
#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
@@ -946,6 +946,11 @@ struct GTY (()) aarch64_frame
946946
STACK_BOUNDARY. */
947947
HOST_WIDE_INT saved_varargs_size;
948948

949+
#ifdef TARGET_AARCH64_MS_ABI
950+
/* Offset to the first variadict argument on the stack. */
951+
HOST_WIDE_INT first_vararg_offset;
952+
#endif
953+
949954
/* The number of bytes between the bottom of the static frame (the bottom
950955
of the outgoing arguments) and the bottom of the register save area.
951956
This value is always a multiple of STACK_BOUNDARY. */

0 commit comments

Comments
 (0)