[3/4] gdb.base/callfuncs.c: factor out float/double functions
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_gdb_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_gdb_check--master-arm |
success
|
Test passed
|
Commit Message
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(-)
Comments
Pedro Alves <pedro@palves.net> writes:
> 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.
LGTM.
Approved-By: Andrew Burgess <aburgess@redhat.com>
Thanks,
Andrew
>
> 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
@@ -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. */