# Changeset View

Changeset View

# Standalone View

Standalone View

# test/Sema/tautological-unsigned-zero-compare.c

1 | // RUN: %clang_cc1 -fsyntax-only -DTEST -verify %s | 1 | // RUN: %clang_cc1 -fsyntax-only -DTEST -verify %s | ||
---|---|---|---|---|---|

2 | // RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-zero-compare -verify %s | 2 | // RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-zero-compare -verify %s | ||

3 | // RUN: %clang_cc1 -fsyntax-only -DTEST -verify -x c++ %s | ||||

4 | // RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-zero-compare -verify -x c++ %s | ||||

3 | 5 | | |||

4 | unsigned value(void); | 6 | unsigned uvalue(void); | ||

7 | signed int svalue(void); | ||||

5 | 8 | | |||

6 | int main() { | 9 | #define macro(val) val | ||

7 | unsigned un = value(); | | |||

8 | 10 | | |||

11 | #ifdef __cplusplus | ||||

12 | template<typename T> | ||||

13 | void TFunc() { | ||||

14 | // Make sure that we do warn for normal variables in template functions ! | ||||

15 | unsigned char c = svalue(); | ||||

9 | #ifdef TEST | 16 | #ifdef TEST | ||

17 | if (c < 0) // expected-warning {{comparison of unsigned expression < 0 is always false}} | ||||

18 | return; | ||||

19 | #else | ||||

20 | if (c < 0) | ||||

21 | return; | ||||

22 | #endif | ||||

23 | | ||||

24 | if (c < macro(0)) | ||||

25 | return; | ||||

26 | | ||||

27 | T v = svalue(); | ||||

28 | if (v < 0) | ||||

29 | return; | ||||

30 | } | ||||

31 | #endif | ||||

32 | | ||||

33 | int main() | ||||

34 | { | ||||

35 | #ifdef __cplusplus | ||||

36 | TFunc<unsigned char>(); | ||||

37 | TFunc<unsigned short>(); | ||||

38 | #endif | ||||

39 | | ||||

40 | unsigned un = uvalue(); | ||||

41 | | ||||

42 | #ifdef TEST | ||||

43 | if (un == 0) | ||||

44 | return 0; | ||||

45 | if (un != 0) | ||||

46 | return 0; | ||||

10 | if (un < 0) // expected-warning {{comparison of unsigned expression < 0 is always false}} | 47 | if (un < 0) // expected-warning {{comparison of unsigned expression < 0 is always false}} | ||

11 | return 0; | 48 | return 0; | ||

49 | if (un <= 0) | ||||

50 | return 0; | ||||

51 | if (un > 0) | ||||

52 | return 0; | ||||

12 | if (un >= 0) // expected-warning {{comparison of unsigned expression >= 0 is always true}} | 53 | if (un >= 0) // expected-warning {{comparison of unsigned expression >= 0 is always true}} | ||

13 | return 0; | 54 | return 0; | ||

55 | | ||||

56 | if (0 == un) | ||||

57 | return 0; | ||||

58 | if (0 != un) | ||||

59 | return 0; | ||||

60 | if (0 < un) | ||||

61 | return 0; | ||||

14 | if (0 <= un) // expected-warning {{comparison of 0 <= unsigned expression is always true}} | 62 | if (0 <= un) // expected-warning {{comparison of 0 <= unsigned expression is always true}} | ||

15 | return 0; | 63 | return 0; | ||

16 | if (0 > un) // expected-warning {{comparison of 0 > unsigned expression is always false}} | 64 | if (0 > un) // expected-warning {{comparison of 0 > unsigned expression is always false}} | ||

17 | return 0; | 65 | return 0; | ||

18 | if (un < 0U) // expected-warning {{comparison of unsigned expression < 0 is always false}} | 66 | if (0 >= un) | ||

67 | return 0; | ||||

68 | | ||||

69 | if (un == 0UL) | ||||

70 | return 0; | ||||

71 | if (un != 0UL) | ||||

19 | return 0; | 72 | return 0; | ||

20 | if (un >= 0U) // expected-warning {{comparison of unsigned expression >= 0 is always true}} | 73 | if (un < 0UL) // expected-warning {{comparison of unsigned expression < 0 is always false}} | ||

21 | return 0; | 74 | return 0; | ||

22 | if (0U <= un) // expected-warning {{comparison of 0 <= unsigned expression is always true}} | 75 | if (un <= 0UL) | ||

23 | return 0; | 76 | return 0; | ||

24 | if (0U > un) // expected-warning {{comparison of 0 > unsigned expression is always false}} | 77 | if (un > 0UL) | ||

78 | return 0; | ||||

79 | if (un >= 0UL) // expected-warning {{comparison of unsigned expression >= 0 is always true}} | ||||

80 | return 0; | ||||

81 | | ||||

82 | if (0UL == un) | ||||

83 | return 0; | ||||

84 | if (0UL != un) | ||||

85 | return 0; | ||||

86 | if (0UL < un) | ||||

87 | return 0; | ||||

88 | if (0UL <= un) // expected-warning {{comparison of 0 <= unsigned expression is always true}} | ||||

89 | return 0; | ||||

90 | if (0UL > un) // expected-warning {{comparison of 0 > unsigned expression is always false}} | ||||

91 | return 0; | ||||

92 | if (0UL >= un) | ||||

25 | return 0; | 93 | return 0; | ||

26 | #else | 94 | #else | ||

27 | // expected-no-diagnostics | 95 | // expected-no-diagnostics | ||

96 | if (un == 0) | ||||

97 | return 0; | ||||

98 | if (un != 0) | ||||

99 | return 0; | ||||

28 | if (un < 0) | 100 | if (un < 0) | ||

29 | return 0; | 101 | return 0; | ||

102 | if (un <= 0) | ||||

103 | return 0; | ||||

104 | if (un > 0) | ||||

105 | return 0; | ||||

30 | if (un >= 0) | 106 | if (un >= 0) | ||

31 | return 0; | 107 | return 0; | ||

108 | | ||||

109 | if (0 == un) | ||||

110 | return 0; | ||||

111 | if (0 != un) | ||||

112 | return 0; | ||||

113 | if (0 < un) | ||||

114 | return 0; | ||||

32 | if (0 <= un) | 115 | if (0 <= un) | ||

33 | return 0; | 116 | return 0; | ||

34 | if (0 > un) | 117 | if (0 > un) | ||

35 | return 0; | 118 | return 0; | ||

36 | if (un < 0U) | 119 | if (0 >= un) | ||

120 | return 0; | ||||

121 | | ||||

122 | if (un == 0UL) | ||||

123 | return 0; | ||||

124 | if (un != 0UL) | ||||

125 | return 0; | ||||

126 | if (un < 0UL) | ||||

127 | return 0; | ||||

128 | if (un <= 0UL) | ||||

129 | return 0; | ||||

130 | if (un > 0UL) | ||||

131 | return 0; | ||||

132 | if (un >= 0UL) | ||||

133 | return 0; | ||||

134 | | ||||

135 | if (0UL == un) | ||||

136 | return 0; | ||||

137 | if (0UL != un) | ||||

138 | return 0; | ||||

139 | if (0UL < un) | ||||

140 | return 0; | ||||

141 | if (0UL <= un) | ||||

142 | return 0; | ||||

143 | if (0UL > un) | ||||

144 | return 0; | ||||

145 | if (0UL >= un) | ||||

146 | return 0; | ||||

147 | #endif | ||||

148 | | ||||

149 | | ||||

150 | signed int a = svalue(); | ||||

151 | | ||||

152 | #ifdef TEST | ||||

153 | if (a == 0) | ||||

154 | return 0; | ||||

155 | if (a != 0) | ||||

156 | return 0; | ||||

157 | if (a < 0) | ||||

158 | return 0; | ||||

159 | if (a <= 0) | ||||

160 | return 0; | ||||

161 | if (a > 0) | ||||

162 | return 0; | ||||

163 | if (a >= 0) | ||||

164 | return 0; | ||||

165 | | ||||

166 | if (0 == a) | ||||

167 | return 0; | ||||

168 | if (0 != a) | ||||

169 | return 0; | ||||

170 | if (0 < a) | ||||

171 | return 0; | ||||

172 | if (0 <= a) | ||||

173 | return 0; | ||||

174 | if (0 > a) | ||||

175 | return 0; | ||||

176 | if (0 >= a) | ||||

177 | return 0; | ||||

178 | | ||||

179 | if (a == 0UL) | ||||

180 | return 0; | ||||

181 | if (a != 0UL) | ||||

182 | return 0; | ||||

183 | if (a < 0UL) // expected-warning {{comparison of unsigned expression < 0 is always false}} | ||||

184 | return 0; | ||||

185 | if (a <= 0UL) | ||||

186 | return 0; | ||||

187 | if (a > 0UL) | ||||

188 | return 0; | ||||

189 | if (a >= 0UL) // expected-warning {{comparison of unsigned expression >= 0 is always true}} | ||||

190 | return 0; | ||||

191 | | ||||

192 | if (0UL == a) | ||||

193 | return 0; | ||||

194 | if (0UL != a) | ||||

195 | return 0; | ||||

196 | if (0UL < a) | ||||

197 | return 0; | ||||

198 | if (0UL <= a) // expected-warning {{comparison of 0 <= unsigned expression is always true}} | ||||

199 | return 0; | ||||

200 | if (0UL > a) // expected-warning {{comparison of 0 > unsigned expression is always false}} | ||||

201 | return 0; | ||||

202 | if (0UL >= a) | ||||

203 | return 0; | ||||

204 | #else | ||||

205 | // expected-no-diagnostics | ||||

206 | if (a == 0) | ||||

207 | return 0; | ||||

208 | if (a != 0) | ||||

209 | return 0; | ||||

210 | if (a < 0) | ||||

211 | return 0; | ||||

212 | if (a <= 0) | ||||

213 | return 0; | ||||

214 | if (a > 0) | ||||

215 | return 0; | ||||

216 | if (a >= 0) | ||||

217 | return 0; | ||||

218 | | ||||

219 | if (0 == a) | ||||

220 | return 0; | ||||

221 | if (0 != a) | ||||

222 | return 0; | ||||

223 | if (0 < a) | ||||

37 | return 0; | 224 | return 0; | ||

38 | if (un >= 0U) | 225 | if (0 <= a) | ||

226 | return 0; | ||||

227 | if (0 > a) | ||||

228 | return 0; | ||||

229 | if (0 >= a) | ||||

230 | return 0; | ||||

231 | | ||||

232 | if (a == 0UL) | ||||

233 | return 0; | ||||

234 | if (a != 0UL) | ||||

235 | return 0; | ||||

236 | if (a < 0UL) | ||||

237 | return 0; | ||||

238 | if (a <= 0UL) | ||||

239 | return 0; | ||||

240 | if (a > 0UL) | ||||

241 | return 0; | ||||

242 | if (a >= 0UL) | ||||

243 | return 0; | ||||

244 | | ||||

245 | if (0UL == a) | ||||

39 | return 0; | 246 | return 0; | ||

40 | if (0U <= un) | 247 | if (0UL != a) | ||

41 | return 0; | 248 | return 0; | ||

42 | if (0U > un) | 249 | if (0UL < a) | ||

250 | return 0; | ||||

251 | if (0UL <= a) | ||||

252 | return 0; | ||||

253 | if (0UL > a) | ||||

254 | return 0; | ||||

255 | if (0UL >= a) | ||||

43 | return 0; | 256 | return 0; | ||

44 | #endif | 257 | #endif | ||

45 | 258 | | |||

259 | | ||||

260 | float fl = 0; | ||||

261 | | ||||

262 | if (fl == 0) | ||||

263 | return 0; | ||||

264 | if (fl != 0) | ||||

265 | return 0; | ||||

266 | if (fl < 0) | ||||

267 | return 0; | ||||

268 | if (fl <= 0) | ||||

269 | return 0; | ||||

270 | if (fl > 0) | ||||

271 | return 0; | ||||

272 | if (fl >= 0) | ||||

273 | return 0; | ||||

274 | | ||||

275 | if (0 == fl) | ||||

276 | return 0; | ||||

277 | if (0 != fl) | ||||

278 | return 0; | ||||

279 | if (0 < fl) | ||||

280 | return 0; | ||||

281 | if (0 <= fl) | ||||

282 | return 0; | ||||

283 | if (0 > fl) | ||||

284 | return 0; | ||||

285 | if (0 >= fl) | ||||

286 | return 0; | ||||

287 | | ||||

288 | if (fl == 0UL) | ||||

289 | return 0; | ||||

290 | if (fl != 0UL) | ||||

291 | return 0; | ||||

292 | if (fl < 0UL) | ||||

293 | return 0; | ||||

294 | if (fl <= 0UL) | ||||

295 | return 0; | ||||

296 | if (fl > 0UL) | ||||

297 | return 0; | ||||

298 | if (fl >= 0UL) | ||||

299 | return 0; | ||||

300 | | ||||

301 | if (0UL == fl) | ||||

302 | return 0; | ||||

303 | if (0UL != fl) | ||||

304 | return 0; | ||||

305 | if (0UL < fl) | ||||

306 | return 0; | ||||

307 | if (0UL <= fl) | ||||

308 | return 0; | ||||

309 | if (0UL > fl) | ||||

310 | return 0; | ||||

311 | if (0UL >= fl) | ||||

312 | return 0; | ||||

313 | | ||||

314 | | ||||

315 | double dl = 0; | ||||

316 | | ||||

317 | if (dl == 0) | ||||

318 | return 0; | ||||

319 | if (dl != 0) | ||||

320 | return 0; | ||||

321 | if (dl < 0) | ||||

322 | return 0; | ||||

323 | if (dl <= 0) | ||||

324 | return 0; | ||||

325 | if (dl > 0) | ||||

326 | return 0; | ||||

327 | if (dl >= 0) | ||||

328 | return 0; | ||||

329 | | ||||

330 | if (0 == dl) | ||||

331 | return 0; | ||||

332 | if (0 != dl) | ||||

333 | return 0; | ||||

334 | if (0 < dl) | ||||

335 | return 0; | ||||

336 | if (0 <= dl) | ||||

337 | return 0; | ||||

338 | if (0 > dl) | ||||

339 | return 0; | ||||

340 | if (0 >= dl) | ||||

341 | return 0; | ||||

342 | | ||||

343 | if (dl == 0UL) | ||||

344 | return 0; | ||||

345 | if (dl != 0UL) | ||||

346 | return 0; | ||||

347 | if (dl < 0UL) | ||||

348 | return 0; | ||||

349 | if (dl <= 0UL) | ||||

350 | return 0; | ||||

351 | if (dl > 0UL) | ||||

352 | return 0; | ||||

353 | if (dl >= 0UL) | ||||

354 | return 0; | ||||

355 | | ||||

356 | if (0UL == dl) | ||||

357 | return 0; | ||||

358 | if (0UL != dl) | ||||

359 | return 0; | ||||

360 | if (0UL < dl) | ||||

361 | return 0; | ||||

362 | if (0UL <= dl) | ||||

363 | return 0; | ||||

364 | if (0UL > dl) | ||||

365 | return 0; | ||||

366 | if (0UL >= dl) | ||||

367 | return 0; | ||||

368 | | ||||

46 | return 1; | 369 | return 1; | ||

47 | } | 370 | } |