Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/4] gdb.base/callfuncs.c: factor out float/double functions
Date: Tue, 14 Jul 2026 23:06:30 +0100	[thread overview]
Message-ID: <20260714220631.1499846-4-pedro@palves.net> (raw)
In-Reply-To: <20260714220631.1499846-1-pedro@palves.net>

Other than float vs double, t_float_values2 and t_double_values are
identical.  Same for t_float_many_args and t_double_many_args.

Adding 'long double' variants would mean even more duplication.

Factor each "values" and "many_args" pair into a macro that generates
the function from the type, so that adding a new type is just one
line.

Tested on x86_64-unknown-linux-gnu.

Change-Id: I43013f4db9ccf1e5d8ac17dc5b557bd44500b9f4
---
 gdb/testsuite/gdb.base/callfuncs.c | 138 +++++++++++++----------------
 1 file changed, 60 insertions(+), 78 deletions(-)

diff --git a/gdb/testsuite/gdb.base/callfuncs.c b/gdb/testsuite/gdb.base/callfuncs.c
index 1d35272a50e..0e6d9dcdd71 100644
--- a/gdb/testsuite/gdb.base/callfuncs.c
+++ b/gdb/testsuite/gdb.base/callfuncs.c
@@ -345,96 +345,78 @@ float float_arg1, float_arg2;
 	  && (float_arg2 - float_val2) > -DELTA);
 }
 
-int
+/* The parameter list of a t_TYPE_values function.  Split out into
+   prototyped vs non-prototyped variants because a macro body cannot
+   contain #ifdef.  */
+
 #ifdef NO_PROTOTYPES
-/* In this case we are just duplicating t_float_values, but that is the
-   easiest way to deal with either ANSI or non-ANSI.  */
-t_float_values2 (float_arg1, float_arg2)
-     float float_arg1, float_arg2;
+# define T_VALUES_PARAMS(TYPE)		\
+  (arg1, arg2)				\
+     TYPE arg1, arg2;
 #else
-t_float_values2 (float float_arg1, float float_arg2)
+# define T_VALUES_PARAMS(TYPE)		\
+  (TYPE arg1, TYPE arg2)
 #endif
-{
-  return ((float_arg1 - float_val1) < DELTA
-	  && (float_arg1 - float_val1) > -DELTA
-	  && (float_arg2 - float_val2) < DELTA
-	  && (float_arg2 - float_val2) > -DELTA);
-}
 
-/* This function has many arguments to force some of them to be passed via
-   the stack instead of registers, to test that GDB can construct correctly
-   the parameter save area. Note that Linux/ppc32 has 8 float registers to use
-   for float parameter passing and Linux/ppc64 has 13, so the number of
-   arguments has to be at least 14 to contemplate these platforms.  */
+/* Define a function NAME comparing its two TYPE arguments against the
+   TYPE_val1 and TYPE_val2 globals.  */
 
-float
-#ifdef NO_PROTOTYPES
-t_float_many_args (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13,
-		   f14, f15)
-     float f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15;
-#else
-t_float_many_args (float f1, float f2, float f3, float f4, float f5, float f6,
-		   float f7, float f8, float f9, float f10, float f11,
-		   float f12, float f13, float f14, float f15)
-#endif
-{
-  float sum_args;
-  float sum_values;
-
-  sum_args = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12
-	     + f13 + f14 + f15;
-  sum_values = float_val1 + float_val2 + float_val3 + float_val4 + float_val5
-	       + float_val6 + float_val7 + float_val8 + float_val9
-	       + float_val10 + float_val11 + float_val12 + float_val13
-	       + float_val14 + float_val15;
-
-  return ((sum_args - sum_values) < DELTA
-	  && (sum_args - sum_values) > -DELTA);
+#define DEFINE_T_FLOAT_VALUES(TYPE, NAME)			\
+int								\
+NAME T_VALUES_PARAMS (TYPE)					\
+{								\
+  return ((arg1 - TYPE##_val1) < DELTA				\
+	  && (arg1 - TYPE##_val1) > -DELTA			\
+	  && (arg2 - TYPE##_val2) < DELTA			\
+	  && (arg2 - TYPE##_val2) > -DELTA);			\
 }
 
-#ifdef PROTOTYPES
-int t_double_values (double double_arg1, double double_arg2)
-#else
-int t_double_values (double_arg1, double_arg2)
-double double_arg1, double_arg2;
-#endif
-{
-  return ((double_arg1 - double_val1) < DELTA
-	  && (double_arg1 - double_val1) > -DELTA
-	  && (double_arg2 - double_val2) < DELTA
-	  && (double_arg2 - double_val2) > -DELTA);
-}
+DEFINE_T_FLOAT_VALUES (float, t_float_values2)
+DEFINE_T_FLOAT_VALUES (double, t_double_values)
 
-/* This function has many arguments to force some of them to be passed via
-   the stack instead of registers, to test that GDB can construct correctly
-   the parameter save area. Note that Linux/ppc32 has 8 float registers to use
-   for float parameter passing and Linux/ppc64 has 13, so the number of
-   arguments has to be at least 14 to contemplate these platforms.  */
+/* The parameter list of a t_TYPE_many_args function.  Split out into
+   prototyped vs non-prototyped variants because a macro body cannot
+   contain #ifdef.  */
 
-double
 #ifdef NO_PROTOTYPES
-t_double_many_args (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13,
-		   f14, f15)
-     double f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15;
+# define T_MANY_ARGS_PARAMS(TYPE)					\
+  (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15)	\
+     TYPE f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15;
 #else
-t_double_many_args (double f1, double f2, double f3, double f4, double f5,
-		    double f6, double f7, double f8, double f9, double f10,
-		    double f11, double f12, double f13, double f14, double f15)
+# define T_MANY_ARGS_PARAMS(TYPE)					\
+  (TYPE f1, TYPE f2, TYPE f3, TYPE f4, TYPE f5, TYPE f6, TYPE f7,	\
+   TYPE f8, TYPE f9, TYPE f10, TYPE f11, TYPE f12, TYPE f13, TYPE f14,	\
+   TYPE f15)
 #endif
-{
-  double sum_args;
-  double sum_values;
-
-  sum_args = f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12
-	     + f13 + f14 + f15;
-  sum_values = double_val1 + double_val2 + double_val3 + double_val4
-	       + double_val5 + double_val6 + double_val7 + double_val8
-	       + double_val9 + double_val10 + double_val11 + double_val12
-	       + double_val13 + double_val14 + double_val15;
-
-  return ((sum_args - sum_values) < DELTA
-	  && (sum_args - sum_values) > -DELTA);
-}
+
+/* Define a function NAME returning TYPE with many arguments, to force
+   some of them to be passed via the stack instead of registers, to
+   test that GDB can construct the parameter save area correctly.
+   Note that Linux/ppc32 has 8 float registers to use for float
+   parameter passing and Linux/ppc64 has 13, so the number of
+   arguments has to be at least 14 to contemplate these platforms.  */
+
+#define DEFINE_T_MANY_ARGS(TYPE, NAME)					\
+TYPE									\
+NAME T_MANY_ARGS_PARAMS (TYPE)						\
+{									\
+  TYPE sum_args;							\
+  TYPE sum_values;							\
+									\
+  sum_args = (f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11	\
+	      + f12 + f13 + f14 + f15);					\
+  sum_values = (TYPE##_val1 + TYPE##_val2 + TYPE##_val3			\
+		+ TYPE##_val4 + TYPE##_val5 + TYPE##_val6		\
+		+ TYPE##_val7 + TYPE##_val8 + TYPE##_val9		\
+		+ TYPE##_val10 + TYPE##_val11 + TYPE##_val12		\
+		+ TYPE##_val13 + TYPE##_val14 + TYPE##_val15);		\
+									\
+  return ((sum_args - sum_values) < DELTA				\
+	  && (sum_args - sum_values) > -DELTA);				\
+}
+
+DEFINE_T_MANY_ARGS (float, t_float_many_args)
+DEFINE_T_MANY_ARGS (double, t_double_many_args)
 
 /* Various functions for _Complex types.  */
 
-- 
2.54.0


  parent reply	other threads:[~2026-07-14 22:07 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14 22:06 [PATCH 0/4] gdb/testsuite: "long double" infcall tests Pedro Alves
2026-07-14 22:06 ` [PATCH 1/4] gdb.base/nodebug.exp: Add long double testing Pedro Alves
2026-07-16 21:14   ` Andrew Burgess
2026-07-17 13:59     ` Pedro Alves
2026-07-22 18:41       ` Andrew Burgess
2026-07-14 22:06 ` [PATCH 2/4] gdb.base/callfuncs.exp: Adjust for Windows Pedro Alves
2026-07-14 22:25   ` Pedro Alves
2026-07-16 21:26     ` Andrew Burgess
2026-07-17 14:27       ` Pedro Alves
2026-07-22 18:42         ` Andrew Burgess
2026-07-14 22:06 ` Pedro Alves [this message]
2026-07-16 21:33   ` [PATCH 3/4] gdb.base/callfuncs.c: factor out float/double functions Andrew Burgess
2026-07-14 22:06 ` [PATCH 4/4] gdb.base/callfuncs.exp: Exercise "long double" Pedro Alves
2026-07-16 21:36   ` Andrew Burgess
2026-07-22 13:01 ` [PATCH 0/4] gdb/testsuite: "long double" infcall tests Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260714220631.1499846-4-pedro@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox