1 // RUN: %clang_analyze_cc1 -std=c99 -Dbool=_Bool -analyzer-checker=core,alpha.core.TestAfterDivZero -analyzer-output=text -verify %s
2 // RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=core,alpha.core.TestAfterDivZero -analyzer-output=text -verify %s
7 var = 77 / x; // expected-note {{Division with compared value made here}}
8 if (x == 0) { } // expected-warning {{Value being compared against zero has already been used for division}}
9 } // expected-note@-1 {{Value being compared against zero has already been used for division}}
12 var = 77 / x; // expected-note {{Division with compared value made here}}
13 if (0 == x) { } // expected-warning {{Value being compared against zero has already been used for division}}
14 } // expected-note@-1 {{Value being compared against zero has already been used for division}}
17 var = 77 / x; // expected-note {{Division with compared value made here}}
18 if (x != 0) { } // expected-warning {{Value being compared against zero has already been used for division}}
19 } // expected-note@-1 {{Value being compared against zero has already been used for division}}
22 var = 77 / x; // expected-note {{Division with compared value made here}}
23 if (x >= 0) { } // expected-warning {{Value being compared against zero has already been used for division}}
24 } // expected-note@-1 {{Value being compared against zero has already been used for division}}
27 var = 77 / x; // expected-note {{Division with compared value made here}}
28 if (x <= 0) {} // expected-warning {{Value being compared against zero has already been used for division}}
29 } // expected-note@-1 {{Value being compared against zero has already been used for division}}
32 var = 77 / x; // expected-note {{Division with compared value made here}}
33 if (x) {} // expected-warning {{Value being compared against zero has already been used for division}}
34 } // expected-note@-1 {{Value being compared against zero has already been used for division}}
36 var = 77 / x; // expected-note {{Division with compared value made here}}
37 if (!x) {} // expected-warning {{Value being compared against zero has already been used for division}}
38 } // expected-note@-1 {{Value being compared against zero has already been used for division}}
40 void err_pnot(int x) {
42 var = 77 / *y; // expected-note {{Division with compared value made here}}
43 if (!x) {} // expected-warning {{Value being compared against zero has already been used for division}}
44 } // expected-note@-1 {{Value being compared against zero has already been used for division}}
46 void err_pnot2(int x) {
48 var = 77 / x; // expected-note {{Division with compared value made here}}
49 if (!*y) {} // expected-warning {{Value being compared against zero has already been used for division}}
50 } // expected-note@-1 {{Value being compared against zero has already been used for division}}
52 void err_ppnot(int x) {
55 var = 77 / **z; // expected-note {{Division with compared value made here}}
56 if (!x) {} // expected-warning {{Value being compared against zero has already been used for division}}
57 } // expected-note@-1 {{Value being compared against zero has already been used for division}}
59 void err_orig_checker(int x) {
60 if (x != 0) // expected-note {{Assuming 'x' is equal to 0}} expected-note {{Taking false branch}}
62 var = 77 / x; // expected-warning {{Division by zero}} expected-note {{Division by zero}}
63 if (!x) {} // no-warning
66 void ok_other(int x, int y) {
72 void ok_assign(int x) {
74 x = var / 77; // <- assignment => don't warn
79 void ok_assign2(int x) {
81 x = var / 77; // <- assignment => don't warn
88 x--; // <- assignment => don't warn
95 x++; // <- assignment => don't warn
100 void do_something_ptr(int *x);
101 void ok_callfunc_ptr(int x) {
103 do_something_ptr(&x); // <- pass address of x to function => don't warn
108 void do_something(int x);
109 void nok_callfunc(int x) {
110 var = 77 / x; // expected-note {{Division with compared value made here}}
112 if (x == 0) {} // expected-warning {{Value being compared against zero has already been used for division}}
113 } // expected-note@-1 {{Value being compared against zero has already been used for division}}
137 int getValue(bool *isPositive);
141 int x = getValue(&isPositive);
155 use(5 / x); // expected-note {{Division with compared value made here}}
156 if (y == 0) {} // expected-warning {{Value being compared against zero has already been used for division}}
157 } // expected-note@-1 {{Value being compared against zero has already been used for division}}
159 void ok_while(int x) {
161 while (x != 0) { // <- do not warn
166 void err_not2(int x, int y) {
177 inline void inline_func(int x) {
178 var = 77 / x; // expected-note {{Division with compared value made here}}
179 if (x == 0) {} // expected-warning {{Value being compared against zero has already been used for division}}
180 } // expected-note@-1 {{Value being compared against zero has already been used for division}}
182 void err_inline(int x) {
184 inline_func(x); // expected-note {{Calling 'inline_func'}}
189 inline void inline_func2(int x) {}
191 void err_inline2(int x) {
192 var = 77 / x; // expected-note {{Division with compared value made here}}
194 if (x == 0) {} // expected-warning {{Value being compared against zero has already been used for division}}
195 } // expected-note@-1 {{Value being compared against zero has already been used for division}}
197 inline void inline_func3(int x) {
200 void ok_inline(int x) {
201 var = 77 / x; // expected-note {{Division with compared value made here}}
203 if (x == 0) {} // expected-warning {{Value being compared against zero has already been used for division}}
204 } // expected-note@-1 {{Value being compared against zero has already been used for division}}