/gcc/testsuite/gcc.target/i386/iamcu/test_passing_structs.c

https://gitlab.com/4144/gcc · C · 237 lines · 197 code · 34 blank · 6 comment · 6 complexity · 0f9d4306224efa0b6b037bcc686e3c22 MD5 · raw file

  1. /* This tests passing of structs. */
  2. #include "defines.h"
  3. #include "args.h"
  4. #include <complex.h>
  5. struct IntegerRegisters iregbits = { ~0, ~0, ~0, ~0, ~0, ~0 };
  6. struct IntegerRegisters iregs;
  7. unsigned int num_iregs;
  8. struct int_struct
  9. {
  10. int i;
  11. };
  12. struct long_struct
  13. {
  14. long l;
  15. };
  16. struct longlong2_struct
  17. {
  18. long long ll1, ll2;
  19. };
  20. struct longlong3_struct
  21. {
  22. long long ll1, ll2, ll3;
  23. };
  24. /* Check that the struct is passed as the individual members in iregs. */
  25. void
  26. check_struct_passing1 (struct int_struct is ATTRIBUTE_UNUSED)
  27. {
  28. check_int_arguments;
  29. }
  30. void
  31. check_struct_passing2 (struct long_struct ls ATTRIBUTE_UNUSED)
  32. {
  33. check_int_arguments;
  34. }
  35. void
  36. check_struct_passing3 (struct longlong2_struct ls ATTRIBUTE_UNUSED)
  37. {
  38. check_int_arguments;
  39. }
  40. void
  41. check_struct_passing4 (struct longlong3_struct ls ATTRIBUTE_UNUSED)
  42. {
  43. /* Check the passing on the stack by comparing the address of the
  44. stack elements to the expected place on the stack. */
  45. assert ((unsigned long)&ls.ll1 == esp+4);
  46. assert ((unsigned long)&ls.ll2 == esp+12);
  47. assert ((unsigned long)&ls.ll3 == esp+20);
  48. }
  49. struct flex1_struct
  50. {
  51. long i;
  52. long flex[];
  53. };
  54. struct flex2_struct
  55. {
  56. long i;
  57. long flex[0];
  58. };
  59. void
  60. check_struct_passing7 (struct flex1_struct is ATTRIBUTE_UNUSED)
  61. {
  62. check_int_arguments;
  63. }
  64. void
  65. check_struct_passing8 (struct flex2_struct is ATTRIBUTE_UNUSED)
  66. {
  67. check_int_arguments;
  68. }
  69. struct complex1_struct
  70. {
  71. __complex__ float x;
  72. };
  73. struct complex1a_struct
  74. {
  75. long l;
  76. union
  77. {
  78. float f;
  79. int i;
  80. } u;
  81. };
  82. void
  83. check_struct_passing9 (struct complex1_struct is ATTRIBUTE_UNUSED)
  84. {
  85. check_int_arguments;
  86. }
  87. struct long3_struct
  88. {
  89. long l1, l2, l3;
  90. };
  91. void
  92. check_struct_passing10 (struct long3_struct ls ATTRIBUTE_UNUSED)
  93. {
  94. /* Check the passing on the stack by comparing the address of the
  95. stack elements to the expected place on the stack. */
  96. assert ((unsigned long)&ls.l1 == esp+4);
  97. assert ((unsigned long)&ls.l2 == esp+8);
  98. assert ((unsigned long)&ls.l3 == esp+12);
  99. }
  100. struct char3_struct
  101. {
  102. char c1, c2, c3;
  103. };
  104. void
  105. check_struct_passing11 (struct char3_struct is ATTRIBUTE_UNUSED)
  106. {
  107. check_int_arguments;
  108. }
  109. struct char7_struct
  110. {
  111. char c1, c2, c3, c4, c5, c6, c7;
  112. };
  113. void
  114. check_struct_passing12 (struct char7_struct is ATTRIBUTE_UNUSED)
  115. {
  116. check_int_arguments;
  117. }
  118. static struct flex1_struct f1s = { 60, { } };
  119. static struct flex2_struct f2s = { 61, { } };
  120. int
  121. main (void)
  122. {
  123. struct int_struct is = { 48 };
  124. struct long_struct ls = { 49 };
  125. #ifdef CHECK_LARGER_STRUCTS
  126. struct longlong2_struct ll2s = { 50, 51 };
  127. struct longlong3_struct ll3s = { 52, 53, 54 };
  128. struct long3_struct l3s = { 60, 61, 62 };
  129. #endif
  130. struct complex1_struct c1s = { ( -13.4 + 3.5*I ) };
  131. union
  132. {
  133. struct complex1_struct c;
  134. struct complex1a_struct u;
  135. } c1u;
  136. struct char3_struct c3 = { 0x12, 0x34, 0x56 };
  137. union
  138. {
  139. struct char3_struct c;
  140. int i;
  141. } c3u;
  142. struct char7_struct c7 = { 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56 };
  143. union
  144. {
  145. struct char7_struct c;
  146. struct
  147. {
  148. int i0, i1;
  149. } i;
  150. } c7u;
  151. clear_struct_registers;
  152. iregs.I0 = is.i;
  153. num_iregs = 1;
  154. clear_int_hardware_registers;
  155. WRAP_CALL (check_struct_passing1)(is);
  156. clear_struct_registers;
  157. iregs.I0 = ls.l;
  158. num_iregs = 1;
  159. clear_int_hardware_registers;
  160. WRAP_CALL (check_struct_passing2)(ls);
  161. #ifdef CHECK_LARGER_STRUCTS
  162. clear_struct_registers;
  163. num_iregs = 0;
  164. clear_int_hardware_registers;
  165. WRAP_CALL (check_struct_passing3)(ll2s);
  166. WRAP_CALL (check_struct_passing4)(ll3s);
  167. WRAP_CALL (check_struct_passing10)(l3s);
  168. #endif
  169. clear_struct_registers;
  170. iregs.I0 = f1s.i;
  171. num_iregs = 1;
  172. clear_int_hardware_registers;
  173. WRAP_CALL (check_struct_passing7)(f1s);
  174. clear_struct_registers;
  175. iregs.I0 = f2s.i;
  176. num_iregs = 1;
  177. clear_int_hardware_registers;
  178. WRAP_CALL (check_struct_passing8)(f2s);
  179. clear_struct_registers;
  180. c1u.c = c1s;
  181. iregs.I0 = c1u.u.l;
  182. iregs.I1 = c1u.u.u.i;
  183. num_iregs = 2;
  184. clear_int_hardware_registers;
  185. WRAP_CALL (check_struct_passing9)(c1s);
  186. clear_struct_registers;
  187. c3u.c = c3;
  188. iregs.I0 = c3u.i;
  189. iregbits.I0 = 0xffffff;
  190. num_iregs = 1;
  191. clear_int_hardware_registers;
  192. WRAP_CALL (check_struct_passing11)(c3);
  193. clear_struct_registers;
  194. c7u.c = c7;
  195. iregs.I0 = c7u.i.i0;
  196. iregs.I1 = c7u.i.i1;
  197. iregbits.I0 = 0xffffffff;
  198. iregbits.I1 = 0xffffff;
  199. num_iregs = 2;
  200. clear_int_hardware_registers;
  201. WRAP_CALL (check_struct_passing12)(c7);
  202. return 0;
  203. }