2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libffi / testsuite / libffi.call / promotion.c
blob75e842159397f6a796e4878e74004d533bda8e89
1 /* Area: ffi_call
2 Purpose: Promotion test.
3 Limitations: none.
4 PR: none.
5 Originator: From the original ffitest.c */
7 /* { dg-do run } */
8 #include "ffitest.h"
9 static int promotion(signed char sc, signed short ss,
10 unsigned char uc, unsigned short us)
12 int r = (int) sc + (int) ss + (int) uc + (int) us;
14 return r;
17 int main (void)
19 ffi_cif cif;
20 ffi_type *args[MAX_ARGS];
21 void *values[MAX_ARGS];
22 ffi_arg rint;
23 signed char sc;
24 unsigned char uc;
25 signed short ss;
26 unsigned short us;
27 unsigned long ul;
29 args[0] = &ffi_type_schar;
30 args[1] = &ffi_type_sshort;
31 args[2] = &ffi_type_uchar;
32 args[3] = &ffi_type_ushort;
33 values[0] = &sc;
34 values[1] = &ss;
35 values[2] = &uc;
36 values[3] = &us;
38 /* Initialize the cif */
39 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
40 &ffi_type_sint, args) == FFI_OK);
42 us = 0;
43 ul = 0;
45 for (sc = (signed char) -127;
46 sc <= (signed char) 120; /*@-type@*/ sc += 1 /*@=type@*/)
47 for (ss = -30000; ss <= 30000; ss += 10000)
48 for (uc = (unsigned char) 0;
49 uc <= (unsigned char) 200; /*@-type@*/ uc += 20 /*@=type@*/)
50 for (us = 0; us <= 60000; us += 10000)
52 ul++;
53 ffi_call(&cif, FFI_FN(promotion), &rint, values);
54 CHECK((int)rint == (signed char) sc + (signed short) ss +
55 (unsigned char) uc + (unsigned short) us);
57 printf("%lu promotion tests run\n", ul);
58 exit(0);