Re: [PATCH] arm: Fixed C23 call compatibility with arm-none-eabi

2024-03-04 Thread Torbjorn SVENSSON




On 2024-03-01 15:58, Richard Earnshaw (lists) wrote:

On 19/02/2024 09:13, Torbjörn SVENSSON wrote:

Ok for trunk and releases/gcc-13?
Regtested on top of 945cb8490cb for arm-none-eabi, without any regression.

Backporting to releases/gcc-13 will change -std=c23 to -std=c2x.


Jakub has just pushed a different fix for this, so I don't think we need this 
now.

R.


Would it still be benificial to have the 2 test cases for the AAPCS 
validation?


Kind regards,
Torbjörn






--

In commit 4fe34cdcc80ac225b80670eabc38ac5e31ce8a5a, -std=c23 support was
introduced to support functions without any named arguments.  For
arm-none-eabi, this is not as simple as placing all arguments on the
stack.  Align the caller to use r0, r1, r2 and r3 for arguments even for
functions without any named arguments, as specified in the AAPCS.

Verify that the generic test case have the arguments are in the right
order and add ARM specific test cases.

gcc/ChangeLog:

* calls.h: Added the type of the function to function_arg_info.
* calls.cc: Save the type of the function.
* config/arm/arm.cc: Check in the AAPCS layout function if
function has no named args.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/c23-stdarg-split-1a.c: Detect out of order
arguments.
* gcc.dg/torture/c23-stdarg-split-1b.c: Likewise.
* gcc.target/arm/aapcs/align_vaarg3.c: New test.
* gcc.target/arm/aapcs/align_vaarg4.c: New test.

Signed-off-by: Torbjörn SVENSSON 
Co-authored-by: Yvan ROUX 
---
  gcc/calls.cc  |  2 +-
  gcc/calls.h   | 20 --
  gcc/config/arm/arm.cc | 13 ---
  .../gcc.dg/torture/c23-stdarg-split-1a.c  |  4 +-
  .../gcc.dg/torture/c23-stdarg-split-1b.c  | 15 +---
  .../gcc.target/arm/aapcs/align_vaarg3.c   | 37 +++
  .../gcc.target/arm/aapcs/align_vaarg4.c   | 31 
  7 files changed, 102 insertions(+), 20 deletions(-)
  create mode 100644 gcc/testsuite/gcc.target/arm/aapcs/align_vaarg3.c
  create mode 100644 gcc/testsuite/gcc.target/arm/aapcs/align_vaarg4.c

diff --git a/gcc/calls.cc b/gcc/calls.cc
index 01f44734743..a1cc283b952 100644
--- a/gcc/calls.cc
+++ b/gcc/calls.cc
@@ -1376,7 +1376,7 @@ initialize_argument_information (int num_actuals 
ATTRIBUTE_UNUSED,
 with those made by function.cc.  */
  
/* See if this argument should be passed by invisible reference.  */

-  function_arg_info arg (type, argpos < n_named_args);
+  function_arg_info arg (type, fntype, argpos < n_named_args);
if (pass_by_reference (args_so_far_pnt, arg))
{
  const bool callee_copies
diff --git a/gcc/calls.h b/gcc/calls.h
index 464a4e34e33..88836559ebe 100644
--- a/gcc/calls.h
+++ b/gcc/calls.h
@@ -35,24 +35,33 @@ class function_arg_info
  {
  public:
function_arg_info ()
-: type (NULL_TREE), mode (VOIDmode), named (false),
+: type (NULL_TREE), fntype (NULL_TREE), mode (VOIDmode), named (false),
pass_by_reference (false)
{}
  
/* Initialize an argument of mode MODE, either before or after promotion.  */

function_arg_info (machine_mode mode, bool named)
-: type (NULL_TREE), mode (mode), named (named), pass_by_reference (false)
+: type (NULL_TREE), fntype (NULL_TREE), mode (mode), named (named),
+pass_by_reference (false)
{}
  
/* Initialize an unpromoted argument of type TYPE.  */

function_arg_info (tree type, bool named)
-: type (type), mode (TYPE_MODE (type)), named (named),
+: type (type), fntype (NULL_TREE), mode (TYPE_MODE (type)), named (named),
pass_by_reference (false)
{}
  
+  /* Initialize an unpromoted argument of type TYPE with a known function type

+ FNTYPE.  */
+  function_arg_info (tree type, tree fntype, bool named)
+: type (type), fntype (fntype), mode (TYPE_MODE (type)), named (named),
+pass_by_reference (false)
+  {}
+
/* Initialize an argument with explicit properties.  */
function_arg_info (tree type, machine_mode mode, bool named)
-: type (type), mode (mode), named (named), pass_by_reference (false)
+: type (type), fntype (NULL_TREE), mode (mode), named (named),
+pass_by_reference (false)
{}
  
/* Return true if the gimple-level type is an aggregate.  */

@@ -96,6 +105,9 @@ public:
   libgcc support functions).  */
tree type;
  
+  /* The type of the function that has this argument, or null if not known.  */

+  tree fntype;
+
/* The mode of the argument.  Depending on context, this might be
   the mode of the argument type or the mode after promotion.  */
machine_mode mode;
diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
index 1cd69268ee9..98e149e5b7e 100644
--- a/gcc/config/arm/arm.cc
+++ b/gcc/config/arm/arm.cc
@@ -7006,7 +7006,7 @@ aapcs_libcall_value (machine_mode mode)
 numbers referred to here are those in the AAPCS.  */

Re: [PATCH] arm: Fixed C23 call compatibility with arm-none-eabi

2024-03-01 Thread Richard Earnshaw (lists)
On 19/02/2024 09:13, Torbjörn SVENSSON wrote:
> Ok for trunk and releases/gcc-13?
> Regtested on top of 945cb8490cb for arm-none-eabi, without any regression.
> 
> Backporting to releases/gcc-13 will change -std=c23 to -std=c2x.

Jakub has just pushed a different fix for this, so I don't think we need this 
now.

R.


> 
> --
> 
> In commit 4fe34cdcc80ac225b80670eabc38ac5e31ce8a5a, -std=c23 support was
> introduced to support functions without any named arguments.  For
> arm-none-eabi, this is not as simple as placing all arguments on the
> stack.  Align the caller to use r0, r1, r2 and r3 for arguments even for
> functions without any named arguments, as specified in the AAPCS.
> 
> Verify that the generic test case have the arguments are in the right
> order and add ARM specific test cases.
> 
> gcc/ChangeLog:
> 
>   * calls.h: Added the type of the function to function_arg_info.
>   * calls.cc: Save the type of the function.
>   * config/arm/arm.cc: Check in the AAPCS layout function if
>   function has no named args.
> 
> gcc/testsuite/ChangeLog:
> 
>   * gcc.dg/torture/c23-stdarg-split-1a.c: Detect out of order
>   arguments.
>   * gcc.dg/torture/c23-stdarg-split-1b.c: Likewise.
>   * gcc.target/arm/aapcs/align_vaarg3.c: New test.
>   * gcc.target/arm/aapcs/align_vaarg4.c: New test.
> 
> Signed-off-by: Torbjörn SVENSSON 
> Co-authored-by: Yvan ROUX 
> ---
>  gcc/calls.cc  |  2 +-
>  gcc/calls.h   | 20 --
>  gcc/config/arm/arm.cc | 13 ---
>  .../gcc.dg/torture/c23-stdarg-split-1a.c  |  4 +-
>  .../gcc.dg/torture/c23-stdarg-split-1b.c  | 15 +---
>  .../gcc.target/arm/aapcs/align_vaarg3.c   | 37 +++
>  .../gcc.target/arm/aapcs/align_vaarg4.c   | 31 
>  7 files changed, 102 insertions(+), 20 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/arm/aapcs/align_vaarg3.c
>  create mode 100644 gcc/testsuite/gcc.target/arm/aapcs/align_vaarg4.c
> 
> diff --git a/gcc/calls.cc b/gcc/calls.cc
> index 01f44734743..a1cc283b952 100644
> --- a/gcc/calls.cc
> +++ b/gcc/calls.cc
> @@ -1376,7 +1376,7 @@ initialize_argument_information (int num_actuals 
> ATTRIBUTE_UNUSED,
>with those made by function.cc.  */
>  
>/* See if this argument should be passed by invisible reference.  */
> -  function_arg_info arg (type, argpos < n_named_args);
> +  function_arg_info arg (type, fntype, argpos < n_named_args);
>if (pass_by_reference (args_so_far_pnt, arg))
>   {
> const bool callee_copies
> diff --git a/gcc/calls.h b/gcc/calls.h
> index 464a4e34e33..88836559ebe 100644
> --- a/gcc/calls.h
> +++ b/gcc/calls.h
> @@ -35,24 +35,33 @@ class function_arg_info
>  {
>  public:
>function_arg_info ()
> -: type (NULL_TREE), mode (VOIDmode), named (false),
> +: type (NULL_TREE), fntype (NULL_TREE), mode (VOIDmode), named (false),
>pass_by_reference (false)
>{}
>  
>/* Initialize an argument of mode MODE, either before or after promotion.  
> */
>function_arg_info (machine_mode mode, bool named)
> -: type (NULL_TREE), mode (mode), named (named), pass_by_reference (false)
> +: type (NULL_TREE), fntype (NULL_TREE), mode (mode), named (named),
> +pass_by_reference (false)
>{}
>  
>/* Initialize an unpromoted argument of type TYPE.  */
>function_arg_info (tree type, bool named)
> -: type (type), mode (TYPE_MODE (type)), named (named),
> +: type (type), fntype (NULL_TREE), mode (TYPE_MODE (type)), named 
> (named),
>pass_by_reference (false)
>{}
>  
> +  /* Initialize an unpromoted argument of type TYPE with a known function 
> type
> + FNTYPE.  */
> +  function_arg_info (tree type, tree fntype, bool named)
> +: type (type), fntype (fntype), mode (TYPE_MODE (type)), named (named),
> +pass_by_reference (false)
> +  {}
> +
>/* Initialize an argument with explicit properties.  */
>function_arg_info (tree type, machine_mode mode, bool named)
> -: type (type), mode (mode), named (named), pass_by_reference (false)
> +: type (type), fntype (NULL_TREE), mode (mode), named (named),
> +pass_by_reference (false)
>{}
>  
>/* Return true if the gimple-level type is an aggregate.  */
> @@ -96,6 +105,9 @@ public:
>   libgcc support functions).  */
>tree type;
>  
> +  /* The type of the function that has this argument, or null if not known.  
> */
> +  tree fntype;
> +
>/* The mode of the argument.  Depending on context, this might be
>   the mode of the argument type or the mode after promotion.  */
>machine_mode mode;
> diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
> index 1cd69268ee9..98e149e5b7e 100644
> --- a/gcc/config/arm/arm.cc
> +++ b/gcc/config/arm/arm.cc
> @@ -7006,7 +7006,7 @@ aapcs_libcall_value (machine_mode mode)
> numbers referred to here are those in the AAPCS.

Re: [PATCH] arm: Fixed C23 call compatibility with arm-none-eabi

2024-02-19 Thread Andrew Pinski
On Mon, Feb 19, 2024 at 1:14 AM Torbjörn SVENSSON
 wrote:
>
> Ok for trunk and releases/gcc-13?
> Regtested on top of 945cb8490cb for arm-none-eabi, without any regression.
>
> Backporting to releases/gcc-13 will change -std=c23 to -std=c2x.
>
> --
>
> In commit 4fe34cdcc80ac225b80670eabc38ac5e31ce8a5a, -std=c23 support was
> introduced to support functions without any named arguments.  For
> arm-none-eabi, this is not as simple as placing all arguments on the
> stack.  Align the caller to use r0, r1, r2 and r3 for arguments even for
> functions without any named arguments, as specified in the AAPCS.
>
> Verify that the generic test case have the arguments are in the right
> order and add ARM specific test cases.
>
> gcc/ChangeLog:
>
> * calls.h: Added the type of the function to function_arg_info.
> * calls.cc: Save the type of the function.
> * config/arm/arm.cc: Check in the AAPCS layout function if
> function has no named args.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.dg/torture/c23-stdarg-split-1a.c: Detect out of order
> arguments.
> * gcc.dg/torture/c23-stdarg-split-1b.c: Likewise.

It is almost always better to add a new testcase for the expanded idea
of the test rather than modifying the original.

Thanks,
Andrew Pinski

> * gcc.target/arm/aapcs/align_vaarg3.c: New test.
> * gcc.target/arm/aapcs/align_vaarg4.c: New test.
>
> Signed-off-by: Torbjörn SVENSSON 
> Co-authored-by: Yvan ROUX 
> ---
>  gcc/calls.cc  |  2 +-
>  gcc/calls.h   | 20 --
>  gcc/config/arm/arm.cc | 13 ---
>  .../gcc.dg/torture/c23-stdarg-split-1a.c  |  4 +-
>  .../gcc.dg/torture/c23-stdarg-split-1b.c  | 15 +---
>  .../gcc.target/arm/aapcs/align_vaarg3.c   | 37 +++
>  .../gcc.target/arm/aapcs/align_vaarg4.c   | 31 
>  7 files changed, 102 insertions(+), 20 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/arm/aapcs/align_vaarg3.c
>  create mode 100644 gcc/testsuite/gcc.target/arm/aapcs/align_vaarg4.c
>
> diff --git a/gcc/calls.cc b/gcc/calls.cc
> index 01f44734743..a1cc283b952 100644
> --- a/gcc/calls.cc
> +++ b/gcc/calls.cc
> @@ -1376,7 +1376,7 @@ initialize_argument_information (int num_actuals 
> ATTRIBUTE_UNUSED,
>  with those made by function.cc.  */
>
>/* See if this argument should be passed by invisible reference.  */
> -  function_arg_info arg (type, argpos < n_named_args);
> +  function_arg_info arg (type, fntype, argpos < n_named_args);
>if (pass_by_reference (args_so_far_pnt, arg))
> {
>   const bool callee_copies
> diff --git a/gcc/calls.h b/gcc/calls.h
> index 464a4e34e33..88836559ebe 100644
> --- a/gcc/calls.h
> +++ b/gcc/calls.h
> @@ -35,24 +35,33 @@ class function_arg_info
>  {
>  public:
>function_arg_info ()
> -: type (NULL_TREE), mode (VOIDmode), named (false),
> +: type (NULL_TREE), fntype (NULL_TREE), mode (VOIDmode), named (false),
>pass_by_reference (false)
>{}
>
>/* Initialize an argument of mode MODE, either before or after promotion.  
> */
>function_arg_info (machine_mode mode, bool named)
> -: type (NULL_TREE), mode (mode), named (named), pass_by_reference (false)
> +: type (NULL_TREE), fntype (NULL_TREE), mode (mode), named (named),
> +pass_by_reference (false)
>{}
>
>/* Initialize an unpromoted argument of type TYPE.  */
>function_arg_info (tree type, bool named)
> -: type (type), mode (TYPE_MODE (type)), named (named),
> +: type (type), fntype (NULL_TREE), mode (TYPE_MODE (type)), named 
> (named),
>pass_by_reference (false)
>{}
>
> +  /* Initialize an unpromoted argument of type TYPE with a known function 
> type
> + FNTYPE.  */
> +  function_arg_info (tree type, tree fntype, bool named)
> +: type (type), fntype (fntype), mode (TYPE_MODE (type)), named (named),
> +pass_by_reference (false)
> +  {}
> +
>/* Initialize an argument with explicit properties.  */
>function_arg_info (tree type, machine_mode mode, bool named)
> -: type (type), mode (mode), named (named), pass_by_reference (false)
> +: type (type), fntype (NULL_TREE), mode (mode), named (named),
> +pass_by_reference (false)
>{}
>
>/* Return true if the gimple-level type is an aggregate.  */
> @@ -96,6 +105,9 @@ public:
>   libgcc support functions).  */
>tree type;
>
> +  /* The type of the function that has this argument, or null if not known.  
> */
> +  tree fntype;
> +
>/* The mode of the argument.  Depending on context, this might be
>   the mode of the argument type or the mode after promotion.  */
>machine_mode mode;
> diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
> index 1cd69268ee9..98e149e5b7e 100644
> --- a/gcc/config/arm/arm.cc
> +++ b/gcc/config/arm/arm.cc
> @@ -7006,7 +7006,7 @@ aapcs_libcall_value (mach

[PATCH] arm: Fixed C23 call compatibility with arm-none-eabi

2024-02-19 Thread Torbjörn SVENSSON
Ok for trunk and releases/gcc-13?
Regtested on top of 945cb8490cb for arm-none-eabi, without any regression.

Backporting to releases/gcc-13 will change -std=c23 to -std=c2x.

--

In commit 4fe34cdcc80ac225b80670eabc38ac5e31ce8a5a, -std=c23 support was
introduced to support functions without any named arguments.  For
arm-none-eabi, this is not as simple as placing all arguments on the
stack.  Align the caller to use r0, r1, r2 and r3 for arguments even for
functions without any named arguments, as specified in the AAPCS.

Verify that the generic test case have the arguments are in the right
order and add ARM specific test cases.

gcc/ChangeLog:

* calls.h: Added the type of the function to function_arg_info.
* calls.cc: Save the type of the function.
* config/arm/arm.cc: Check in the AAPCS layout function if
function has no named args.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/c23-stdarg-split-1a.c: Detect out of order
arguments.
* gcc.dg/torture/c23-stdarg-split-1b.c: Likewise.
* gcc.target/arm/aapcs/align_vaarg3.c: New test.
* gcc.target/arm/aapcs/align_vaarg4.c: New test.

Signed-off-by: Torbjörn SVENSSON 
Co-authored-by: Yvan ROUX 
---
 gcc/calls.cc  |  2 +-
 gcc/calls.h   | 20 --
 gcc/config/arm/arm.cc | 13 ---
 .../gcc.dg/torture/c23-stdarg-split-1a.c  |  4 +-
 .../gcc.dg/torture/c23-stdarg-split-1b.c  | 15 +---
 .../gcc.target/arm/aapcs/align_vaarg3.c   | 37 +++
 .../gcc.target/arm/aapcs/align_vaarg4.c   | 31 
 7 files changed, 102 insertions(+), 20 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/arm/aapcs/align_vaarg3.c
 create mode 100644 gcc/testsuite/gcc.target/arm/aapcs/align_vaarg4.c

diff --git a/gcc/calls.cc b/gcc/calls.cc
index 01f44734743..a1cc283b952 100644
--- a/gcc/calls.cc
+++ b/gcc/calls.cc
@@ -1376,7 +1376,7 @@ initialize_argument_information (int num_actuals 
ATTRIBUTE_UNUSED,
 with those made by function.cc.  */
 
   /* See if this argument should be passed by invisible reference.  */
-  function_arg_info arg (type, argpos < n_named_args);
+  function_arg_info arg (type, fntype, argpos < n_named_args);
   if (pass_by_reference (args_so_far_pnt, arg))
{
  const bool callee_copies
diff --git a/gcc/calls.h b/gcc/calls.h
index 464a4e34e33..88836559ebe 100644
--- a/gcc/calls.h
+++ b/gcc/calls.h
@@ -35,24 +35,33 @@ class function_arg_info
 {
 public:
   function_arg_info ()
-: type (NULL_TREE), mode (VOIDmode), named (false),
+: type (NULL_TREE), fntype (NULL_TREE), mode (VOIDmode), named (false),
   pass_by_reference (false)
   {}
 
   /* Initialize an argument of mode MODE, either before or after promotion.  */
   function_arg_info (machine_mode mode, bool named)
-: type (NULL_TREE), mode (mode), named (named), pass_by_reference (false)
+: type (NULL_TREE), fntype (NULL_TREE), mode (mode), named (named),
+pass_by_reference (false)
   {}
 
   /* Initialize an unpromoted argument of type TYPE.  */
   function_arg_info (tree type, bool named)
-: type (type), mode (TYPE_MODE (type)), named (named),
+: type (type), fntype (NULL_TREE), mode (TYPE_MODE (type)), named (named),
   pass_by_reference (false)
   {}
 
+  /* Initialize an unpromoted argument of type TYPE with a known function type
+ FNTYPE.  */
+  function_arg_info (tree type, tree fntype, bool named)
+: type (type), fntype (fntype), mode (TYPE_MODE (type)), named (named),
+pass_by_reference (false)
+  {}
+
   /* Initialize an argument with explicit properties.  */
   function_arg_info (tree type, machine_mode mode, bool named)
-: type (type), mode (mode), named (named), pass_by_reference (false)
+: type (type), fntype (NULL_TREE), mode (mode), named (named),
+pass_by_reference (false)
   {}
 
   /* Return true if the gimple-level type is an aggregate.  */
@@ -96,6 +105,9 @@ public:
  libgcc support functions).  */
   tree type;
 
+  /* The type of the function that has this argument, or null if not known.  */
+  tree fntype;
+
   /* The mode of the argument.  Depending on context, this might be
  the mode of the argument type or the mode after promotion.  */
   machine_mode mode;
diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
index 1cd69268ee9..98e149e5b7e 100644
--- a/gcc/config/arm/arm.cc
+++ b/gcc/config/arm/arm.cc
@@ -7006,7 +7006,7 @@ aapcs_libcall_value (machine_mode mode)
numbers referred to here are those in the AAPCS.  */
 static void
 aapcs_layout_arg (CUMULATIVE_ARGS *pcum, machine_mode mode,
- const_tree type, bool named)
+ const_tree type, bool named, const_tree fntype)
 {
   int nregs, nregs2;
   int ncrn;
@@ -7018,8 +7018,9 @@ aapcs_layout_arg (CUMULATIVE_ARGS *pcum, machine_mode 
mode,
   pcum->aapcs_arg_processed = true;
 
   /* S