Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libffi / testsuite / libffi.call / float1.c
blobfb81d7d7fd0d8db6bf5eb16d8982a339b6de0203
1 /* Area: ffi_call
2 Purpose: Check return value double.
3 Limitations: none.
4 PR: none.
5 Originator: From the original ffitest.c */
7 /* { dg-do run } */
8 #include "ffitest.h"
9 #include "float.h"
11 typedef union
13 double d;
14 unsigned char c[sizeof (double)];
15 } value_type;
17 #define CANARY 0xba
19 static double dblit(float f)
21 return f/3.0;
24 int main (void)
26 ffi_cif cif;
27 ffi_type *args[MAX_ARGS];
28 void *values[MAX_ARGS];
29 float f;
30 value_type result[2];
31 int i;
33 args[0] = &ffi_type_float;
34 values[0] = &f;
36 /* Initialize the cif */
37 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
38 &ffi_type_double, args) == FFI_OK);
40 f = 3.14159;
42 /* Put a canary in the return array. This is a regression test for
43 a buffer overrun. */
44 memset(result[1].c, CANARY, sizeof (double));
46 ffi_call(&cif, FFI_FN(dblit), &result[0].d, values);
48 /* These are not always the same!! Check for a reasonable delta */
50 CHECK(result[0].d - dblit(f) < DBL_EPSILON);
52 /* Check the canary. */
53 for (i = 0; i < sizeof (double); ++i)
54 CHECK(result[1].c[i] == CANARY);
56 exit(0);