2009-07-17 Richard Guenther <rguenther@suse.de>
[official-gcc.git] / libffi / testsuite / libffi.call / cls_pointer.c
blob34e4209640b8e121e8de5e8c26d4b99150162d72
1 /* Area: ffi_call, closure_call
2 Purpose: Check pointer arguments.
3 Limitations: none.
4 PR: none.
5 Originator: Blake Chaffin 6/6/2007 */
7 /* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
8 #include "ffitest.h"
10 void* cls_pointer_fn(void* a1, void* a2)
12 void* result = (void*)((intptr_t)a1 + (intptr_t)a2);
14 printf("0x%08x 0x%08x: 0x%08x\n",
15 (unsigned int)(uintptr_t) a1,
16 (unsigned int)(uintptr_t) a2,
17 (unsigned int)(uintptr_t) result);
19 return result;
22 static void
23 cls_pointer_gn(ffi_cif* cif __UNUSED__, void* resp,
24 void** args, void* userdata __UNUSED__)
26 void* a1 = *(void**)(args[0]);
27 void* a2 = *(void**)(args[1]);
29 *(void**)resp = cls_pointer_fn(a1, a2);
32 int main (void)
34 ffi_cif cif;
35 void *code;
36 ffi_closure* pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
37 void* args[3];
38 // ffi_type cls_pointer_type;
39 ffi_type* arg_types[3];
41 /* cls_pointer_type.size = sizeof(void*);
42 cls_pointer_type.alignment = 0;
43 cls_pointer_type.type = FFI_TYPE_POINTER;
44 cls_pointer_type.elements = NULL;*/
46 void* arg1 = (void*)0x12345678;
47 void* arg2 = (void*)0x89abcdef;
48 ffi_arg res = 0;
50 arg_types[0] = &ffi_type_pointer;
51 arg_types[1] = &ffi_type_pointer;
52 arg_types[2] = NULL;
54 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_pointer,
55 arg_types) == FFI_OK);
57 args[0] = &arg1;
58 args[1] = &arg2;
59 args[2] = NULL;
61 ffi_call(&cif, FFI_FN(cls_pointer_fn), &res, args);
62 /* { dg-output "0x12345678 0x89abcdef: 0x9be02467" } */
63 printf("res: 0x%08x\n", (unsigned int) res);
64 /* { dg-output "\nres: 0x9be02467" } */
66 CHECK(ffi_prep_closure_loc(pcl, &cif, cls_pointer_gn, NULL, code) == FFI_OK);
68 res = (ffi_arg)((void*(*)(void*, void*))(code))(arg1, arg2);
69 /* { dg-output "\n0x12345678 0x89abcdef: 0x9be02467" } */
70 printf("res: 0x%08x\n", (unsigned int) res);
71 /* { dg-output "\nres: 0x9be02467" } */
73 exit(0);