Home | History | Annotate | Download | only in libffi.call
      1 /* Area:	ffi_call
      2    Purpose:	Promotion test.
      3    Limitations:	none.
      4    PR:		none.
      5    Originator:	From the original ffitest.c  */
      6 
      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)
     11 {
     12   int r = (int) sc + (int) ss + (int) uc + (int) us;
     13 
     14   return r;
     15 }
     16 
     17 int main (void)
     18 {
     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;
     28 
     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] = ≻
     34   values[1] = &ss;
     35   values[2] = &uc;
     36   values[3] = &us;
     37 
     38   /* Initialize the cif */
     39   CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
     40 		     &ffi_type_sint, args) == FFI_OK);
     41 
     42   us = 0;
     43   ul = 0;
     44 
     45   for (sc = (signed char) -127;
     46        sc <= (signed char) 120; sc += 1)
     47     for (ss = -30000; ss <= 30000; ss += 10000)
     48       for (uc = (unsigned char) 0;
     49 	   uc <= (unsigned char) 200; uc += 20)
     50 	for (us = 0; us <= 60000; us += 10000)
     51 	  {
     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);
     56 	  }
     57   printf("%lu promotion tests run\n", ul);
     58   exit(0);
     59 }
     60