OSDN Git Service

Initial Contribution
[android-x86/external-libffi.git] / testsuite / libffi.call / return_fl2.c
1 /* Area:        ffi_call
2    Purpose:     Check return value float.
3    Limitations: none.
4    PR:          none.
5    Originator:  <andreast@gcc.gnu.org> 20050212  */
6
7 /* { dg-do run } */
8 #include "ffitest.h"
9
10 /* To avoid a false negative on ix86 do not declare the return_fl static.
11    See PR323.
12 */
13 float return_fl(float fl1, float fl2, float fl3, float fl4)
14 {
15   return fl1 + fl2 + fl3 + fl4;
16 }
17 int main (void)
18 {
19   ffi_cif cif;
20   ffi_type *args[MAX_ARGS];
21   void *values[MAX_ARGS];
22   float fl1, fl2, fl3, fl4, rfl;
23
24   args[0] = &ffi_type_float;
25   args[1] = &ffi_type_float;
26   args[2] = &ffi_type_float;
27   args[3] = &ffi_type_float;
28   values[0] = &fl1;
29   values[1] = &fl2;
30   values[2] = &fl3;
31   values[3] = &fl4;
32
33   /* Initialize the cif */
34   CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
35                      &ffi_type_float, args) == FFI_OK);
36   fl1 = 127.0;
37   fl2 = 128.0;
38   fl3 = 255.1;
39   fl4 = 512.7;
40
41   ffi_call(&cif, FFI_FN(return_fl), &rfl, values);
42   printf ("%f vs %f\n", rfl, return_fl(fl1, fl2, fl3, fl4));
43   CHECK(rfl ==  fl1 + fl2 + fl3 + fl4);
44   exit(0);
45 }