Ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5ad0e4688e963d9de019557c78feed9)
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
13typedef union
14{
15 double d;
16 unsigned char c[sizeof (double)];
18
19#define CANARY 0xba
20
21static double dblit(double d)
22{
23 return d;
24}
25
26int 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}
void ffi_call(ffi_cif *cif, void(*fn)(void), void *rvalue, void **avalue)
Definition: ffi.c:813
@ FFI_DEFAULT_ABI
Definition: ffitarget.h:38
#define CHECK(sub)
Definition: compile.c:448
enum ruby_value_type value_type
Definition: debug.c:25
#define CANARY
Definition: float4.c:19
int main(void)
Definition: float4.c:26
#define MAX_ARGS
Definition: function.c:15
#define DBL_MIN
Definition: numeric.c:37
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
uint32_t i
void * memset(void *, int, size_t)
void exit(int __status) __attribute__((__noreturn__))