/gcc/testsuite/gfortran.dg/PR100914.c

https://gitlab.com/adotout/gcc · C · 225 lines · 187 code · 33 blank · 5 comment · 19 complexity · dec037af65c7ffffad780f0faaa0445b MD5 · raw file

  1. /* Test the fix for PR100914 */
  2. #include <assert.h>
  3. #include <complex.h>
  4. #include <stdbool.h>
  5. #include <stdio.h>
  6. #include <math.h>
  7. #include <ISO_Fortran_binding.h>
  8. #define _CFI_type_mask 0xFF
  9. #define _CFI_type_kind_shift 8
  10. #define _CFI_decode_type(NAME) (signed char)((NAME) & CFI_type_mask)
  11. #define _CFI_decode_kind(NAME) (signed char)(((NAME) >> CFI_type_kind_shift) & CFI_type_mask)
  12. #define _CFI_encode_type(TYPE, KIND) (int16_t)\
  13. ((((KIND) & CFI_type_mask) << CFI_type_kind_shift)\
  14. | ((TYPE) & CFI_type_mask))
  15. #undef CMPLXF
  16. #define CMPLXF(x, y) ((float complex)((float)(x) + I * (float)(y)))
  17. #undef CMPLX
  18. #define CMPLX(x, y) ((double complex)((double)(x) + (double complex)I * (double)(y)))
  19. #undef CMPLXL
  20. #define CMPLXL(x, y) ((long double complex)((long double)(x) + (long double complex)I * (long double)(y)))
  21. #undef CMPLX
  22. #define CMPLX(x, y) ((_Float128 _Complex )((double)(x) + (double complex)I * (double)(y)))
  23. #define N 11
  24. #define M 7
  25. typedef float _Complex c_float_complex;
  26. typedef double _Complex c_double_complex;
  27. typedef long double _Complex c_long_double_complex;
  28. typedef _Float128 _Complex c_float128_complex;
  29. bool c_vrfy_c_float_complex (const CFI_cdesc_t *restrict);
  30. bool c_vrfy_c_double_complex (const CFI_cdesc_t *restrict);
  31. bool c_vrfy_c_long_double_complex (const CFI_cdesc_t *restrict);
  32. bool c_vrfy_c_float128_complex (const CFI_cdesc_t *restrict);
  33. bool c_vrfy_complex (const CFI_cdesc_t *restrict);
  34. bool c_vrfy_desc (const CFI_cdesc_t*restrict, const CFI_type_t, const signed char, const size_t, const size_t);
  35. void check_tk (const CFI_cdesc_t*restrict, const CFI_type_t, const signed char, const size_t, const size_t);
  36. bool
  37. c_vrfy_c_float_complex (const CFI_cdesc_t *restrict auxp)
  38. {
  39. CFI_index_t i, lb, ub, ex;
  40. size_t sz;
  41. c_float_complex *ip = NULL;
  42. assert (auxp);
  43. assert (auxp->base_addr);
  44. assert (auxp->elem_len>0);
  45. lb = auxp->dim[0].lower_bound;
  46. ex = auxp->dim[0].extent;
  47. assert (ex==11);
  48. sz = (size_t)auxp->elem_len / sizeof (c_float_complex);
  49. assert (sz==1);
  50. ub = ex + lb - 1;
  51. ip = (c_float_complex*)auxp->base_addr;
  52. for (i=0; i<ex; i++, ip+=sz)
  53. if ((cabsf (*ip-(c_float_complex)(CMPLXF((i+1), (2*(i+1)))))>(float)0.0))
  54. return false;
  55. for (i=lb; i<ub+1; i++)
  56. {
  57. ip = (c_float_complex*)CFI_address(auxp, &i);
  58. if ((cabsf (*ip-(c_float_complex)(CMPLXF((i-lb+1), (2*(i-lb+1)))))>(float)0.0))
  59. return false;
  60. }
  61. return true;
  62. }
  63. bool
  64. c_vrfy_c_double_complex (const CFI_cdesc_t *restrict auxp)
  65. {
  66. CFI_index_t i, lb, ub, ex;
  67. size_t sz;
  68. c_double_complex *ip = NULL;
  69. assert (auxp);
  70. assert (auxp->base_addr);
  71. assert (auxp->elem_len>0);
  72. lb = auxp->dim[0].lower_bound;
  73. ex = auxp->dim[0].extent;
  74. assert (ex==11);
  75. sz = (size_t)auxp->elem_len / sizeof (c_double_complex);
  76. assert (sz==1);
  77. ub = ex + lb - 1;
  78. ip = (c_double_complex*)auxp->base_addr;
  79. for (i=0; i<ex; i++, ip+=sz)
  80. if ((cabs (*ip-(c_double_complex)(CMPLX((i+1), (2*(i+1)))))>(double)0.0))
  81. return false;
  82. for (i=lb; i<ub+1; i++)
  83. {
  84. ip = (c_double_complex*)CFI_address(auxp, &i);
  85. if ((cabs (*ip-(c_double_complex)(CMPLX((i-lb+1), (2*(i-lb+1)))))>(double)0.0))
  86. return false;
  87. }
  88. return true;
  89. }
  90. bool
  91. c_vrfy_c_long_double_complex (const CFI_cdesc_t *restrict auxp)
  92. {
  93. CFI_index_t i, lb, ub, ex;
  94. size_t sz;
  95. c_long_double_complex *ip = NULL;
  96. assert (auxp);
  97. assert (auxp->base_addr);
  98. assert (auxp->elem_len>0);
  99. lb = auxp->dim[0].lower_bound;
  100. ex = auxp->dim[0].extent;
  101. assert (ex==11);
  102. sz = (size_t)auxp->elem_len / sizeof (c_long_double_complex);
  103. assert (sz==1);
  104. ub = ex + lb - 1;
  105. ip = (c_long_double_complex*)auxp->base_addr;
  106. for (i=0; i<ex; i++, ip+=sz)
  107. if ((cabsl (*ip-(c_long_double_complex)(CMPLXL((i+1), (2*(i+1)))))>(long double)0.0))
  108. return false;
  109. for (i=lb; i<ub+1; i++)
  110. {
  111. ip = (c_long_double_complex*)CFI_address(auxp, &i);
  112. if ((cabsl (*ip-(c_long_double_complex)(CMPLXL((i-lb+1), (2*(i-lb+1)))))>(long double)0.0))
  113. return false;
  114. }
  115. return true;
  116. }
  117. bool
  118. c_vrfy_c_float128_complex (const CFI_cdesc_t *restrict auxp)
  119. {
  120. CFI_index_t i, lb, ub, ex;
  121. size_t sz;
  122. c_float128_complex *ip = NULL;
  123. assert (auxp);
  124. assert (auxp->base_addr);
  125. assert (auxp->elem_len>0);
  126. lb = auxp->dim[0].lower_bound;
  127. ex = auxp->dim[0].extent;
  128. assert (ex==11);
  129. sz = (size_t)auxp->elem_len / sizeof (c_float128_complex);
  130. assert (sz==1);
  131. ub = ex + lb - 1;
  132. ip = (c_float128_complex*)auxp->base_addr;
  133. for (i=0; i<ex; i++, ip+=sz)
  134. if ((cabs ((double complex)(*ip-(c_float128_complex)(CMPLX((i+1), (2*(i+1))))))>(double)0.0))
  135. return false;
  136. for (i=lb; i<ub+1; i++)
  137. {
  138. ip = (c_float128_complex*)CFI_address(auxp, &i);
  139. if ((cabs ((double complex)(*ip-(c_float128_complex)(CMPLX((i-lb+1), (2*(i-lb+1))))))>(double)0.0))
  140. return false;
  141. }
  142. return true;
  143. }
  144. bool
  145. c_vrfy_complex (const CFI_cdesc_t *restrict auxp)
  146. {
  147. signed char type, kind;
  148. assert (auxp);
  149. type = _CFI_decode_type(auxp->type);
  150. kind = _CFI_decode_kind(auxp->type);
  151. assert (type == CFI_type_Complex);
  152. switch (kind)
  153. {
  154. case 4:
  155. return c_vrfy_c_float_complex (auxp);
  156. break;
  157. case 8:
  158. return c_vrfy_c_double_complex (auxp);
  159. break;
  160. case 10:
  161. return c_vrfy_c_long_double_complex (auxp);
  162. break;
  163. case 16:
  164. return c_vrfy_c_float128_complex (auxp);
  165. break;
  166. default:
  167. assert (false);
  168. }
  169. return true;
  170. }
  171. void
  172. check_tk (const CFI_cdesc_t *restrict auxp, const CFI_type_t type, const signed char kind, const size_t elem_len, const size_t nelem)
  173. {
  174. signed char ityp, iknd;
  175. assert (auxp);
  176. assert (auxp->elem_len==elem_len*nelem);
  177. assert (auxp->rank==1);
  178. assert (auxp->dim[0].sm>0);
  179. assert ((size_t)auxp->dim[0].sm==elem_len*nelem);
  180. /* */
  181. assert (auxp->type==type);
  182. ityp = _CFI_decode_type(auxp->type);
  183. assert (ityp == CFI_type_Complex);
  184. iknd = _CFI_decode_kind(auxp->type);
  185. assert (_CFI_decode_type(type)==ityp);
  186. assert (kind==iknd);
  187. assert (c_vrfy_complex (auxp));
  188. return;
  189. }
  190. // Local Variables:
  191. // mode: C
  192. // End: