For PR 26483, IA-64 denorm failure due to unwanted rounding.
[official-gcc.git] / libffi / testsuite / libffi.call / float4.c
blobfebad5eb917af88dbb4a1bcd6c9f2daa9f6c09fc
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 #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(double d)
21 return d;
24 int main (void)
26 ffi_cif cif;
27 ffi_type *args[MAX_ARGS];
28 void *values[MAX_ARGS];
29 double d;
30 value_type result[2];
31 unsigned int i;
33 args[0] = &ffi_type_double;
34 values[0] = &d;
36 /* Initialize the cif */
37 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
38 &ffi_type_double, args) == FFI_OK);
40 d = DBL_MIN / 2;
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 /* The standard delta check doesn't work for denorms. Since we didn't do
49 any arithmetic, we should get the original result back, and hence an
50 exact check should be OK here. */
52 CHECK(result[0].d == dblit(d));
54 /* Check the canary. */
55 for (i = 0; i < sizeof (double); ++i)
56 CHECK(result[1].c[i] == CANARY);
58 exit(0);