Ruby  2.4.2p198(2017-09-14revision59899)
float4.c
Go to the documentation of this file.
1 /* Area: ffi_call
2  Purpose: Check denorm double value.
3  Limitations: none.
4  PR: PR26483.
5  Originator: From the original ffitest.c */
6 
7 /* { dg-do run } */
8 /* { dg-options "-mieee" { target alpha*-*-* } } */
9 
10 #include "ffitest.h"
11 #include "float.h"
12 
13 typedef union
14 {
15  double d;
16  unsigned char c[sizeof (double)];
17 } value_type;
18 
19 #define CANARY 0xba
20 
21 static double dblit(double d)
22 {
23  return d;
24 }
25 
26 int main (void)
27 {
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;
34 
35  args[0] = &ffi_type_double;
36  values[0] = &d;
37 
38  /* Initialize the cif */
40  &ffi_type_double, args) == FFI_OK);
41 
42  d = DBL_MIN / 2;
43 
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));
47 
48  ffi_call(&cif, FFI_FN(dblit), &result[0].d, values);
49 
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. */
53 
54  CHECK(result[0].d == dblit(d));
55 
56  /* Check the canary. */
57  for (i = 0; i < sizeof (double); ++i)
58  CHECK(result[1].c[i] == CANARY);
59 
60  exit(0);
61 
62 }
static double dblit(double d)
Definition: float4.c:21
unsigned c
int main(void)
Definition: float4.c:26
#define DBL_MIN
Definition: numeric.c:36
void ffi_call(ffi_cif *cif, void(*fn)(void), void *rvalue, void **avalue)
Definition: ffi.c:813
#define MAX_ARGS
Definition: function.c:15
static VALUE result
Definition: nkf.c:40
enum ruby_value_type value_type
Definition: debug.c:23
unsigned d
#define CHECK(sub)
Definition: compile.c:408
#define CANARY
Definition: float4.c:19
ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs, ffi_type *rtype, ffi_type **atypes)
Definition: prep_cif.c:226