From acf0ce9e9b0bcd73d39f599a53e9924ba74c13c1 Mon Sep 17 00:00:00 2001 From: Anthony Green Date: Sun, 18 Sep 2022 11:04:54 -0400 Subject: Add test case --- testsuite/libffi.call/s55.c | 60 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 testsuite/libffi.call/s55.c diff --git a/testsuite/libffi.call/s55.c b/testsuite/libffi.call/s55.c new file mode 100644 index 0000000..94dfd5f --- /dev/null +++ b/testsuite/libffi.call/s55.c @@ -0,0 +1,60 @@ +/* Area: ffi_call + Purpose: Check structures. + Limitations: none. + PR: none. + Originator: From the original ffitest.c */ + +/* { dg-do run } */ +#include "ffitest.h" + +typedef struct +{ + float f; +} s55; + +static s55 ABI_ATTR f55(s55 ts, float f) +{ + s55 r; + r.f = ts.f + f; + printf ("f55>> %g + %g = %g\n", ts.f, f, r.f); + return r; +} + +int main (void) +{ + ffi_cif cif; + s55 F, Fr; + float f; + void *values[] = { &F, &f }; + ffi_type s55_type; + ffi_type *args[] = { &s55_type, &ffi_type_float }; + ffi_type *s55_type_elements[] = { &ffi_type_float, NULL }; + + /* This is a hack to get a properly aligned result buffer */ + s55 *s55_result = + (s55 *) malloc (sizeof(s55)); + + s55_type.size = 0; + s55_type.alignment = 0; + s55_type.type = FFI_TYPE_STRUCT; + s55_type.elements = s55_type_elements; + + /* Initialize the cif */ + CHECK(ffi_prep_cif(&cif, ABI_NUM, 2, &s55_type, args) == FFI_OK); + + F.f = 1; + Fr = f55(F, 2.14); + printf ("%g\n", Fr.f); + + F.f = 1; + f = 2.14; + ffi_call(&cif, FFI_FN(f55), s55_result, values); + printf ("%g\n", s55_result->f); + + fflush(0); + + CHECK(fabs(Fr.f - s55_result->f) < FLT_EPSILON); + + free (s55_result); + exit(0); +} -- cgit v1.2.1