Imported File#ftype spec from rubyspecs.
[rbx.git] / shotgun / external_libs / libffi / testsuite / libffi.call / float4.c
blob0dd6d85e7aa0307211322103f66f9ce7d5d614cf
1 /* Area: ffi_call
2 Purpose: Check denorm double value.
3 Limitations: none.
4 PR: PR26483.
5 Originator: From the original ffitest.c */
7 /* { dg-do run } */
8 /* { dg-options "-mieee" { target alpha*-*-* } } */
10 #include "ffitest.h"
11 #include "float.h"
13 typedef union
15 double d;
16 unsigned char c[sizeof (double)];
17 } value_type;
19 #define CANARY 0xba
21 static double dblit(double d)
23 return d;
26 int main (void)
28 ffi_cif cif;
29 ffi_type *args[MAX_ARGS];
30 void *values[MAX_ARGS];
31 double d;
32 value_type result[2];
33 unsigned int i;
35 args[0] = &ffi_type_double;
36 values[0] = &d;
38 /* Initialize the cif */
39 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
40 &ffi_type_double, args) == FFI_OK);
42 d = DBL_MIN / 2;
44 /* Put a canary in the return array. This is a regression test for
45 a buffer overrun. */
46 memset(result[1].c, CANARY, sizeof (double));
48 ffi_call(&cif, FFI_FN(dblit), &result[0].d, values);
50 /* The standard delta check doesn't work for denorms. Since we didn't do
51 any arithmetic, we should get the original result back, and hence an
52 exact check should be OK here. */
54 CHECK(result[0].d == dblit(d));
56 /* Check the canary. */
57 for (i = 0; i < sizeof (double); ++i)
58 CHECK(result[1].c[i] == CANARY);
60 exit(0);