1457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique/* Area: closure_call 2457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique Purpose: Test anonymous unsigned long argument. 3457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique Limitations: none. 4457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique PR: none. 5457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique Originator: ARM Ltd. */ 6457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique 7457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique/* { dg-do run } */ 8457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique 9457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique#include "ffitest.h" 10457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique 11457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Piquetypedef unsigned long T; 12457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique 13457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Piquestatic void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, 14457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique void* userdata __UNUSED__) 15457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique { 16457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique *(T *)resp = *(T *)args[0]; 17457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique 18457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique printf("%ld: %ld %ld\n", *(T *)resp, *(T *)args[0], *(T *)args[1]); 19457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique } 20457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique 21457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Piquetypedef T (*cls_ret_T)(T, ...); 22457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique 23457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Piqueint main (void) 24457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique{ 25457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique ffi_cif cif; 26457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique void *code; 27457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 28457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique ffi_type * cl_arg_types[3]; 29457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique T res; 30457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique 31457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique cl_arg_types[0] = &ffi_type_ulong; 32457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique cl_arg_types[1] = &ffi_type_ulong; 33457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique cl_arg_types[2] = NULL; 34457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique 35457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique /* Initialize the cif */ 36457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, 37457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique &ffi_type_ulong, cl_arg_types) == FFI_OK); 38457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique 39457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK); 40457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique res = ((((cls_ret_T)code)(67, 4))); 41457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique /* { dg-output "67: 67 4" } */ 42457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique printf("res: %ld\n", res); 43457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique /* { dg-output "\nres: 67" } */ 44457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique exit(0); 45457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique} 46