From b6b02c5528b662733f3555dec2a397b3269c22d6 Mon Sep 17 00:00:00 2001 From: Kai Tietz Date: Sun, 6 Jul 2008 14:49:32 +0000 Subject: [PATCH] callabi.h: New. 2008-07-06 Kai Tietz * gcc.dg/callabi/callabi.h: New. * gcc.dg/callabi/vaarg-1.c: New. * gcc.dg/callabi/vaarg-2.c: New. * gcc.dg/callabi/vaarg-3.c: New. * gcc.dg/callabi/func-1.c: New. From-SVN: r137524 --- gcc/testsuite/ChangeLog | 8 +++++ gcc/testsuite/gcc.dg/callabi/callabi.h | 50 ++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/callabi/func-1.c | 40 +++++++++++++++++++++ gcc/testsuite/gcc.dg/callabi/vaarg-1.c | 47 ++++++++++++++++++++++++ gcc/testsuite/gcc.dg/callabi/vaarg-2.c | 47 ++++++++++++++++++++++++ gcc/testsuite/gcc.dg/callabi/vaarg-3.c | 47 ++++++++++++++++++++++++ 6 files changed, 239 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/callabi/callabi.h create mode 100644 gcc/testsuite/gcc.dg/callabi/func-1.c create mode 100644 gcc/testsuite/gcc.dg/callabi/vaarg-1.c create mode 100644 gcc/testsuite/gcc.dg/callabi/vaarg-2.c create mode 100644 gcc/testsuite/gcc.dg/callabi/vaarg-3.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7eb21a42d71..cf6ba6ba1ce 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2008-07-06 Kai Tietz + + * gcc.dg/callabi/callabi.h: New. + * gcc.dg/callabi/vaarg-1.c: New. + * gcc.dg/callabi/vaarg-2.c: New. + * gcc.dg/callabi/vaarg-3.c: New. + * gcc.dg/callabi/func-1.c: New. + 2008-07-05 Andrew Pinski * g++.dg/tree-ssa/ptrmemfield.C: New testcase. diff --git a/gcc/testsuite/gcc.dg/callabi/callabi.h b/gcc/testsuite/gcc.dg/callabi/callabi.h new file mode 100644 index 00000000000..d008ad659cb --- /dev/null +++ b/gcc/testsuite/gcc.dg/callabi/callabi.h @@ -0,0 +1,50 @@ +/* First the default target definition. */ +#ifndef __GNUC_VA_LIST +#define __GNUC_VA_LIST + typedef __builtin_va_list __gnuc_va_list; +#endif + +#ifndef _VA_LIST_DEFINED +#define _VA_LIST_DEFINED + typedef __gnuc_va_list va_list; +#endif + +#define __va_copy(d,s) __builtin_va_copy(d,s) +#define __va_start(v,l) __builtin_va_start(v,l) +#define __va_arg(v,l) __builtin_va_arg(v,l) +#define __va_end(v) __builtin_va_end(v) + +#define __ms_va_copy(d,s) __builtin_ms_va_copy(d,s) +#define __ms_va_start(v,l) __builtin_ms_va_start(v,l) +#define __ms_va_arg(v,l) __builtin_va_arg(v,l) +#define __ms_va_end(v) __builtin_ms_va_end(v) + +#define __sysv_va_copy(d,s) __builtin_sysv_va_copy(d,s) +#define __sysv_va_start(v,l) __builtin_sysv_va_start(v,l) +#define __sysv_va_arg(v,l) __builtin_va_arg(v,l) +#define __sysv_va_end(v) __builtin_sysv_va_end(v) + +#define CALLABI_NATIVE + +#ifdef _WIN64 +#define CALLABI_CROSS __attribute__ ((sysv_abi)) + +#define CROSS_VA_LIST __builtin_sysv_va_list + +#define CROSS_VA_COPY(d,s) __sysv_va_copy(d,s) +#define CROSS_VA_START(v,l) __sysv_va_start(v,l) +#define CROSS_VA_ARG(v,l) __sysv_va_arg(v,l) +#define CROSS_VA_END(v) __sysv_va_end(v) + +#else + +#define CALLABI_CROSS __attribute__ ((ms_abi)) + +#define CROSS_VA_LIST __builtin_ms_va_list + +#define CROSS_VA_COPY(d,s) __ms_va_copy(d,s) +#define CROSS_VA_START(v,l) __ms_va_start(v,l) +#define CROSS_VA_ARG(v,l) __ms_va_arg(v,l) +#define CROSS_VA_END(v) __ms_va_end(v) + +#endif \ No newline at end of file diff --git a/gcc/testsuite/gcc.dg/callabi/func-1.c b/gcc/testsuite/gcc.dg/callabi/func-1.c new file mode 100644 index 00000000000..c727dbe6e53 --- /dev/null +++ b/gcc/testsuite/gcc.dg/callabi/func-1.c @@ -0,0 +1,40 @@ +/* Test for cross x86_64<->w64 abi standard calls. +*/ +/* Origin: Kai Tietz */ +/* { dg-do run { target { x86_64-*-* } } } */ +/* { dg-options "-std=gnu99 -ffast-math" } */ +#include "callabi.h" + +extern void abort (void); + +long double +CALLABI_CROSS func_cross (long double a, double b, float c, long d, int e, + char f) +{ + long double ret; + ret = a + (long double) b + (long double) c; + ret *= (long double) (d + (long) e); + if (f>0) + ret += func_cross (a,b,c,d,e,-f); + return ret; +} + +long double +CALLABI_NATIVE func_native (long double a, double b, float c, long d, int e, + char f) +{ + long double ret; + ret = a + (long double) b + (long double) c; + ret *= (long double) (d + (long) e); + if (f>0) + ret += func_native (a,b,c,d,e,-f); + return ret; +} + +int main () +{ + if (func_cross (1.0,2.0,3.0,1,2,3) + != func_native (1.0,2.0,3.0,1,2,3)) + abort (); + return 0; +} \ No newline at end of file diff --git a/gcc/testsuite/gcc.dg/callabi/vaarg-1.c b/gcc/testsuite/gcc.dg/callabi/vaarg-1.c new file mode 100644 index 00000000000..1e745e56085 --- /dev/null +++ b/gcc/testsuite/gcc.dg/callabi/vaarg-1.c @@ -0,0 +1,47 @@ +/* Test for cross x86_64<->w64 abi va_list calls. +*/ +/* Origin: Kai Tietz */ +/* { dg-do run { target { x86_64-*-* } } } */ +/* { dg-options "-std=gnu99" } */ +#include "callabi.h" + +extern __SIZE_TYPE__ strlen (const char *); +extern int sprintf (char *,const char *, ...); +extern void abort (void); + +static +void CALLABI_CROSS vdo_cpy (char *s, CROSS_VA_LIST argp) +{ + __SIZE_TYPE__ len; + char *r = s; + char *e; + *r = 0; + for (;;) { + e = CROSS_VA_ARG (argp,char *); + if (*e == 0) break; + sprintf (r,"%s", e); + r += strlen (r); + } +} + +static +void CALLABI_CROSS do_cpy (char *s, ...) +{ + CROSS_VA_LIST argp; + CROSS_VA_START (argp, s); + vdo_cpy (s, argp); + CROSS_VA_END (argp); +} + +int main () +{ + char s[256]; + + do_cpy (s, "1","2","3","4", "5", "6", "7", ""); + + if (s[0] != '1' || s[1] !='2' || s[2] != '3' || s[3] != '4' + || s[4] != '5' || s[5] != '6' || s[6] != '7' || s[7] != 0) + abort (); + + return 0; +} diff --git a/gcc/testsuite/gcc.dg/callabi/vaarg-2.c b/gcc/testsuite/gcc.dg/callabi/vaarg-2.c new file mode 100644 index 00000000000..c9b716194a6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/callabi/vaarg-2.c @@ -0,0 +1,47 @@ +/* Test for cross x86_64<->w64 abi va_list calls. +*/ +/* Origin: Kai Tietz */ +/* { dg-do run { target { x86_64-*-* } } } */ +/* { dg-options "-std=gnu99" } */ +#include "callabi.h" + +extern void abort (void); + +#define SZ_ARGS 1ll,2ll,3ll,4ll,5ll,6ll,7ll,0ll + +static +int CALLABI_CROSS fct1 (va_list argp, ...) +{ + long long p1,p2; + int ret = 1; + CROSS_VA_LIST argp_2; + CROSS_VA_START (argp_2,argp); + + do { + p1 = CROSS_VA_ARG (argp_2, long long); + p2 = __va_arg (argp, long long); + if (p1 != p2) + ret = 0; + } while (ret && p1 != 0); + CROSS_VA_END (argp_2); + return ret; +} + +static +int fct2 (int dummy, ...) +{ + va_list argp; + int ret = dummy; + + __va_start (argp, dummy); + ret += fct1 (argp, SZ_ARGS); + __va_end (argp); + return ret; +} + +int main() +{ + if (fct2 (-1, SZ_ARGS) != 0) + abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/callabi/vaarg-3.c b/gcc/testsuite/gcc.dg/callabi/vaarg-3.c new file mode 100644 index 00000000000..d0d068754e1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/callabi/vaarg-3.c @@ -0,0 +1,47 @@ +/* Test for cross x86_64<->w64 abi va_list calls. +*/ +/* Origin: Kai Tietz */ +/* { dg-do run { target { x86_64-*-* } } } */ +/* { dg-options "-std=gnu99" } */ +#include "callabi.h" + +extern void abort (void); + +#define SZ_ARGS 1ll,2ll,3ll,4ll,5ll,6ll,7ll,0ll + +static +int fct1 (CROSS_VA_LIST argp, ...) +{ + long long p1,p2; + int ret = 1; + va_list argp_2; + + __va_start (argp_2,argp); + do { + p1 = __va_arg (argp_2, long long); + p2 = CROSS_VA_ARG (argp, long long); + if (p1 != p2) + ret = 0; + } while (ret && p1 != 0); + __va_end (argp_2); + return ret; +} + +static +int CALLABI_CROSS fct2 (int dummy, ...) +{ + CROSS_VA_LIST argp; + int ret = dummy; + + CROSS_VA_START (argp, dummy); + ret += fct1 (argp, SZ_ARGS); + CROSS_VA_END (argp); + return ret; +} + +int main() +{ + if (fct2 (-1, SZ_ARGS) != 0) + abort (); + return 0; +} -- 2.30.2