AArch64 port
This commit is contained in:
114
testsuite/libffi.call/cls_struct_va1.c
Normal file
114
testsuite/libffi.call/cls_struct_va1.c
Normal file
@@ -0,0 +1,114 @@
|
||||
/* Area: ffi_call, closure_call
|
||||
Purpose: Test doubles passed in variable argument lists.
|
||||
Limitations: none.
|
||||
PR: none.
|
||||
Originator: Blake Chaffin 6/6/2007 */
|
||||
|
||||
/* { dg-do run } */
|
||||
/* { dg-output "" { xfail avr32*-*-* } } */
|
||||
#include "ffitest.h"
|
||||
|
||||
struct small_tag
|
||||
{
|
||||
unsigned char a;
|
||||
unsigned char b;
|
||||
};
|
||||
|
||||
struct large_tag
|
||||
{
|
||||
unsigned a;
|
||||
unsigned b;
|
||||
unsigned c;
|
||||
unsigned d;
|
||||
unsigned e;
|
||||
};
|
||||
|
||||
static void
|
||||
test_fn (ffi_cif* cif __UNUSED__, void* resp,
|
||||
void** args, void* userdata __UNUSED__)
|
||||
{
|
||||
int n = *(int*)args[0];
|
||||
struct small_tag s1 = * (struct small_tag *) args[1];
|
||||
struct large_tag l1 = * (struct large_tag *) args[2];
|
||||
struct small_tag s2 = * (struct small_tag *) args[3];
|
||||
|
||||
printf ("%d %d %d %d %d %d %d %d %d %d\n", n, s1.a, s1.b,
|
||||
l1.a, l1.b, l1.c, l1.d, l1.e,
|
||||
s2.a, s2.b);
|
||||
* (int*) resp = 42;
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
ffi_cif cif;
|
||||
void *code;
|
||||
ffi_closure *pcl = ffi_closure_alloc (sizeof (ffi_closure), &code);
|
||||
ffi_type* arg_types[5];
|
||||
|
||||
ffi_arg res = 0;
|
||||
|
||||
ffi_type s_type;
|
||||
ffi_type *s_type_elements[3];
|
||||
|
||||
ffi_type l_type;
|
||||
ffi_type *l_type_elements[6];
|
||||
|
||||
struct small_tag s1;
|
||||
struct small_tag s2;
|
||||
struct large_tag l1;
|
||||
|
||||
int si;
|
||||
|
||||
s_type.size = 0;
|
||||
s_type.alignment = 0;
|
||||
s_type.type = FFI_TYPE_STRUCT;
|
||||
s_type.elements = s_type_elements;
|
||||
|
||||
s_type_elements[0] = &ffi_type_uchar;
|
||||
s_type_elements[1] = &ffi_type_uchar;
|
||||
s_type_elements[2] = NULL;
|
||||
|
||||
l_type.size = 0;
|
||||
l_type.alignment = 0;
|
||||
l_type.type = FFI_TYPE_STRUCT;
|
||||
l_type.elements = l_type_elements;
|
||||
|
||||
l_type_elements[0] = &ffi_type_uint;
|
||||
l_type_elements[1] = &ffi_type_uint;
|
||||
l_type_elements[2] = &ffi_type_uint;
|
||||
l_type_elements[3] = &ffi_type_uint;
|
||||
l_type_elements[4] = &ffi_type_uint;
|
||||
l_type_elements[5] = NULL;
|
||||
|
||||
arg_types[0] = &ffi_type_sint;
|
||||
arg_types[1] = &s_type;
|
||||
arg_types[2] = &l_type;
|
||||
arg_types[3] = &s_type;
|
||||
arg_types[4] = NULL;
|
||||
|
||||
CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 4, &ffi_type_sint,
|
||||
arg_types) == FFI_OK);
|
||||
|
||||
si = 4;
|
||||
s1.a = 5;
|
||||
s1.b = 6;
|
||||
|
||||
s2.a = 20;
|
||||
s2.b = 21;
|
||||
|
||||
l1.a = 10;
|
||||
l1.b = 11;
|
||||
l1.c = 12;
|
||||
l1.d = 13;
|
||||
l1.e = 14;
|
||||
|
||||
CHECK(ffi_prep_closure_loc(pcl, &cif, test_fn, NULL, code) == FFI_OK);
|
||||
|
||||
res = ((int (*)(int, ...))(code))(si, s1, l1, s2);
|
||||
// { dg-output "4 5 6 10 11 12 13 14 20 21" }
|
||||
printf("res: %d\n", (int) res);
|
||||
// { dg-output "\nres: 42" }
|
||||
|
||||
exit(0);
|
||||
}
|
||||
44
testsuite/libffi.call/cls_uchar_va.c
Normal file
44
testsuite/libffi.call/cls_uchar_va.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/* Area: closure_call
|
||||
Purpose: Test anonymous unsigned char argument.
|
||||
Limitations: none.
|
||||
PR: none.
|
||||
Originator: ARM Ltd. */
|
||||
|
||||
/* { dg-do run } */
|
||||
#include "ffitest.h"
|
||||
|
||||
typedef unsigned char T;
|
||||
|
||||
static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
|
||||
void* userdata __UNUSED__)
|
||||
{
|
||||
*(T *)resp = *(T *)args[0];
|
||||
|
||||
printf("%d: %d %d\n", *(T *)resp, *(T *)args[0], *(T *)args[1]);
|
||||
}
|
||||
|
||||
typedef T (*cls_ret_T)(T, ...);
|
||||
|
||||
int main (void)
|
||||
{
|
||||
ffi_cif cif;
|
||||
void *code;
|
||||
ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
|
||||
ffi_type * cl_arg_types[3];
|
||||
T res;
|
||||
|
||||
cl_arg_types[0] = &ffi_type_uchar;
|
||||
cl_arg_types[1] = &ffi_type_uchar;
|
||||
cl_arg_types[2] = NULL;
|
||||
|
||||
/* Initialize the cif */
|
||||
CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2,
|
||||
&ffi_type_uchar, cl_arg_types) == FFI_OK);
|
||||
|
||||
CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK);
|
||||
res = ((((cls_ret_T)code)(67, 4)));
|
||||
/* { dg-output "67: 67 4" } */
|
||||
printf("res: %d\n", res);
|
||||
/* { dg-output "\nres: 67" } */
|
||||
exit(0);
|
||||
}
|
||||
45
testsuite/libffi.call/cls_uint_va.c
Normal file
45
testsuite/libffi.call/cls_uint_va.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/* Area: closure_call
|
||||
Purpose: Test anonymous unsigned int argument.
|
||||
Limitations: none.
|
||||
PR: none.
|
||||
Originator: ARM Ltd. */
|
||||
|
||||
/* { dg-do run } */
|
||||
|
||||
#include "ffitest.h"
|
||||
|
||||
typedef unsigned int T;
|
||||
|
||||
static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
|
||||
void* userdata __UNUSED__)
|
||||
{
|
||||
*(T *)resp = *(T *)args[0];
|
||||
|
||||
printf("%d: %d %d\n", *(T *)resp, *(T *)args[0], *(T *)args[1]);
|
||||
}
|
||||
|
||||
typedef T (*cls_ret_T)(T, ...);
|
||||
|
||||
int main (void)
|
||||
{
|
||||
ffi_cif cif;
|
||||
void *code;
|
||||
ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
|
||||
ffi_type * cl_arg_types[3];
|
||||
T res;
|
||||
|
||||
cl_arg_types[0] = &ffi_type_uint;
|
||||
cl_arg_types[1] = &ffi_type_uint;
|
||||
cl_arg_types[2] = NULL;
|
||||
|
||||
/* Initialize the cif */
|
||||
CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2,
|
||||
&ffi_type_uint, cl_arg_types) == FFI_OK);
|
||||
|
||||
CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK);
|
||||
res = ((((cls_ret_T)code)(67, 4)));
|
||||
/* { dg-output "67: 67 4" } */
|
||||
printf("res: %d\n", res);
|
||||
/* { dg-output "\nres: 67" } */
|
||||
exit(0);
|
||||
}
|
||||
45
testsuite/libffi.call/cls_ulong_va.c
Normal file
45
testsuite/libffi.call/cls_ulong_va.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/* Area: closure_call
|
||||
Purpose: Test anonymous unsigned long argument.
|
||||
Limitations: none.
|
||||
PR: none.
|
||||
Originator: ARM Ltd. */
|
||||
|
||||
/* { dg-do run } */
|
||||
|
||||
#include "ffitest.h"
|
||||
|
||||
typedef unsigned long T;
|
||||
|
||||
static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
|
||||
void* userdata __UNUSED__)
|
||||
{
|
||||
*(T *)resp = *(T *)args[0];
|
||||
|
||||
printf("%ld: %ld %ld\n", *(T *)resp, *(T *)args[0], *(T *)args[1]);
|
||||
}
|
||||
|
||||
typedef T (*cls_ret_T)(T, ...);
|
||||
|
||||
int main (void)
|
||||
{
|
||||
ffi_cif cif;
|
||||
void *code;
|
||||
ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
|
||||
ffi_type * cl_arg_types[3];
|
||||
T res;
|
||||
|
||||
cl_arg_types[0] = &ffi_type_ulong;
|
||||
cl_arg_types[1] = &ffi_type_ulong;
|
||||
cl_arg_types[2] = NULL;
|
||||
|
||||
/* Initialize the cif */
|
||||
CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2,
|
||||
&ffi_type_ulong, cl_arg_types) == FFI_OK);
|
||||
|
||||
CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK);
|
||||
res = ((((cls_ret_T)code)(67, 4)));
|
||||
/* { dg-output "67: 67 4" } */
|
||||
printf("res: %ld\n", res);
|
||||
/* { dg-output "\nres: 67" } */
|
||||
exit(0);
|
||||
}
|
||||
44
testsuite/libffi.call/cls_ushort_va.c
Normal file
44
testsuite/libffi.call/cls_ushort_va.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/* Area: closure_call
|
||||
Purpose: Test anonymous unsigned short argument.
|
||||
Limitations: none.
|
||||
PR: none.
|
||||
Originator: ARM Ltd. */
|
||||
|
||||
/* { dg-do run } */
|
||||
#include "ffitest.h"
|
||||
|
||||
typedef unsigned short T;
|
||||
|
||||
static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
|
||||
void* userdata __UNUSED__)
|
||||
{
|
||||
*(T *)resp = *(T *)args[0];
|
||||
|
||||
printf("%d: %d %d\n", *(T *)resp, *(T *)args[0], *(T *)args[1]);
|
||||
}
|
||||
|
||||
typedef T (*cls_ret_T)(T, ...);
|
||||
|
||||
int main (void)
|
||||
{
|
||||
ffi_cif cif;
|
||||
void *code;
|
||||
ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
|
||||
ffi_type * cl_arg_types[3];
|
||||
T res;
|
||||
|
||||
cl_arg_types[0] = &ffi_type_ushort;
|
||||
cl_arg_types[1] = &ffi_type_ushort;
|
||||
cl_arg_types[2] = NULL;
|
||||
|
||||
/* Initialize the cif */
|
||||
CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2,
|
||||
&ffi_type_ushort, cl_arg_types) == FFI_OK);
|
||||
|
||||
CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK);
|
||||
res = ((((cls_ret_T)code)(67, 4)));
|
||||
/* { dg-output "67: 67 4" } */
|
||||
printf("res: %d\n", res);
|
||||
/* { dg-output "\nres: 67" } */
|
||||
exit(0);
|
||||
}
|
||||
121
testsuite/libffi.call/nested_struct11.c
Normal file
121
testsuite/libffi.call/nested_struct11.c
Normal file
@@ -0,0 +1,121 @@
|
||||
/* Area: ffi_call, closure_call
|
||||
Purpose: Check parameter passing with nested structs
|
||||
of a single type. This tests the special cases
|
||||
for homogenous floating-point aggregates in the
|
||||
AArch64 PCS.
|
||||
Limitations: none.
|
||||
PR: none.
|
||||
Originator: ARM Ltd. */
|
||||
|
||||
/* { dg-do run } */
|
||||
#include "ffitest.h"
|
||||
|
||||
typedef struct A {
|
||||
float a_x;
|
||||
float a_y;
|
||||
} A;
|
||||
|
||||
typedef struct B {
|
||||
float b_x;
|
||||
float b_y;
|
||||
} B;
|
||||
|
||||
typedef struct C {
|
||||
A a;
|
||||
B b;
|
||||
} C;
|
||||
|
||||
static C C_fn (int x, int y, int z, C source, int i, int j, int k)
|
||||
{
|
||||
C result;
|
||||
result.a.a_x = source.a.a_x;
|
||||
result.a.a_y = source.a.a_y;
|
||||
result.b.b_x = source.b.b_x;
|
||||
result.b.b_y = source.b.b_y;
|
||||
|
||||
printf ("%d, %d, %d, %d, %d, %d\n", x, y, z, i, j, k);
|
||||
|
||||
printf ("%.1f, %.1f, %.1f, %.1f, "
|
||||
"%.1f, %.1f, %.1f, %.1f\n",
|
||||
source.a.a_x, source.a.a_y,
|
||||
source.b.b_x, source.b.b_y,
|
||||
result.a.a_x, result.a.a_y,
|
||||
result.b.b_x, result.b.b_y);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
ffi_cif cif;
|
||||
|
||||
ffi_type* struct_fields_source_a[3];
|
||||
ffi_type* struct_fields_source_b[3];
|
||||
ffi_type* struct_fields_source_c[3];
|
||||
ffi_type* arg_types[8];
|
||||
|
||||
ffi_type struct_type_a, struct_type_b, struct_type_c;
|
||||
|
||||
struct A source_fld_a = {1.0, 2.0};
|
||||
struct B source_fld_b = {4.0, 8.0};
|
||||
int k = 1;
|
||||
|
||||
struct C result;
|
||||
struct C source = {source_fld_a, source_fld_b};
|
||||
|
||||
struct_type_a.size = 0;
|
||||
struct_type_a.alignment = 0;
|
||||
struct_type_a.type = FFI_TYPE_STRUCT;
|
||||
struct_type_a.elements = struct_fields_source_a;
|
||||
|
||||
struct_type_b.size = 0;
|
||||
struct_type_b.alignment = 0;
|
||||
struct_type_b.type = FFI_TYPE_STRUCT;
|
||||
struct_type_b.elements = struct_fields_source_b;
|
||||
|
||||
struct_type_c.size = 0;
|
||||
struct_type_c.alignment = 0;
|
||||
struct_type_c.type = FFI_TYPE_STRUCT;
|
||||
struct_type_c.elements = struct_fields_source_c;
|
||||
|
||||
struct_fields_source_a[0] = &ffi_type_float;
|
||||
struct_fields_source_a[1] = &ffi_type_float;
|
||||
struct_fields_source_a[2] = NULL;
|
||||
|
||||
struct_fields_source_b[0] = &ffi_type_float;
|
||||
struct_fields_source_b[1] = &ffi_type_float;
|
||||
struct_fields_source_b[2] = NULL;
|
||||
|
||||
struct_fields_source_c[0] = &struct_type_a;
|
||||
struct_fields_source_c[1] = &struct_type_b;
|
||||
struct_fields_source_c[2] = NULL;
|
||||
|
||||
arg_types[0] = &ffi_type_sint32;
|
||||
arg_types[1] = &ffi_type_sint32;
|
||||
arg_types[2] = &ffi_type_sint32;
|
||||
arg_types[3] = &struct_type_c;
|
||||
arg_types[4] = &ffi_type_sint32;
|
||||
arg_types[5] = &ffi_type_sint32;
|
||||
arg_types[6] = &ffi_type_sint32;
|
||||
arg_types[7] = NULL;
|
||||
|
||||
void *args[7];
|
||||
args[0] = &k;
|
||||
args[1] = &k;
|
||||
args[2] = &k;
|
||||
args[3] = &source;
|
||||
args[4] = &k;
|
||||
args[5] = &k;
|
||||
args[6] = &k;
|
||||
CHECK (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, 7, &struct_type_c,
|
||||
arg_types) == FFI_OK);
|
||||
|
||||
ffi_call (&cif, FFI_FN (C_fn), &result, args);
|
||||
/* { dg-output "1, 1, 1, 1, 1, 1\n" } */
|
||||
/* { dg-output "1.0, 2.0, 4.0, 8.0, 1.0, 2.0, 4.0, 8.0" } */
|
||||
CHECK (result.a.a_x == source.a.a_x);
|
||||
CHECK (result.a.a_y == source.a.a_y);
|
||||
CHECK (result.b.b_x == source.b.b_x);
|
||||
CHECK (result.b.b_y == source.b.b_y);
|
||||
exit (0);
|
||||
}
|
||||
61
testsuite/libffi.call/uninitialized.c
Normal file
61
testsuite/libffi.call/uninitialized.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/* { dg-do run } */
|
||||
#include "ffitest.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned char uc;
|
||||
double d;
|
||||
unsigned int ui;
|
||||
} test_structure_1;
|
||||
|
||||
static test_structure_1 struct1(test_structure_1 ts)
|
||||
{
|
||||
ts.uc++;
|
||||
ts.d--;
|
||||
ts.ui++;
|
||||
|
||||
return ts;
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
ffi_cif cif;
|
||||
ffi_type *args[MAX_ARGS];
|
||||
void *values[MAX_ARGS];
|
||||
ffi_type ts1_type;
|
||||
ffi_type *ts1_type_elements[4];
|
||||
|
||||
memset(&cif, 1, sizeof(cif));
|
||||
ts1_type.size = 0;
|
||||
ts1_type.alignment = 0;
|
||||
ts1_type.type = FFI_TYPE_STRUCT;
|
||||
ts1_type.elements = ts1_type_elements;
|
||||
ts1_type_elements[0] = &ffi_type_uchar;
|
||||
ts1_type_elements[1] = &ffi_type_double;
|
||||
ts1_type_elements[2] = &ffi_type_uint;
|
||||
ts1_type_elements[3] = NULL;
|
||||
|
||||
test_structure_1 ts1_arg;
|
||||
/* This is a hack to get a properly aligned result buffer */
|
||||
test_structure_1 *ts1_result =
|
||||
(test_structure_1 *) malloc (sizeof(test_structure_1));
|
||||
|
||||
args[0] = &ts1_type;
|
||||
values[0] = &ts1_arg;
|
||||
|
||||
/* Initialize the cif */
|
||||
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
|
||||
&ts1_type, args) == FFI_OK);
|
||||
|
||||
ts1_arg.uc = '\x01';
|
||||
ts1_arg.d = 3.14159;
|
||||
ts1_arg.ui = 555;
|
||||
|
||||
ffi_call(&cif, FFI_FN(struct1), ts1_result, values);
|
||||
|
||||
CHECK(ts1_result->ui == 556);
|
||||
CHECK(ts1_result->d == 3.14159 - 1);
|
||||
|
||||
free (ts1_result);
|
||||
exit(0);
|
||||
}
|
||||
196
testsuite/libffi.call/va_1.c
Normal file
196
testsuite/libffi.call/va_1.c
Normal file
@@ -0,0 +1,196 @@
|
||||
/* Area: ffi_call
|
||||
Purpose: Test passing struct in variable argument lists.
|
||||
Limitations: none.
|
||||
PR: none.
|
||||
Originator: ARM Ltd. */
|
||||
|
||||
/* { dg-do run } */
|
||||
/* { dg-output "" { xfail avr32*-*-* x86_64-*-*-* } } */
|
||||
|
||||
#include "ffitest.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
struct small_tag
|
||||
{
|
||||
unsigned char a;
|
||||
unsigned char b;
|
||||
};
|
||||
|
||||
struct large_tag
|
||||
{
|
||||
unsigned a;
|
||||
unsigned b;
|
||||
unsigned c;
|
||||
unsigned d;
|
||||
unsigned e;
|
||||
};
|
||||
|
||||
static int
|
||||
test_fn (int n, ...)
|
||||
{
|
||||
va_list ap;
|
||||
struct small_tag s1;
|
||||
struct small_tag s2;
|
||||
struct large_tag l;
|
||||
unsigned char uc;
|
||||
signed char sc;
|
||||
unsigned short us;
|
||||
signed short ss;
|
||||
unsigned int ui;
|
||||
signed int si;
|
||||
unsigned long ul;
|
||||
signed long sl;
|
||||
float f;
|
||||
double d;
|
||||
|
||||
va_start (ap, n);
|
||||
s1 = va_arg (ap, struct small_tag);
|
||||
l = va_arg (ap, struct large_tag);
|
||||
s2 = va_arg (ap, struct small_tag);
|
||||
|
||||
uc = va_arg (ap, unsigned);
|
||||
sc = va_arg (ap, signed);
|
||||
|
||||
us = va_arg (ap, unsigned);
|
||||
ss = va_arg (ap, signed);
|
||||
|
||||
ui = va_arg (ap, unsigned int);
|
||||
si = va_arg (ap, signed int);
|
||||
|
||||
ul = va_arg (ap, unsigned long);
|
||||
sl = va_arg (ap, signed long);
|
||||
|
||||
f = va_arg (ap, double); /* C standard promotes float->double
|
||||
when anonymous */
|
||||
d = va_arg (ap, double);
|
||||
|
||||
printf ("%u %u %u %u %u %u %u %u %u uc=%u sc=%d %u %d %u %d %lu %ld %f %f\n",
|
||||
s1.a, s1.b, l.a, l.b, l.c, l.d, l.e,
|
||||
s2.a, s2.b,
|
||||
uc, sc,
|
||||
us, ss,
|
||||
ui, si,
|
||||
ul, sl,
|
||||
f, d);
|
||||
va_end (ap);
|
||||
return n + 1;
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
ffi_cif cif;
|
||||
void* args[15];
|
||||
ffi_type* arg_types[15];
|
||||
|
||||
ffi_type s_type;
|
||||
ffi_type *s_type_elements[3];
|
||||
|
||||
ffi_type l_type;
|
||||
ffi_type *l_type_elements[6];
|
||||
|
||||
struct small_tag s1;
|
||||
struct small_tag s2;
|
||||
struct large_tag l1;
|
||||
|
||||
int n;
|
||||
int res;
|
||||
|
||||
unsigned char uc;
|
||||
signed char sc;
|
||||
unsigned short us;
|
||||
signed short ss;
|
||||
unsigned int ui;
|
||||
signed int si;
|
||||
unsigned long ul;
|
||||
signed long sl;
|
||||
double d1;
|
||||
double f1;
|
||||
|
||||
s_type.size = 0;
|
||||
s_type.alignment = 0;
|
||||
s_type.type = FFI_TYPE_STRUCT;
|
||||
s_type.elements = s_type_elements;
|
||||
|
||||
s_type_elements[0] = &ffi_type_uchar;
|
||||
s_type_elements[1] = &ffi_type_uchar;
|
||||
s_type_elements[2] = NULL;
|
||||
|
||||
l_type.size = 0;
|
||||
l_type.alignment = 0;
|
||||
l_type.type = FFI_TYPE_STRUCT;
|
||||
l_type.elements = l_type_elements;
|
||||
|
||||
l_type_elements[0] = &ffi_type_uint;
|
||||
l_type_elements[1] = &ffi_type_uint;
|
||||
l_type_elements[2] = &ffi_type_uint;
|
||||
l_type_elements[3] = &ffi_type_uint;
|
||||
l_type_elements[4] = &ffi_type_uint;
|
||||
l_type_elements[5] = NULL;
|
||||
|
||||
arg_types[0] = &ffi_type_sint;
|
||||
arg_types[1] = &s_type;
|
||||
arg_types[2] = &l_type;
|
||||
arg_types[3] = &s_type;
|
||||
arg_types[4] = &ffi_type_uint;
|
||||
arg_types[5] = &ffi_type_sint;
|
||||
arg_types[6] = &ffi_type_uint;
|
||||
arg_types[7] = &ffi_type_sint;
|
||||
arg_types[8] = &ffi_type_uint;
|
||||
arg_types[9] = &ffi_type_sint;
|
||||
arg_types[10] = &ffi_type_ulong;
|
||||
arg_types[11] = &ffi_type_slong;
|
||||
arg_types[12] = &ffi_type_double;
|
||||
arg_types[13] = &ffi_type_double;
|
||||
arg_types[14] = NULL;
|
||||
|
||||
CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 14, &ffi_type_sint, arg_types) == FFI_OK);
|
||||
|
||||
s1.a = 5;
|
||||
s1.b = 6;
|
||||
|
||||
l1.a = 10;
|
||||
l1.b = 11;
|
||||
l1.c = 12;
|
||||
l1.d = 13;
|
||||
l1.e = 14;
|
||||
|
||||
s2.a = 7;
|
||||
s2.b = 8;
|
||||
|
||||
n = 41;
|
||||
|
||||
uc = 9;
|
||||
sc = 10;
|
||||
us = 11;
|
||||
ss = 12;
|
||||
ui = 13;
|
||||
si = 14;
|
||||
ul = 15;
|
||||
sl = 16;
|
||||
f1 = 2.12;
|
||||
d1 = 3.13;
|
||||
|
||||
args[0] = &n;
|
||||
args[1] = &s1;
|
||||
args[2] = &l1;
|
||||
args[3] = &s2;
|
||||
args[4] = &uc;
|
||||
args[5] = ≻
|
||||
args[6] = &us;
|
||||
args[7] = &ss;
|
||||
args[8] = &ui;
|
||||
args[9] = &si;
|
||||
args[10] = &ul;
|
||||
args[11] = &sl;
|
||||
args[12] = &f1;
|
||||
args[13] = &d1;
|
||||
args[14] = NULL;
|
||||
|
||||
ffi_call(&cif, FFI_FN(test_fn), &res, args);
|
||||
/* { dg-output "5 6 10 11 12 13 14 7 8 uc=9 sc=10 11 12 13 14 15 16 2.120000 3.130000" } */
|
||||
printf("res: %d\n", (int) res);
|
||||
/* { dg-output "\nres: 42" } */
|
||||
|
||||
return 0;
|
||||
}
|
||||
121
testsuite/libffi.call/va_struct1.c
Normal file
121
testsuite/libffi.call/va_struct1.c
Normal file
@@ -0,0 +1,121 @@
|
||||
/* Area: ffi_call
|
||||
Purpose: Test passing struct in variable argument lists.
|
||||
Limitations: none.
|
||||
PR: none.
|
||||
Originator: ARM Ltd. */
|
||||
|
||||
/* { dg-do run } */
|
||||
/* { dg-output "" { xfail avr32*-*-* } } */
|
||||
|
||||
#include "ffitest.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
struct small_tag
|
||||
{
|
||||
unsigned char a;
|
||||
unsigned char b;
|
||||
};
|
||||
|
||||
struct large_tag
|
||||
{
|
||||
unsigned a;
|
||||
unsigned b;
|
||||
unsigned c;
|
||||
unsigned d;
|
||||
unsigned e;
|
||||
};
|
||||
|
||||
static int
|
||||
test_fn (int n, ...)
|
||||
{
|
||||
va_list ap;
|
||||
struct small_tag s1;
|
||||
struct small_tag s2;
|
||||
struct large_tag l;
|
||||
|
||||
va_start (ap, n);
|
||||
s1 = va_arg (ap, struct small_tag);
|
||||
l = va_arg (ap, struct large_tag);
|
||||
s2 = va_arg (ap, struct small_tag);
|
||||
printf ("%u %u %u %u %u %u %u %u %u\n", s1.a, s1.b, l.a, l.b, l.c, l.d, l.e,
|
||||
s2.a, s2.b);
|
||||
va_end (ap);
|
||||
return n + 1;
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
ffi_cif cif;
|
||||
void* args[5];
|
||||
ffi_type* arg_types[5];
|
||||
|
||||
ffi_type s_type;
|
||||
ffi_type *s_type_elements[3];
|
||||
|
||||
ffi_type l_type;
|
||||
ffi_type *l_type_elements[6];
|
||||
|
||||
struct small_tag s1;
|
||||
struct small_tag s2;
|
||||
struct large_tag l1;
|
||||
|
||||
int n;
|
||||
int res;
|
||||
|
||||
s_type.size = 0;
|
||||
s_type.alignment = 0;
|
||||
s_type.type = FFI_TYPE_STRUCT;
|
||||
s_type.elements = s_type_elements;
|
||||
|
||||
s_type_elements[0] = &ffi_type_uchar;
|
||||
s_type_elements[1] = &ffi_type_uchar;
|
||||
s_type_elements[2] = NULL;
|
||||
|
||||
l_type.size = 0;
|
||||
l_type.alignment = 0;
|
||||
l_type.type = FFI_TYPE_STRUCT;
|
||||
l_type.elements = l_type_elements;
|
||||
|
||||
l_type_elements[0] = &ffi_type_uint;
|
||||
l_type_elements[1] = &ffi_type_uint;
|
||||
l_type_elements[2] = &ffi_type_uint;
|
||||
l_type_elements[3] = &ffi_type_uint;
|
||||
l_type_elements[4] = &ffi_type_uint;
|
||||
l_type_elements[5] = NULL;
|
||||
|
||||
arg_types[0] = &ffi_type_sint;
|
||||
arg_types[1] = &s_type;
|
||||
arg_types[2] = &l_type;
|
||||
arg_types[3] = &s_type;
|
||||
arg_types[4] = NULL;
|
||||
|
||||
CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 4, &ffi_type_sint, arg_types) == FFI_OK);
|
||||
|
||||
s1.a = 5;
|
||||
s1.b = 6;
|
||||
|
||||
l1.a = 10;
|
||||
l1.b = 11;
|
||||
l1.c = 12;
|
||||
l1.d = 13;
|
||||
l1.e = 14;
|
||||
|
||||
s2.a = 7;
|
||||
s2.b = 8;
|
||||
|
||||
n = 41;
|
||||
|
||||
args[0] = &n;
|
||||
args[1] = &s1;
|
||||
args[2] = &l1;
|
||||
args[3] = &s2;
|
||||
args[4] = NULL;
|
||||
|
||||
ffi_call(&cif, FFI_FN(test_fn), &res, args);
|
||||
/* { dg-output "5 6 10 11 12 13 14 7 8" } */
|
||||
printf("res: %d\n", (int) res);
|
||||
/* { dg-output "\nres: 42" } */
|
||||
|
||||
return 0;
|
||||
}
|
||||
123
testsuite/libffi.call/va_struct2.c
Normal file
123
testsuite/libffi.call/va_struct2.c
Normal file
@@ -0,0 +1,123 @@
|
||||
/* Area: ffi_call
|
||||
Purpose: Test passing struct in variable argument lists.
|
||||
Limitations: none.
|
||||
PR: none.
|
||||
Originator: ARM Ltd. */
|
||||
|
||||
/* { dg-do run } */
|
||||
/* { dg-output "" { xfail avr32*-*-* } } */
|
||||
|
||||
#include "ffitest.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
struct small_tag
|
||||
{
|
||||
unsigned char a;
|
||||
unsigned char b;
|
||||
};
|
||||
|
||||
struct large_tag
|
||||
{
|
||||
unsigned a;
|
||||
unsigned b;
|
||||
unsigned c;
|
||||
unsigned d;
|
||||
unsigned e;
|
||||
};
|
||||
|
||||
static struct small_tag
|
||||
test_fn (int n, ...)
|
||||
{
|
||||
va_list ap;
|
||||
struct small_tag s1;
|
||||
struct small_tag s2;
|
||||
struct large_tag l;
|
||||
|
||||
va_start (ap, n);
|
||||
s1 = va_arg (ap, struct small_tag);
|
||||
l = va_arg (ap, struct large_tag);
|
||||
s2 = va_arg (ap, struct small_tag);
|
||||
printf ("%u %u %u %u %u %u %u %u %u\n", s1.a, s1.b, l.a, l.b, l.c, l.d, l.e,
|
||||
s2.a, s2.b);
|
||||
va_end (ap);
|
||||
s1.a += s2.a;
|
||||
s1.b += s2.b;
|
||||
return s1;
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
ffi_cif cif;
|
||||
void* args[5];
|
||||
ffi_type* arg_types[5];
|
||||
|
||||
ffi_type s_type;
|
||||
ffi_type *s_type_elements[3];
|
||||
|
||||
ffi_type l_type;
|
||||
ffi_type *l_type_elements[6];
|
||||
|
||||
struct small_tag s1;
|
||||
struct small_tag s2;
|
||||
struct large_tag l1;
|
||||
|
||||
int n;
|
||||
struct small_tag res;
|
||||
|
||||
s_type.size = 0;
|
||||
s_type.alignment = 0;
|
||||
s_type.type = FFI_TYPE_STRUCT;
|
||||
s_type.elements = s_type_elements;
|
||||
|
||||
s_type_elements[0] = &ffi_type_uchar;
|
||||
s_type_elements[1] = &ffi_type_uchar;
|
||||
s_type_elements[2] = NULL;
|
||||
|
||||
l_type.size = 0;
|
||||
l_type.alignment = 0;
|
||||
l_type.type = FFI_TYPE_STRUCT;
|
||||
l_type.elements = l_type_elements;
|
||||
|
||||
l_type_elements[0] = &ffi_type_uint;
|
||||
l_type_elements[1] = &ffi_type_uint;
|
||||
l_type_elements[2] = &ffi_type_uint;
|
||||
l_type_elements[3] = &ffi_type_uint;
|
||||
l_type_elements[4] = &ffi_type_uint;
|
||||
l_type_elements[5] = NULL;
|
||||
|
||||
arg_types[0] = &ffi_type_sint;
|
||||
arg_types[1] = &s_type;
|
||||
arg_types[2] = &l_type;
|
||||
arg_types[3] = &s_type;
|
||||
arg_types[4] = NULL;
|
||||
|
||||
CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 4, &s_type, arg_types) == FFI_OK);
|
||||
|
||||
s1.a = 5;
|
||||
s1.b = 6;
|
||||
|
||||
l1.a = 10;
|
||||
l1.b = 11;
|
||||
l1.c = 12;
|
||||
l1.d = 13;
|
||||
l1.e = 14;
|
||||
|
||||
s2.a = 7;
|
||||
s2.b = 8;
|
||||
|
||||
n = 41;
|
||||
|
||||
args[0] = &n;
|
||||
args[1] = &s1;
|
||||
args[2] = &l1;
|
||||
args[3] = &s2;
|
||||
args[4] = NULL;
|
||||
|
||||
ffi_call(&cif, FFI_FN(test_fn), &res, args);
|
||||
/* { dg-output "5 6 10 11 12 13 14 7 8" } */
|
||||
printf("res: %d %d\n", res.a, res.b);
|
||||
/* { dg-output "\nres: 12 14" } */
|
||||
|
||||
return 0;
|
||||
}
|
||||
125
testsuite/libffi.call/va_struct3.c
Normal file
125
testsuite/libffi.call/va_struct3.c
Normal file
@@ -0,0 +1,125 @@
|
||||
/* Area: ffi_call
|
||||
Purpose: Test passing struct in variable argument lists.
|
||||
Limitations: none.
|
||||
PR: none.
|
||||
Originator: ARM Ltd. */
|
||||
|
||||
/* { dg-do run } */
|
||||
/* { dg-output "" { xfail avr32*-*-* } } */
|
||||
|
||||
#include "ffitest.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
struct small_tag
|
||||
{
|
||||
unsigned char a;
|
||||
unsigned char b;
|
||||
};
|
||||
|
||||
struct large_tag
|
||||
{
|
||||
unsigned a;
|
||||
unsigned b;
|
||||
unsigned c;
|
||||
unsigned d;
|
||||
unsigned e;
|
||||
};
|
||||
|
||||
static struct large_tag
|
||||
test_fn (int n, ...)
|
||||
{
|
||||
va_list ap;
|
||||
struct small_tag s1;
|
||||
struct small_tag s2;
|
||||
struct large_tag l;
|
||||
|
||||
va_start (ap, n);
|
||||
s1 = va_arg (ap, struct small_tag);
|
||||
l = va_arg (ap, struct large_tag);
|
||||
s2 = va_arg (ap, struct small_tag);
|
||||
printf ("%u %u %u %u %u %u %u %u %u\n", s1.a, s1.b, l.a, l.b, l.c, l.d, l.e,
|
||||
s2.a, s2.b);
|
||||
va_end (ap);
|
||||
l.a += s1.a;
|
||||
l.b += s1.b;
|
||||
l.c += s2.a;
|
||||
l.d += s2.b;
|
||||
return l;
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
ffi_cif cif;
|
||||
void* args[5];
|
||||
ffi_type* arg_types[5];
|
||||
|
||||
ffi_type s_type;
|
||||
ffi_type *s_type_elements[3];
|
||||
|
||||
ffi_type l_type;
|
||||
ffi_type *l_type_elements[6];
|
||||
|
||||
struct small_tag s1;
|
||||
struct small_tag s2;
|
||||
struct large_tag l1;
|
||||
|
||||
int n;
|
||||
struct large_tag res;
|
||||
|
||||
s_type.size = 0;
|
||||
s_type.alignment = 0;
|
||||
s_type.type = FFI_TYPE_STRUCT;
|
||||
s_type.elements = s_type_elements;
|
||||
|
||||
s_type_elements[0] = &ffi_type_uchar;
|
||||
s_type_elements[1] = &ffi_type_uchar;
|
||||
s_type_elements[2] = NULL;
|
||||
|
||||
l_type.size = 0;
|
||||
l_type.alignment = 0;
|
||||
l_type.type = FFI_TYPE_STRUCT;
|
||||
l_type.elements = l_type_elements;
|
||||
|
||||
l_type_elements[0] = &ffi_type_uint;
|
||||
l_type_elements[1] = &ffi_type_uint;
|
||||
l_type_elements[2] = &ffi_type_uint;
|
||||
l_type_elements[3] = &ffi_type_uint;
|
||||
l_type_elements[4] = &ffi_type_uint;
|
||||
l_type_elements[5] = NULL;
|
||||
|
||||
arg_types[0] = &ffi_type_sint;
|
||||
arg_types[1] = &s_type;
|
||||
arg_types[2] = &l_type;
|
||||
arg_types[3] = &s_type;
|
||||
arg_types[4] = NULL;
|
||||
|
||||
CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 4, &l_type, arg_types) == FFI_OK);
|
||||
|
||||
s1.a = 5;
|
||||
s1.b = 6;
|
||||
|
||||
l1.a = 10;
|
||||
l1.b = 11;
|
||||
l1.c = 12;
|
||||
l1.d = 13;
|
||||
l1.e = 14;
|
||||
|
||||
s2.a = 7;
|
||||
s2.b = 8;
|
||||
|
||||
n = 41;
|
||||
|
||||
args[0] = &n;
|
||||
args[1] = &s1;
|
||||
args[2] = &l1;
|
||||
args[3] = &s2;
|
||||
args[4] = NULL;
|
||||
|
||||
ffi_call(&cif, FFI_FN(test_fn), &res, args);
|
||||
/* { dg-output "5 6 10 11 12 13 14 7 8" } */
|
||||
printf("res: %d %d %d %d %d\n", res.a, res.b, res.c, res.d, res.e);
|
||||
/* { dg-output "\nres: 15 17 19 21 14" } */
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user