/regress/usr.bin/xlint/test-25.c

https://github.com/avsm/src · C · 266 lines · 209 code · 43 blank · 14 comment · 28 complexity · f4d4209914341531e73ce0dadc91afb3 MD5 · raw file

  1. /* $OpenBSD: test-25.c,v 1.1 2010/07/25 23:00:05 guenther Exp $ */
  2. /*
  3. * Placed in the public domain by Philip Guenther <guenther@openbsd.org>.
  4. *
  5. * Test _Complex handling, based on test-19.c
  6. */
  7. #include <limits.h>
  8. #include <complex.h>
  9. int
  10. f(void)
  11. {
  12. float f1;
  13. double d1;
  14. long double l1;
  15. float _Complex fc1;
  16. _Complex float fc2;
  17. double _Complex dc1;
  18. _Complex double dc2;
  19. long double _Complex lc1;
  20. double long _Complex lc2;
  21. double _Complex long lc3;
  22. long _Complex double lc4;
  23. _Complex long double lc5;
  24. _Complex double long lc6;
  25. /* test type compatibility by mixing pointers */
  26. if (&fc1 == &fc2)
  27. return 0;
  28. if (&dc1 == &dc2)
  29. return 0;
  30. if (&fc1 == &dc1 || &dc1 == &lc1 || &lc1 == &fc1)
  31. return 1;
  32. if (&__real__ fc1 == &f1 || &__imag__ fc1 == &f1 ||
  33. &__real__ dc1 == &d1 || &__imag__ dc1 == &d1 ||
  34. &__real__ lc1 == &l1 || &__imag__ lc1 == &l1)
  35. return 1;
  36. return (&lc1 != &lc2 && &lc1 != &lc3 && &lc1 != &lc4 &&
  37. &lc1 != &lc5 && &lc1 != &lc6);
  38. }
  39. void b1 (_Bool b){ b++; }
  40. void c1 (signed char c){ c++; }
  41. void uc1 (unsigned char uc) { uc++; }
  42. void s1 (short s) { s++; }
  43. void us1 (unsigned short us) { us++; }
  44. void i1 (int i) { i++; }
  45. void ui1 (unsigned int ui) { ui++; }
  46. void f1 (float f) { f++; }
  47. void l1 (long l) { l++; }
  48. void ul1 (unsigned long ul) { ul++; }
  49. void d1 (double d) { d++; }
  50. void ll1 (long long ll) { ll++; }
  51. void ull1 (unsigned long long ull) { ull++; }
  52. void ld1 (long double ld) { ld++; }
  53. void fc1 (float _Complex f) { f++; }
  54. void dc1 (double _Complex d) { d++; }
  55. void ldc1 (long double _Complex ld) { ld++; }
  56. /* ARGSUSED */
  57. int
  58. main(int argc, char* argv[])
  59. {
  60. _Bool B = 1;
  61. signed char C = 1;
  62. unsigned char UC = 1;
  63. short S = 1;
  64. unsigned short US = 1;
  65. int II = 1;
  66. unsigned int UI = 1;
  67. long L = 1;
  68. unsigned long UL = 1;
  69. long long LL = 1;
  70. unsigned long long ULL = 1;
  71. float F = 1.0f;
  72. double D = 1.0;
  73. long double LD = 1.0L;
  74. float _Complex FC = 1.0f + I;
  75. double _Complex DC = 1.0 + I;
  76. long double _Complex LDC = 1.0L + I;
  77. f();
  78. /* test with variables */
  79. b1(FC);
  80. b1(DC);
  81. b1(LDC);
  82. c1(FC);
  83. c1(DC);
  84. c1(LDC);
  85. uc1(FC);
  86. uc1(DC);
  87. uc1(LDC);
  88. s1(FC);
  89. s1(DC);
  90. s1(LDC);
  91. us1(FC);
  92. us1(DC);
  93. us1(LDC);
  94. i1(FC);
  95. i1(DC);
  96. i1(LDC);
  97. ui1(FC);
  98. ui1(DC);
  99. ui1(LDC);
  100. f1(FC);
  101. f1(DC);
  102. f1(LDC);
  103. l1(FC);
  104. l1(DC);
  105. l1(LDC);
  106. ul1(FC);
  107. ul1(DC);
  108. ul1(LDC);
  109. d1(FC);
  110. d1(DC);
  111. d1(LDC);
  112. ll1(FC);
  113. ll1(DC);
  114. ll1(LDC);
  115. ull1(FC);
  116. ull1(DC);
  117. ull1(LDC);
  118. ld1(FC);
  119. ld1(DC);
  120. ld1(LDC);
  121. fc1(B);
  122. fc1(C);
  123. fc1(UC);
  124. fc1(S);
  125. fc1(US);
  126. fc1(II);
  127. fc1(UI);
  128. fc1(L);
  129. fc1(UL);
  130. fc1(LL);
  131. fc1(ULL);
  132. fc1(F);
  133. fc1(D);
  134. fc1(LD);
  135. fc1(FC);
  136. fc1(DC);
  137. fc1(LDC);
  138. dc1(B);
  139. dc1(C);
  140. dc1(UC);
  141. dc1(S);
  142. dc1(US);
  143. dc1(II);
  144. dc1(UI);
  145. dc1(L);
  146. dc1(UL);
  147. dc1(LL);
  148. dc1(ULL);
  149. dc1(F);
  150. dc1(D);
  151. dc1(LD);
  152. dc1(FC);
  153. dc1(DC);
  154. dc1(LDC);
  155. ldc1(B);
  156. ldc1(C);
  157. ldc1(UC);
  158. ldc1(S);
  159. ldc1(US);
  160. ldc1(II);
  161. ldc1(UI);
  162. ldc1(L);
  163. ldc1(UL);
  164. ldc1(LL);
  165. ldc1(ULL);
  166. ldc1(F);
  167. ldc1(D);
  168. ldc1(LD);
  169. ldc1(FC);
  170. ldc1(DC);
  171. ldc1(LDC);
  172. /* now test with int constants */
  173. fc1(-1);
  174. fc1(0);
  175. fc1(1);
  176. dc1(-1);
  177. dc1(0);
  178. dc1(1);
  179. ldc1(-1);
  180. ldc1(0);
  181. ldc1(1);
  182. /* now test with long constants */
  183. fc1(-1L);
  184. fc1(0L);
  185. fc1(1L);
  186. dc1(-1L);
  187. dc1(0L);
  188. dc1(1L);
  189. ldc1(-1L);
  190. ldc1(0L);
  191. ldc1(1L);
  192. /* now test with float constants */
  193. fc1(-1.0f);
  194. fc1(0.0f);
  195. fc1(1.0f);
  196. dc1(-1.0f);
  197. dc1(0.0f);
  198. dc1(1.0f);
  199. ldc1(-1.0f);
  200. ldc1(0.0f);
  201. ldc1(1.0f);
  202. /* now test with double constants */
  203. fc1(-1.0);
  204. fc1(0.0);
  205. fc1(1.0);
  206. dc1(-1.0);
  207. dc1(0.0);
  208. dc1(1.0);
  209. ldc1(-1.0);
  210. ldc1(0.0);
  211. ldc1(1.0);
  212. /* now test with long double constants */
  213. fc1(-1.0L);
  214. fc1(0.0L);
  215. fc1(1.0L);
  216. dc1(-1.0L);
  217. dc1(0.0L);
  218. dc1(1.0L);
  219. ldc1(-1.0L);
  220. ldc1(0.0L);
  221. ldc1(1.0L);
  222. return 0;
  223. }