cls_9byte2.c: New test case.

2003-11-08  Andreas Tobler  <a.tobler@schweiz.ch>

	* testsuite/libffi.call/cls_9byte2.c: New test case.
	* testsuite/libffi.call/cls_9byte1.c: Likewise.
	* testsuite/libffi.call/cls_64byte.c: Likewise.
	* testsuite/libffi.call/cls_20byte1.c: Likewise.
	* testsuite/libffi.call/cls_19byte.c: Likewise.
	* testsuite/libffi.call/cls_18byte.c: Likewise.
	* testsuite/libffi.call/closure_fn4.c: Likewise.
	* testsuite/libffi.call/closure_fn5.c: Likewise.
	* testsuite/libffi.call/cls_schar.c: Likewise.
	* testsuite/libffi.call/cls_sint.c: Likewise.
	* testsuite/libffi.call/cls_sshort.c: Likewise.
	* testsuite/libffi.call/nested_struct2.c: Likewise.
	* testsuite/libffi.call/nested_struct3.c: Likewise.

From-SVN: r73372
This commit is contained in:
Andreas Tobler 2003-11-08 20:03:58 +01:00 committed by Andreas Tobler
parent 49b8ea5ab0
commit ac47cc13ab
14 changed files with 1154 additions and 0 deletions

View File

@ -1,3 +1,19 @@
2003-11-08 Andreas Tobler <a.tobler@schweiz.ch>
* testsuite/libffi.call/cls_9byte2.c: New test case.
* testsuite/libffi.call/cls_9byte1.c: Likewise.
* testsuite/libffi.call/cls_64byte.c: Likewise.
* testsuite/libffi.call/cls_20byte1.c: Likewise.
* testsuite/libffi.call/cls_19byte.c: Likewise.
* testsuite/libffi.call/cls_18byte.c: Likewise.
* testsuite/libffi.call/closure_fn4.c: Likewise.
* testsuite/libffi.call/closure_fn5.c: Likewise.
* testsuite/libffi.call/cls_schar.c: Likewise.
* testsuite/libffi.call/cls_sint.c: Likewise.
* testsuite/libffi.call/cls_sshort.c: Likewise.
* testsuite/libffi.call/nested_struct2.c: Likewise.
* testsuite/libffi.call/nested_struct3.c: Likewise.
2003-11-08 Andreas Tobler <a.tobler@schweiz.ch>
* testsuite/libffi.call/cls_double.c: Do a check on the result.

View File

@ -0,0 +1,87 @@
/* Area: closure_call
Purpose: Check multiple long long values passing.
Also, exceed the limit of gpr and fpr registers on PowerPC
Darwin.
Limitations: none.
PR: none.
Originator: <andreast@gcc.gnu.org> 20031026 */
/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
#include "ffitest.h"
static void
closure_test_fn0(ffi_cif* cif,void* resp,void** args, void* userdata)
{
*(ffi_arg*)resp =
(int)*(unsigned long long *)args[0] + (int)*(unsigned long long *)args[1] +
(int)*(unsigned long long *)args[2] + (int)*(unsigned long long *)args[3] +
(int)*(unsigned long long *)args[4] + (int)*(unsigned long long *)args[5] +
(int)*(unsigned long long *)args[6] + (int)*(unsigned long long *)args[7] +
(int)*(unsigned long long *)args[8] + (int)*(unsigned long long *)args[9] +
(int)*(unsigned long long *)args[10] +
(int)*(unsigned long long *)args[11] +
(int)*(unsigned long long *)args[12] +
(int)*(unsigned long long *)args[13] +
(int)*(unsigned long long *)args[14] +
*(int *)args[15] + (int)(long)userdata;
printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d: %d\n",
(int)*(unsigned long long *)args[0],
(int)*(unsigned long long *)args[1],
(int)*(unsigned long long *)args[2],
(int)*(unsigned long long *)args[3],
(int)*(unsigned long long *)args[4],
(int)*(unsigned long long *)args[5],
(int)*(unsigned long long *)args[6],
(int)*(unsigned long long *)args[7],
(int)*(unsigned long long *)args[8],
(int)*(unsigned long long *)args[9],
(int)*(unsigned long long *)args[10],
(int)*(unsigned long long *)args[11],
(int)*(unsigned long long *)args[12],
(int)*(unsigned long long *)args[13],
(int)*(unsigned long long *)args[14],
*(int *)args[15],
(int)(long)userdata, (int)*(ffi_arg *)resp);
}
typedef int (*closure_test_type0)(unsigned long long, unsigned long long,
unsigned long long, unsigned long long,
unsigned long long, unsigned long long,
unsigned long long, unsigned long long,
unsigned long long, unsigned long long,
unsigned long long, unsigned long long,
unsigned long long, unsigned long long,
unsigned long long, int);
int main (void)
{
ffi_cif cif;
static ffi_closure cl;
ffi_closure *pcl = &cl;
ffi_type * cl_arg_types[17];
int i, res;
for (i = 0; i < 15; i++) {
cl_arg_types[i] = &ffi_type_uint64;
}
cl_arg_types[15] = &ffi_type_uint;
cl_arg_types[16] = NULL;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 16,
&ffi_type_sint, cl_arg_types) == FFI_OK);
CHECK(ffi_prep_closure(pcl, &cif, closure_test_fn0,
(void *) 3 /* userdata */) == FFI_OK);
res = (*((closure_test_type0)pcl))
(1LL, 2LL, 3LL, 4LL, 127LL, 429LL, 7LL, 8LL, 9LL, 10LL, 11LL, 12LL,
13LL, 19LL, 21LL, 1);
/* { dg-output "1 2 3 4 127 429 7 8 9 10 11 12 13 19 21 1 3: 680" } */
CHECK(res == 680);
exit(0);
}

View File

@ -0,0 +1,90 @@
/* Area: closure_call
Purpose: Check multiple long long values passing.
Exceed the limit of gpr registers on PowerPC
Darwin.
Limitations: none.
PR: none.
Originator: <andreast@gcc.gnu.org> 20031026 */
/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
#include "ffitest.h"
static void
closure_test_fn5(ffi_cif* cif,void* resp,void** args, void* userdata)
{
*(ffi_arg*)resp =
(int)*(unsigned long long *)args[0] + (int)*(unsigned long long *)args[1] +
(int)*(unsigned long long *)args[2] + (int)*(unsigned long long *)args[3] +
(int)*(unsigned long long *)args[4] + (int)*(unsigned long long *)args[5] +
(int)*(unsigned long long *)args[6] + (int)*(unsigned long long *)args[7] +
(int)*(unsigned long long *)args[8] + (int)*(unsigned long long *)args[9] +
(int)*(int *)args[10] +
(int)*(unsigned long long *)args[11] +
(int)*(unsigned long long *)args[12] +
(int)*(unsigned long long *)args[13] +
(int)*(unsigned long long *)args[14] +
*(int *)args[15] + (int)(long)userdata;
printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d: %d\n",
(int)*(unsigned long long *)args[0],
(int)*(unsigned long long *)args[1],
(int)*(unsigned long long *)args[2],
(int)*(unsigned long long *)args[3],
(int)*(unsigned long long *)args[4],
(int)*(unsigned long long *)args[5],
(int)*(unsigned long long *)args[6],
(int)*(unsigned long long *)args[7],
(int)*(unsigned long long *)args[8],
(int)*(unsigned long long *)args[9],
(int)*(int *)args[10],
(int)*(unsigned long long *)args[11],
(int)*(unsigned long long *)args[12],
(int)*(unsigned long long *)args[13],
(int)*(unsigned long long *)args[14],
*(int *)args[15],
(int)(long)userdata, (int)*(ffi_arg *)resp);
}
typedef int (*closure_test_type0)(unsigned long long, unsigned long long,
unsigned long long, unsigned long long,
unsigned long long, unsigned long long,
unsigned long long, unsigned long long,
unsigned long long, unsigned long long,
int, unsigned long long,
unsigned long long, unsigned long long,
unsigned long long, int);
int main (void)
{
ffi_cif cif;
static ffi_closure cl;
ffi_closure *pcl = &cl;
ffi_type * cl_arg_types[17];
int i, res;
for (i = 0; i < 10; i++) {
cl_arg_types[i] = &ffi_type_uint64;
}
cl_arg_types[10] = &ffi_type_uint;
for (i = 11; i < 15; i++) {
cl_arg_types[i] = &ffi_type_uint64;
}
cl_arg_types[15] = &ffi_type_uint;
cl_arg_types[16] = NULL;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 16,
&ffi_type_sint, cl_arg_types) == FFI_OK);
CHECK(ffi_prep_closure(pcl, &cif, closure_test_fn5,
(void *) 3 /* userdata */) == FFI_OK);
res = (*((closure_test_type0)pcl))
(1LL, 2LL, 3LL, 4LL, 127LL, 429LL, 7LL, 8LL, 9LL, 10LL, 11, 12LL,
13LL, 19LL, 21LL, 1);
/* { dg-output "1 2 3 4 127 429 7 8 9 10 11 12 13 19 21 1 3: 680" } */
CHECK(res == 680);
exit(0);
}

View File

@ -0,0 +1,99 @@
/* Area: ffi_call, closure_call
Purpose: Check structure passing with different structure size.
Depending on the ABI. Double alignment check on darwin.
Limitations: none.
PR: none.
Originator: <andreast@gcc.gnu.org> 20030915 */
/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
#include "ffitest.h"
typedef struct cls_struct_18byte {
double a;
unsigned char b;
unsigned char c;
double d;
} cls_struct_18byte;
cls_struct_18byte cls_struct_18byte_fn(struct cls_struct_18byte a1,
struct cls_struct_18byte a2)
{
struct cls_struct_18byte result;
result.a = a1.a + a2.a;
result.b = a1.b + a2.b;
result.c = a1.c + a2.c;
result.d = a1.d + a2.d;
printf("%g %d %d %g %g %d %d %g: %g %d %d %g\n", a1.a, a1.b, a1.c, a1.d,
a2.a, a2.b, a2.c, a2.d,
result.a, result.b, result.c, result.d);
return result;
}
static void
cls_struct_18byte_gn(ffi_cif* cif, void* resp, void** args, void* userdata)
{
struct cls_struct_18byte a1, a2;
a1 = *(struct cls_struct_18byte*)(args[0]);
a2 = *(struct cls_struct_18byte*)(args[1]);
*(cls_struct_18byte*)resp = cls_struct_18byte_fn(a1, a2);
}
int main (void)
{
ffi_cif cif;
static ffi_closure cl;
ffi_closure *pcl = &cl;
void* args_dbl[3];
ffi_type* cls_struct_fields[5];
ffi_type cls_struct_type;
ffi_type* dbl_arg_types[3];
cls_struct_type.size = 0;
cls_struct_type.alignment = 0;
cls_struct_type.type = FFI_TYPE_STRUCT;
cls_struct_type.elements = cls_struct_fields;
struct cls_struct_18byte g_dbl = { 1.0, 127, 126, 3.0 };
struct cls_struct_18byte f_dbl = { 4.0, 125, 124, 5.0 };
struct cls_struct_18byte res_dbl;
cls_struct_fields[0] = &ffi_type_double;
cls_struct_fields[1] = &ffi_type_uchar;
cls_struct_fields[2] = &ffi_type_uchar;
cls_struct_fields[3] = &ffi_type_double;
cls_struct_fields[4] = NULL;
dbl_arg_types[0] = &cls_struct_type;
dbl_arg_types[1] = &cls_struct_type;
dbl_arg_types[2] = NULL;
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type,
dbl_arg_types) == FFI_OK);
args_dbl[0] = &g_dbl;
args_dbl[1] = &f_dbl;
args_dbl[2] = NULL;
ffi_call(&cif, FFI_FN(cls_struct_18byte_fn), &res_dbl, args_dbl);
/* { dg-output "1 127 126 3 4 125 124 5: 5 252 250 8" } */
CHECK( res_dbl.a == (g_dbl.a + f_dbl.a));
CHECK( res_dbl.b == (g_dbl.b + f_dbl.b));
CHECK( res_dbl.c == (g_dbl.c + f_dbl.c));
CHECK( res_dbl.d == (g_dbl.d + f_dbl.d));
CHECK(ffi_prep_closure(pcl, &cif, cls_struct_18byte_gn, NULL) == FFI_OK);
res_dbl = ((cls_struct_18byte(*)(cls_struct_18byte, cls_struct_18byte))(pcl))(g_dbl, f_dbl);
/* { dg-output "\n1 127 126 3 4 125 124 5: 5 252 250 8" } */
CHECK( res_dbl.a == (g_dbl.a + f_dbl.a));
CHECK( res_dbl.b == (g_dbl.b + f_dbl.b));
CHECK( res_dbl.c == (g_dbl.c + f_dbl.c));
CHECK( res_dbl.d == (g_dbl.d + f_dbl.d));
exit(0);
}

View File

@ -0,0 +1,105 @@
/* Area: ffi_call, closure_call
Purpose: Check structure passing with different structure size.
Depending on the ABI. Double alignment check on darwin.
Limitations: none.
PR: none.
Originator: <andreast@gcc.gnu.org> 20030915 */
/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
#include "ffitest.h"
typedef struct cls_struct_19byte {
double a;
unsigned char b;
unsigned char c;
double d;
unsigned char e;
} cls_struct_19byte;
cls_struct_19byte cls_struct_19byte_fn(struct cls_struct_19byte a1,
struct cls_struct_19byte a2)
{
struct cls_struct_19byte result;
result.a = a1.a + a2.a;
result.b = a1.b + a2.b;
result.c = a1.c + a2.c;
result.d = a1.d + a2.d;
result.e = a1.e + a2.e;
printf("%g %d %d %g %d %g %d %d %g %d: %g %d %d %g %d\n",
a1.a, a1.b, a1.c, a1.d, a1.e,
a2.a, a2.b, a2.c, a2.d, a2.e,
result.a, result.b, result.c, result.d, result.e);
return result;
}
static void
cls_struct_19byte_gn(ffi_cif* cif, void* resp, void** args, void* userdata)
{
struct cls_struct_19byte a1, a2;
a1 = *(struct cls_struct_19byte*)(args[0]);
a2 = *(struct cls_struct_19byte*)(args[1]);
*(cls_struct_19byte*)resp = cls_struct_19byte_fn(a1, a2);
}
int main (void)
{
ffi_cif cif;
static ffi_closure cl;
ffi_closure *pcl = &cl;
void* args_dbl[3];
ffi_type* cls_struct_fields[6];
ffi_type cls_struct_type;
ffi_type* dbl_arg_types[3];
cls_struct_type.size = 0;
cls_struct_type.alignment = 0;
cls_struct_type.type = FFI_TYPE_STRUCT;
cls_struct_type.elements = cls_struct_fields;
struct cls_struct_19byte g_dbl = { 1.0, 127, 126, 3.0, 120 };
struct cls_struct_19byte f_dbl = { 4.0, 125, 124, 5.0, 119 };
struct cls_struct_19byte res_dbl;
cls_struct_fields[0] = &ffi_type_double;
cls_struct_fields[1] = &ffi_type_uchar;
cls_struct_fields[2] = &ffi_type_uchar;
cls_struct_fields[3] = &ffi_type_double;
cls_struct_fields[4] = &ffi_type_uchar;
cls_struct_fields[5] = NULL;
dbl_arg_types[0] = &cls_struct_type;
dbl_arg_types[1] = &cls_struct_type;
dbl_arg_types[2] = NULL;
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type,
dbl_arg_types) == FFI_OK);
args_dbl[0] = &g_dbl;
args_dbl[1] = &f_dbl;
args_dbl[2] = NULL;
ffi_call(&cif, FFI_FN(cls_struct_19byte_fn), &res_dbl, args_dbl);
/* { dg-output "1 127 126 3 120 4 125 124 5 119: 5 252 250 8 239" } */
CHECK( res_dbl.a == (g_dbl.a + f_dbl.a));
CHECK( res_dbl.b == (g_dbl.b + f_dbl.b));
CHECK( res_dbl.c == (g_dbl.c + f_dbl.c));
CHECK( res_dbl.d == (g_dbl.d + f_dbl.d));
CHECK( res_dbl.e == (g_dbl.e + f_dbl.e));
CHECK(ffi_prep_closure(pcl, &cif, cls_struct_19byte_gn, NULL) == FFI_OK);
res_dbl = ((cls_struct_19byte(*)(cls_struct_19byte, cls_struct_19byte))(pcl))(g_dbl, f_dbl);
/* { dg-output "\n1 127 126 3 120 4 125 124 5 119: 5 252 250 8 239" } */
CHECK( res_dbl.a == (g_dbl.a + f_dbl.a));
CHECK( res_dbl.b == (g_dbl.b + f_dbl.b));
CHECK( res_dbl.c == (g_dbl.c + f_dbl.c));
CHECK( res_dbl.d == (g_dbl.d + f_dbl.d));
CHECK( res_dbl.e == (g_dbl.e + f_dbl.e));
exit(0);
}

View File

@ -0,0 +1,92 @@
/* Area: ffi_call, closure_call
Purpose: Check structure passing with different structure size.
Depending on the ABI. Check overlapping.
Limitations: none.
PR: none.
Originator: <andreast@gcc.gnu.org> 20030828 */
/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
#include "ffitest.h"
typedef struct cls_struct_20byte {
int a;
double b;
double c;
} cls_struct_20byte;
cls_struct_20byte cls_struct_20byte_fn(struct cls_struct_20byte a1,
struct cls_struct_20byte a2)
{
struct cls_struct_20byte result;
result.a = a1.a + a2.a;
result.b = a1.b + a2.b;
result.c = a1.c + a2.c;
printf("%d %g %g %d %g %g: %d %g %g\n", a1.a, a1.b, a1.c, a2.a, a2.b, a2.c,
result.a, result.b, result.c);
return result;
}
static void
cls_struct_20byte_gn(ffi_cif* cif, void* resp, void** args, void* userdata)
{
struct cls_struct_20byte a1, a2;
a1 = *(struct cls_struct_20byte*)(args[0]);
a2 = *(struct cls_struct_20byte*)(args[1]);
*(cls_struct_20byte*)resp = cls_struct_20byte_fn(a1, a2);
}
int main (void)
{
ffi_cif cif;
static ffi_closure cl;
ffi_closure *pcl = &cl;
void* args_dbl[3];
ffi_type* cls_struct_fields[4];
ffi_type cls_struct_type;
ffi_type* dbl_arg_types[3];
cls_struct_type.size = 0;
cls_struct_type.alignment = 0;
cls_struct_type.type = FFI_TYPE_STRUCT;
cls_struct_type.elements = cls_struct_fields;
struct cls_struct_20byte g_dbl = { 1, 2.0, 3.0 };
struct cls_struct_20byte f_dbl = { 4, 5.0, 7.0 };
struct cls_struct_20byte res_dbl;
cls_struct_fields[0] = &ffi_type_uint32;
cls_struct_fields[1] = &ffi_type_double;
cls_struct_fields[2] = &ffi_type_double;
cls_struct_fields[3] = NULL;
dbl_arg_types[0] = &cls_struct_type;
dbl_arg_types[1] = &cls_struct_type;
dbl_arg_types[2] = NULL;
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type,
dbl_arg_types) == FFI_OK);
args_dbl[0] = &g_dbl;
args_dbl[1] = &f_dbl;
args_dbl[2] = NULL;
ffi_call(&cif, FFI_FN(cls_struct_20byte_fn), &res_dbl, args_dbl);
/* { dg-output "1 2 3 4 5 7: 5 7 10" } */
CHECK( res_dbl.a == (g_dbl.a + f_dbl.a));
CHECK( res_dbl.b == (g_dbl.b + f_dbl.b));
CHECK( res_dbl.c == (g_dbl.c + f_dbl.c));
CHECK(ffi_prep_closure(pcl, &cif, cls_struct_20byte_gn, NULL) == FFI_OK);
res_dbl = ((cls_struct_20byte(*)(cls_struct_20byte, cls_struct_20byte))(pcl))(g_dbl, f_dbl);
/* { dg-output "\n1 2 3 4 5 7: 5 7 10" } */
CHECK( res_dbl.a == (g_dbl.a + f_dbl.a));
CHECK( res_dbl.b == (g_dbl.b + f_dbl.b));
CHECK( res_dbl.c == (g_dbl.c + f_dbl.c));
exit(0);
}

View File

@ -0,0 +1,133 @@
/* Area: ffi_call, closure_call
Purpose: Check structure passing with different structure size.
Depending on the ABI. Check bigger struct which overlaps
the gp and fp register count on Darwin/AIX/ppc64.
Limitations: none.
PR: none.
Originator: <andreast@gcc.gnu.org> 20030828 */
/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
#include "ffitest.h"
typedef struct cls_struct_64byte {
double a;
double b;
double c;
double d;
double e;
double f;
double g;
double h;
} cls_struct_64byte;
cls_struct_64byte cls_struct_64byte_fn(struct cls_struct_64byte b0,
struct cls_struct_64byte b1,
struct cls_struct_64byte b2,
struct cls_struct_64byte b3)
{
struct cls_struct_64byte result;
result.a = b0.a + b1.a + b2.a + b3.a;
result.b = b0.b + b1.b + b2.b + b3.b;
result.c = b0.c + b1.c + b2.c + b3.c;
result.d = b0.d + b1.d + b2.d + b3.d;
result.e = b0.e + b1.e + b2.e + b3.e;
result.f = b0.f + b1.f + b2.f + b3.f;
result.g = b0.g + b1.g + b2.g + b3.g;
result.h = b0.h + b1.h + b2.h + b3.h;
printf("%g %g %g %g %g %g %g %g\n", result.a, result.b, result.c,
result.d, result.e, result.f, result.g, result.h);
return result;
}
static void
cls_struct_64byte_gn(ffi_cif* cif, void* resp, void** args, void* userdata)
{
struct cls_struct_64byte b0, b1, b2, b3;
b0 = *(struct cls_struct_64byte*)(args[0]);
b1 = *(struct cls_struct_64byte*)(args[1]);
b2 = *(struct cls_struct_64byte*)(args[2]);
b3 = *(struct cls_struct_64byte*)(args[3]);
*(cls_struct_64byte*)resp = cls_struct_64byte_fn(b0, b1, b2, b3);
}
int main (void)
{
ffi_cif cif;
static ffi_closure cl;
ffi_closure *pcl = &cl;
void* args_dbl[5];
ffi_type* cls_struct_fields[9];
ffi_type cls_struct_type;
ffi_type* dbl_arg_types[5];
cls_struct_type.size = 0;
cls_struct_type.alignment = 0;
cls_struct_type.type = FFI_TYPE_STRUCT;
cls_struct_type.elements = cls_struct_fields;
struct cls_struct_64byte e_dbl = { 9.0, 2.0, 6.0, 5.0, 3.0, 4.0, 8.0, 1.0 };
struct cls_struct_64byte f_dbl = { 1.0, 2.0, 3.0, 7.0, 2.0, 5.0, 6.0, 7.0 };
struct cls_struct_64byte g_dbl = { 4.0, 5.0, 7.0, 9.0, 1.0, 1.0, 2.0, 9.0 };
struct cls_struct_64byte h_dbl = { 8.0, 6.0, 1.0, 4.0, 0.0, 3.0, 3.0, 1.0 };
struct cls_struct_64byte res_dbl;
cls_struct_fields[0] = &ffi_type_double;
cls_struct_fields[1] = &ffi_type_double;
cls_struct_fields[2] = &ffi_type_double;
cls_struct_fields[3] = &ffi_type_double;
cls_struct_fields[4] = &ffi_type_double;
cls_struct_fields[5] = &ffi_type_double;
cls_struct_fields[6] = &ffi_type_double;
cls_struct_fields[7] = &ffi_type_double;
cls_struct_fields[8] = NULL;
dbl_arg_types[0] = &cls_struct_type;
dbl_arg_types[1] = &cls_struct_type;
dbl_arg_types[2] = &cls_struct_type;
dbl_arg_types[3] = &cls_struct_type;
dbl_arg_types[4] = NULL;
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, &cls_struct_type,
dbl_arg_types) == FFI_OK);
args_dbl[0] = &e_dbl;
args_dbl[1] = &f_dbl;
args_dbl[2] = &g_dbl;
args_dbl[3] = &h_dbl;
args_dbl[4] = NULL;
ffi_call(&cif, FFI_FN(cls_struct_64byte_fn), &res_dbl, args_dbl);
/* { dg-output "22 15 17 25 6 13 19 18" } */
CHECK( res_dbl.a == (e_dbl.a + f_dbl.a + g_dbl.a + h_dbl.a));
CHECK( res_dbl.b == (e_dbl.b + f_dbl.b + g_dbl.b + h_dbl.b));
CHECK( res_dbl.c == (e_dbl.c + f_dbl.c + g_dbl.c + h_dbl.c));
CHECK( res_dbl.d == (e_dbl.d + f_dbl.d + g_dbl.d + h_dbl.d));
CHECK( res_dbl.e == (e_dbl.e + f_dbl.e + g_dbl.e + h_dbl.e));
CHECK( res_dbl.f == (e_dbl.f + f_dbl.f + g_dbl.f + h_dbl.f));
CHECK( res_dbl.g == (e_dbl.g + f_dbl.g + g_dbl.g + h_dbl.g));
CHECK( res_dbl.h == (e_dbl.h + f_dbl.h + g_dbl.h + h_dbl.h));
CHECK(ffi_prep_closure(pcl, &cif, cls_struct_64byte_gn, NULL) == FFI_OK);
res_dbl = ((cls_struct_64byte(*)(cls_struct_64byte,
cls_struct_64byte,
cls_struct_64byte,
cls_struct_64byte))
(pcl))(e_dbl, f_dbl, g_dbl, h_dbl);
/* { dg-output "\n22 15 17 25 6 13 19 18" } */
CHECK( res_dbl.a == (e_dbl.a + f_dbl.a + g_dbl.a + h_dbl.a));
CHECK( res_dbl.b == (e_dbl.b + f_dbl.b + g_dbl.b + h_dbl.b));
CHECK( res_dbl.c == (e_dbl.c + f_dbl.c + g_dbl.c + h_dbl.c));
CHECK( res_dbl.d == (e_dbl.d + f_dbl.d + g_dbl.d + h_dbl.d));
CHECK( res_dbl.e == (e_dbl.e + f_dbl.e + g_dbl.e + h_dbl.e));
CHECK( res_dbl.f == (e_dbl.f + f_dbl.f + g_dbl.f + h_dbl.f));
CHECK( res_dbl.g == (e_dbl.g + f_dbl.g + g_dbl.g + h_dbl.g));
CHECK( res_dbl.h == (e_dbl.h + f_dbl.h + g_dbl.h + h_dbl.h));
exit(0);
}

View File

@ -0,0 +1,90 @@
/* Area: ffi_call, closure_call
Purpose: Check structure passing with different structure size.
Depending on the ABI. Darwin/AIX do double-word
alignment of the struct if the first element is a double.
Check that it does not here.
Limitations: none.
PR: none.
Originator: <andreast@gcc.gnu.org> 20030914 */
/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
#include "ffitest.h"
typedef struct cls_struct_9byte {
int a;
double b;
} cls_struct_9byte;
cls_struct_9byte cls_struct_9byte_fn(struct cls_struct_9byte b1,
struct cls_struct_9byte b2)
{
struct cls_struct_9byte result;
result.a = b1.a + b2.a;
result.b = b1.b + b2.b;
printf("%d %g %d %g: %d %g\n", b1.a, b1.b, b2.a, b2.b,
result.a, result.b);
return result;
}
static void cls_struct_9byte_gn(ffi_cif* cif, void* resp, void** args,
void* userdata)
{
struct cls_struct_9byte b1, b2;
b1 = *(struct cls_struct_9byte*)(args[0]);
b2 = *(struct cls_struct_9byte*)(args[1]);
*(cls_struct_9byte*)resp = cls_struct_9byte_fn(b1, b2);
}
int main (void)
{
ffi_cif cif;
static ffi_closure cl;
ffi_closure *pcl = &cl;
void* args_dbl[3];
ffi_type* cls_struct_fields[3];
ffi_type cls_struct_type;
ffi_type* dbl_arg_types[3];
cls_struct_type.size = 0;
cls_struct_type.alignment = 0;
cls_struct_type.type = FFI_TYPE_STRUCT;
cls_struct_type.elements = cls_struct_fields;
struct cls_struct_9byte h_dbl = { 7, 8.0};
struct cls_struct_9byte j_dbl = { 1, 9.0};
struct cls_struct_9byte res_dbl;
cls_struct_fields[0] = &ffi_type_uint32;
cls_struct_fields[1] = &ffi_type_double;
cls_struct_fields[2] = NULL;
dbl_arg_types[0] = &cls_struct_type;
dbl_arg_types[1] = &cls_struct_type;
dbl_arg_types[2] = NULL;
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type,
dbl_arg_types) == FFI_OK);
args_dbl[0] = &h_dbl;
args_dbl[1] = &j_dbl;
args_dbl[2] = NULL;
ffi_call(&cif, FFI_FN(cls_struct_9byte_fn), &res_dbl, args_dbl);
/* { dg-output "7 8 1 9: 8 17" } */
CHECK( res_dbl.a == (h_dbl.a + j_dbl.a));
CHECK( res_dbl.b == (h_dbl.b + j_dbl.b));
CHECK(ffi_prep_closure(pcl, &cif, cls_struct_9byte_gn, NULL) == FFI_OK);
res_dbl = ((cls_struct_9byte(*)(cls_struct_9byte, cls_struct_9byte))(pcl))(h_dbl, j_dbl);
/* { dg-output "\n7 8 1 9: 8 17" } */
CHECK( res_dbl.a == (h_dbl.a + j_dbl.a));
CHECK( res_dbl.b == (h_dbl.b + j_dbl.b));
exit(0);
}

View File

@ -0,0 +1,90 @@
/* Area: ffi_call, closure_call
Purpose: Check structure passing with different structure size.
Depending on the ABI. Darwin/AIX do double-word
alignment of the struct if the first element is a double.
Check that it does here.
Limitations: none.
PR: none.
Originator: <andreast@gcc.gnu.org> 20030914 */
/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
#include "ffitest.h"
typedef struct cls_struct_9byte {
double a;
int b;
} cls_struct_9byte;
cls_struct_9byte cls_struct_9byte_fn(struct cls_struct_9byte b1,
struct cls_struct_9byte b2)
{
struct cls_struct_9byte result;
result.a = b1.a + b2.a;
result.b = b1.b + b2.b;
printf("%g %d %g %d: %g %d\n", b1.a, b1.b, b2.a, b2.b,
result.a, result.b);
return result;
}
static void cls_struct_9byte_gn(ffi_cif* cif, void* resp, void** args,
void* userdata)
{
struct cls_struct_9byte b1, b2;
b1 = *(struct cls_struct_9byte*)(args[0]);
b2 = *(struct cls_struct_9byte*)(args[1]);
*(cls_struct_9byte*)resp = cls_struct_9byte_fn(b1, b2);
}
int main (void)
{
ffi_cif cif;
static ffi_closure cl;
ffi_closure *pcl = &cl;
void* args_dbl[3];
ffi_type* cls_struct_fields[3];
ffi_type cls_struct_type;
ffi_type* dbl_arg_types[3];
cls_struct_type.size = 0;
cls_struct_type.alignment = 0;
cls_struct_type.type = FFI_TYPE_STRUCT;
cls_struct_type.elements = cls_struct_fields;
struct cls_struct_9byte h_dbl = { 7.0, 8};
struct cls_struct_9byte j_dbl = { 1.0, 9};
struct cls_struct_9byte res_dbl;
cls_struct_fields[0] = &ffi_type_double;
cls_struct_fields[1] = &ffi_type_uint32;
cls_struct_fields[2] = NULL;
dbl_arg_types[0] = &cls_struct_type;
dbl_arg_types[1] = &cls_struct_type;
dbl_arg_types[2] = NULL;
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type,
dbl_arg_types) == FFI_OK);
args_dbl[0] = &h_dbl;
args_dbl[1] = &j_dbl;
args_dbl[2] = NULL;
ffi_call(&cif, FFI_FN(cls_struct_9byte_fn), &res_dbl, args_dbl);
/* { dg-output "7 8 1 9: 8 17" } */
CHECK( res_dbl.a == (h_dbl.a + j_dbl.a));
CHECK( res_dbl.b == (h_dbl.b + j_dbl.b));
CHECK(ffi_prep_closure(pcl, &cif, cls_struct_9byte_gn, NULL) == FFI_OK);
res_dbl = ((cls_struct_9byte(*)(cls_struct_9byte, cls_struct_9byte))(pcl))(h_dbl, j_dbl);
/* { dg-output "\n7 8 1 9: 8 17" } */
CHECK( res_dbl.a == (h_dbl.a + j_dbl.a));
CHECK( res_dbl.b == (h_dbl.b + j_dbl.b));
exit(0);
}

View File

@ -0,0 +1,41 @@
/* Area: closure_call
Purpose: Check return value schar.
Limitations: none.
PR: none.
Originator: <andreast@gcc.gnu.org> 20031108 */
/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
#include "ffitest.h"
static void cls_ret_schar_fn(ffi_cif* cif,void* resp,void** args,
void* userdata)
{
*(ffi_arg*)resp = *(signed char *)args[0];
printf("%d: %d\n",*(signed char *)args[0],
*(ffi_arg*)resp);
}
typedef signed char (*cls_ret_schar)(signed char);
int main (void)
{
ffi_cif cif;
static ffi_closure cl;
ffi_closure *pcl = &cl;
ffi_type * cl_arg_types[2];
signed char res;
cl_arg_types[0] = &ffi_type_schar;
cl_arg_types[1] = NULL;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
&ffi_type_schar, cl_arg_types) == FFI_OK);
CHECK(ffi_prep_closure(pcl, &cif, cls_ret_schar_fn, NULL) == FFI_OK);
res = (*((cls_ret_schar)pcl))(127);
/* { dg-output "127: 127" } */
CHECK(res == 127);
exit(0);
}

View File

@ -0,0 +1,41 @@
/* Area: closure_call
Purpose: Check return value sint32.
Limitations: none.
PR: none.
Originator: <andreast@gcc.gnu.org> 20031108 */
/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
#include "ffitest.h"
static void cls_ret_sint_fn(ffi_cif* cif,void* resp,void** args,
void* userdata)
{
*(ffi_arg*)resp = *(signed int *)args[0];
printf("%d: %d\n",*(signed int *)args[0],
*(ffi_arg*)resp);
}
typedef signed int (*cls_ret_sint)(signed int);
int main (void)
{
ffi_cif cif;
static ffi_closure cl;
ffi_closure *pcl = &cl;
ffi_type * cl_arg_types[2];
signed int res;
cl_arg_types[0] = &ffi_type_sint32;
cl_arg_types[1] = NULL;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
&ffi_type_sint32, cl_arg_types) == FFI_OK);
CHECK(ffi_prep_closure(pcl, &cif, cls_ret_sint_fn, NULL) == FFI_OK);
res = (*((cls_ret_sint)pcl))(65534);
/* { dg-output "65534: 65534" } */
CHECK(res == 65534);
exit(0);
}

View File

@ -0,0 +1,41 @@
/* Area: closure_call
Purpose: Check return value sshort.
Limitations: none.
PR: none.
Originator: <andreast@gcc.gnu.org> 20031108 */
/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
#include "ffitest.h"
static void cls_ret_sshort_fn(ffi_cif* cif,void* resp,void** args,
void* userdata)
{
*(ffi_arg*)resp = *(signed short *)args[0];
printf("%d: %d\n",*(signed short *)args[0],
*(ffi_arg*)resp);
}
typedef signed short (*cls_ret_sshort)(signed short);
int main (void)
{
ffi_cif cif;
static ffi_closure cl;
ffi_closure *pcl = &cl;
ffi_type * cl_arg_types[2];
signed short res;
cl_arg_types[0] = &ffi_type_sint16;
cl_arg_types[1] = NULL;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
&ffi_type_sint16, cl_arg_types) == FFI_OK);
CHECK(ffi_prep_closure(pcl, &cif, cls_ret_sshort_fn, NULL) == FFI_OK);
res = (*((cls_ret_sshort)pcl))(255);
/* { dg-output "255: 255" } */
CHECK(res == 255);
exit(0);
}

View File

@ -0,0 +1,119 @@
/* Area: ffi_call, closure_call
Purpose: Check structure passing with different structure size.
Contains structs as parameter of the struct itself.
Sample taken from Alan Modras patch to src/prep_cif.c.
Limitations: none.
PR: none.
Originator: <andreast@gcc.gnu.org> 20030911 */
/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
#include "ffitest.h"
#if LONG_MAX == 2147483647
#define ffi_type_mylong ffi_type_uint32
#else
#if LONG_MAX == 9223372036854775807
#define ffi_type_mylong ffi_type_uint64
#else
#error "Error, size LONG not defined as expected"
#endif
#endif
typedef struct A {
unsigned long a;
unsigned char b;
} A;
typedef struct B {
struct A x;
unsigned char y;
} B;
B B_fn(struct A b0, struct B b1)
{
struct B result;
result.x.a = b0.a + b1.x.a;
result.x.b = b0.b + b1.x.b + b1.y;
result.y = b0.b + b1.x.b;
printf("%d %d %d %d %d: %d %d %d\n", b0.a, b0.b, b1.x.a, b1.x.b, b1.y,
result.x.a, result.x.b, result.y);
return result;
}
static void
B_gn(ffi_cif* cif, void* resp, void** args, void* userdata)
{
struct A b0;
struct B b1;
b0 = *(struct A*)(args[0]);
b1 = *(struct B*)(args[1]);
*(B*)resp = B_fn(b0, b1);
}
int main (void)
{
ffi_cif cif;
static ffi_closure cl;
ffi_closure *pcl = &cl;
void* args_dbl[3];
ffi_type* cls_struct_fields[3];
ffi_type* cls_struct_fields1[3];
ffi_type cls_struct_type, cls_struct_type1;
ffi_type* dbl_arg_types[3];
cls_struct_type.size = 0;
cls_struct_type.alignment = 0;
cls_struct_type.type = FFI_TYPE_STRUCT;
cls_struct_type.elements = cls_struct_fields;
cls_struct_type1.size = 0;
cls_struct_type1.alignment = 0;
cls_struct_type1.type = FFI_TYPE_STRUCT;
cls_struct_type1.elements = cls_struct_fields1;
struct A e_dbl = { 1, 7};
struct B f_dbl = {{12 , 127}, 99};
struct B res_dbl;
cls_struct_fields[0] = &ffi_type_mylong;
cls_struct_fields[1] = &ffi_type_uchar;
cls_struct_fields[2] = NULL;
cls_struct_fields1[0] = &cls_struct_type;
cls_struct_fields1[1] = &ffi_type_uchar;
cls_struct_fields1[2] = NULL;
dbl_arg_types[0] = &cls_struct_type;
dbl_arg_types[1] = &cls_struct_type1;
dbl_arg_types[2] = NULL;
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type1,
dbl_arg_types) == FFI_OK);
args_dbl[0] = &e_dbl;
args_dbl[1] = &f_dbl;
args_dbl[2] = NULL;
ffi_call(&cif, FFI_FN(B_fn), &res_dbl, args_dbl);
/* { dg-output "1 7 12 127 99: 13 233 134" } */
CHECK( res_dbl.x.a == (e_dbl.a + f_dbl.x.a));
CHECK( res_dbl.x.b == (e_dbl.b + f_dbl.x.b + f_dbl.y));
CHECK( res_dbl.y == (e_dbl.b + f_dbl.x.b));
CHECK(ffi_prep_closure(pcl, &cif, B_gn, NULL) == FFI_OK);
res_dbl = ((B(*)(A, B))(pcl))(e_dbl, f_dbl);
/* { dg-output "\n1 7 12 127 99: 13 233 134" } */
CHECK( res_dbl.x.a == (e_dbl.a + f_dbl.x.a));
CHECK( res_dbl.x.b == (e_dbl.b + f_dbl.x.b + f_dbl.y));
CHECK( res_dbl.y == (e_dbl.b + f_dbl.x.b));
exit(0);
}

View File

@ -0,0 +1,110 @@
/* Area: ffi_call, closure_call
Purpose: Check structure passing with different structure size.
Contains structs as parameter of the struct itself.
Sample taken from Alan Modras patch to src/prep_cif.c.
Limitations: none.
PR: none.
Originator: <andreast@gcc.gnu.org> 20030911 */
/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
#include "ffitest.h"
typedef struct A {
unsigned long long a;
unsigned char b;
} A;
typedef struct B {
struct A x;
unsigned char y;
} B;
B B_fn(struct A b0, struct B b1)
{
struct B result;
result.x.a = b0.a + b1.x.a;
result.x.b = b0.b + b1.x.b + b1.y;
result.y = b0.b + b1.x.b;
printf("%d %d %d %d %d: %d %d %d\n", (int)b0.a, b0.b,
(int)b1.x.a, b1.x.b, b1.y,
(int)result.x.a, result.x.b, result.y);
return result;
}
static void
B_gn(ffi_cif* cif, void* resp, void** args, void* userdata)
{
struct A b0;
struct B b1;
b0 = *(struct A*)(args[0]);
b1 = *(struct B*)(args[1]);
*(B*)resp = B_fn(b0, b1);
}
int main (void)
{
ffi_cif cif;
static ffi_closure cl;
ffi_closure *pcl = &cl;
void* args_dbl[3];
ffi_type* cls_struct_fields[3];
ffi_type* cls_struct_fields1[3];
ffi_type cls_struct_type, cls_struct_type1;
ffi_type* dbl_arg_types[3];
cls_struct_type.size = 0;
cls_struct_type.alignment = 0;
cls_struct_type.type = FFI_TYPE_STRUCT;
cls_struct_type.elements = cls_struct_fields;
cls_struct_type1.size = 0;
cls_struct_type1.alignment = 0;
cls_struct_type1.type = FFI_TYPE_STRUCT;
cls_struct_type1.elements = cls_struct_fields1;
struct A e_dbl = { 1LL, 7};
struct B f_dbl = {{12LL , 127}, 99};
struct B res_dbl;
cls_struct_fields[0] = &ffi_type_uint64;
cls_struct_fields[1] = &ffi_type_uchar;
cls_struct_fields[2] = NULL;
cls_struct_fields1[0] = &cls_struct_type;
cls_struct_fields1[1] = &ffi_type_uchar;
cls_struct_fields1[2] = NULL;
dbl_arg_types[0] = &cls_struct_type;
dbl_arg_types[1] = &cls_struct_type1;
dbl_arg_types[2] = NULL;
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type1,
dbl_arg_types) == FFI_OK);
args_dbl[0] = &e_dbl;
args_dbl[1] = &f_dbl;
args_dbl[2] = NULL;
ffi_call(&cif, FFI_FN(B_fn), &res_dbl, args_dbl);
/* { dg-output "1 7 12 127 99: 13 233 134" } */
CHECK( res_dbl.x.a == (e_dbl.a + f_dbl.x.a));
CHECK( res_dbl.x.b == (e_dbl.b + f_dbl.x.b + f_dbl.y));
CHECK( res_dbl.y == (e_dbl.b + f_dbl.x.b));
CHECK(ffi_prep_closure(pcl, &cif, B_gn, NULL) == FFI_OK);
res_dbl = ((B(*)(A, B))(pcl))(e_dbl, f_dbl);
/* { dg-output "\n1 7 12 127 99: 13 233 134" } */
CHECK( res_dbl.x.a == (e_dbl.a + f_dbl.x.a));
CHECK( res_dbl.x.b == (e_dbl.b + f_dbl.x.b + f_dbl.y));
CHECK( res_dbl.y == (e_dbl.b + f_dbl.x.b));
exit(0);
}