# Changeset View

Changeset View

# Standalone View

Standalone View

# test/Sema/outof-range-constant-compare.c

1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -Wtautological-constant-out-of-range-compare -verify %s | 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -Wtautological-constant-out-of-range-compare -verify %s | ||
---|---|---|---|---|---|

2 | // rdar://12202422 | 2 | // rdar://12202422 | ||

3 | 3 | | |||

4 | int value(void); | 4 | int value(void); | ||

5 | 5 | | |||

6 | int main() | 6 | int main() | ||

7 | { | 7 | { | ||

8 | int a = value(); | 8 | int a = value(); | ||

9 | 9 | | |||

10 | if (a == 0x0000000000000000L) | | |||

11 | return 0; | | |||

12 | if (a != 0x0000000000000000L) | | |||

13 | return 0; | | |||

14 | if (a < 0x0000000000000000L) | | |||

15 | return 0; | | |||

16 | if (a <= 0x0000000000000000L) | | |||

17 | return 0; | | |||

18 | if (a > 0x0000000000000000L) | | |||

19 | return 0; | | |||

20 | if (a >= 0x0000000000000000L) | | |||

21 | return 0; | | |||

22 | | ||||

23 | if (0x0000000000000000L == a) | | |||

24 | return 0; | | |||

25 | if (0x0000000000000000L != a) | | |||

26 | return 0; | | |||

27 | if (0x0000000000000000L < a) | | |||

28 | return 0; | | |||

29 | if (0x0000000000000000L <= a) | | |||

30 | return 0; | | |||

31 | if (0x0000000000000000L > a) | | |||

32 | return 0; | | |||

33 | if (0x0000000000000000L >= a) | | |||

34 | return 0; | | |||

35 | | ||||

36 | if (a == 0x0000000000000000UL) | | |||

37 | return 0; | | |||

38 | if (a != 0x0000000000000000UL) | | |||

39 | return 0; | | |||

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

41 | return 0; | | |||

42 | if (a <= 0x0000000000000000UL) | | |||

43 | return 0; | | |||

44 | if (a > 0x0000000000000000UL) | | |||

45 | return 0; | | |||

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

47 | return 0; | | |||

48 | | ||||

49 | if (0x0000000000000000UL == a) | | |||

50 | return 0; | | |||

51 | if (0x0000000000000000UL != a) | | |||

52 | return 0; | | |||

53 | if (0x0000000000000000UL < a) | | |||

54 | return 0; | | |||

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

56 | return 0; | | |||

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

58 | return 0; | | |||

59 | if (0x0000000000000000UL >= a) | | |||

60 | return 0; | | |||

61 | | ||||

62 | if (a == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} | 10 | if (a == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} | ||

63 | return 0; | 11 | return 0; | ||

64 | if (a != 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} | 12 | if (a != 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} | ||

65 | return 0; | 13 | return 0; | ||

66 | if (a < 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} | 14 | if (a < 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} | ||

67 | return 0; | 15 | return 0; | ||

68 | if (a <= 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} | 16 | if (a <= 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} | ||

69 | return 0; | 17 | return 0; | ||

▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Line(s) | 97 | if (0x1234567812345678L < l) | |||

150 | return 0; | 98 | return 0; | ||

151 | if (0x1234567812345678L <= l) | 99 | if (0x1234567812345678L <= l) | ||

152 | return 0; | 100 | return 0; | ||

153 | if (0x1234567812345678L > l) | 101 | if (0x1234567812345678L > l) | ||

154 | return 0; | 102 | return 0; | ||

155 | if (0x1234567812345678L >= l) | 103 | if (0x1234567812345678L >= l) | ||

156 | return 0; | 104 | return 0; | ||

157 | 105 | | |||

158 | unsigned un = 0; | | |||

159 | if (un == 0x0000000000000000L) | | |||

160 | return 0; | | |||

161 | if (un != 0x0000000000000000L) | | |||

162 | return 0; | | |||

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

164 | return 0; | | |||

165 | if (un <= 0x0000000000000000L) | | |||

166 | return 0; | | |||

167 | if (un > 0x0000000000000000L) | | |||

168 | return 0; | | |||

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

170 | return 0; | | |||

171 | | ||||

172 | if (0x0000000000000000L == un) | | |||

173 | return 0; | | |||

174 | if (0x0000000000000000L != un) | | |||

175 | return 0; | | |||

176 | if (0x0000000000000000L < un) | | |||

177 | return 0; | | |||

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

179 | return 0; | | |||

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

181 | return 0; | | |||

182 | if (0x0000000000000000L >= un) | | |||

183 | return 0; | | |||

184 | | ||||

185 | if (un == 0x0000000000000000UL) | | |||

186 | return 0; | | |||

187 | if (un != 0x0000000000000000UL) | | |||

188 | return 0; | | |||

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

190 | return 0; | | |||

191 | if (un <= 0x0000000000000000UL) | | |||

192 | return 0; | | |||

193 | if (un > 0x0000000000000000UL) | | |||

194 | return 0; | | |||

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

196 | return 0; | | |||

197 | | ||||

198 | if (0x0000000000000000UL == un) | | |||

199 | return 0; | | |||

200 | if (0x0000000000000000UL != un) | | |||

201 | return 0; | | |||

202 | if (0x0000000000000000UL < un) | | |||

203 | return 0; | | |||

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

205 | return 0; | | |||

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

207 | return 0; | | |||

208 | if (0x0000000000000000UL >= un) | | |||

209 | return 0; | | |||

210 | | ||||

211 | float fl = 0; | | |||

212 | if (fl == 0x0000000000000000L) | | |||

213 | return 0; | | |||

214 | if (fl != 0x0000000000000000L) | | |||

215 | return 0; | | |||

216 | if (fl < 0x0000000000000000L) | | |||

217 | return 0; | | |||

218 | if (fl <= 0x0000000000000000L) | | |||

219 | return 0; | | |||

220 | if (fl > 0x0000000000000000L) | | |||

221 | return 0; | | |||

222 | if (fl >= 0x0000000000000000L) | | |||

223 | return 0; | | |||

224 | | ||||

225 | if (0x0000000000000000L == fl) | | |||

226 | return 0; | | |||

227 | if (0x0000000000000000L != fl) | | |||

228 | return 0; | | |||

229 | if (0x0000000000000000L < fl) | | |||

230 | return 0; | | |||

231 | if (0x0000000000000000L <= fl) | | |||

232 | return 0; | | |||

233 | if (0x0000000000000000L > fl) | | |||

234 | return 0; | | |||

235 | if (0x0000000000000000L >= fl) | | |||

236 | return 0; | | |||

237 | | ||||

238 | double dl = 0; | | |||

239 | if (dl == 0x0000000000000000L) | | |||

240 | return 0; | | |||

241 | if (dl != 0x0000000000000000L) | | |||

242 | return 0; | | |||

243 | if (dl < 0x0000000000000000L) | | |||

244 | return 0; | | |||

245 | if (dl <= 0x0000000000000000L) | | |||

246 | return 0; | | |||

247 | if (dl > 0x0000000000000000L) | | |||

248 | return 0; | | |||

249 | if (dl >= 0x0000000000000000L) | | |||

250 | return 0; | | |||

251 | | ||||

252 | if (0x0000000000000000L == dl) | | |||

253 | return 0; | | |||

254 | if (0x0000000000000000L != dl) | | |||

255 | return 0; | | |||

256 | if (0x0000000000000000L < dl) | | |||

257 | return 0; | | |||

258 | if (0x0000000000000000L <= dl) | | |||

259 | return 0; | | |||

260 | if (0x0000000000000000L > dl) | | |||

261 | return 0; | | |||

262 | if (0x0000000000000000L >= dl) | | |||

263 | return 0; | | |||

264 | | ||||

265 | enum E { | 106 | enum E { | ||

266 | yes, | 107 | yes, | ||

267 | no, | 108 | no, | ||

268 | maybe | 109 | maybe | ||

269 | }; | 110 | }; | ||

270 | enum E e; | 111 | enum E e; | ||

271 | 112 | | |||

272 | if (e == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'enum E' is always false}} | 113 | if (e == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'enum E' is always false}} | ||

273 | return 0; | 114 | return 0; | ||

274 | 115 | | |||

275 | return 1; | 116 | return 1; | ||

276 | } | 117 | } |