1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 
3 // Math stuff
4 
5 double       g0  = __builtin_huge_val();
6 float        g1  = __builtin_huge_valf();
7 long double  g2  = __builtin_huge_vall();
8 #if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)
9 __float128   g2_2 = __builtin_huge_valf128();
10 #endif
11 
12 double       g3  = __builtin_inf();
13 float        g4  = __builtin_inff();
14 long double  g5  = __builtin_infl();
15 #if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)
16 __float128   g5_2 = __builtin_inff128();
17 #endif
18 
19 double       g6  = __builtin_nan("");
20 float        g7  = __builtin_nanf("");
21 long double  g8  = __builtin_nanl("");
22 #if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)
23 __float128   g8_2 = __builtin_nanf128("");
24 #endif
25 
26 // GCC constant folds these too (via native strtol):
27 //double       g6_1  = __builtin_nan("1");
28 //float        g7_1  = __builtin_nanf("1");
29 //long double  g8_1  = __builtin_nanl("1");
30 
31 double       g9  = __builtin_nans("");
32 float        g10 = __builtin_nansf("");
33 long double  g11 = __builtin_nansl("");
34 #if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)
35 __float128   g11_2 = __builtin_nansf128("");
36 #endif
37 
38 //int          g12 = __builtin_abs(-12);
39 
40 double       g13 = __builtin_fabs(-12.);
41 double       g13_0 = __builtin_fabs(-0.);
42 double       g13_1 = __builtin_fabs(-__builtin_inf());
43 float        g14 = __builtin_fabsf(-12.f);
44 // GCC doesn't eat this one.
45 //long double  g15 = __builtin_fabsfl(-12.0L);
46 #if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)
47 __float128   g15_2 = __builtin_fabsf128(-12.q);
48 #endif
49 
50 float        g16 = __builtin_copysign(1.0, -1.0);
51 double       g17 = __builtin_copysignf(1.0f, -1.0f);
52 long double  g18 = __builtin_copysignl(1.0L, -1.0L);
53 #if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)
54 __float128   g18_2 = __builtin_copysignf128(1.0q, -1.0q);
55 #endif
56 
57 char classify_nan     [__builtin_fpclassify(+1, -1, -1, -1, -1, __builtin_nan(""))];
58 char classify_snan    [__builtin_fpclassify(+1, -1, -1, -1, -1, __builtin_nans(""))];
59 char classify_inf     [__builtin_fpclassify(-1, +1, -1, -1, -1, __builtin_inf())];
60 char classify_neg_inf [__builtin_fpclassify(-1, +1, -1, -1, -1, -__builtin_inf())];
61 char classify_normal  [__builtin_fpclassify(-1, -1, +1, -1, -1, 1.539)];
62 char classify_normal2 [__builtin_fpclassify(-1, -1, +1, -1, -1, 1e-307)];
63 char classify_denorm  [__builtin_fpclassify(-1, -1, -1, +1, -1, 1e-308)];
64 char classify_denorm2 [__builtin_fpclassify(-1, -1, -1, +1, -1, -1e-308)];
65 char classify_zero    [__builtin_fpclassify(-1, -1, -1, -1, +1, 0.0)];
66 char classify_neg_zero[__builtin_fpclassify(-1, -1, -1, -1, +1, -0.0)];
67 
68 char isinf_sign_noninf1[__builtin_isinf_sign(-0.0) == 0 ? 1 : -1];
69 char isinf_sign_noninf2[__builtin_isinf_sign(1e307) == 0 ? 1 : -1];
70 char isinf_sign_noninf3[__builtin_isinf_sign(__builtin_nan("")) == 0 ? 1 : -1];
71 char isinf_sign_noninf4[__builtin_isinf_sign(-436.) == 0 ? 1 : -1];
72 char isinf_sign_inf    [__builtin_isinf_sign(__builtin_inf()) == 1 ? 1 : -1];
73 char isinf_sign_neg_inf[__builtin_isinf_sign(-__builtin_inf()) == -1 ? 1 : -1];
74 
75 char isinf_inf_pos[__builtin_isinf(__builtin_inf()) ? 1 : -1];
76 char isinf_pos    [!__builtin_isinf(1.0) ? 1 : -1];
77 char isinf_normf  [!__builtin_isinf(1e-37f) ? 1 : -1];
78 char isinf_denormf[!__builtin_isinf(1e-38f) ? 1 : -1];
79 char isinf_norm   [!__builtin_isinf(1e-307) ? 1 : -1];
80 char isinf_denorm [!__builtin_isinf(1e-308) ? 1 : -1];
81 char isinf_zero   [!__builtin_isinf(0.0) ? 1 : -1];
82 char isinf_negzero[!__builtin_isinf(-0.0) ? 1 : -1];
83 char isinf_neg    [!__builtin_isinf(-1.0) ? 1 : -1];
84 char isinf_inf_neg[__builtin_isinf(-__builtin_inf()) ? 1 : -1];
85 char isinf_nan    [!__builtin_isinf(__builtin_nan("")) ? 1 : -1];
86 char isinf_snan   [!__builtin_isinf(__builtin_nans("")) ? 1 : -1];
87 
88 char isfinite_inf_pos[!__builtin_isfinite(__builtin_inf()) ? 1 : -1];
89 char isfinite_pos    [__builtin_isfinite(1.0) ? 1 : -1];
90 char isfinite_normf  [__builtin_isfinite(1e-37f) ? 1 : -1];
91 char isfinite_denormf[__builtin_isfinite(1e-38f) ? 1 : -1];
92 char isfinite_norm   [__builtin_isfinite(1e-307) ? 1 : -1];
93 char isfinite_denorm [__builtin_isfinite(1e-308) ? 1 : -1];
94 char isfinite_zero   [__builtin_isfinite(0.0) ? 1 : -1];
95 char isfinite_negzero[__builtin_isfinite(-0.0) ? 1 : -1];
96 char isfinite_neg    [__builtin_isfinite(-1.0) ? 1 : -1];
97 char isfinite_inf_neg[!__builtin_isfinite(-__builtin_inf()) ? 1 : -1];
98 char isfinite_nan    [!__builtin_isfinite(__builtin_nan("")) ? 1 : -1];
99 char isfinite_snan   [!__builtin_isfinite(__builtin_nans("")) ? 1 : -1];
100 
101 char isnan_inf_pos[!__builtin_isnan(__builtin_inf()) ? 1 : -1];
102 char isnan_pos    [!__builtin_isnan(1.0) ? 1 : -1];
103 char isnan_normf  [!__builtin_isnan(1e-37f) ? 1 : -1];
104 char isnan_denormf[!__builtin_isnan(1e-38f) ? 1 : -1];
105 char isnan_norm   [!__builtin_isnan(1e-307) ? 1 : -1];
106 char isnan_denorm [!__builtin_isnan(1e-308) ? 1 : -1];
107 char isnan_zero   [!__builtin_isnan(0.0) ? 1 : -1];
108 char isnan_negzero[!__builtin_isnan(-0.0) ? 1 : -1];
109 char isnan_neg    [!__builtin_isnan(-1.0) ? 1 : -1];
110 char isnan_inf_neg[!__builtin_isnan(-__builtin_inf()) ? 1 : -1];
111 char isnan_nan    [__builtin_isnan(__builtin_nan("")) ? 1 : -1];
112 char isnan_snan   [__builtin_isnan(__builtin_nans("")) ? 1 : -1];
113 
114 char isnormal_inf_pos[!__builtin_isnormal(__builtin_inf()) ? 1 : -1];
115 char isnormal_pos    [__builtin_isnormal(1.0) ? 1 : -1];
116 char isnormal_normf  [__builtin_isnormal(1e-37f) ? 1 : -1];
117 char isnormal_denormf[!__builtin_isnormal(1e-38f) ? 1 : -1];
118 char isnormal_norm   [__builtin_isnormal(1e-307) ? 1 : -1];
119 char isnormal_denorm [!__builtin_isnormal(1e-308) ? 1 : -1];
120 char isnormal_zero   [!__builtin_isnormal(0.0) ? 1 : -1];
121 char isnormal_negzero[!__builtin_isnormal(-0.0) ? 1 : -1];
122 char isnormal_neg    [__builtin_isnormal(-1.0) ? 1 : -1];
123 char isnormal_inf_neg[!__builtin_isnormal(-__builtin_inf()) ? 1 : -1];
124 char isnormal_nan    [!__builtin_isnormal(__builtin_nan("")) ? 1 : -1];
125 char isnormal_snan   [!__builtin_isnormal(__builtin_nans("")) ? 1 : -1];
126 
127 //double       g19 = __builtin_powi(2.0, 4);
128 //float        g20 = __builtin_powif(2.0f, 4);
129 //long double  g21 = __builtin_powil(2.0L, 4);
130 
131 #define BITSIZE(x) (sizeof(x) * 8)
132 char clz1[__builtin_clz(1) == BITSIZE(int) - 1 ? 1 : -1];
133 char clz2[__builtin_clz(7) == BITSIZE(int) - 3 ? 1 : -1];
134 char clz3[__builtin_clz(1 << (BITSIZE(int) - 1)) == 0 ? 1 : -1];
135 int clz4 = __builtin_clz(0); // expected-error {{not a compile-time constant}}
136 char clz5[__builtin_clzl(0xFL) == BITSIZE(long) - 4 ? 1 : -1];
137 char clz6[__builtin_clzll(0xFFLL) == BITSIZE(long long) - 8 ? 1 : -1];
138 char clz7[__builtin_clzs(0x1) == BITSIZE(short) - 1 ? 1 : -1];
139 char clz8[__builtin_clzs(0xf) == BITSIZE(short) - 4 ? 1 : -1];
140 char clz9[__builtin_clzs(0xfff) == BITSIZE(short) - 12 ? 1 : -1];
141 
142 char ctz1[__builtin_ctz(1) == 0 ? 1 : -1];
143 char ctz2[__builtin_ctz(8) == 3 ? 1 : -1];
144 char ctz3[__builtin_ctz(1 << (BITSIZE(int) - 1)) == BITSIZE(int) - 1 ? 1 : -1];
145 int ctz4 = __builtin_ctz(0); // expected-error {{not a compile-time constant}}
146 char ctz5[__builtin_ctzl(0x10L) == 4 ? 1 : -1];
147 char ctz6[__builtin_ctzll(0x100LL) == 8 ? 1 : -1];
148 char ctz7[__builtin_ctzs(1 << (BITSIZE(short) - 1)) == BITSIZE(short) - 1 ? 1 : -1];
149 
150 char popcount1[__builtin_popcount(0) == 0 ? 1 : -1];
151 char popcount2[__builtin_popcount(0xF0F0) == 8 ? 1 : -1];
152 char popcount3[__builtin_popcount(~0) == BITSIZE(int) ? 1 : -1];
153 char popcount4[__builtin_popcount(~0L) == BITSIZE(int) ? 1 : -1];
154 char popcount5[__builtin_popcountl(0L) == 0 ? 1 : -1];
155 char popcount6[__builtin_popcountl(0xF0F0L) == 8 ? 1 : -1];
156 char popcount7[__builtin_popcountl(~0L) == BITSIZE(long) ? 1 : -1];
157 char popcount8[__builtin_popcountll(0LL) == 0 ? 1 : -1];
158 char popcount9[__builtin_popcountll(0xF0F0LL) == 8 ? 1 : -1];
159 char popcount10[__builtin_popcountll(~0LL) == BITSIZE(long long) ? 1 : -1];
160 
161 char parity1[__builtin_parity(0) == 0 ? 1 : -1];
162 char parity2[__builtin_parity(0xb821) == 0 ? 1 : -1];
163 char parity3[__builtin_parity(0xb822) == 0 ? 1 : -1];
164 char parity4[__builtin_parity(0xb823) == 1 ? 1 : -1];
165 char parity5[__builtin_parity(0xb824) == 0 ? 1 : -1];
166 char parity6[__builtin_parity(0xb825) == 1 ? 1 : -1];
167 char parity7[__builtin_parity(0xb826) == 1 ? 1 : -1];
168 char parity8[__builtin_parity(~0) == 0 ? 1 : -1];
169 char parity9[__builtin_parityl(1L << (BITSIZE(long) - 1)) == 1 ? 1 : -1];
170 char parity10[__builtin_parityll(1LL << (BITSIZE(long long) - 1)) == 1 ? 1 : -1];
171 
172 char ffs1[__builtin_ffs(0) == 0 ? 1 : -1];
173 char ffs2[__builtin_ffs(1) == 1 ? 1 : -1];
174 char ffs3[__builtin_ffs(0xfbe71) == 1 ? 1 : -1];
175 char ffs4[__builtin_ffs(0xfbe70) == 5 ? 1 : -1];
176 char ffs5[__builtin_ffs(1U << (BITSIZE(int) - 1)) == BITSIZE(int) ? 1 : -1];
177 char ffs6[__builtin_ffsl(0x10L) == 5 ? 1 : -1];
178 char ffs7[__builtin_ffsll(0x100LL) == 9 ? 1 : -1];
179 
180 char clrsb1[__builtin_clrsb(0) == BITSIZE(int) - 1 ? 1 : -1];
181 char clrsb2[__builtin_clrsbl(0L) == BITSIZE(long) - 1 ? 1 : -1];
182 char clrsb3[__builtin_clrsbll(0LL) == BITSIZE(long long) - 1 ? 1 : -1];
183 char clrsb4[__builtin_clrsb(~0) == BITSIZE(int) - 1 ? 1 : -1];
184 char clrsb5[__builtin_clrsbl(~0L) == BITSIZE(long) - 1 ? 1 : -1];
185 char clrsb6[__builtin_clrsbll(~0LL) == BITSIZE(long long) - 1 ? 1 : -1];
186 char clrsb7[__builtin_clrsb(1) == BITSIZE(int) - 2 ? 1 : -1];
187 char clrsb8[__builtin_clrsb(~1) == BITSIZE(int) - 2 ? 1 : -1];
188 char clrsb9[__builtin_clrsb(1 << (BITSIZE(int) - 1)) == 0 ? 1 : -1];
189 char clrsb10[__builtin_clrsb(~(1 << (BITSIZE(int) - 1))) == 0 ? 1 : -1];
190 char clrsb11[__builtin_clrsb(0xf) == BITSIZE(int) - 5 ? 1 : -1];
191 char clrsb12[__builtin_clrsb(~0x1f) == BITSIZE(int) - 6 ? 1 : -1];
192 #undef BITSIZE
193 
194 // GCC misc stuff
195 
196 extern int f();
197 
198 int h0 = __builtin_types_compatible_p(int, float);
199 //int h1 = __builtin_choose_expr(1, 10, f());
200 //int h2 = __builtin_expect(0, 0);
201 int h3 = __builtin_bswap16(0x1234) == 0x3412 ? 1 : f();
202 int h4 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f();
203 int h5 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f();
204 extern long int bi0;
205 extern __typeof__(__builtin_expect(0, 0)) bi0;
206 
207 // Strings
208 int array1[__builtin_strlen("ab\0cd")];
209 int array2[(sizeof(array1)/sizeof(int)) == 2? 1 : -1];
210