1457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique/* Area:	ffi_call
2457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique   Purpose:	Promotion test.
3457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique   Limitations:	none.
4457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique   PR:		none.
5457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique   Originator:	From the original ffitest.c  */
6457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique
7457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique/* { dg-do run } */
8457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique#include "ffitest.h"
9457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Piquestatic int promotion(signed char sc, signed short ss,
10457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique		     unsigned char uc, unsigned short us)
11457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique{
12457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  int r = (int) sc + (int) ss + (int) uc + (int) us;
13457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique
14457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  return r;
15457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique}
16457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique
17457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Piqueint main (void)
18457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique{
19457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  ffi_cif cif;
20457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  ffi_type *args[MAX_ARGS];
21457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  void *values[MAX_ARGS];
22457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  ffi_arg rint;
23457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  signed char sc;
24457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  unsigned char uc;
25457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  signed short ss;
26457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  unsigned short us;
27457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  unsigned long ul;
28457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique
29457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  args[0] = &ffi_type_schar;
30457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  args[1] = &ffi_type_sshort;
31457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  args[2] = &ffi_type_uchar;
32457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  args[3] = &ffi_type_ushort;
33457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  values[0] = ≻
34457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  values[1] = &ss;
35457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  values[2] = &uc;
36457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  values[3] = &us;
37457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique
38457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  /* Initialize the cif */
39457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
40457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique		     &ffi_type_sint, args) == FFI_OK);
41457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique
42457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  us = 0;
43457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  ul = 0;
44457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique
45457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  for (sc = (signed char) -127;
46457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique       sc <= (signed char) 120; sc += 1)
47457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique    for (ss = -30000; ss <= 30000; ss += 10000)
48457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique      for (uc = (unsigned char) 0;
49457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique	   uc <= (unsigned char) 200; uc += 20)
50457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique	for (us = 0; us <= 60000; us += 10000)
51457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique	  {
52457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique	    ul++;
53457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique	    ffi_call(&cif, FFI_FN(promotion), &rint, values);
54457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique	    CHECK((int)rint == (signed char) sc + (signed short) ss +
55457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique		  (unsigned char) uc + (unsigned short) us);
56457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique	  }
57457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  printf("%lu promotion tests run\n", ul);
58457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  exit(0);
59457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique}
60