1 // RUN: %clang_analyze_cc1 %s \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-checker=debug.ExprInspection \
6 void clang_analyzer_warnIfReached(void);
7 void clang_analyzer_eval(int);
9 void rem_constant_rhs_ne_zero(int x
, int y
) {
10 if (x
% 3 == 0) // x % 3 != 0 -> x != 0
12 if (x
* y
!= 0) // x * y == 0
14 if (y
!= 1) // y == 1 -> x == 0
16 clang_analyzer_warnIfReached(); // no-warning
17 (void)x
; // keep the constraints alive.
20 void rem_symbolic_rhs_ne_zero(int x
, int y
, int z
) {
21 if (x
% z
== 0) // x % z != 0 -> x != 0
23 if (x
* y
!= 0) // x * y == 0
25 if (y
!= 1) // y == 1 -> x == 0
27 clang_analyzer_warnIfReached(); // no-warning
28 (void)x
; // keep the constraints alive.
31 void rem_symbolic_rhs_ne_zero_nested(int w
, int x
, int y
, int z
) {
32 if (w
% x
% z
== 0) // w % x % z != 0 -> w % x != 0
34 if (w
% x
* y
!= 0) // w % x * y == 0
36 if (y
!= 1) // y == 1 -> w % x == 0
38 clang_analyzer_warnIfReached(); // no-warning
39 (void)(w
* x
); // keep the constraints alive.
42 void rem_constant_rhs_ne_zero_early_contradiction(int x
, int y
) {
43 if ((x
+ y
) != 0) // (x + y) == 0
45 if ((x
+ y
) % 3 == 0) // (x + y) % 3 != 0 -> (x + y) != 0 -> contradiction
47 clang_analyzer_warnIfReached(); // no-warning
48 (void)x
; // keep the constraints alive.
51 void rem_symbolic_rhs_ne_zero_early_contradiction(int x
, int y
, int z
) {
52 if ((x
+ y
) != 0) // (x + y) == 0
54 if ((x
+ y
) % z
== 0) // (x + y) % z != 0 -> (x + y) != 0 -> contradiction
56 clang_analyzer_warnIfReached(); // no-warning
57 (void)x
; // keep the constraints alive.
60 void internal_unsigned_signed_mismatch(unsigned a
) {
62 // Implicit casts are not handled, thus the analyzer models `d % 2` as
63 // `(reg_$0<unsigned int a>) % 2`
64 // However, this should not result in internal signedness mismatch error when
65 // we assign new constraints below.
70 void remainder_with_adjustment(int x
) {
71 if ((x
+ 1) % 3 == 0) // (x + 1) % 3 != 0 -> x + 1 != 0 -> x != -1
73 clang_analyzer_eval(x
+ 1 != 0); // expected-warning{{TRUE}}
74 clang_analyzer_eval(x
!= -1); // expected-warning{{TRUE}}
75 (void)x
; // keep the constraints alive.
78 void remainder_with_adjustment_of_composit_lhs(int x
, int y
) {
79 if ((x
+ y
+ 1) % 3 == 0) // (x + 1) % 3 != 0 -> x + 1 != 0 -> x != -1
81 clang_analyzer_eval(x
+ y
+ 1 != 0); // expected-warning{{TRUE}}
82 clang_analyzer_eval(x
+ y
!= -1); // expected-warning{{TRUE}}
83 (void)(x
* y
); // keep the constraints alive.