Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

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 */
39 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
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 }
value_type
enum ruby_value_type value_type
Definition: debug.c:34
memset
void * memset(void *, int, size_t)
large_tag::c
unsigned c
Definition: cls_struct_va1.c:21
exit
void exit(int __status) __attribute__((__noreturn__))
ffitest.h
DBL_MIN
#define DBL_MIN
Definition: numeric.c:37
main
int main(void)
Definition: float4.c:26
double
double
Definition: rb_mjit_min_header-2.7.0.h:5923
i
uint32_t i
Definition: rb_mjit_min_header-2.7.0.h:5464
CHECK
#define CHECK(sub)
Definition: compile.c:448
FFI_DEFAULT_ABI
@ FFI_DEFAULT_ABI
Definition: ffitarget.h:38
CANARY
#define CANARY
Definition: float4.c:19
large_tag::d
unsigned d
Definition: cls_struct_va1.c:22
ffi_prep_cif
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
MAX_ARGS
#define MAX_ARGS
Definition: function.c:15
ffi_call
void ffi_call(ffi_cif *cif, void(*fn)(void), void *rvalue, void **avalue)
Definition: ffi.c:813
value_type
Definition: float1.c:11