1 // RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=core -analyzer-output=text -verify %s
3 typedef unsigned char uint8_t;
6 #define TCP_MAXWIN 65535
8 uint8_t get_uint8_max() {
9 uint8_t rcvscale
= UINT8_MAX
; // expected-note{{'rcvscale' initialized to 255}}
10 return rcvscale
; // expected-note{{Returning the value 255 (loaded from 'rcvscale')}}
13 void shift_by_undefined_value() {
14 uint8_t shift_amount
= get_uint8_max(); // expected-note{{'shift_amount' initialized to 255}}
15 // expected-note@-1{{Calling 'get_uint8_max'}}
16 // expected-note@-2{{Returning from 'get_uint8_max'}}
17 (void)(TCP_MAXWIN
<< shift_amount
); // expected-warning{{The result of the left shift is undefined due to shifting by '255', which is greater or equal to the width of type 'int'}}
18 // expected-note@-1{{The result of the left shift is undefined due to shifting by '255', which is greater or equal to the width of type 'int'}}
21 namespace array_index_tracking
{
26 if (x
> 0) // expected-note {{Assuming 'x' is > 0}}
27 // expected-note@-1 {{Taking true branch}}
28 a
= 3; // expected-note {{The value 3 is assigned to 'a'}}
31 return a
; // expected-note {{Returning the value 3 (loaded from 'a')}}
36 void testArrayIndexTracking() {
39 for (int i
= 0; i
< 3; ++i
)
40 // expected-note@-1 3{{Loop condition is true. Entering loop body}}
41 // expected-note@-2 {{Loop condition is false. Execution continues on line 43}}
44 int n
= getIndex(x
); // expected-note {{Calling 'getIndex'}}
45 // expected-note@-1 {{Returning from 'getIndex'}}
46 // expected-note@-2 {{'n' initialized to 3}}
48 // expected-note@-1 {{1st function call argument is an uninitialized value}}
49 // expected-warning@-2{{1st function call argument is an uninitialized value}}
51 } // end of namespace array_index_tracking
53 namespace multi_array_index_tracking
{
58 if (x
> 0) // expected-note {{Assuming 'x' is > 0}}
59 // expected-note@-1 {{Taking true branch}}
60 a
= 3; // expected-note {{The value 3 is assigned to 'a'}}
63 return a
; // expected-note {{Returning the value 3 (loaded from 'a')}}
68 void testArrayIndexTracking() {
71 for (int i
= 0; i
< 3; ++i
)
72 // expected-note@-1 3{{Loop condition is true. Entering loop body}}
73 // expected-note@-2 {{Loop condition is false. Execution continues on line 75}}
76 int n
= getIndex(x
); // expected-note {{Calling 'getIndex'}}
77 // expected-note@-1 {{Returning from 'getIndex'}}
78 // expected-note@-2 {{'n' initialized to 3}}
80 // expected-note@-1 {{1st function call argument is an uninitialized value}}
81 // expected-warning@-2{{1st function call argument is an uninitialized value}}
83 } // end of namespace mulit_array_index_tracking