1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
3 void clang_analyzer_eval(int);
4 void clang_analyzer_warnIfReached(void);
6 #define INT_MIN 0x80000000
7 #define INT_MAX 0x7fffffff
9 // PR16833: Analyzer consumes memory until killed by kernel OOM killer
10 // while analyzing large case ranges.
11 void PR16833(unsigned op
) {
13 case 0x02 << 26 ... 0x03 << 26: // Analyzer should not hang here.
18 void testAdjustment(int t
) {
21 clang_analyzer_eval(t
== 1); // expected-warning{{TRUE}}
24 clang_analyzer_eval(t
> 1); // expected-warning{{TRUE}}
25 clang_analyzer_eval(t
+ 2 <= 11); // expected-warning{{TRUE}}
26 clang_analyzer_eval(t
> 2); // expected-warning{{UNKNOWN}}
27 clang_analyzer_eval(t
+ 1 == 3); // expected-warning{{UNKNOWN}}
28 clang_analyzer_eval(t
+ 1 == 10); // expected-warning{{UNKNOWN}}
31 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
35 void testUnknownVal(int value
, int mask
) {
36 // Once ConstraintManager will process '&' and this test will require some changes.
37 switch (value
& mask
) {
39 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
42 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
45 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
49 void testSwitchCond(int arg
) {
53 clang_analyzer_warnIfReached(); // no-warning
56 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
59 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
64 clang_analyzer_warnIfReached(); // no-warning
67 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
68 clang_analyzer_eval(arg
> 10); // expected-warning{{TRUE}}
71 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
76 void testDefaultUnreachable(int arg
) {
80 clang_analyzer_warnIfReached(); // no-warning
83 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
84 clang_analyzer_eval(arg
> 10); // expected-warning{{TRUE}}
87 clang_analyzer_warnIfReached(); // no-warning
92 void testBranchReachability(int arg
) {
93 if (arg
> 10 && arg
< 20) {
96 clang_analyzer_warnIfReached(); // no-warning
99 clang_analyzer_warnIfReached(); // no-warning
102 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
103 clang_analyzer_eval(arg
> 10 && arg
<= 15); // expected-warning{{TRUE}}
106 clang_analyzer_warnIfReached(); // no-warning
109 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
110 clang_analyzer_eval(arg
>= 17 && arg
< 20); // expected-warning{{TRUE}}
113 clang_analyzer_warnIfReached(); // no-warning
116 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
117 clang_analyzer_eval(arg
== 16); // expected-warning{{TRUE}}
123 void testDefaultBranchRange(int arg
) {
126 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
129 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
130 clang_analyzer_eval(arg
>= 20); // expected-warning{{TRUE}}
133 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
134 clang_analyzer_eval(arg
== 16); // expected-warning{{FALSE}}
135 clang_analyzer_eval(arg
> 9); // expected-warning{{TRUE}}
136 clang_analyzer_eval(arg
<= 20); // expected-warning{{TRUE}}
139 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
143 void testAllUnreachableButDefault(int arg
) {
147 clang_analyzer_warnIfReached(); // no-warning
150 clang_analyzer_warnIfReached(); // no-warning
153 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
156 clang_analyzer_warnIfReached(); // no-warning
158 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
162 void testAllUnreachable(int arg
) {
166 clang_analyzer_warnIfReached(); // no-warning
169 clang_analyzer_warnIfReached(); // no-warning
172 clang_analyzer_warnIfReached(); // no-warning
174 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
178 void testDifferentTypes(int arg
) {
180 case -1U ... 400000000LL:
181 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
184 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
189 void testDifferentTypes2(unsigned long arg
) {
191 case 1UL ... 400000000UL:
192 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
195 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
200 void testDifferentTypes3(int arg
) {
202 case 1UL ... 400000000UL:
203 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
206 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
211 void testConstant(void) {
214 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
217 clang_analyzer_warnIfReached(); // no-warning
222 void testExhaustiveSwitch(unsigned int a
) {
225 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
228 clang_analyzer_warnIfReached(); // no-warning