Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Sema / tautological-unsigned-zero-compare.c
blobe24ec94bf6e3bf288388719c7afc1d936be53a37
1 // RUN: %clang_cc1 -fsyntax-only \
2 // RUN: -Wtautological-unsigned-zero-compare \
3 // RUN: -verify %s
4 // RUN: %clang_cc1 -fsyntax-only \
5 // RUN: -verify=silence %s
6 // RUN: %clang_cc1 -fsyntax-only \
7 // RUN: -Wtautological-unsigned-zero-compare \
8 // RUN: -verify -x c++ %s
9 // RUN: %clang_cc1 -fsyntax-only \
10 // RUN: -verify=silence -x c++ %s
12 unsigned uvalue(void);
13 signed int svalue(void);
15 #define macro(val) val
17 #ifdef __cplusplus
18 template<typename T>
19 void TFunc() {
20 // Make sure that we do warn for normal variables in template functions !
21 unsigned char c = svalue();
22 if (c < 0) // expected-warning {{comparison of unsigned expression < 0 is always false}}
23 return;
25 if (c < macro(0))
26 return;
28 T v = svalue();
29 if (v < 0)
30 return;
32 #endif
34 int main(void)
36 #ifdef __cplusplus
37 TFunc<unsigned char>();
38 TFunc<unsigned short>();
39 #endif
41 short s = svalue();
43 unsigned un = uvalue();
45 // silence-no-diagnostics
47 // Note: both sides are promoted to unsigned long prior to the comparison.
48 if (s == 0UL)
49 return 0;
50 if (s != 0UL)
51 return 0;
52 if (s < 0UL) // expected-warning {{comparison of unsigned expression < 0 is always false}}
53 return 0;
54 if (s <= 0UL)
55 return 0;
56 if (s > 0UL)
57 return 0;
58 if (s >= 0UL) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
59 return 0;
61 if (0UL == s)
62 return 0;
63 if (0UL != s)
64 return 0;
65 if (0UL < s)
66 return 0;
67 if (0UL <= s) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
68 return 0;
69 if (0UL > s) // expected-warning {{comparison of 0 > unsigned expression is always false}}
70 return 0;
71 if (0UL >= s)
72 return 0;
74 if (un == 0)
75 return 0;
76 if (un != 0)
77 return 0;
78 if (un < 0) // expected-warning {{comparison of unsigned expression < 0 is always false}}
79 return 0;
80 if (un <= 0)
81 return 0;
82 if (un > 0)
83 return 0;
84 if (un >= 0) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
85 return 0;
87 if (0 == un)
88 return 0;
89 if (0 != un)
90 return 0;
91 if (0 < un)
92 return 0;
93 if (0 <= un) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
94 return 0;
95 if (0 > un) // expected-warning {{comparison of 0 > unsigned expression is always false}}
96 return 0;
97 if (0 >= un)
98 return 0;
100 if (un == 0UL)
101 return 0;
102 if (un != 0UL)
103 return 0;
104 if (un < 0UL) // expected-warning {{comparison of unsigned expression < 0 is always false}}
105 return 0;
106 if (un <= 0UL)
107 return 0;
108 if (un > 0UL)
109 return 0;
110 if (un >= 0UL) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
111 return 0;
113 if (0UL == un)
114 return 0;
115 if (0UL != un)
116 return 0;
117 if (0UL < un)
118 return 0;
119 if (0UL <= un) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
120 return 0;
121 if (0UL > un) // expected-warning {{comparison of 0 > unsigned expression is always false}}
122 return 0;
123 if (0UL >= un)
124 return 0;
127 signed int a = svalue();
129 if (a == 0)
130 return 0;
131 if (a != 0)
132 return 0;
133 if (a < 0)
134 return 0;
135 if (a <= 0)
136 return 0;
137 if (a > 0)
138 return 0;
139 if (a >= 0)
140 return 0;
142 if (0 == a)
143 return 0;
144 if (0 != a)
145 return 0;
146 if (0 < a)
147 return 0;
148 if (0 <= a)
149 return 0;
150 if (0 > a)
151 return 0;
152 if (0 >= a)
153 return 0;
155 if (a == 0UL)
156 return 0;
157 if (a != 0UL)
158 return 0;
159 if (a < 0UL) // expected-warning {{comparison of unsigned expression < 0 is always false}}
160 return 0;
161 if (a <= 0UL)
162 return 0;
163 if (a > 0UL)
164 return 0;
165 if (a >= 0UL) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
166 return 0;
168 if (0UL == a)
169 return 0;
170 if (0UL != a)
171 return 0;
172 if (0UL < a)
173 return 0;
174 if (0UL <= a) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
175 return 0;
176 if (0UL > a) // expected-warning {{comparison of 0 > unsigned expression is always false}}
177 return 0;
178 if (0UL >= a)
179 return 0;
182 float fl = 0;
184 if (fl == 0)
185 return 0;
186 if (fl != 0)
187 return 0;
188 if (fl < 0)
189 return 0;
190 if (fl <= 0)
191 return 0;
192 if (fl > 0)
193 return 0;
194 if (fl >= 0)
195 return 0;
197 if (0 == fl)
198 return 0;
199 if (0 != fl)
200 return 0;
201 if (0 < fl)
202 return 0;
203 if (0 <= fl)
204 return 0;
205 if (0 > fl)
206 return 0;
207 if (0 >= fl)
208 return 0;
210 if (fl == 0UL)
211 return 0;
212 if (fl != 0UL)
213 return 0;
214 if (fl < 0UL)
215 return 0;
216 if (fl <= 0UL)
217 return 0;
218 if (fl > 0UL)
219 return 0;
220 if (fl >= 0UL)
221 return 0;
223 if (0UL == fl)
224 return 0;
225 if (0UL != fl)
226 return 0;
227 if (0UL < fl)
228 return 0;
229 if (0UL <= fl)
230 return 0;
231 if (0UL > fl)
232 return 0;
233 if (0UL >= fl)
234 return 0;
237 double dl = 0;
239 if (dl == 0)
240 return 0;
241 if (dl != 0)
242 return 0;
243 if (dl < 0)
244 return 0;
245 if (dl <= 0)
246 return 0;
247 if (dl > 0)
248 return 0;
249 if (dl >= 0)
250 return 0;
252 if (0 == dl)
253 return 0;
254 if (0 != dl)
255 return 0;
256 if (0 < dl)
257 return 0;
258 if (0 <= dl)
259 return 0;
260 if (0 > dl)
261 return 0;
262 if (0 >= dl)
263 return 0;
265 if (dl == 0UL)
266 return 0;
267 if (dl != 0UL)
268 return 0;
269 if (dl < 0UL)
270 return 0;
271 if (dl <= 0UL)
272 return 0;
273 if (dl > 0UL)
274 return 0;
275 if (dl >= 0UL)
276 return 0;
278 if (0UL == dl)
279 return 0;
280 if (0UL != dl)
281 return 0;
282 if (0UL < dl)
283 return 0;
284 if (0UL <= dl)
285 return 0;
286 if (0UL > dl)
287 return 0;
288 if (0UL >= dl)
289 return 0;
291 return 1;