1 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED -verify %s
2 // RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -DSIGNED -verify %s
3 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED -DSILENCE -Wno-tautological-constant-out-of-range-compare -verify %s
4 // RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -DSIGNED -DSILENCE -Wno-tautological-constant-out-of-range-compare -verify %s
5 
main()6 int main() {
7   enum A { A_a = 2 };
8   enum A a;
9 
10 #ifdef SILENCE
11   // expected-no-diagnostics
12 #endif
13 
14 #ifdef UNSIGNED
15 #ifndef SILENCE
16   if (a < 4294967296) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always true}}
17     return 0;
18   if (4294967296 >= a) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always true}}
19     return 0;
20   if (a > 4294967296) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always false}}
21     return 0;
22   if (4294967296 <= a) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always false}}
23     return 0;
24   if (a <= 4294967296) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always true}}
25     return 0;
26   if (4294967296 > a) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always true}}
27     return 0;
28   if (a >= 4294967296) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always false}}
29     return 0;
30   if (4294967296 < a) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always false}}
31     return 0;
32   if (a == 4294967296) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always false}}
33     return 0;
34   if (4294967296 != a) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always true}}
35     return 0;
36   if (a != 4294967296) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always true}}
37     return 0;
38   if (4294967296 == a) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always false}}
39     return 0;
40 
41   if (a < 4294967296U) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always true}}
42     return 0;
43   if (4294967296U >= a) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always true}}
44     return 0;
45   if (a > 4294967296U) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always false}}
46     return 0;
47   if (4294967296U <= a) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always false}}
48     return 0;
49   if (a <= 4294967296U) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always true}}
50     return 0;
51   if (4294967296U > a) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always true}}
52     return 0;
53   if (a >= 4294967296U) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always false}}
54     return 0;
55   if (4294967296U < a) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always false}}
56     return 0;
57   if (a == 4294967296U) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always false}}
58     return 0;
59   if (4294967296U != a) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always true}}
60     return 0;
61   if (a != 4294967296U) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always true}}
62     return 0;
63   if (4294967296U == a) // expected-warning {{comparison of constant 4294967296 with expression of type 'enum A' is always false}}
64     return 0;
65 #else // SILENCE
66   if (a < 4294967296)
67     return 0;
68   if (4294967296 >= a)
69     return 0;
70   if (a > 4294967296)
71     return 0;
72   if (4294967296 <= a)
73     return 0;
74   if (a <= 4294967296)
75     return 0;
76   if (4294967296 > a)
77     return 0;
78   if (a >= 4294967296)
79     return 0;
80   if (4294967296 < a)
81     return 0;
82   if (a == 4294967296)
83     return 0;
84   if (4294967296 != a)
85     return 0;
86   if (a != 4294967296)
87     return 0;
88   if (4294967296 == a)
89     return 0;
90 
91   if (a < 4294967296U)
92     return 0;
93   if (4294967296U >= a)
94     return 0;
95   if (a > 4294967296U)
96     return 0;
97   if (4294967296U <= a)
98     return 0;
99   if (a <= 4294967296U)
100     return 0;
101   if (4294967296U > a)
102     return 0;
103   if (a >= 4294967296U)
104     return 0;
105   if (4294967296U < a)
106     return 0;
107   if (a == 4294967296U)
108     return 0;
109   if (4294967296U != a)
110     return 0;
111   if (a != 4294967296U)
112     return 0;
113   if (4294967296U == a)
114     return 0;
115 #endif
116 #elif defined(SIGNED)
117 #ifndef SILENCE
118   if (a < -2147483649) // expected-warning {{comparison of constant -2147483649 with expression of type 'enum A' is always false}}
119     return 0;
120   if (-2147483649 >= a) // expected-warning {{comparison of constant -2147483649 with expression of type 'enum A' is always false}}
121     return 0;
122   if (a > -2147483649) // expected-warning {{comparison of constant -2147483649 with expression of type 'enum A' is always true}}
123     return 0;
124   if (-2147483649 <= a) // expected-warning {{comparison of constant -2147483649 with expression of type 'enum A' is always true}}
125     return 0;
126   if (a <= -2147483649) // expected-warning {{comparison of constant -2147483649 with expression of type 'enum A' is always false}}
127     return 0;
128   if (-2147483649 > a) // expected-warning {{comparison of constant -2147483649 with expression of type 'enum A' is always false}}
129     return 0;
130   if (a >= -2147483649) // expected-warning {{comparison of constant -2147483649 with expression of type 'enum A' is always true}}
131     return 0;
132   if (-2147483649 < a) // expected-warning {{comparison of constant -2147483649 with expression of type 'enum A' is always true}}
133     return 0;
134   if (a == -2147483649) // expected-warning {{comparison of constant -2147483649 with expression of type 'enum A' is always false}}
135     return 0;
136   if (-2147483649 != a) // expected-warning {{comparison of constant -2147483649 with expression of type 'enum A' is always true}}
137     return 0;
138   if (a != -2147483649) // expected-warning {{comparison of constant -2147483649 with expression of type 'enum A' is always true}}
139     return 0;
140   if (-2147483649 == a) // expected-warning {{comparison of constant -2147483649 with expression of type 'enum A' is always false}}
141     return 0;
142 
143   if (a < 2147483648) // expected-warning {{comparison of constant 2147483648 with expression of type 'enum A' is always true}}
144     return 0;
145   if (2147483648 >= a) // expected-warning {{comparison of constant 2147483648 with expression of type 'enum A' is always true}}
146     return 0;
147   if (a > 2147483648) // expected-warning {{comparison of constant 2147483648 with expression of type 'enum A' is always false}}
148     return 0;
149   if (2147483648 <= a) // expected-warning {{comparison of constant 2147483648 with expression of type 'enum A' is always false}}
150     return 0;
151   if (a <= 2147483648) // expected-warning {{comparison of constant 2147483648 with expression of type 'enum A' is always true}}
152     return 0;
153   if (2147483648 > a) // expected-warning {{comparison of constant 2147483648 with expression of type 'enum A' is always true}}
154     return 0;
155   if (a >= 2147483648) // expected-warning {{comparison of constant 2147483648 with expression of type 'enum A' is always false}}
156     return 0;
157   if (2147483648 < a) // expected-warning {{comparison of constant 2147483648 with expression of type 'enum A' is always false}}
158     return 0;
159   if (a == 2147483648) // expected-warning {{comparison of constant 2147483648 with expression of type 'enum A' is always false}}
160     return 0;
161   if (2147483648 != a) // expected-warning {{comparison of constant 2147483648 with expression of type 'enum A' is always true}}
162     return 0;
163   if (a != 2147483648) // expected-warning {{comparison of constant 2147483648 with expression of type 'enum A' is always true}}
164     return 0;
165   if (2147483648 == a) // expected-warning {{comparison of constant 2147483648 with expression of type 'enum A' is always false}}
166     return 0;
167 #else // SILENCE
168   if (a < -2147483649)
169     return 0;
170   if (-2147483649 >= a)
171     return 0;
172   if (a > -2147483649)
173     return 0;
174   if (-2147483649 <= a)
175     return 0;
176   if (a <= -2147483649)
177     return 0;
178   if (-2147483649 > a)
179     return 0;
180   if (a >= -2147483649)
181     return 0;
182   if (-2147483649 < a)
183     return 0;
184   if (a == -2147483649)
185     return 0;
186   if (-2147483649 != a)
187     return 0;
188   if (a != -2147483649)
189     return 0;
190   if (-2147483649 == a)
191     return 0;
192 
193   if (a < 2147483648)
194     return 0;
195   if (2147483648 >= a)
196     return 0;
197   if (a > 2147483648)
198     return 0;
199   if (2147483648 <= a)
200     return 0;
201   if (a <= 2147483648)
202     return 0;
203   if (2147483648 > a)
204     return 0;
205   if (a >= 2147483648)
206     return 0;
207   if (2147483648 < a)
208     return 0;
209   if (a == 2147483648)
210     return 0;
211   if (2147483648 != a)
212     return 0;
213   if (a != 2147483648)
214     return 0;
215   if (2147483648 == a)
216     return 0;
217 #endif
218 #endif
219 }
220 
221 // https://bugs.llvm.org/show_bug.cgi?id=35009
PR35009()222 int PR35009() {
223   enum A { A_a = 2 };
224   enum A a;
225 
226   // in C, this should not warn.
227 
228   if (a < 1)
229     return 0;
230   if (1 >= a)
231     return 0;
232   if (a > 1)
233     return 0;
234   if (1 <= a)
235     return 0;
236   if (a <= 1)
237     return 0;
238   if (1 > a)
239     return 0;
240   if (a >= 1)
241     return 0;
242   if (1 < a)
243     return 0;
244   if (a == 1)
245     return 0;
246   if (1 != a)
247     return 0;
248   if (a != 1)
249     return 0;
250   if (1 == a)
251     return 0;
252 
253   if (a < 1U)
254     return 0;
255   if (1U >= a)
256     return 0;
257   if (a > 1U)
258     return 0;
259   if (1U <= a)
260     return 0;
261   if (a <= 1U)
262     return 0;
263   if (1U > a)
264     return 0;
265   if (a >= 1U)
266     return 0;
267   if (1U < a)
268     return 0;
269   if (a == 1U)
270     return 0;
271   if (1U != a)
272     return 0;
273   if (a != 1U)
274     return 0;
275   if (1U == a)
276     return 0;
277 
278   if (a < 2)
279     return 0;
280   if (2 >= a)
281     return 0;
282   if (a > 2)
283     return 0;
284   if (2 <= a)
285     return 0;
286   if (a <= 2)
287     return 0;
288   if (2 > a)
289     return 0;
290   if (a >= 2)
291     return 0;
292   if (2 < a)
293     return 0;
294   if (a == 2)
295     return 0;
296   if (2 != a)
297     return 0;
298   if (a != 2)
299     return 0;
300   if (2 == a)
301     return 0;
302 
303   if (a < 2U)
304     return 0;
305   if (2U >= a)
306     return 0;
307   if (a > 2U)
308     return 0;
309   if (2U <= a)
310     return 0;
311   if (a <= 2U)
312     return 0;
313   if (2U > a)
314     return 0;
315   if (a >= 2U)
316     return 0;
317   if (2U < a)
318     return 0;
319   if (a == 2U)
320     return 0;
321   if (2U != a)
322     return 0;
323   if (a != 2U)
324     return 0;
325   if (2U == a)
326     return 0;
327 
328   if (a < 3)
329     return 0;
330   if (3 >= a)
331     return 0;
332   if (a > 3)
333     return 0;
334   if (3 <= a)
335     return 0;
336   if (a <= 3)
337     return 0;
338   if (3 > a)
339     return 0;
340   if (a >= 3)
341     return 0;
342   if (3 < a)
343     return 0;
344   if (a == 3)
345     return 0;
346   if (3 != a)
347     return 0;
348   if (a != 3)
349     return 0;
350   if (3 == a)
351     return 0;
352 
353   if (a < 3U)
354     return 0;
355   if (3U >= a)
356     return 0;
357   if (a > 3U)
358     return 0;
359   if (3U <= a)
360     return 0;
361   if (a <= 3U)
362     return 0;
363   if (3U > a)
364     return 0;
365   if (a >= 3U)
366     return 0;
367   if (3U < a)
368     return 0;
369   if (a == 3U)
370     return 0;
371   if (3U != a)
372     return 0;
373   if (a != 3U)
374     return 0;
375   if (3U == a)
376     return 0;
377 
378   return 1;
379 }
380