Hi gcc-patches mailing list,
Saurabh Jha <[email protected]> has requested that the following 
forgejo pull request
be published on the mailing list.

Created on: 2025-10-28 12:52:52+00:00
Latest update: 2025-11-26 10:27:07+00:00
Changes: 19 changed files, 763 additions, 37 deletions
Head revision: saurabh.jha/gcc-TEST ref mingw-data-types-abi commit 
81a24486b40846a206051ab949f1bb319f10c543
Base revision: gcc/gcc-TEST ref trunk commit 
72ac4625d2a257bcc2ca562ffa360f560d7c1fd9 r16-5579-g72ac4625d2a257
Merge base: 72ac4625d2a257bcc2ca562ffa360f560d7c1fd9
Full diff url: https://forge.sourceware.org/gcc/gcc-TEST/pulls/118.diff
Discussion:  https://forge.sourceware.org/gcc/gcc-TEST/pulls/118
Requested Reviewers: pinskia

Hey,

Mostly addressed comments by Evgeny here:
https://gcc.gnu.org/pipermail/gcc-patches/2025-November/701145.html.

In particular, while the code hasn't changed much from v4, the file
organisation has changed. New ABI functions are now defined in
aarch64-abi-ms.cc and declared in aarch64-abi-ms-protos.h.

Thanks,
Saurabh

Saurabh Jha (3):
  aarch64: mingw: emit seh_endproc as comment
  aarch64: mingw: Make long double 64 bit
  aarch64: mingw: Implement support for variadic ABI

 gcc/config.gcc                                |   3 +-
 gcc/config/aarch64/aarch64-abi-ms-protos.h    |  32 +++
 gcc/config/aarch64/aarch64-abi-ms.cc          | 106 ++++++++
 gcc/config/aarch64/aarch64-abi-ms.h           |  20 ++
 gcc/config/aarch64/aarch64-builtins.cc        |  33 +++
 gcc/config/aarch64/aarch64-coff.h             |   5 -
 gcc/config/aarch64/aarch64-protos.h           |   1 +
 gcc/config/aarch64/aarch64.cc                 | 253 ++++++++++++++++--
 gcc/config/aarch64/aarch64.h                  |  16 ++
 gcc/config/aarch64/cygming.h                  |   5 +-
 gcc/config/aarch64/t-aarch64-mingw            |  25 ++
 gcc/config/mingw/winnt.cc                     |  22 ++
 gcc/config/mingw/winnt.h                      |   1 +
 .../aarch64/mingw/long_double_size.c          |  23 ++
 .../gcc.target/aarch64/mingw/mingw.exp        |  41 +++
 .../gcc.target/aarch64/mingw/variadic_hfa.c   |  71 +++++
 .../gcc.target/aarch64/mingw/variadic_hva.c   |  89 ++++++
 .../gcc.target/aarch64/mingw/variadic_int.c   |  41 +++
 gcc/testsuite/lib/scanasm.exp                 |  12 +-
 19 files changed, 763 insertions(+), 36 deletions(-)
 create mode 100644 gcc/config/aarch64/aarch64-abi-ms-protos.h
 create mode 100644 gcc/config/aarch64/aarch64-abi-ms.cc
 create mode 100644 gcc/config/aarch64/t-aarch64-mingw
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mingw/long_double_size.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mingw/mingw.exp
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mingw/variadic_hfa.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mingw/variadic_hva.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mingw/variadic_int.c

--
2.34.1


Changed files:
- A: gcc/config/aarch64/aarch64-abi-ms-protos.h
- A: gcc/config/aarch64/aarch64-abi-ms.cc
- A: gcc/config/aarch64/t-aarch64-mingw
- A: gcc/testsuite/gcc.target/aarch64/mingw/long_double_size.c
- A: gcc/testsuite/gcc.target/aarch64/mingw/mingw.exp
- A: gcc/testsuite/gcc.target/aarch64/mingw/variadic_hfa.c
- A: gcc/testsuite/gcc.target/aarch64/mingw/variadic_hva.c
- A: gcc/testsuite/gcc.target/aarch64/mingw/variadic_int.c
- M: gcc/config.gcc
- M: gcc/config/aarch64/aarch64-abi-ms.h
- M: gcc/config/aarch64/aarch64-builtins.cc
- M: gcc/config/aarch64/aarch64-coff.h
- M: gcc/config/aarch64/aarch64-protos.h
- M: gcc/config/aarch64/aarch64.cc
- M: gcc/config/aarch64/aarch64.h
- M: gcc/config/aarch64/cygming.h
- M: gcc/config/mingw/winnt.cc
- M: gcc/config/mingw/winnt.h
- M: gcc/testsuite/lib/scanasm.exp


Saurabh Jha (3):
  aarch64: mingw: emit seh_endproc as comment
  aarch64: mingw: Make long double 64 bit
  aarch64: mingw: Implement support for variadic ABI

 gcc/config.gcc                                |   3 +-
 gcc/config/aarch64/aarch64-abi-ms-protos.h    |  34 +++
 gcc/config/aarch64/aarch64-abi-ms.cc          | 106 ++++++++
 gcc/config/aarch64/aarch64-abi-ms.h           |  20 ++
 gcc/config/aarch64/aarch64-builtins.cc        |  33 +++
 gcc/config/aarch64/aarch64-coff.h             |   5 -
 gcc/config/aarch64/aarch64-protos.h           |   1 +
 gcc/config/aarch64/aarch64.cc                 | 250 ++++++++++++++++--
 gcc/config/aarch64/aarch64.h                  |  16 ++
 gcc/config/aarch64/cygming.h                  |   5 +-
 gcc/config/aarch64/t-aarch64-mingw            |  25 ++
 gcc/config/mingw/winnt.cc                     |  22 ++
 gcc/config/mingw/winnt.h                      |   1 +
 .../aarch64/mingw/long_double_size.c          |  23 ++
 .../gcc.target/aarch64/mingw/mingw.exp        |  41 +++
 .../gcc.target/aarch64/mingw/variadic_hfa.c   |  71 +++++
 .../gcc.target/aarch64/mingw/variadic_hva.c   |  89 +++++++
 .../gcc.target/aarch64/mingw/variadic_int.c   |  41 +++
 gcc/testsuite/lib/scanasm.exp                 |  12 +-
 19 files changed, 762 insertions(+), 36 deletions(-)
 create mode 100644 gcc/config/aarch64/aarch64-abi-ms-protos.h
 create mode 100644 gcc/config/aarch64/aarch64-abi-ms.cc
 create mode 100644 gcc/config/aarch64/t-aarch64-mingw
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mingw/long_double_size.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mingw/mingw.exp
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mingw/variadic_hfa.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mingw/variadic_hva.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/mingw/variadic_int.c

Range-diff against v4:
1:  02b91e42c20c ! 1:  671127733b03 aarch64: mingw: emit seh_endproc as comment
    @@ Commit message
     
         gcc/ChangeLog:
     
    -            * config/aarch64/aarch64-coff.h
    +            * config/aarch64/aarch64-abi-ms.h
                 (ASM_COMMENT_START): Specify start of comment.
    +            (ASM_OUTPUT_TYPE_DIRECTIVE): Moved from aarch64-coff.h.
                 (ASM_DECLARE_FUNCTION_SIZE): Specify end of function as 
comment.
    +            * config/aarch64/aarch64-coff.h
    +            (ASM_OUTPUT_TYPE_DIRECTIVE): Moved to aarch64-abi-ms.h.
    +            (ASM_DECLARE_FUNCTION_SIZE): Moved to aarch64-abi-ms.h.
     
         gcc/testsuite/ChangeLog:
     
                 * lib/scanasm.exp: Add support for mingw targets.
     
    - ## gcc/config/aarch64/aarch64-coff.h ##
    -@@
    - #define ASM_OUTPUT_SKIP(STREAM, NBYTES)   \
    -   fprintf (STREAM, "\t.space\t%d  // skip\n", (int) (NBYTES))
    + ## gcc/config/aarch64/aarch64-abi-ms.h ##
    +@@ gcc/config/aarch64/aarch64-abi-ms.h: along with GCC; see the file 
COPYING3.  If not see
    + #undef  STATIC_CHAIN_REGNUM
    + #define STATIC_CHAIN_REGNUM R17_REGNUM
      
    --/* Definitions that are not yet supported by binutils for the
     +#define ASM_COMMENT_START "//"
     +
     +/* ASM_OUTPUT_TYPE_DIRECTIVE is not yet supported by binutils for the
    -    aarch64-w64-mingw32 target.  */
    - #define ASM_OUTPUT_TYPE_DIRECTIVE(STREAM, NAME, TYPE)
    --#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)
    ++   aarch64-w64-mingw32 target.  */
    ++#define ASM_OUTPUT_TYPE_DIRECTIVE(STREAM, NAME, TYPE)
     +
     +/* Structured Exception Handling (SEH) is not yet supported by binutils
     +   so adding seh_endproc as an assembly comment to mark the end of a
     +   function.  */
     +#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL) \
     +  fprintf (FILE, "\t" ASM_COMMENT_START "  seh_endproc\n")
    ++
    + #endif /* GCC_AARCH64_ABI_MS_H.  */
    +
    + ## gcc/config/aarch64/aarch64-coff.h ##
    +@@
    + #define ASM_OUTPUT_SKIP(STREAM, NBYTES)   \
    +   fprintf (STREAM, "\t.space\t%d  // skip\n", (int) (NBYTES))
      
    +-/* Definitions that are not yet supported by binutils for the
    +-   aarch64-w64-mingw32 target.  */
    +-#define ASM_OUTPUT_TYPE_DIRECTIVE(STREAM, NAME, TYPE)
    +-#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)
    +-
      #define TEXT_SECTION_ASM_OP       "\t.text"
      #define DATA_SECTION_ASM_OP       "\t.data"
    + #define BSS_SECTION_ASM_OP        "\t.bss"
     
      ## gcc/testsuite/lib/scanasm.exp ##
     @@
2:  e4cd37d2dbde ! 2:  a1e357254cd6 aarch64: mingw: Make long double 64 bit
    @@ Commit message
     
         gcc/ChangeLog:
     
    -            * config/aarch64/aarch64-coff.h
    +            * config/aarch64/aarch64-abi-ms.h
                 (TARGET_LONG_DOUBLE_128): Set this to 0.
                 (__NO_BINARY80__): Define this so that __ENABLE_BINARY80__ is
                 set to 0.
    @@ Commit message
         co-authored-by: Radek Barton <[email protected]>
         co-authored-by: Martin Vejbora <[email protected]>
     
    - ## gcc/config/aarch64/aarch64-coff.h ##
    -@@
    - #undef PTRDIFF_TYPE
    - #define PTRDIFF_TYPE      "long long int"
    + ## gcc/config/aarch64/aarch64-abi-ms.h ##
    +@@ gcc/config/aarch64/aarch64-abi-ms.h: along with GCC; see the file 
COPYING3.  If not see
    + #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL) \
    +   fprintf (FILE, "\t" ASM_COMMENT_START "  seh_endproc\n")
      
     +/* Long double is 64 bit for Coff targets.
     +   Reference:
    @@ gcc/config/aarch64/aarch64-coff.h
     +#undef TARGET_LONG_DOUBLE_128
     +#define TARGET_LONG_DOUBLE_128 0
     +
    - #undef LONG_TYPE_SIZE
    - #define LONG_TYPE_SIZE 32
    - 
     +#define __NO_BINARY80__
     +
    - #ifndef ASM_GENERATE_INTERNAL_LABEL
    - # define ASM_GENERATE_INTERNAL_LABEL(STRING, PREFIX, NUM)  \
    -   sprintf (STRING, "*%s%s%u", LOCAL_LABEL_PREFIX, PREFIX, (unsigned 
int)(NUM))
    + #endif /* GCC_AARCH64_ABI_MS_H.  */
     
      ## gcc/config/aarch64/aarch64.cc ##
     @@ gcc/config/aarch64/aarch64.cc: aarch64_scalar_mode_supported_p 
(scalar_mode mode)
3:  7ea34c526e79 ! 3:  81a24486b408 aarch64: mingw: Implement support for 
variadic ABI
    @@ Commit message
         2. SIMD and Floating-Point registers aren't used.
     
         This patch implements these differences for the aarch64-w64-mingw32
    -    target.
    +    target. The new ABI specific functions to be used in target hooks are
    +    declared in aarch64-abi-ms-protos.h and defined aarch64-abi-ms.cc. We
    +    identify whether we are on aarch64-w64-mingw32 by the
    +    TARGET_AARCH64_MS_ABI macro.
     
         gcc/ChangeLog:
     
    +            * config.gcc: Add new Makefile fragment and new object file.
                 * config/aarch64/aarch64-builtins.cc
                 (aarch64_ms_variadic_abi_init_builtins): Initialize builtin
                 variadic functions for aarch64-w64-mingw32.
    @@ Commit message
                 * config/aarch64/aarch64.cc
                 (handle_aarch64_vector_pcs_attribute): Add support for
                 ARM_PCS_MS_VARIADIC.
    -            (aarch64_ms_is_variadic_function_type): Check whether a 
function
    -            on aarch64-w64-mingw32 target has variadic arguments.
                 (aarch64_ms_variadic_abi): Return descriptor to variadic
                 function call ABI for aarch64-w64-mingw32 target.
                 (aarch64_fntype_abi): Add support for variadic functions for
                 aarch64-w64-mingw32 target.
                 (aarch64_reg_save_mode): Add support for ARM_PCS_MS_VARIADIC.
                 (num_pcs_arg_regs): Add support for ARM_PCS_MS_VARIADIC.
    +            (get_pcs_arg_reg): Add support for ARM_PCS_MS_VARIADIC.
                 (aarch64_arg_size): Returns size of argument.
                 (aarch64_ms_variadic_abi_layout_arg): aarch64-w64-mingw32
                 specific support for variadic ABI.
                 (aarch64_layout_arg): Add support for ARM_PCS_MS_VARIADIC.
    -            (aarch64_arg_partial_bytes): Implement 
TARGET_ARG_PARTIAL_BYTES.
                 (aarch64_function_arg): Implement TARGET_FUNCTION_ARG.
                 (aarch64_function_arg_advance): Add support for
                 ARM_PCS_MS_VARIADIC.
                 (aarch64_function_arg_regno_p): Add support for
                 ARM_PCS_MS_VARIADIC.
    -            (aarch64_ms_variadic_abi_build_builtin_va_list): Implement
    -            TARGET_BUILD_BUILTIN_VA_LIST.
    +            (aarch64_init_builtins): Add support for TARGET_AARCH64_MS_ABI.
    +            (aarch64_ms_variadic_abi_build_builtin_va_list): Setup va_list
    +            for aarch64-w64-mingw32.
    +            (aarch64_build_builtin_va_list): Add support for
    +            TARGET_AARCH64_MS_ABI.
                 (aarch64_ms_variadic_abi_expand_builtin_va_start): Implement
                 TARGET_BUILD_BUILTIN_VA_START.
    -            (aarch64_ms_variadic_abi_enum_va_list): Implement
    -            TARGET_ENUM_VA_LIST_P.
    -            (aarch64_ms_variadic_abi_fn_abi_va_list): Implement
    -            TARGET_FN_ABI_VA_LIST.
    -            (aarch64_ms_variadic_abi_canonical_va_list_type): Implement
    -            TARGET_CANONICAL_VA_LIST_TYPE.
                 (aarch64_setup_incoming_varargs): Implement
                 TARGET_SETUP_INCOMING_VARARGS.
                 (aarch64_mangle_type): Implement TARGET_MANGLE_TYPE.
    @@ Commit message
                 ARM_PCS_MS_VARIADIC.
                 * config/aarch64/cygming.h
                 (SUBTARGET_ATTRIBUTE_TABLE): Add support for ms_abi.
    -            (SUBTARGET_INIT_BUILTINS): Handles variadic ABI.
                 * config/mingw/winnt.cc
                 (aarch64_handle_ms_abi_attribute): Handle ms_abi attribue.
                 * config/mingw/winnt.h
                 (aarch64_handle_ms_abi_attribute): Handle ms_abi attribute.
    +            * config/aarch64/aarch64-abi-ms-protos.h:
    +            (aarch64_arg_partial_bytes): Declare.
    +            (aarch64_ms_variadic_abi_canonical_va_list_type): Declare.
    +            (aarch64_ms_variadic_abi_enum_va_list): Declare.
    +            (aarch64_ms_variadic_abi_fn_abi_va_list): Implement
    +            TARGET_FN_ABI_VA_LIST.
    +            * config/aarch64/aarch64-abi-ms.cc:
    +            (aarch64_arg_partial_bytes): Implement 
TARGET_ARG_PARTIAL_BYTES.
    +            (aarch64_ms_variadic_abi_canonical_va_list_type): Implement
    +            TARGET_CANONICAL_VA_LIST_TYPE.
    +            (aarch64_ms_variadic_abi_enum_va_list): Implement
    +            TARGET_ENUM_VA_LIST_P.
    +            (aarch64_ms_variadic_abi_fn_abi_va_list): Implement
    +            TARGET_FN_ABI_VA_LIST.
    +            * config/aarch64/t-aarch64-mingw: New Makefile fragment.
     
         gcc/testsuite/ChangeLog:
     
    @@ Commit message
     
         co-authored-by: Radek Barton <[email protected]>
     
    + ## gcc/config.gcc ##
    +@@ gcc/config.gcc: aarch64-*-mingw*)
    +   tm_file="${tm_file} mingw/winnt.h"
    +   tm_file="${tm_file} mingw/winnt-dll.h"
    +   tmake_file="${tmake_file} aarch64/t-aarch64"
    ++  tmake_file="${tmake_file} aarch64/t-aarch64-mingw"
    +         native_system_header_dir=/mingw/include
    +   target_gtfiles="$target_gtfiles \$(srcdir)/config/mingw/winnt.cc"
    +   target_gtfiles="$target_gtfiles \$(srcdir)/config/mingw/winnt-dll.cc"
    +   extra_options="${extra_options} mingw/cygming.opt mingw/mingw.opt"
    +-  extra_objs="${extra_objs} winnt.o winnt-dll.o"
    ++  extra_objs="${extra_objs} aarch64-abi-ms.o winnt.o winnt-dll.o"
    +   c_target_objs="${c_target_objs} msformat-c.o"
    +   cxx_target_objs="${cxx_target_objs} msformat-c.o"
    +   d_target_objs="${d_target_objs} winnt-d.o"
    +
    + ## gcc/config/aarch64/aarch64-abi-ms-protos.h (new) ##
    +@@
    ++/* Windows specific ABI for AArch64 architecture.
    ++   Copyright (C) 2025 Free Software Foundation, Inc.
    ++   Contributed by ARM Ltd.
    ++
    ++   This file is part of GCC.
    ++
    ++   GCC is free software; you can redistribute it and/or modify it
    ++   under the terms of the GNU General Public License as published by
    ++   the Free Software Foundation; either version 3, or (at your option)
    ++   any later version.
    ++
    ++   GCC is distributed in the hope that it will be useful, but
    ++   WITHOUT ANY WARRANTY; without even the implied warranty of
    ++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    ++   General Public License for more details.
    ++
    ++   You should have received a copy of the GNU General Public License
    ++   along with GCC; see the file COPYING3.  If not see
    ++   <http://www.gnu.org/licenses/>.  */
    ++
    ++#ifndef GCC_AARCH64_ABI_MS_PROTOS_H
    ++#define GCC_AARCH64_ABI_MS_PROTOS_H
    ++
    ++extern int aarch64_ms_variadic_abi_enum_va_list (int, const char **,
    ++                                           tree *ptree);
    ++
    ++extern tree aarch64_ms_variadic_abi_fn_abi_va_list (tree fndecl);
    ++
    ++extern tree aarch64_ms_variadic_abi_canonical_va_list_type (tree type);
    ++
    ++extern int aarch64_arg_partial_bytes (cumulative_args_t,
    ++                                const function_arg_info &);
    ++
    ++#endif
    +
    + ## gcc/config/aarch64/aarch64-abi-ms.cc (new) ##
    +@@
    ++/* Windows specific ABI for AArch64 architecture.
    ++   Copyright (C) 2025 Free Software Foundation, Inc.
    ++   Contributed by ARM Ltd.
    ++
    ++   This file is part of GCC.
    ++
    ++   GCC is free software; you can redistribute it and/or modify it
    ++   under the terms of the GNU General Public License as published by
    ++   the Free Software Foundation; either version 3, or (at your option)
    ++   any later version.
    ++
    ++   GCC is distributed in the hope that it will be useful, but
    ++   WITHOUT ANY WARRANTY; without even the implied warranty of
    ++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    ++   General Public License for more details.
    ++
    ++   You should have received a copy of the GNU General Public License
    ++   along with GCC; see the file COPYING3.  If not see
    ++   <http://www.gnu.org/licenses/>.  */
    ++
    ++#define IN_TARGET_CODE 1
    ++
    ++#include "config.h"
    ++#include "system.h"
    ++#include "coretypes.h"
    ++#include "target.h"
    ++#include "backend.h"
    ++#include "rtl.h"
    ++#include "tree.h"
    ++#include "stringpool.h"
    ++#include "attribs.h"
    ++#include "regs.h"
    ++#include "function-abi.h"
    ++#include "builtins.h"
    ++#include "aarch64-abi-ms-protos.h"
    ++
    ++/* Iterate through the target-specific builtin types for va_list.
    ++   IDX denotes the iterator, *PTREE is set to the result type of
    ++   the va_list builtin, and *PNAME to its internal type.
    ++   Returns zero if there is no element for this index, otherwise
    ++   IDX should be increased upon the next call.
    ++   Note, do not iterate a base builtin's name like __builtin_va_list.
    ++   Used from c_common_nodes_and_builtins.  */
    ++
    ++int
    ++aarch64_ms_variadic_abi_enum_va_list (int idx, const char **pname, tree 
*ptree)
    ++{
    ++  switch (idx)
    ++    {
    ++    default:
    ++      break;
    ++
    ++    case 0:
    ++      *ptree = ms_va_list_type_node;
    ++      *pname = "__builtin_ms_va_list";
    ++      return 1;
    ++    }
    ++
    ++  return 0;
    ++}
    ++
    ++/* This function returns the calling abi specific va_list type node.
    ++   It returns  the FNDECL specific va_list type.  */
    ++
    ++tree
    ++aarch64_ms_variadic_abi_fn_abi_va_list (tree fndecl)
    ++{
    ++  gcc_assert (fndecl != NULL_TREE);
    ++
    ++  arm_pcs pcs = (arm_pcs) fndecl_abi (fndecl).id ();
    ++  if (pcs == ARM_PCS_MS_VARIADIC)
    ++    return ms_va_list_type_node;
    ++
    ++  return std_fn_abi_va_list (fndecl);
    ++}
    ++
    ++/* Returns the canonical va_list type specified by TYPE.
    ++   If there is no valid TYPE provided, it return NULL_TREE.  */
    ++
    ++tree
    ++aarch64_ms_variadic_abi_canonical_va_list_type (tree type)
    ++{
    ++  if (lookup_attribute ("ms_abi va_list", TYPE_ATTRIBUTES (type)))
    ++    return ms_va_list_type_node;
    ++
    ++  return NULL_TREE;
    ++}
    ++
    ++/* Implement TARGET_ARG_PARTIAL_BYTES.  */
    ++
    ++int
    ++aarch64_arg_partial_bytes (cumulative_args_t pcum_v,
    ++                     const function_arg_info &arg ATTRIBUTE_UNUSED)
    ++{
    ++  CUMULATIVE_ARGS *pcum = get_cumulative_args (pcum_v);
    ++
    ++  if (pcum->pcs_variant != ARM_PCS_MS_VARIADIC)
    ++    return 0;
    ++
    ++  /* Handle the case when argument is split between the last registers and
    ++     the stack.  */
    ++  if ((pcum->aapcs_reg != NULL_RTX) && (pcum->aapcs_stack_words != 0))
    ++    return pcum->aapcs_stack_words * UNITS_PER_WORD;
    ++
    ++  return 0;
    ++}
    +
      ## gcc/config/aarch64/aarch64-builtins.cc ##
     @@ gcc/config/aarch64/aarch64-builtins.cc: aarch64_general_init_builtins 
(void)
          handle_arm_acle_h ();
    @@ gcc/config/aarch64/aarch64-protos.h: gimple 
*aarch64_general_gimple_fold_builtin
      
     
      ## gcc/config/aarch64/aarch64.cc ##
    +@@
    + #include "rtlanal.h"
    + #include "tree-dfa.h"
    + #include "asan.h"
    ++#include "aarch64-abi-ms-protos.h"
    + #include "aarch64-elf-metadata.h"
    + #include "aarch64-feature-deps.h"
    + #include "config/arm/aarch-common.h"
     @@
      #define HAVE_AS_AEABI_BUILD_ATTRIBUTES 0
      #endif
    @@ gcc/config/aarch64/aarch64.cc: handle_aarch64_vector_pcs_attribute (tree 
*node,
            return NULL_TREE;
      
     -      /* Rely on the exclusions list for preserve_none.  */
    ++    case ARM_PCS_MS_VARIADIC:
     +    /* Rely on the exclusions list for preserve_none.  */
          case ARM_PCS_PRESERVE_NONE:
    -+    case ARM_PCS_MS_VARIADIC:
          case ARM_PCS_TLSDESC:
          case ARM_PCS_UNKNOWN:
    -       break;
     @@ gcc/config/aarch64/aarch64.cc: aarch64_takes_arguments_in_sve_regs_p 
(const_tree fntype)
        return false;
      }
      
    -+/* Returns true if a function has variadic arguments.
    -+   Only works for Windows ABI.  */
    -+
    -+static bool
    -+aarch64_ms_is_variadic_function_type (const_tree fntype)
    -+{
    -+  if (!TARGET_AARCH64_MS_ABI)
    -+    return false;
    -+
    -+  if (TYPE_NO_NAMED_ARGS_STDARG_P (fntype))
    -+    return true;
    -+
    -+  auto arg_count = 0;
    -+  for (tree arg = TYPE_ARG_TYPES (fntype); arg; arg = TREE_CHAIN (arg))
    -+    {
    -+      if (TREE_VALUE (arg) == void_type_node)
    -+  return false;
    -+      arg_count++;
    -+    }
    -+
    -+  return arg_count > 0;
    -+}
    -+
     +/* Return the descriptor of the Windows Arm64 variadic function call ABI. 
 */
     +
     +static const predefined_function_abi &
    @@ gcc/config/aarch64/aarch64.cc: aarch64_takes_arguments_in_sve_regs_p 
(const_tree
      static const predefined_function_abi &
      aarch64_fntype_abi (const_tree fntype)
      {
    -+  if (aarch64_ms_is_variadic_function_type (fntype))
    -+    return aarch64_ms_variadic_abi ();
    -+
    -+  if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (fntype)))
    ++  if (TARGET_AARCH64_MS_ABI && stdarg_p (fntype))
     +    return aarch64_ms_variadic_abi ();
     +
        if (lookup_attribute ("aarch64_vector_pcs", TYPE_ATTRIBUTES (fntype)))
          return aarch64_simd_abi ();
      
     @@ gcc/config/aarch64/aarch64.cc: aarch64_reg_save_mode (unsigned int 
regno)
    -   /* Only the low 64 bits are saved by the base PCS.  */
    +   if (FP_REGNUM_P (regno))
    +     switch (crtl->abi->id ())
    +       {
    ++      case ARM_PCS_AAPCS64:
    ++  /* Only the low 64 bits are saved by the base PCS.  */
    +       case ARM_PCS_PRESERVE_NONE:
    +   /* In preserve_none all fpr registers are caller saved, so the choice
    +      here should not matter.  Nevertheless, fall back to the base AAPCS
    +      for consistency.  */
    +-      case ARM_PCS_AAPCS64:
    +-  /* Only the low 64 bits are saved by the base PCS.  */
        return DFmode;
      
     +      case ARM_PCS_MS_VARIADIC:
    @@ gcc/config/aarch64/aarch64.cc: aarch64_reg_save_mode (unsigned int regno)
        /* The vector PCS saves the low 128 bits (which is the full
           register on non-SVE targets).  */
     @@ gcc/config/aarch64/aarch64.cc: num_pcs_arg_regs (enum arm_pcs pcs)
    +     case ARM_PCS_PRESERVE_NONE:
    +       return NUM_PRESERVE_NONE_ARG_REGS;
    +     case ARM_PCS_AAPCS64:
    ++    case ARM_PCS_MS_VARIADIC:
          case ARM_PCS_SIMD:
          case ARM_PCS_SVE:
          case ARM_PCS_TLSDESC:
    -+    case ARM_PCS_MS_VARIADIC:
    -     case ARM_PCS_UNKNOWN:
    -       return NUM_ARG_REGS;
    -     }
     @@ gcc/config/aarch64/aarch64.cc: get_pcs_arg_reg (enum arm_pcs pcs, int 
num)
    +     case ARM_PCS_PRESERVE_NONE:
    +       return ARM_PCS_PRESERVE_NONE_REGISTERS[num];
    +     case ARM_PCS_AAPCS64:
    ++    case ARM_PCS_MS_VARIADIC:
          case ARM_PCS_SIMD:
          case ARM_PCS_SVE:
          case ARM_PCS_TLSDESC:
    -+    case ARM_PCS_MS_VARIADIC:
    -     case ARM_PCS_UNKNOWN:
    -       return R0_REGNUM + num;
    -     }
    +@@ gcc/config/aarch64/aarch64.cc: get_pcs_arg_reg (enum arm_pcs pcs, int 
num)
        gcc_unreachable ();
      }
      
    @@ gcc/config/aarch64/aarch64.cc: aarch64_layout_arg (cumulative_args_t 
pcum_v, con
        allocate_nvrn = aarch64_vfp_is_call_candidate (pcum_v,
                                                 mode,
     @@ gcc/config/aarch64/aarch64.cc: aarch64_function_arg (cumulative_args_t 
pcum_v, const function_arg_info &arg)
    + {
    +   CUMULATIVE_ARGS *pcum = get_cumulative_args (pcum_v);
        gcc_assert (pcum->pcs_variant == ARM_PCS_AAPCS64
    ++        || pcum->pcs_variant == ARM_PCS_PRESERVE_NONE
    ++        || pcum->pcs_variant == ARM_PCS_MS_VARIADIC
              || pcum->pcs_variant == ARM_PCS_SIMD
    -         || pcum->pcs_variant == ARM_PCS_SVE
    +-        || pcum->pcs_variant == ARM_PCS_SVE
     -        || pcum->pcs_variant == ARM_PCS_PRESERVE_NONE);
    -+        || pcum->pcs_variant == ARM_PCS_PRESERVE_NONE
    -+        || pcum->pcs_variant == ARM_PCS_MS_VARIADIC);
    - 
    +-
    ++        || pcum->pcs_variant == ARM_PCS_SVE);
        if (arg.end_marker_p ())
          {
    +       rtx abi_cookie = aarch64_gen_callee_cookie (pcum->isa_mode,
     @@ gcc/config/aarch64/aarch64.cc: aarch64_function_arg_advance 
(cumulative_args_t pcum_v,
        if (pcum->pcs_variant == ARM_PCS_AAPCS64
            || pcum->pcs_variant == ARM_PCS_SIMD
    @@ gcc/config/aarch64/aarch64.cc: aarch64_function_arg_advance 
(cumulative_args_t p
     +      || pcum->pcs_variant == ARM_PCS_MS_VARIADIC)
          {
            aarch64_layout_arg (pcum_v, arg);
    --      gcc_assert ((pcum->aapcs_reg != NULL_RTX)
    --            != (pcum->aapcs_stack_words != 0));
    -+      gcc_assert ((pcum->pcs_variant == ARM_PCS_MS_VARIADIC)
    -+             || (pcum->aapcs_reg != NULL_RTX)
    -+                 != (pcum->aapcs_stack_words != 0));
    -       if (pcum->aapcs_reg
    -     && aarch64_call_switches_pstate_sm (pcum->isa_mode))
    -   aarch64_record_sme_mode_switch_args (pcum);
    +       if (pcum->aapcs_reg && aarch64_call_switches_pstate_sm 
(pcum->isa_mode))
     @@ gcc/config/aarch64/aarch64.cc: aarch64_function_arg_regno_p (unsigned 
regno)
    +   switch (pcs)
    +     {
    +     case ARM_PCS_AAPCS64:
    ++    case ARM_PCS_MS_VARIADIC:
          case ARM_PCS_SIMD:
          case ARM_PCS_SVE:
          case ARM_PCS_TLSDESC:
    -+    case ARM_PCS_MS_VARIADIC:
    -     case ARM_PCS_UNKNOWN:
    -       return ((GP_REGNUM_P (regno) && regno < R0_REGNUM + NUM_ARG_REGS)
    -         || (FP_REGNUM_P (regno) && regno < V0_REGNUM + NUM_FP_ARG_REGS)
    +@@ gcc/config/aarch64/aarch64.cc: aarch64_init_builtins ()
    + {
    +   aarch64_general_init_builtins ();
    +   aarch64_sve::init_builtins ();
    ++  if (TARGET_AARCH64_MS_ABI)
    ++    {
    ++      do
    ++  {
    ++    aarch64_ms_variadic_abi_init_builtins ();
    ++  } while (0);
    ++    }
    + #ifdef SUBTARGET_INIT_BUILTINS
    +   SUBTARGET_INIT_BUILTINS;
    + #endif
     @@ gcc/config/aarch64/aarch64.cc: aarch64_load_tp (rtx target)
        return target;
      }
      
     +/* Windows Arm64 variadic function call ABI specific va_list type node.  
*/
    -+tree ms_va_list_type_node;
    ++tree ms_va_list_type_node = NULL_TREE;
     +
     +/* Setup the builtin va_list data type and for 64-bit the additional
     +   calling convention specific va_list data types.  */
    @@ gcc/config/aarch64/aarch64.cc: aarch64_build_builtin_va_list (void)
        tree f_stack, f_grtop, f_vrtop, f_groff, f_vroff;
        tree stack, grtop, vrtop, groff, vroff;
     @@ gcc/config/aarch64/aarch64.cc: aarch64_expand_builtin_va_start (tree 
valist, rtx nextarg ATTRIBUTE_UNUSED)
    -   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
    - }
      
    -+#if TARGET_AARCH64_MS_ABI == 1
    -+
    -+/* Iterate through the target-specific builtin types for va_list.
    -+   IDX denotes the iterator, *PTREE is set to the result type of
    -+   the va_list builtin, and *PNAME to its internal type.
    -+   Returns zero if there is no element for this index, otherwise
    -+   IDX should be increased upon the next call.
    -+   Note, do not iterate a base builtin's name like __builtin_va_list.
    -+   Used from c_common_nodes_and_builtins.  */
    -+
    -+static int
    -+aarch64_ms_variadic_abi_enum_va_list (int idx, const char **pname, tree 
*ptree)
    -+{
    -+  switch (idx)
    -+    {
    -+    default:
    -+      break;
    -+
    -+    case 0:
    -+      *ptree = ms_va_list_type_node;
    -+      *pname = "__builtin_ms_va_list";
    -+      return 1;
    -+    }
    -+
    -+  return 0;
    -+}
    -+
    -+/* This function returns the calling abi specific va_list type node.
    -+   It returns  the FNDECL specific va_list type.  */
    -+
    -+static tree
    -+aarch64_ms_variadic_abi_fn_abi_va_list (tree fndecl)
    -+{
    -+  gcc_assert (fndecl != NULL_TREE);
    -+
    -+  arm_pcs pcs = (arm_pcs) fndecl_abi (fndecl).id ();
    -+  if (pcs == ARM_PCS_MS_VARIADIC)
    -+    return ms_va_list_type_node;
    -+
    -+  return std_fn_abi_va_list (fndecl);
    -+}
    -+
    -+/* Returns the canonical va_list type specified by TYPE.
    -+   If there is no valid TYPE provided, it return NULL_TREE.  */
    -+
    -+static tree
    -+aarch64_ms_variadic_abi_canonical_va_list_type (tree type)
    -+{
    -+  if (lookup_attribute ("ms_abi va_list", TYPE_ATTRIBUTES (type)))
    -+    return ms_va_list_type_node;
    -+
    -+  return NULL_TREE;
    -+}
    -+
    -+/* Implement TARGET_ARG_PARTIAL_BYTES.  */
    -+
    -+static int
    -+aarch64_arg_partial_bytes (cumulative_args_t pcum_v,
    -+                          const function_arg_info &arg ATTRIBUTE_UNUSED)
    -+{
    -+  CUMULATIVE_ARGS *pcum = get_cumulative_args (pcum_v);
    -+
    -+  if (pcum->pcs_variant != ARM_PCS_MS_VARIADIC)
    -+    return 0;
    -+
    -+  /* Handle the case when argument is split between the last registers and
    -+     the stack.  */
    -+  if ((pcum->aapcs_reg != NULL_RTX) && (pcum->aapcs_stack_words != 0))
    -+    return pcum->aapcs_stack_words * UNITS_PER_WORD;
    -+
    -+  return 0;
    -+}
    -+
    -+#endif
    -+
      /* Implement TARGET_GIMPLIFY_VA_ARG_EXPR.  */
      
     +#if TARGET_AARCH64_MS_ABI == 0
    @@ gcc/config/aarch64/cygming.h: still needed for compilation.  */
      
      #undef SUB_TARGET_RECORD_STUB
      #define SUB_TARGET_RECORD_STUB(NAME, DECL) mingw_pe_record_stub((NAME), \
    -@@ gcc/config/aarch64/cygming.h: still needed for compilation.  */
    - #define TARGET_ASM_LTO_END mingw_pe_asm_lto_end
    - 
    - #endif
    -+
    -+/* aarch64-w64-mingw32 handles variadic ABI differently.  */
    -+#undef  SUBTARGET_INIT_BUILTINS
    -+#define SUBTARGET_INIT_BUILTINS   \
    -+  do                                                      \
    -+  {                                                       \
    -+          aarch64_ms_variadic_abi_init_builtins (); \
    -+  } while (0)
    +
    + ## gcc/config/aarch64/t-aarch64-mingw (new) ##
    +@@
    ++# Windows specific ABI for AArch64 architecture.
    ++# Copyright (C) 2025 Free Software Foundation, Inc.
    ++# Contributed by ARM Ltd.
    ++#
    ++# This file is part of GCC.
    ++#
    ++# GCC is free software; you can redistribute it and/or modify it
    ++# under the terms of the GNU General Public License as published by
    ++# the Free Software Foundation; either version 3, or (at your option)
    ++# any later version.
    ++#
    ++# GCC is distributed in the hope that it will be useful, but
    ++# WITHOUT ANY WARRANTY; without even the implied warranty of
    ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    ++# General Public License for more details.
    ++#
    ++# You should have received a copy of the GNU General Public License
    ++# along with GCC; see the file COPYING3.  If not see
    ++# <http://www.gnu.org/licenses/>.
    ++
    ++aarch64-abi-ms.o: \
    ++  $(srcdir)/config/aarch64/aarch64-abi-ms.cc \
    ++  $(TREE_H)
    ++  $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
    ++          $(srcdir)/config/aarch64/aarch64-abi-ms.cc
     
      ## gcc/config/mingw/winnt.cc ##
     @@ gcc/config/mingw/winnt.cc: mingw_pe_encode_section_info (tree decl, rtx 
rtl, int first)
    @@ gcc/config/mingw/winnt.cc: mingw_pe_encode_section_info (tree decl, rtx 
rtl, int
     
      ## gcc/config/mingw/winnt.h ##
     @@ gcc/config/mingw/winnt.h: http://www.gnu.org/licenses/.  */
    + 
      #ifndef USED_FOR_TARGET
      
    - extern tree mingw_handle_selectany_attribute (tree *, tree, tree, int, 
bool *);
     +extern tree aarch64_handle_ms_abi_attribute (tree *, tree, tree, int, 
bool *);
    + extern tree mingw_handle_selectany_attribute (tree *, tree, tree, int, 
bool *);
      
      extern void mingw_pe_asm_named_section (const char *, unsigned int, tree);
    - extern void mingw_pe_asm_lto_start (void);
     
      ## gcc/testsuite/gcc.target/aarch64/mingw/variadic_hfa.c (new) ##
     @@
-- 
2.52.0


Reply via email to