cls_struct_va1.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* Area: ffi_call, closure_call
  2. Purpose: Test doubles passed in variable argument lists.
  3. Limitations: none.
  4. PR: none.
  5. Originator: Blake Chaffin 6/6/2007 */
  6. /* { dg-do run } */
  7. /* { dg-output "" { xfail avr32*-*-* } } */
  8. #include "ffitest.h"
  9. struct small_tag
  10. {
  11. unsigned char a;
  12. unsigned char b;
  13. };
  14. struct large_tag
  15. {
  16. unsigned a;
  17. unsigned b;
  18. unsigned c;
  19. unsigned d;
  20. unsigned e;
  21. };
  22. static void
  23. test_fn (ffi_cif* cif __UNUSED__, void* resp,
  24. void** args, void* userdata __UNUSED__)
  25. {
  26. int n = *(int*)args[0];
  27. struct small_tag s1 = * (struct small_tag *) args[1];
  28. struct large_tag l1 = * (struct large_tag *) args[2];
  29. struct small_tag s2 = * (struct small_tag *) args[3];
  30. printf ("%d %d %d %d %d %d %d %d %d %d\n", n, s1.a, s1.b,
  31. l1.a, l1.b, l1.c, l1.d, l1.e,
  32. s2.a, s2.b);
  33. * (ffi_arg*) resp = 42;
  34. }
  35. int
  36. main (void)
  37. {
  38. ffi_cif cif;
  39. void *code;
  40. ffi_closure *pcl = ffi_closure_alloc (sizeof (ffi_closure), &code);
  41. ffi_type* arg_types[5];
  42. ffi_arg res = 0;
  43. ffi_type s_type;
  44. ffi_type *s_type_elements[3];
  45. ffi_type l_type;
  46. ffi_type *l_type_elements[6];
  47. struct small_tag s1;
  48. struct small_tag s2;
  49. struct large_tag l1;
  50. int si;
  51. s_type.size = 0;
  52. s_type.alignment = 0;
  53. s_type.type = FFI_TYPE_STRUCT;
  54. s_type.elements = s_type_elements;
  55. s_type_elements[0] = &ffi_type_uchar;
  56. s_type_elements[1] = &ffi_type_uchar;
  57. s_type_elements[2] = NULL;
  58. l_type.size = 0;
  59. l_type.alignment = 0;
  60. l_type.type = FFI_TYPE_STRUCT;
  61. l_type.elements = l_type_elements;
  62. l_type_elements[0] = &ffi_type_uint;
  63. l_type_elements[1] = &ffi_type_uint;
  64. l_type_elements[2] = &ffi_type_uint;
  65. l_type_elements[3] = &ffi_type_uint;
  66. l_type_elements[4] = &ffi_type_uint;
  67. l_type_elements[5] = NULL;
  68. arg_types[0] = &ffi_type_sint;
  69. arg_types[1] = &s_type;
  70. arg_types[2] = &l_type;
  71. arg_types[3] = &s_type;
  72. arg_types[4] = NULL;
  73. CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 4, &ffi_type_sint,
  74. arg_types) == FFI_OK);
  75. si = 4;
  76. s1.a = 5;
  77. s1.b = 6;
  78. s2.a = 20;
  79. s2.b = 21;
  80. l1.a = 10;
  81. l1.b = 11;
  82. l1.c = 12;
  83. l1.d = 13;
  84. l1.e = 14;
  85. CHECK(ffi_prep_closure_loc(pcl, &cif, test_fn, NULL, code) == FFI_OK);
  86. res = ((int (*)(int, ...))(code))(si, s1, l1, s2);
  87. /* { dg-output "4 5 6 10 11 12 13 14 20 21" } */
  88. printf("res: %d\n", (int) res);
  89. /* { dg-output "\nres: 42" } */
  90. exit(0);
  91. }