1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core -analyzer-max-loop 2 -analyzer-config widen-loops=true -analyzer-output=text -verify -analyzer-config eagerly-assume=false %s
6 int test_for_bug_25609() {
7 if (p_a
== 0) // expected-note {{Assuming 'p_a' is equal to null}}
8 // expected-note@-1 {{Taking true branch}}
10 for (int i
= 0; // expected-note {{Loop condition is true. Entering loop body}}
11 // expected-note@-1 {{Loop condition is false. Execution continues on line 16}}
12 ++i
, // expected-note {{Value assigned to 'p_a'}}
16 *p_a
= 25609; // no-crash expected-warning {{Dereference of null pointer (loaded from variable 'p_a')}}
17 // expected-note@-1 {{Dereference of null pointer (loaded from variable 'p_a')}}
22 int while_analyzer_output() {
25 while (flag_b
-- > 0) { // expected-note {{Loop condition is true. Entering loop body}}
26 // expected-note@-1 {{Value assigned to 'num'}}
27 // expected-note@-2 {{Loop condition is false. Execution continues on line 30}}
30 if (num
< 0) // expected-note {{Assuming 'num' is >= 0}}
31 // expected-note@-1 {{Taking false branch}}
33 else if (num
>= 1) // expected-note {{Assuming 'num' is < 1}}
34 // expected-note@-1 {{Taking false branch}}
38 return flag_b
/ num
; // no-crash expected-warning {{Division by zero}}
39 // expected-note@-1 {{Division by zero}}
43 int do_while_analyzer_output() {
45 do { // expected-note {{Loop condition is true. Execution continues on line 47}}
46 // expected-note@-1 {{Loop condition is false. Exiting loop}}
48 } while (flag_c
-- > 0); //expected-note {{Value assigned to 'num'}}
50 if (num
== 0) // expected-note {{Assuming 'num' is equal to 0}}
51 // expected-note@-1 {{Taking true branch}}
52 local
= 10 / num
; // no-crash expected-warning {{Division by zero}}
53 // expected-note@-1 {{Division by zero}}
60 for (int i
= 0; // expected-note {{Loop condition is true. Entering loop body}}
61 // expected-note@-1 {{Loop condition is false. Execution continues on line 67}}
62 new int(10), // expected-note {{Value assigned to 'num'}}
67 if (num
== 0) // expected-note {{Assuming 'num' is equal to 0}}
68 // expected-note@-1 {{Taking true branch}}
70 return flag_d
/ num
; // no-crash expected-warning {{Division by zero}}
71 // expected-note@-1 {{Division by zero}}
74 int test_for_range_loop() {
76 for(auto x
: arr
) { // expected-note {{Assigning value}}
79 if (arr
[0] == 0) // expected-note {{Assuming the condition is true}}
80 // expected-note@-1 {{Taking true branch}}
81 return 1/arr
[0]; // expected-warning {{Division by zero}}
82 // expected-note@-1 {{Division by zero}}