1 // RUN: %clang_analyze_cc1 \
2 // RUN: -analyzer-checker=debug.ExprInspection,core.builtin \
3 // RUN: -analyzer-config aggressive-binary-operation-simplification=true \
4 // RUN: -analyzer-config support-symbolic-integer-casts=false \
5 // RUN: -analyzer-config eagerly-assume=false \
8 // RUN: %clang_analyze_cc1 \
9 // RUN: -analyzer-checker=debug.ExprInspection,core.builtin \
10 // RUN: -analyzer-config aggressive-binary-operation-simplification=true \
11 // RUN: -analyzer-config support-symbolic-integer-casts=true \
12 // RUN: -DSUPPORT_SYMBOLIC_INTEGER_CASTS \
13 // RUN: -analyzer-config eagerly-assume=false \
16 void clang_analyzer_eval(bool x
);
18 void clang_analyzer_denote(T x
, const char *literal
);
20 void clang_analyzer_express(T x
);
24 #define UINT_MAX (~0U)
25 #define INT_MAX (UINT_MAX & (UINT_MAX >> 1))
27 extern void __assert_fail (__const
char *__assertion
, __const
char *__file
,
28 unsigned int __line
, __const
char *__function
)
29 __attribute__ ((__noreturn__
));
30 #define assert(expr) \
31 ((expr) ? (void)(0) : __assert_fail (#expr, __FILE__, __LINE__, __func__))
36 // Assert that no overflows occur in this test file.
37 // Assuming that concrete integers are also within that range.
38 assert(x
<= ((int)INT_MAX
/ 4));
39 assert(x
>= -((int)INT_MAX
/ 4));
43 void compare_different_symbol_equal(void) {
45 clang_analyzer_denote(x
, "$x");
46 clang_analyzer_denote(y
, "$y");
47 clang_analyzer_express(x
== y
); // expected-warning {{$x - $y == 0}}
50 void compare_different_symbol_plus_left_int_equal(void) {
52 clang_analyzer_denote(x
, "$x");
53 clang_analyzer_denote(y
, "$y");
55 clang_analyzer_express(x
== y
); // expected-warning {{$y - $x == 1}}
58 void compare_different_symbol_minus_left_int_equal(void) {
60 clang_analyzer_denote(x
, "$x");
61 clang_analyzer_denote(y
, "$y");
63 clang_analyzer_express(x
== y
); // expected-warning {{$x - $y == 1}}
66 void compare_different_symbol_plus_right_int_equal(void) {
68 clang_analyzer_denote(x
, "$x");
69 clang_analyzer_denote(y
, "$y");
71 clang_analyzer_express(y
); // expected-warning {{$y + 2}}
72 clang_analyzer_express(x
== y
); // expected-warning {{$x - $y == 2}}
75 void compare_different_symbol_minus_right_int_equal(void) {
77 clang_analyzer_denote(x
, "$x");
78 clang_analyzer_denote(y
, "$y");
80 clang_analyzer_express(y
); // expected-warning {{$y - 2}}
81 clang_analyzer_express(x
== y
); // expected-warning {{$y - $x == 2}}
84 void compare_different_symbol_plus_left_plus_right_int_equal(void) {
86 clang_analyzer_denote(x
, "$x");
87 clang_analyzer_denote(y
, "$y");
90 clang_analyzer_express(x
); // expected-warning {{$x + 2}}
91 clang_analyzer_express(y
); // expected-warning {{$y + 1}}
92 clang_analyzer_express(x
== y
); // expected-warning {{$y - $x == 1}}
95 void compare_different_symbol_plus_left_minus_right_int_equal(void) {
97 clang_analyzer_denote(x
, "$x");
98 clang_analyzer_denote(y
, "$y");
101 clang_analyzer_express(x
); // expected-warning {{$x + 2}}
102 clang_analyzer_express(y
); // expected-warning {{$y - 1}}
103 clang_analyzer_express(x
== y
); // expected-warning {{$y - $x == 3}}
106 void compare_different_symbol_minus_left_plus_right_int_equal(void) {
107 int x
= f(), y
= f();
108 clang_analyzer_denote(x
, "$x");
109 clang_analyzer_denote(y
, "$y");
112 clang_analyzer_express(x
); // expected-warning {{$x - 2}}
113 clang_analyzer_express(y
); // expected-warning {{$y + 1}}
114 clang_analyzer_express(x
== y
); // expected-warning {{$x - $y == 3}}
117 void compare_different_symbol_minus_left_minus_right_int_equal(void) {
118 int x
= f(), y
= f();
119 clang_analyzer_denote(x
, "$x");
120 clang_analyzer_denote(y
, "$y");
123 clang_analyzer_express(x
); // expected-warning {{$x - 2}}
124 clang_analyzer_express(y
); // expected-warning {{$y - 1}}
125 clang_analyzer_express(x
== y
); // expected-warning {{$x - $y == 1}}
128 void compare_same_symbol_equal(void) {
130 clang_analyzer_denote(x
, "$x");
131 clang_analyzer_express(y
); // expected-warning {{$x}}
132 clang_analyzer_eval(x
== y
); // expected-warning {{TRUE}}
135 void compare_same_symbol_plus_left_int_equal(void) {
137 clang_analyzer_denote(x
, "$x");
139 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
140 clang_analyzer_express(y
); // expected-warning {{$x}}
141 clang_analyzer_eval(x
== y
); // expected-warning {{FALSE}}
144 void compare_same_symbol_minus_left_int_equal(void) {
146 clang_analyzer_denote(x
, "$x");
148 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
149 clang_analyzer_express(y
); // expected-warning {{$x}}
150 clang_analyzer_eval(x
== y
); // expected-warning {{FALSE}}
153 void compare_same_symbol_plus_right_int_equal(void) {
154 int x
= f(), y
= x
+ 1;
155 clang_analyzer_denote(x
, "$x");
156 clang_analyzer_express(y
); // expected-warning {{$x + 1}}
157 clang_analyzer_eval(x
== y
); // expected-warning {{FALSE}}
160 void compare_same_symbol_minus_right_int_equal(void) {
161 int x
= f(), y
= x
- 1;
162 clang_analyzer_denote(x
, "$x");
163 clang_analyzer_express(y
); // expected-warning {{$x - 1}}
164 clang_analyzer_eval(x
== y
); // expected-warning {{FALSE}}
167 void compare_same_symbol_plus_left_plus_right_int_equal(void) {
168 int x
= f(), y
= x
+ 1;
169 clang_analyzer_denote(x
, "$x");
171 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
172 clang_analyzer_express(y
); // expected-warning {{$x + 1}}
173 clang_analyzer_eval(x
== y
); // expected-warning {{TRUE}}
176 void compare_same_symbol_plus_left_minus_right_int_equal(void) {
177 int x
= f(), y
= x
- 1;
178 clang_analyzer_denote(x
, "$x");
180 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
181 clang_analyzer_express(y
); // expected-warning {{$x - 1}}
182 clang_analyzer_eval(x
== y
); // expected-warning {{FALSE}}
185 void compare_same_symbol_minus_left_plus_right_int_equal(void) {
186 int x
= f(), y
= x
+ 1;
187 clang_analyzer_denote(x
, "$x");
189 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
190 clang_analyzer_express(y
); // expected-warning {{$x + 1}}
191 clang_analyzer_eval(x
== y
); // expected-warning {{FALSE}}
194 void compare_same_symbol_minus_left_minus_right_int_equal(void) {
195 int x
= f(), y
= x
- 1;
196 clang_analyzer_denote(x
, "$x");
198 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
199 clang_analyzer_express(y
); // expected-warning {{$x - 1}}
200 clang_analyzer_eval(x
== y
); // expected-warning {{TRUE}}
203 void compare_different_symbol_less_or_equal(void) {
204 int x
= f(), y
= f();
205 clang_analyzer_denote(x
, "$x");
206 clang_analyzer_denote(y
, "$y");
207 clang_analyzer_express(x
<= y
); // expected-warning {{$x - $y <= 0}}
210 void compare_different_symbol_plus_left_int_less_or_equal(void) {
211 int x
= f(), y
= f();
212 clang_analyzer_denote(x
, "$x");
213 clang_analyzer_denote(y
, "$y");
215 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
216 clang_analyzer_express(x
<= y
); // expected-warning {{$y - $x >= 1}}
219 void compare_different_symbol_minus_left_int_less_or_equal(void) {
220 int x
= f(), y
= f();
221 clang_analyzer_denote(x
, "$x");
222 clang_analyzer_denote(y
, "$y");
224 clang_analyzer_express(x
<= y
); // expected-warning {{$x - $y <= 1}}
227 void compare_different_symbol_plus_right_int_less_or_equal(void) {
228 int x
= f(), y
= f();
229 clang_analyzer_denote(x
, "$x");
230 clang_analyzer_denote(y
, "$y");
232 clang_analyzer_express(x
<= y
); // expected-warning {{$x - $y <= 2}}
235 void compare_different_symbol_minus_right_int_less_or_equal(void) {
236 int x
= f(), y
= f();
237 clang_analyzer_denote(x
, "$x");
238 clang_analyzer_denote(y
, "$y");
240 clang_analyzer_express(y
); // expected-warning {{$y - 2}}
241 clang_analyzer_express(x
<= y
); // expected-warning {{$y - $x >= 2}}
244 void compare_different_symbol_plus_left_plus_right_int_less_or_equal(void) {
245 int x
= f(), y
= f();
246 clang_analyzer_denote(x
, "$x");
247 clang_analyzer_denote(y
, "$y");
250 clang_analyzer_express(x
); // expected-warning {{$x + 2}}
251 clang_analyzer_express(y
); // expected-warning {{$y + 1}}
252 clang_analyzer_express(x
<= y
); // expected-warning {{$y - $x >= 1}}
255 void compare_different_symbol_plus_left_minus_right_int_less_or_equal(void) {
256 int x
= f(), y
= f();
257 clang_analyzer_denote(x
, "$x");
258 clang_analyzer_denote(y
, "$y");
261 clang_analyzer_express(x
); // expected-warning {{$x + 2}}
262 clang_analyzer_express(y
); // expected-warning {{$y - 1}}
263 clang_analyzer_express(x
<= y
); // expected-warning {{$y - $x >= 3}}
266 void compare_different_symbol_minus_left_plus_right_int_less_or_equal(void) {
267 int x
= f(), y
= f();
268 clang_analyzer_denote(x
, "$x");
269 clang_analyzer_denote(y
, "$y");
272 clang_analyzer_express(x
); // expected-warning {{$x - 2}}
273 clang_analyzer_express(y
); // expected-warning {{$y + 1}}
274 clang_analyzer_express(x
<= y
); // expected-warning {{$x - $y <= 3}}
277 void compare_different_symbol_minus_left_minus_right_int_less_or_equal(void) {
278 int x
= f(), y
= f();
279 clang_analyzer_denote(x
, "$x");
280 clang_analyzer_denote(y
, "$y");
283 clang_analyzer_express(x
); // expected-warning {{$x - 2}}
284 clang_analyzer_express(y
); // expected-warning {{$y - 1}}
285 clang_analyzer_express(x
<= y
); // expected-warning {{$x - $y <= 1}}
288 void compare_same_symbol_less_or_equal(void) {
290 clang_analyzer_denote(x
, "$x");
291 clang_analyzer_express(y
); // expected-warning {{$x}}
292 clang_analyzer_eval(x
<= y
); // expected-warning {{TRUE}}
295 void compare_same_symbol_plus_left_int_less_or_equal(void) {
297 clang_analyzer_denote(x
, "$x");
299 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
300 clang_analyzer_express(y
); // expected-warning {{$x}}
301 clang_analyzer_eval(x
<= y
); // expected-warning {{FALSE}}
304 void compare_same_symbol_minus_left_int_less_or_equal(void) {
306 clang_analyzer_denote(x
, "$x");
308 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
309 clang_analyzer_express(y
); // expected-warning {{$x}}
310 clang_analyzer_eval(x
<= y
); // expected-warning {{TRUE}}
313 void compare_same_symbol_plus_right_int_less_or_equal(void) {
314 int x
= f(), y
= x
+ 1;
315 clang_analyzer_denote(x
, "$x");
316 clang_analyzer_express(y
); // expected-warning {{$x + 1}}
317 clang_analyzer_eval(x
<= y
); // expected-warning {{TRUE}}
320 void compare_same_symbol_minus_right_int_less_or_equal(void) {
321 int x
= f(), y
= x
- 1;
322 clang_analyzer_denote(x
, "$x");
323 clang_analyzer_express(y
); // expected-warning {{$x - 1}}
324 clang_analyzer_eval(x
<= y
); // expected-warning {{FALSE}}
327 void compare_same_symbol_plus_left_plus_right_int_less_or_equal(void) {
328 int x
= f(), y
= x
+ 1;
329 clang_analyzer_denote(x
, "$x");
331 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
332 clang_analyzer_express(y
); // expected-warning {{$x + 1}}
333 clang_analyzer_eval(x
<= y
); // expected-warning {{TRUE}}
336 void compare_same_symbol_plus_left_minus_right_int_less_or_equal(void) {
337 int x
= f(), y
= x
- 1;
338 clang_analyzer_denote(x
, "$x");
340 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
341 clang_analyzer_express(y
); // expected-warning {{$x - 1}}
342 clang_analyzer_eval(x
<= y
); // expected-warning {{FALSE}}
345 void compare_same_symbol_minus_left_plus_right_int_less_or_equal(void) {
346 int x
= f(), y
= x
+ 1;
347 clang_analyzer_denote(x
, "$x");
349 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
350 clang_analyzer_express(y
); // expected-warning {{$x + 1}}
351 clang_analyzer_eval(x
<= y
); // expected-warning {{TRUE}}
354 void compare_same_symbol_minus_left_minus_right_int_less_or_equal(void) {
355 int x
= f(), y
= x
- 1;
356 clang_analyzer_denote(x
, "$x");
358 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
359 clang_analyzer_express(y
); // expected-warning {{$x - 1}}
360 clang_analyzer_eval(x
<= y
); // expected-warning {{TRUE}}
363 void compare_different_symbol_less(void) {
364 int x
= f(), y
= f();
365 clang_analyzer_denote(x
, "$x");
366 clang_analyzer_denote(y
, "$y");
367 clang_analyzer_express(y
); // expected-warning {{$y}}
368 clang_analyzer_express(x
< y
); // expected-warning {{$x - $y < 0}}
371 void compare_different_symbol_plus_left_int_less(void) {
372 int x
= f(), y
= f();
373 clang_analyzer_denote(x
, "$x");
374 clang_analyzer_denote(y
, "$y");
376 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
377 clang_analyzer_express(y
); // expected-warning {{$y}}
378 clang_analyzer_express(x
< y
); // expected-warning {{$y - $x > 1}}
381 void compare_different_symbol_minus_left_int_less(void) {
382 int x
= f(), y
= f();
383 clang_analyzer_denote(x
, "$x");
384 clang_analyzer_denote(y
, "$y");
386 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
387 clang_analyzer_express(y
); // expected-warning {{$y}}
388 clang_analyzer_express(x
< y
); // expected-warning {{$x - $y < 1}}
391 void compare_different_symbol_plus_right_int_less(void) {
392 int x
= f(), y
= f();
393 clang_analyzer_denote(x
, "$x");
394 clang_analyzer_denote(y
, "$y");
396 clang_analyzer_express(y
); // expected-warning {{$y + 2}}
397 clang_analyzer_express(x
< y
); // expected-warning {{$x - $y < 2}}
400 void compare_different_symbol_minus_right_int_less(void) {
401 int x
= f(), y
= f();
402 clang_analyzer_denote(x
, "$x");
403 clang_analyzer_denote(y
, "$y");
405 clang_analyzer_express(y
); // expected-warning {{$y - 2}}
406 clang_analyzer_express(x
< y
); // expected-warning {{$y - $x > 2}}
409 void compare_different_symbol_plus_left_plus_right_int_less(void) {
410 int x
= f(), y
= f();
411 clang_analyzer_denote(x
, "$x");
412 clang_analyzer_denote(y
, "$y");
415 clang_analyzer_express(x
); // expected-warning {{$x + 2}}
416 clang_analyzer_express(y
); // expected-warning {{$y + 1}}
417 clang_analyzer_express(x
< y
); // expected-warning {{$y - $x > 1}}
420 void compare_different_symbol_plus_left_minus_right_int_less(void) {
421 int x
= f(), y
= f();
422 clang_analyzer_denote(x
, "$x");
423 clang_analyzer_denote(y
, "$y");
426 clang_analyzer_express(x
); // expected-warning {{$x + 2}}
427 clang_analyzer_express(y
); // expected-warning {{$y - 1}}
428 clang_analyzer_express(x
< y
); // expected-warning {{$y - $x > 3}}
431 void compare_different_symbol_minus_left_plus_right_int_less(void) {
432 int x
= f(), y
= f();
433 clang_analyzer_denote(x
, "$x");
434 clang_analyzer_denote(y
, "$y");
437 clang_analyzer_express(x
); // expected-warning {{$x - 2}}
438 clang_analyzer_express(y
); // expected-warning {{$y + 1}}
439 clang_analyzer_express(x
< y
); // expected-warning {{$x - $y < 3}}
442 void compare_different_symbol_minus_left_minus_right_int_less(void) {
443 int x
= f(), y
= f();
444 clang_analyzer_denote(x
, "$x");
445 clang_analyzer_denote(y
, "$y");
448 clang_analyzer_express(x
); // expected-warning {{$x - 2}}
449 clang_analyzer_express(y
); // expected-warning {{$y - 1}}
450 clang_analyzer_express(x
< y
); // expected-warning {{$x - $y < 1}}
453 void compare_same_symbol_less(void) {
455 clang_analyzer_denote(x
, "$x");
456 clang_analyzer_express(y
); // expected-warning {{$x}}
457 clang_analyzer_eval(x
< y
); // expected-warning {{FALSE}}
460 void compare_same_symbol_plus_left_int_less(void) {
462 clang_analyzer_denote(x
, "$x");
464 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
465 clang_analyzer_express(y
); // expected-warning {{$x}}
466 clang_analyzer_eval(x
< y
); // expected-warning {{FALSE}}
469 void compare_same_symbol_minus_left_int_less(void) {
471 clang_analyzer_denote(x
, "$x");
473 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
474 clang_analyzer_express(y
); // expected-warning {{$x}}
475 clang_analyzer_eval(x
< y
); // expected-warning {{TRUE}}
478 void compare_same_symbol_plus_right_int_less(void) {
479 int x
= f(), y
= x
+ 1;
480 clang_analyzer_denote(x
, "$x");
481 clang_analyzer_express(y
); // expected-warning {{$x + 1}}
482 clang_analyzer_eval(x
< y
); // expected-warning {{TRUE}}
485 void compare_same_symbol_minus_right_int_less(void) {
486 int x
= f(), y
= x
- 1;
487 clang_analyzer_denote(x
, "$x");
488 clang_analyzer_express(y
); // expected-warning {{$x - 1}}
489 clang_analyzer_eval(x
< y
); // expected-warning {{FALSE}}
492 void compare_same_symbol_plus_left_plus_right_int_less(void) {
493 int x
= f(), y
= x
+ 1;
494 clang_analyzer_denote(x
, "$x");
496 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
497 clang_analyzer_express(y
); // expected-warning {{$x + 1}}
498 clang_analyzer_eval(x
< y
); // expected-warning {{FALSE}}
501 void compare_same_symbol_plus_left_minus_right_int_less(void) {
502 int x
= f(), y
= x
- 1;
503 clang_analyzer_denote(x
, "$x");
505 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
506 clang_analyzer_express(y
); // expected-warning {{$x - 1}}
507 clang_analyzer_eval(x
< y
); // expected-warning {{FALSE}}
510 void compare_same_symbol_minus_left_plus_right_int_less(void) {
511 int x
= f(), y
= x
+ 1;
512 clang_analyzer_denote(x
, "$x");
514 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
515 clang_analyzer_express(y
); // expected-warning {{$x + 1}}
516 clang_analyzer_eval(x
< y
); // expected-warning {{TRUE}}
519 void compare_same_symbol_minus_left_minus_right_int_less(void) {
520 int x
= f(), y
= x
- 1;
521 clang_analyzer_denote(x
, "$x");
523 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
524 clang_analyzer_express(y
); // expected-warning {{$x - 1}}
525 clang_analyzer_eval(x
< y
); // expected-warning {{FALSE}}
528 // Rearrange should happen on signed types only (tryRearrange):
530 // // Rearrange signed symbolic expressions only
531 // if (!SingleTy->isSignedIntegerOrEnumerationType())
532 // return std::nullopt;
534 // Without the symbolic casts, the SVal for `x` in `unsigned x = f()` will be
535 // the signed `int`. However, with the symbolic casts it will be `unsigned`.
536 // Thus, these tests are meaningful only if the cast is not emitted.
537 #ifndef SUPPORT_SYMBOLIC_INTEGER_CASTS
539 void compare_different_symbol_equal_unsigned(void) {
540 unsigned x
= f(), y
= f();
541 clang_analyzer_denote(x
, "$x");
542 clang_analyzer_denote(y
, "$y");
543 clang_analyzer_express(y
); // expected-warning {{$y}}
544 clang_analyzer_express(x
== y
); // expected-warning {{$x - $y == 0}}
547 void compare_different_symbol_plus_left_int_equal_unsigned(void) {
548 unsigned x
= f() + 1, y
= f();
549 clang_analyzer_denote(x
- 1, "$x");
550 clang_analyzer_denote(y
, "$y");
551 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
552 clang_analyzer_express(y
); // expected-warning {{$y}}
553 clang_analyzer_express(x
== y
); // expected-warning {{$y - $x == 1}}
556 void compare_different_symbol_minus_left_int_equal_unsigned(void) {
557 unsigned x
= f() - 1, y
= f();
558 clang_analyzer_denote(x
+ 1, "$x");
559 clang_analyzer_denote(y
, "$y");
560 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
561 clang_analyzer_express(y
); // expected-warning {{$y}}
562 clang_analyzer_express(x
== y
); // expected-warning {{$x - $y == 1}}
565 void compare_different_symbol_plus_right_int_equal_unsigned(void) {
566 unsigned x
= f(), y
= f() + 2;
567 clang_analyzer_denote(x
, "$x");
568 clang_analyzer_denote(y
- 2, "$y");
569 clang_analyzer_express(y
); // expected-warning {{$y + 2}}
570 clang_analyzer_express(x
== y
); // expected-warning {{$x - $y == 2}}
573 void compare_different_symbol_minus_right_int_equal_unsigned(void) {
574 unsigned x
= f(), y
= f() - 2;
575 clang_analyzer_denote(x
, "$x");
576 clang_analyzer_denote(y
+ 2, "$y");
577 clang_analyzer_express(y
); // expected-warning {{$y - 2}}
578 clang_analyzer_express(x
== y
); // expected-warning {{$y - $x == 2}}
581 void compare_different_symbol_plus_left_plus_right_int_equal_unsigned(void) {
582 unsigned x
= f() + 2, y
= f() + 1;
583 clang_analyzer_denote(x
- 2, "$x");
584 clang_analyzer_denote(y
- 1, "$y");
585 clang_analyzer_express(x
); // expected-warning {{$x + 2}}
586 clang_analyzer_express(y
); // expected-warning {{$y + 1}}
587 clang_analyzer_express(x
== y
); // expected-warning {{$y - $x == 1}}
590 void compare_different_symbol_plus_left_minus_right_int_equal_unsigned(void) {
591 unsigned x
= f() + 2, y
= f() - 1;
592 clang_analyzer_denote(x
- 2, "$x");
593 clang_analyzer_denote(y
+ 1, "$y");
594 clang_analyzer_express(x
); // expected-warning {{$x + 2}}
595 clang_analyzer_express(y
); // expected-warning {{$y - 1}}
596 clang_analyzer_express(x
== y
); // expected-warning {{$y - $x == 3}}
599 void compare_different_symbol_minus_left_plus_right_int_equal_unsigned(void) {
600 unsigned x
= f() - 2, y
= f() + 1;
601 clang_analyzer_denote(x
+ 2, "$x");
602 clang_analyzer_denote(y
- 1, "$y");
603 clang_analyzer_express(x
); // expected-warning {{$x - 2}}
604 clang_analyzer_express(y
); // expected-warning {{$y + 1}}
605 clang_analyzer_express(x
== y
); // expected-warning {{$x - $y == 3}}
608 void compare_different_symbol_minus_left_minus_right_int_equal_unsigned(void) {
609 unsigned x
= f() - 2, y
= f() - 1;
610 clang_analyzer_denote(x
+ 2, "$x");
611 clang_analyzer_denote(y
+ 1, "$y");
612 clang_analyzer_express(x
); // expected-warning {{$x - 2}}
613 clang_analyzer_express(y
); // expected-warning {{$y - 1}}
614 clang_analyzer_express(x
== y
); // expected-warning {{$x - $y == 1}}
617 void compare_same_symbol_equal_unsigned(void) {
618 unsigned x
= f(), y
= x
;
619 clang_analyzer_denote(x
, "$x");
620 clang_analyzer_express(y
); // expected-warning {{$x}}
621 clang_analyzer_eval(x
== y
); // expected-warning {{TRUE}}
624 void compare_same_symbol_plus_left_int_equal_unsigned(void) {
625 unsigned x
= f(), y
= x
;
626 clang_analyzer_denote(x
, "$x");
628 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
629 clang_analyzer_express(y
); // expected-warning {{$x}}
630 clang_analyzer_express(x
== y
); // expected-warning {{$x + 1U == $x}}
633 void compare_same_symbol_minus_left_int_equal_unsigned(void) {
634 unsigned x
= f(), y
= x
;
635 clang_analyzer_denote(x
, "$x");
637 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
638 clang_analyzer_express(y
); // expected-warning {{$x}}
639 clang_analyzer_express(x
== y
); // expected-warning {{$x - 1U == $x}}
642 void compare_same_symbol_plus_right_int_equal_unsigned(void) {
643 unsigned x
= f(), y
= x
+ 1;
644 clang_analyzer_denote(x
, "$x");
645 clang_analyzer_express(y
); // expected-warning {{$x + 1}}
646 clang_analyzer_express(x
== y
); // expected-warning {{$x == $x + 1U}}
649 void compare_same_symbol_minus_right_int_equal_unsigned(void) {
650 unsigned x
= f(), y
= x
- 1;
651 clang_analyzer_denote(x
, "$x");
652 clang_analyzer_express(y
); // expected-warning {{$x - 1}}
653 clang_analyzer_express(x
== y
); // expected-warning {{$x == $x - 1U}}
656 void compare_same_symbol_plus_left_plus_right_int_equal_unsigned(void) {
657 unsigned x
= f(), y
= x
+ 1;
658 clang_analyzer_denote(x
, "$x");
660 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
661 clang_analyzer_express(y
); // expected-warning {{$x + 1}}
662 clang_analyzer_eval(x
== y
); // expected-warning {{TRUE}}
665 void compare_same_symbol_plus_left_minus_right_int_equal_unsigned(void) {
666 unsigned x
= f(), y
= x
- 1;
667 clang_analyzer_denote(x
, "$x");
669 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
670 clang_analyzer_express(y
); // expected-warning {{$x - 1}}
671 clang_analyzer_express(x
== y
); // expected-warning {{$x + 1U == $x - 1U}}
674 void compare_same_symbol_minus_left_plus_right_int_equal_unsigned(void) {
675 unsigned x
= f(), y
= x
+ 1;
676 clang_analyzer_denote(x
, "$x");
678 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
679 clang_analyzer_express(y
); // expected-warning {{$x + 1}}
680 clang_analyzer_express(x
== y
); // expected-warning {{$x - 1U == $x + 1U}}
683 void compare_same_symbol_minus_left_minus_right_int_equal_unsigned(void) {
684 unsigned x
= f(), y
= x
- 1;
685 clang_analyzer_denote(x
, "$x");
687 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
688 clang_analyzer_express(y
); // expected-warning {{$x - 1}}
689 clang_analyzer_eval(x
== y
); // expected-warning {{TRUE}}
692 void compare_different_symbol_less_or_equal_unsigned(void) {
693 unsigned x
= f(), y
= f();
694 clang_analyzer_denote(x
, "$x");
695 clang_analyzer_denote(y
, "$y");
696 clang_analyzer_express(y
); // expected-warning {{$y}}
697 clang_analyzer_express(x
<= y
); // expected-warning {{$x - $y <= 0}}
700 void compare_different_symbol_plus_left_int_less_or_equal_unsigned(void) {
701 unsigned x
= f() + 1, y
= f();
702 clang_analyzer_denote(x
- 1, "$x");
703 clang_analyzer_denote(y
, "$y");
704 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
705 clang_analyzer_express(y
); // expected-warning {{$y}}
706 clang_analyzer_express(x
<= y
); // expected-warning {{$y - $x >= 1}}
709 void compare_different_symbol_minus_left_int_less_or_equal_unsigned(void) {
710 unsigned x
= f() - 1, y
= f();
711 clang_analyzer_denote(x
+ 1, "$x");
712 clang_analyzer_denote(y
, "$y");
713 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
714 clang_analyzer_express(y
); // expected-warning {{$y}}
715 clang_analyzer_express(x
<= y
); // expected-warning {{$x - $y <= 1}}
718 void compare_different_symbol_plus_right_int_less_or_equal_unsigned(void) {
719 unsigned x
= f(), y
= f() + 2;
720 clang_analyzer_denote(x
, "$x");
721 clang_analyzer_denote(y
- 2, "$y");
722 clang_analyzer_express(y
); // expected-warning {{$y + 2}}
723 clang_analyzer_express(x
<= y
); // expected-warning {{$x - $y <= 2}}
726 void compare_different_symbol_minus_right_int_less_or_equal_unsigned(void) {
727 unsigned x
= f(), y
= f() - 2;
728 clang_analyzer_denote(x
, "$x");
729 clang_analyzer_denote(y
+ 2, "$y");
730 clang_analyzer_express(y
); // expected-warning {{$y - 2}}
731 clang_analyzer_express(x
<= y
); // expected-warning {{$y - $x >= 2}}
734 void compare_different_symbol_plus_left_plus_right_int_less_or_equal_unsigned(void) {
735 unsigned x
= f() + 2, y
= f() + 1;
736 clang_analyzer_denote(x
- 2, "$x");
737 clang_analyzer_denote(y
- 1, "$y");
738 clang_analyzer_express(x
); // expected-warning {{$x + 2}}
739 clang_analyzer_express(y
); // expected-warning {{$y + 1}}
740 clang_analyzer_express(x
<= y
); // expected-warning {{$y - $x >= 1}}
743 void compare_different_symbol_plus_left_minus_right_int_less_or_equal_unsigned(void) {
744 unsigned x
= f() + 2, y
= f() - 1;
745 clang_analyzer_denote(x
- 2, "$x");
746 clang_analyzer_denote(y
+ 1, "$y");
747 clang_analyzer_express(x
); // expected-warning {{$x + 2}}
748 clang_analyzer_express(y
); // expected-warning {{$y - 1}}
749 clang_analyzer_express(x
<= y
); // expected-warning {{$y - $x >= 3}}
752 void compare_different_symbol_minus_left_plus_right_int_less_or_equal_unsigned(void) {
753 unsigned x
= f() - 2, y
= f() + 1;
754 clang_analyzer_denote(x
+ 2, "$x");
755 clang_analyzer_denote(y
- 1, "$y");
756 clang_analyzer_express(x
); // expected-warning {{$x - 2}}
757 clang_analyzer_express(y
); // expected-warning {{$y + 1}}
758 clang_analyzer_express(x
<= y
); // expected-warning {{$x - $y <= 3}}
761 void compare_different_symbol_minus_left_minus_right_int_less_or_equal_unsigned(void) {
762 unsigned x
= f() - 2, y
= f() - 1;
763 clang_analyzer_denote(x
+ 2, "$x");
764 clang_analyzer_denote(y
+ 1, "$y");
765 clang_analyzer_express(x
); // expected-warning {{$x - 2}}
766 clang_analyzer_express(y
); // expected-warning {{$y - 1}}
767 clang_analyzer_express(x
<= y
); // expected-warning {{$x - $y <= 1}}
770 void compare_same_symbol_less_or_equal_unsigned(void) {
771 unsigned x
= f(), y
= x
;
772 clang_analyzer_denote(x
, "$x");
773 clang_analyzer_express(y
); // expected-warning {{$x}}
774 clang_analyzer_eval(x
<= y
); // expected-warning {{TRUE}}
777 void compare_same_symbol_plus_left_int_less_or_equal_unsigned(void) {
778 unsigned x
= f(), y
= x
;
779 clang_analyzer_denote(x
, "$x");
781 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
782 clang_analyzer_express(y
); // expected-warning {{$x}}
783 clang_analyzer_express(x
<= y
); // expected-warning {{$x + 1U <= $x}}
786 void compare_same_symbol_minus_left_int_less_or_equal_unsigned(void) {
787 unsigned x
= f(), y
= x
;
788 clang_analyzer_denote(x
, "$x");
790 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
791 clang_analyzer_express(y
); // expected-warning {{$x}}
792 clang_analyzer_express(x
<= y
); // expected-warning {{$x - 1U <= $x}}
795 void compare_same_symbol_plus_right_int_less_or_equal_unsigned(void) {
796 unsigned x
= f(), y
= x
+ 1;
797 clang_analyzer_denote(x
, "$x");
798 clang_analyzer_express(y
); // expected-warning {{$x + 1}}
799 clang_analyzer_express(x
<= y
); // expected-warning {{$x <= $x + 1U}}
802 void compare_same_symbol_minus_right_int_less_or_equal_unsigned(void) {
803 unsigned x
= f(), y
= x
- 1;
804 clang_analyzer_denote(x
, "$x");
805 clang_analyzer_express(y
); // expected-warning {{$x - 1}}
806 clang_analyzer_express(x
<= y
); // expected-warning {{$x <= $x - 1U}}
809 void compare_same_symbol_plus_left_plus_right_int_less_or_equal_unsigned(void) {
810 unsigned x
= f(), y
= x
+ 1;
811 clang_analyzer_denote(x
, "$x");
813 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
814 clang_analyzer_express(y
); // expected-warning {{$x + 1}}
815 clang_analyzer_eval(x
<= y
); // expected-warning {{TRUE}}
818 void compare_same_symbol_plus_left_minus_right_int_less_or_equal_unsigned(void) {
819 unsigned x
= f(), y
= x
- 1;
820 clang_analyzer_denote(x
, "$x");
822 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
823 clang_analyzer_express(y
); // expected-warning {{$x - 1}}
824 clang_analyzer_express(x
<= y
); // expected-warning {{$x + 1U <= $x - 1U}}
827 void compare_same_symbol_minus_left_plus_right_int_less_or_equal_unsigned(void) {
828 unsigned x
= f(), y
= x
+ 1;
829 clang_analyzer_denote(x
, "$x");
831 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
832 clang_analyzer_express(y
); // expected-warning {{$x + 1}}
833 clang_analyzer_express(x
<= y
); // expected-warning {{$x - 1U <= $x + 1U}}
836 void compare_same_symbol_minus_left_minus_right_int_less_or_equal_unsigned(void) {
837 unsigned x
= f(), y
= x
- 1;
838 clang_analyzer_denote(x
, "$x");
840 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
841 clang_analyzer_express(y
); // expected-warning {{$x - 1}}
842 clang_analyzer_eval(x
<= y
); // expected-warning {{TRUE}}
845 void compare_different_symbol_less_unsigned(void) {
846 unsigned x
= f(), y
= f();
847 clang_analyzer_denote(x
, "$x");
848 clang_analyzer_denote(y
, "$y");
849 clang_analyzer_express(y
); // expected-warning {{$y}}
850 clang_analyzer_express(x
< y
); // expected-warning {{$x - $y < 0}}
853 void compare_different_symbol_plus_left_int_less_unsigned(void) {
854 unsigned x
= f() + 1, y
= f();
855 clang_analyzer_denote(x
- 1, "$x");
856 clang_analyzer_denote(y
, "$y");
857 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
858 clang_analyzer_express(y
); // expected-warning {{$y}}
859 clang_analyzer_express(x
< y
); // expected-warning {{$y - $x > 1}}
862 void compare_different_symbol_minus_left_int_less_unsigned(void) {
863 unsigned x
= f() - 1, y
= f();
864 clang_analyzer_denote(x
+ 1, "$x");
865 clang_analyzer_denote(y
, "$y");
866 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
867 clang_analyzer_express(y
); // expected-warning {{$y}}
868 clang_analyzer_express(x
< y
); // expected-warning {{$x - $y < 1}}
871 void compare_different_symbol_plus_right_int_less_unsigned(void) {
872 unsigned x
= f(), y
= f() + 2;
873 clang_analyzer_denote(x
, "$x");
874 clang_analyzer_denote(y
- 2, "$y");
875 clang_analyzer_express(y
); // expected-warning {{$y + 2}}
876 clang_analyzer_express(x
< y
); // expected-warning {{$x - $y < 2}}
879 void compare_different_symbol_minus_right_int_less_unsigned(void) {
880 unsigned x
= f(), y
= f() - 2;
881 clang_analyzer_denote(x
, "$x");
882 clang_analyzer_denote(y
+ 2, "$y");
883 clang_analyzer_express(y
); // expected-warning {{$y - 2}}
884 clang_analyzer_express(x
< y
); // expected-warning {{$y - $x > 2}}
887 void compare_different_symbol_plus_left_plus_right_int_less_unsigned(void) {
888 unsigned x
= f() + 2, y
= f() + 1;
889 clang_analyzer_denote(x
- 2, "$x");
890 clang_analyzer_denote(y
- 1, "$y");
891 clang_analyzer_express(x
); // expected-warning {{$x + 2}}
892 clang_analyzer_express(y
); // expected-warning {{$y + 1}}
893 clang_analyzer_express(x
< y
); // expected-warning {{$y - $x > 1}}
896 void compare_different_symbol_plus_left_minus_right_int_less_unsigned(void) {
897 unsigned x
= f() + 2, y
= f() - 1;
898 clang_analyzer_denote(x
- 2, "$x");
899 clang_analyzer_denote(y
+ 1, "$y");
900 clang_analyzer_express(x
); // expected-warning {{$x + 2}}
901 clang_analyzer_express(y
); // expected-warning {{$y - 1}}
902 clang_analyzer_express(x
< y
); // expected-warning {{$y - $x > 3}}
905 void compare_different_symbol_minus_left_plus_right_int_less_unsigned(void) {
906 unsigned x
= f() - 2, y
= f() + 1;
907 clang_analyzer_denote(x
+ 2, "$x");
908 clang_analyzer_denote(y
- 1, "$y");
909 clang_analyzer_express(x
); // expected-warning {{$x - 2}}
910 clang_analyzer_express(y
); // expected-warning {{$y + 1}}
911 clang_analyzer_express(x
< y
); // expected-warning {{$x - $y < 3}}
914 void compare_different_symbol_minus_left_minus_right_int_less_unsigned(void) {
915 unsigned x
= f() - 2, y
= f() - 1;
916 clang_analyzer_denote(x
+ 2, "$x");
917 clang_analyzer_denote(y
+ 1, "$y");
918 clang_analyzer_express(x
); // expected-warning {{$x - 2}}
919 clang_analyzer_express(y
); // expected-warning {{$y - 1}}
920 clang_analyzer_express(x
< y
); // expected-warning {{$x - $y < 1}}
925 // These pass even with aggressive-binary-operation-simplification=false
927 void compare_same_symbol_less_unsigned(void) {
928 unsigned x
= f(), y
= x
;
929 clang_analyzer_denote(x
, "$x");
930 clang_analyzer_express(y
); // expected-warning {{$x}}
931 clang_analyzer_eval(x
< y
); // expected-warning {{FALSE}}
934 void compare_same_symbol_plus_left_int_less_unsigned(void) {
935 unsigned x
= f(), y
= x
;
936 clang_analyzer_denote(x
, "$x");
938 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
939 clang_analyzer_express(y
); // expected-warning {{$x}}
940 clang_analyzer_express(x
< y
); // expected-warning {{$x + 1U < $x}}
943 void compare_same_symbol_minus_left_int_less_unsigned(void) {
944 unsigned x
= f(), y
= x
;
945 clang_analyzer_denote(x
, "$x");
947 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
948 clang_analyzer_express(y
); // expected-warning {{$x}}
949 clang_analyzer_express(x
< y
); // expected-warning {{$x - 1U < $x}}
952 void compare_same_symbol_plus_right_int_less_unsigned(void) {
953 unsigned x
= f(), y
= x
+ 1;
954 clang_analyzer_denote(x
, "$x");
955 clang_analyzer_express(y
); // expected-warning {{$x + 1}}
956 clang_analyzer_express(x
< y
); // expected-warning {{$x < $x + 1U}}
959 void compare_same_symbol_minus_right_int_less_unsigned(void) {
960 unsigned x
= f(), y
= x
- 1;
961 clang_analyzer_denote(x
, "$x");
962 clang_analyzer_express(y
); // expected-warning {{$x - 1}}
963 clang_analyzer_express(x
< y
); // expected-warning {{$x < $x - 1U}}
966 void compare_same_symbol_plus_left_plus_right_int_less_unsigned(void) {
967 unsigned x
= f(), y
= x
+ 1;
968 clang_analyzer_denote(x
, "$x");
970 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
971 clang_analyzer_express(y
); // expected-warning {{$x + 1}}
972 clang_analyzer_eval(x
< y
); // expected-warning {{FALSE}}
975 void compare_same_symbol_plus_left_minus_right_int_less_unsigned(void) {
976 unsigned x
= f(), y
= x
- 1;
977 clang_analyzer_denote(x
, "$x");
979 clang_analyzer_express(x
); // expected-warning {{$x + 1}}
980 clang_analyzer_express(y
); // expected-warning {{$x - 1}}
981 clang_analyzer_express(x
< y
); // expected-warning {{$x + 1U < $x - 1U}}
984 void compare_same_symbol_minus_left_plus_right_int_less_unsigned(void) {
985 unsigned x
= f(), y
= x
+ 1;
986 clang_analyzer_denote(x
, "$x");
988 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
989 clang_analyzer_express(y
); // expected-warning {{$x + 1}}
990 clang_analyzer_express(x
< y
); // expected-warning {{$x - 1U < $x + 1U}}
993 void compare_same_symbol_minus_left_minus_right_int_less_unsigned(void) {
994 unsigned x
= f(), y
= x
- 1;
995 clang_analyzer_denote(x
, "$x");
997 clang_analyzer_express(x
); // expected-warning {{$x - 1}}
998 clang_analyzer_express(y
); // expected-warning {{$x - 1}}
999 clang_analyzer_eval(x
< y
); // expected-warning {{FALSE}}
1002 void overflow(signed char n
, signed char m
) {
1003 if (n
+ 0 > m
+ 0) {
1004 clang_analyzer_eval(n
- 126 == m
+ 3); // expected-warning {{UNKNOWN}}
1008 int mixed_integer_types(int x
, int y
) {
1016 // Assert that no overflows occur in this test file.
1017 // Assuming that concrete integers are also within that range.
1018 assert(x
<= ((unsigned)UINT_MAX
/ 4));
1022 void unsigned_concrete_int_no_crash(void) {
1023 unsigned x
= fu() + 1U, y
= fu() + 1U;
1024 clang_analyzer_denote(x
- 1U, "$x");
1025 clang_analyzer_denote(y
- 1U, "$y");
1026 clang_analyzer_express(y
); // expected-warning {{$y}}
1027 clang_analyzer_express(x
== y
); // expected-warning {{$x + 1U == $y + 1U}}