summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorAnthony Green <green@moxielogic.com>2022-09-18 11:04:54 -0400
committerAnthony Green <green@moxielogic.com>2022-09-18 11:04:54 -0400
commitacf0ce9e9b0bcd73d39f599a53e9924ba74c13c1 (patch)
treed532407e50037b02586fe8856522e0dd24c55a3b /testsuite
parentb49308eaac7288e01a36894598fb62bfaf61b238 (diff)
downloadlibffi-acf0ce9e9b0bcd73d39f599a53e9924ba74c13c1.tar.gz
Add test case
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/libffi.call/s55.c60
1 files changed, 60 insertions, 0 deletions
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);
+}