Ruby: ext/fiddle/libffi-3.2.1/testsuite/libffi.call/float4.c Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

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)];
17} value_type;
18
19#define CANARY 0xba
20
21static 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}
ffi_call
void ffi_call(ffi_cif *cif, void(*fn)(void), void *rvalue, void **avalue)
Definition: ffi.c:813
FFI_DEFAULT_ABI
@ FFI_DEFAULT_ABI
Definition: ffitarget.h:38
CHECK
#define CHECK(sub)
Definition: compile.c:429
ffitest.h
CANARY
#define CANARY
Definition: float4.c:19
main
int main(void)
Definition: float4.c:26
MAX_ARGS
#define MAX_ARGS
Definition: function.c:17
DBL_MIN
#define DBL_MIN
Definition: numeric.c:49
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
value_type
Definition: float1.c:12