1 // RUN: %clang_analyze_cc1 -analyzer-checker=core \
2 // RUN: -analyzer-output=text \
5 namespace test_tracking_of_lhs_multiplier
{
7 bool p0
= x
< 0; // expected-note {{Assuming 'x' is >= 0}} \
8 // expected-note {{'p0' initialized to 0}}
9 int div
= p0
* y
; // expected-note {{'div' initialized to 0}}
10 return 1 / div
; // expected-note {{Division by zero}} \
11 // expected-warning {{Division by zero}}
13 } // namespace test_tracking_of_lhs_multiplier
15 namespace test_tracking_of_rhs_multiplier
{
17 bool p0
= x
< 0; // expected-note {{Assuming 'x' is >= 0}} \
18 // expected-note {{'p0' initialized to 0}}
19 int div
= y
* p0
; // expected-note {{'div' initialized to 0}}
20 return 1 / div
; // expected-note {{Division by zero}} \
21 // expected-warning {{Division by zero}}
23 } // namespace test_tracking_of_rhs_multiplier
25 namespace test_tracking_of_nested_multiplier
{
26 int f(int x
, int y
, int z
) {
27 bool p0
= x
< 0; // expected-note {{Assuming 'x' is >= 0}} \
28 // expected-note {{'p0' initialized to 0}}
29 int div
= y
*z
*p0
; // expected-note {{'div' initialized to 0}}
30 return 1 / div
; // expected-note {{Division by zero}} \
31 // expected-warning {{Division by zero}}
33 } // namespace test_tracking_of_nested_multiplier
35 namespace test_tracking_through_multiple_stmts
{
37 bool p0
= x
< 0; // expected-note {{Assuming 'x' is >= 0}}
38 bool p1
= p0
? 0 : 1; // expected-note {{'p0' is false}} \
39 // expected-note {{'?' condition is false}}
40 bool p2
= 1 - p1
; // expected-note {{'p2' initialized to 0}}
41 int div
= p2
* y
; // expected-note {{'div' initialized to 0}}
42 return 1 / div
; // expected-note {{Division by zero}} \
43 // expected-warning {{Division by zero}}
45 } // namespace test_tracking_through_multiple_stmts
47 namespace test_tracking_both_lhs_and_rhs
{
49 bool p0
= x
< 0; // expected-note {{Assuming 'x' is >= 0}} \
50 // expected-note {{'p0' initialized to 0}}
51 bool p1
= y
< 0; // expected-note {{Assuming 'y' is >= 0}} \
52 // expected-note {{'p1' initialized to 0}}
53 int div
= p0
* p1
; // expected-note {{'div' initialized to 0}}
54 return 1 / div
; // expected-note {{Division by zero}} \
55 // expected-warning {{Division by zero}}
57 } // namespace test_tracking_both_lhs_and_rhs
59 namespace test_tracking_of_multiplier_and_parens
{
60 int f(int x
, int y
, int z
) {
61 bool p0
= x
< 0; // expected-note {{Assuming 'x' is >= 0}} \
62 // expected-note {{'p0' initialized to 0}}
63 int div
= y
*(z
*p0
); // expected-note {{'div' initialized to 0}}
64 return 1 / div
; // expected-note {{Division by zero}} \
65 // expected-warning {{Division by zero}}
67 } // namespace test_tracking_of_multiplier_and_parens
69 namespace test_tracking_of_divisible
{
71 bool p0
= x
< 0; // expected-note {{Assuming 'x' is >= 0}} \
72 // expected-note {{'p0' initialized to 0}}
73 int div
= p0
/ y
; // expected-note {{'div' initialized to 0}}
74 return 1 / div
; // expected-note {{Division by zero}} \
75 // expected-warning {{Division by zero}}
77 } // namespace test_tracking_of_divisible
79 namespace test_tracking_of_modulo
{
81 bool p0
= x
< 0; // expected-note {{Assuming 'x' is >= 0}} \
82 // expected-note {{'p0' initialized to 0}}
83 int div
= p0
% y
; // expected-note {{'div' initialized to 0}}
84 return 1 / div
; // expected-note {{Division by zero}} \
85 // expected-warning {{Division by zero}}
87 } // namespace test_tracking_of_modulo
89 namespace test_tracking_of_assignment
{
91 bool p0
= x
< 0; // expected-note {{Assuming 'x' is >= 0}} \
92 // expected-note {{'p0' initialized to 0}}
94 div
*= p0
; // expected-note {{The value 0 is assigned to 'div'}}
95 return 1 / div
; // expected-note {{Division by zero}} \
96 // expected-warning {{Division by zero}}
98 } // namespace test_tracking_of_assignment