uninitialized.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* { dg-do run } */
  2. #include "ffitest.h"
  3. typedef struct
  4. {
  5. unsigned char uc;
  6. double d;
  7. unsigned int ui;
  8. } test_structure_1;
  9. static test_structure_1 struct1(test_structure_1 ts)
  10. {
  11. ts.uc++;
  12. ts.d--;
  13. ts.ui++;
  14. return ts;
  15. }
  16. int main (void)
  17. {
  18. ffi_cif cif;
  19. ffi_type *args[MAX_ARGS];
  20. void *values[MAX_ARGS];
  21. ffi_type ts1_type;
  22. ffi_type *ts1_type_elements[4];
  23. memset(&cif, 1, sizeof(cif));
  24. ts1_type.size = 0;
  25. ts1_type.alignment = 0;
  26. ts1_type.type = FFI_TYPE_STRUCT;
  27. ts1_type.elements = ts1_type_elements;
  28. ts1_type_elements[0] = &ffi_type_uchar;
  29. ts1_type_elements[1] = &ffi_type_double;
  30. ts1_type_elements[2] = &ffi_type_uint;
  31. ts1_type_elements[3] = NULL;
  32. test_structure_1 ts1_arg;
  33. /* This is a hack to get a properly aligned result buffer */
  34. test_structure_1 *ts1_result =
  35. (test_structure_1 *) malloc (sizeof(test_structure_1));
  36. args[0] = &ts1_type;
  37. values[0] = &ts1_arg;
  38. /* Initialize the cif */
  39. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
  40. &ts1_type, args) == FFI_OK);
  41. ts1_arg.uc = '\x01';
  42. ts1_arg.d = 3.14159;
  43. ts1_arg.ui = 555;
  44. ffi_call(&cif, FFI_FN(struct1), ts1_result, values);
  45. CHECK(ts1_result->ui == 556);
  46. CHECK(ts1_result->d == 3.14159 - 1);
  47. free (ts1_result);
  48. exit(0);
  49. }