blob: b9ea02a731a3edaee90079b39a6f74b9a38132c9 [file] [log] [blame]
Hal Finkel05e46482017-12-16 02:23:22 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-zero-compare -verify=silence %s
3// RUN: %clang_cc1 -fsyntax-only -verify -x c++ %s
4// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-zero-compare -verify=silence -x c++ %s
Roman Lebedev309b7f52017-09-08 13:56:45 +00005
Roman Lebedev6de129e2017-10-15 20:13:17 +00006unsigned uvalue(void);
7signed int svalue(void);
Roman Lebedev309b7f52017-09-08 13:56:45 +00008
Roman Lebedev6de129e2017-10-15 20:13:17 +00009#define macro(val) val
10
11#ifdef __cplusplus
12template<typename T>
13void TFunc() {
14 // Make sure that we do warn for normal variables in template functions !
15 unsigned char c = svalue();
Roman Lebedev6de129e2017-10-15 20:13:17 +000016 if (c < 0) // expected-warning {{comparison of unsigned expression < 0 is always false}}
17 return;
Roman Lebedev6de129e2017-10-15 20:13:17 +000018
19 if (c < macro(0))
20 return;
21
22 T v = svalue();
23 if (v < 0)
24 return;
25}
26#endif
27
28int main()
29{
30#ifdef __cplusplus
31 TFunc<unsigned char>();
32 TFunc<unsigned short>();
33#endif
34
35 unsigned un = uvalue();
Roman Lebedev309b7f52017-09-08 13:56:45 +000036
Hal Finkel05e46482017-12-16 02:23:22 +000037 // silence-no-diagnostics
38
Roman Lebedev6de129e2017-10-15 20:13:17 +000039 if (un == 0)
40 return 0;
41 if (un != 0)
42 return 0;
Roman Lebedev309b7f52017-09-08 13:56:45 +000043 if (un < 0) // expected-warning {{comparison of unsigned expression < 0 is always false}}
Roman Lebedev6de129e2017-10-15 20:13:17 +000044 return 0;
45 if (un <= 0)
46 return 0;
47 if (un > 0)
48 return 0;
Roman Lebedev309b7f52017-09-08 13:56:45 +000049 if (un >= 0) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
Roman Lebedev6de129e2017-10-15 20:13:17 +000050 return 0;
51
52 if (0 == un)
53 return 0;
54 if (0 != un)
55 return 0;
56 if (0 < un)
57 return 0;
Roman Lebedev309b7f52017-09-08 13:56:45 +000058 if (0 <= un) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
Roman Lebedev6de129e2017-10-15 20:13:17 +000059 return 0;
Roman Lebedev309b7f52017-09-08 13:56:45 +000060 if (0 > un) // expected-warning {{comparison of 0 > unsigned expression is always false}}
Roman Lebedev6de129e2017-10-15 20:13:17 +000061 return 0;
62 if (0 >= un)
63 return 0;
64
65 if (un == 0UL)
66 return 0;
67 if (un != 0UL)
68 return 0;
69 if (un < 0UL) // expected-warning {{comparison of unsigned expression < 0 is always false}}
70 return 0;
71 if (un <= 0UL)
72 return 0;
73 if (un > 0UL)
74 return 0;
75 if (un >= 0UL) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
76 return 0;
77
78 if (0UL == un)
79 return 0;
80 if (0UL != un)
81 return 0;
82 if (0UL < un)
83 return 0;
84 if (0UL <= un) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
85 return 0;
86 if (0UL > un) // expected-warning {{comparison of 0 > unsigned expression is always false}}
87 return 0;
88 if (0UL >= un)
89 return 0;
Roman Lebedev309b7f52017-09-08 13:56:45 +000090
Roman Lebedev6de129e2017-10-15 20:13:17 +000091
92 signed int a = svalue();
93
Roman Lebedev6de129e2017-10-15 20:13:17 +000094 if (a == 0)
95 return 0;
96 if (a != 0)
97 return 0;
98 if (a < 0)
99 return 0;
100 if (a <= 0)
101 return 0;
102 if (a > 0)
103 return 0;
104 if (a >= 0)
105 return 0;
106
107 if (0 == a)
108 return 0;
109 if (0 != a)
110 return 0;
111 if (0 < a)
112 return 0;
113 if (0 <= a)
114 return 0;
115 if (0 > a)
116 return 0;
117 if (0 >= a)
118 return 0;
119
120 if (a == 0UL)
121 return 0;
122 if (a != 0UL)
123 return 0;
124 if (a < 0UL) // expected-warning {{comparison of unsigned expression < 0 is always false}}
125 return 0;
126 if (a <= 0UL)
127 return 0;
128 if (a > 0UL)
129 return 0;
130 if (a >= 0UL) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
131 return 0;
132
133 if (0UL == a)
134 return 0;
135 if (0UL != a)
136 return 0;
137 if (0UL < a)
138 return 0;
139 if (0UL <= a) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
140 return 0;
141 if (0UL > a) // expected-warning {{comparison of 0 > unsigned expression is always false}}
142 return 0;
143 if (0UL >= a)
144 return 0;
Roman Lebedev6de129e2017-10-15 20:13:17 +0000145
146
147 float fl = 0;
148
149 if (fl == 0)
150 return 0;
151 if (fl != 0)
152 return 0;
153 if (fl < 0)
154 return 0;
155 if (fl <= 0)
156 return 0;
157 if (fl > 0)
158 return 0;
159 if (fl >= 0)
160 return 0;
161
162 if (0 == fl)
163 return 0;
164 if (0 != fl)
165 return 0;
166 if (0 < fl)
167 return 0;
168 if (0 <= fl)
169 return 0;
170 if (0 > fl)
171 return 0;
172 if (0 >= fl)
173 return 0;
174
175 if (fl == 0UL)
176 return 0;
177 if (fl != 0UL)
178 return 0;
179 if (fl < 0UL)
180 return 0;
181 if (fl <= 0UL)
182 return 0;
183 if (fl > 0UL)
184 return 0;
185 if (fl >= 0UL)
186 return 0;
187
188 if (0UL == fl)
189 return 0;
190 if (0UL != fl)
191 return 0;
192 if (0UL < fl)
193 return 0;
194 if (0UL <= fl)
195 return 0;
196 if (0UL > fl)
197 return 0;
198 if (0UL >= fl)
199 return 0;
200
201
202 double dl = 0;
203
204 if (dl == 0)
205 return 0;
206 if (dl != 0)
207 return 0;
208 if (dl < 0)
209 return 0;
210 if (dl <= 0)
211 return 0;
212 if (dl > 0)
213 return 0;
214 if (dl >= 0)
215 return 0;
216
217 if (0 == dl)
218 return 0;
219 if (0 != dl)
220 return 0;
221 if (0 < dl)
222 return 0;
223 if (0 <= dl)
224 return 0;
225 if (0 > dl)
226 return 0;
227 if (0 >= dl)
228 return 0;
229
230 if (dl == 0UL)
231 return 0;
232 if (dl != 0UL)
233 return 0;
234 if (dl < 0UL)
235 return 0;
236 if (dl <= 0UL)
237 return 0;
238 if (dl > 0UL)
239 return 0;
240 if (dl >= 0UL)
241 return 0;
242
243 if (0UL == dl)
244 return 0;
245 if (0UL != dl)
246 return 0;
247 if (0UL < dl)
248 return 0;
249 if (0UL <= dl)
250 return 0;
251 if (0UL > dl)
252 return 0;
253 if (0UL >= dl)
254 return 0;
255
Roman Lebedev309b7f52017-09-08 13:56:45 +0000256 return 1;
257}