1 // RUN: %clang_analyze_cc1 %s \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-checker=debug.ExprInspection \
4 // RUN: -analyzer-config eagerly-assume=false \
7 // Here we test whether the SValBuilder is capable to simplify existing
8 // compound SVals (where there are at leaset 3 symbols in the tree) based on
9 // newly added constraints.
11 void clang_analyzer_eval(bool);
12 void clang_analyzer_warnIfReached();
14 void test_left_tree_constrained(int x
, int y
, int z
) {
19 clang_analyzer_eval(x
+ y
+ z
== 0); // expected-warning{{TRUE}}
20 clang_analyzer_eval(x
+ y
== 0); // expected-warning{{TRUE}}
21 clang_analyzer_eval(z
== 0); // expected-warning{{TRUE}}
26 void test_right_tree_constrained(int x
, int y
, int z
) {
31 clang_analyzer_eval(x
+ y
* z
== 0); // expected-warning{{TRUE}}
32 clang_analyzer_eval(y
* z
== 0); // expected-warning{{TRUE}}
33 clang_analyzer_eval(x
== 0); // expected-warning{{TRUE}}
37 void test_left_tree_constrained_minus(int x
, int y
, int z
) {
42 clang_analyzer_eval(x
- y
- z
== 0); // expected-warning{{TRUE}}
43 clang_analyzer_eval(x
- y
== 0); // expected-warning{{TRUE}}
44 clang_analyzer_eval(z
== 0); // expected-warning{{TRUE}}
49 void test_SymInt_constrained(int x
, int y
, int z
) {
55 clang_analyzer_warnIfReached(); // no-warning
61 void test_SValBuilder_simplifies_IntSym(int x
, int y
, int z
) {
62 // Most IntSym BinOps are transformed to SymInt in SimpleSValBuilder.
63 // Division is one exception.
67 clang_analyzer_eval(x
== 77); // expected-warning{{TRUE}}
71 void recurring_symbol(int b
) {
73 if ((b
* b
) * b
* b
!= (b
* b
) * b
)
74 if (b
* b
== 1) // no-crash (assert should not fire)
75 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}