c-language-features.inc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. //-*- C -*-
  2. /* This is a
  3. multiline comment */
  4. // Intended to exercise all syntactic parts of the C language.
  5. int g0;
  6. int g1, g2;
  7. struct s0;
  8. struct s0 {
  9. int x;
  10. };
  11. int g3 = 10;
  12. __asm("");
  13. typedef int td0;
  14. td0 g4;
  15. enum e0 {
  16. ec0
  17. };
  18. static void f0(int x) {
  19. }
  20. inline void f0_0(int x) {
  21. ;
  22. }
  23. extern void f0_1(int x) {
  24. }
  25. void f1(int, ...);
  26. // Statements.
  27. void f2() {
  28. for (;;) {
  29. break;
  30. continue;
  31. }
  32. while (0) {
  33. }
  34. do {
  35. } while (0);
  36. void *label = &&theif;
  37. goto *label;
  38. goto theif;
  39. theif:
  40. if (0) {
  41. ;
  42. } else if (0) {
  43. } else {
  44. }
  45. switch(0) {
  46. case 0:
  47. case 1 ... 2:
  48. break;
  49. default:
  50. break;
  51. }
  52. asm ("nop");
  53. int cond;
  54. asm goto("testl %0, %0; jne %l1;" :: "r"(cond)::label_true);
  55. label_true:
  56. return;
  57. }
  58. // Expressions.
  59. #include <stdarg.h>
  60. typedef struct ipair {
  61. int first, second;
  62. } ipair;
  63. void f4(int a0, int a1, int a2, va_list ap) {
  64. int t0 = a0 ? a1 : a2;
  65. float t1 = (float) a0;
  66. ipair t2 = {1, 2};
  67. ipair t2a = { .second = 2 };
  68. int t3 = sizeof(ipair);
  69. ipair t4;
  70. t4 = (ipair) {1, 2};
  71. extern int g(int);
  72. int t5 = g(a0);
  73. int t6 = t4.first;
  74. int t7[10];
  75. int t8 = t7[a0];
  76. t8++;
  77. const char *t9 = __FUNCTION__;
  78. char t10 = 'x';
  79. int t11 = __builtin_offsetof(ipair, first);
  80. int t12 = __builtin_types_compatible_p(ipair, int);
  81. int t12_0 = __builtin_classify_type(t0);
  82. int t12_1 = __builtin_classify_type(t1);
  83. int t12_2 = __builtin_classify_type(t2);
  84. // FIXME: Add _Complex and aggregate cases.
  85. int t13 = va_arg(ap, int);
  86. va_list t13_0;
  87. va_copy(t13_0, ap);
  88. int t14 = __extension__(t13);
  89. int t15 = +t13;
  90. unsigned t16 = t14 ^ t15;
  91. int t17 = t14 % t15;
  92. int t17_0 = t16 % t16;
  93. float t18;
  94. int t19 = t18 ? 0 : 1;
  95. char *t20; ++t20; --t20;
  96. float t21; ++t21; --t21;
  97. double t22; ++t22; --t22;
  98. long double t23; ++t23; --t23;
  99. int t24 = !t19;
  100. int t25 = __real t24;
  101. int t26 = __imag t24;
  102. const char *t27 = t9;
  103. t27 += (unsigned char) 0xFF;
  104. t27 += (signed char) 0xFF;
  105. struct { char f0[10]; } *t28;
  106. int t29 = t28 - t28;
  107. char *t30 = &t28->f0[1];
  108. struct s1 { int f0; };
  109. struct s1 t31_a, t31_b;
  110. int t31_cond;
  111. int t31 = (t31_cond ? t31_a : t31_b).f0;
  112. _Complex float t32_a, t32_b;
  113. int t32_cond;
  114. int t32 = __real (t32_cond ? t32_a : t32_b);
  115. struct { int x, y; } t33, *t34, t35[12], t36(int, float);
  116. float t37, *t38, t39[9], t40(double);
  117. }
  118. // Extended vectors
  119. typedef __attribute__((ext_vector_type(2))) float float2;
  120. typedef __attribute__((ext_vector_type(4))) float float4;
  121. void f5() {
  122. float4 t0 = (float4) { 0, 1, 2, 3 };
  123. float4 t1 = t0;
  124. t0.lo.even = t1.hi.x;
  125. // irgen doesn't support this yet.
  126. #if 0
  127. int t2_cond;
  128. float2 t2 = (t2_cond ? t0 : t1).lo;
  129. #endif
  130. }
  131. void f6() {
  132. const char *s0 = __func__;
  133. const char *s1 = __FUNCTION__;
  134. const char *s2 = __PRETTY_FUNCTION__;
  135. }
  136. // Arg mismatch with passed type.
  137. void f7(x)
  138. float x;
  139. {
  140. }
  141. void f8(x)
  142. short x;
  143. {
  144. }
  145. // Function which inputs an array
  146. void f9(int x[]) { }
  147. // Object literals.
  148. void f10() {
  149. struct f10_s0 {
  150. char iv0[10];
  151. } x;
  152. x = (struct f10_s0) { .iv0 = "name" };
  153. }
  154. // Nested structures.
  155. struct s11 {
  156. struct s11_2 {
  157. int f0;
  158. } f0;
  159. int f1;
  160. };
  161. // Unnamed structures.
  162. struct s12 {
  163. struct {
  164. unsigned char aa;
  165. unsigned char bb;
  166. };
  167. };
  168. void f11() {
  169. struct s12 var = { .aa = 33 };
  170. }