@@ -15,8 +15,8 @@ int TenElements[10];
1515
1616int irrelevantAssumptions (int arg ) {
1717 int a = TenElements [arg ];
18- // expected-warning@-1 {{Out of bound access to memory around 'TenElements'}}
19- // expected-note@-2 {{Access of 'TenElements' at a negative or overflowing index, while it holds only 10 'int' elements}}
18+ // Here the analyzer assumes that `arg` is in bounds, but doesn't report this
19+ // because `arg` is not interesting for the bug.
2020 int b = TenElements [13 ];
2121 // expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
2222 // expected-note@-2 {{Access of 'TenElements' at index 13, while it holds only 10 'int' elements}}
@@ -26,10 +26,8 @@ int irrelevantAssumptions(int arg) {
2626
2727int assumingBoth (int arg ) {
2828 int a = TenElements [arg ];
29- // expected-warning@-1 {{Out of bound access to memory around 'TenElements'}}
30- // expected-note@-2 {{Access of 'TenElements' at a negative or overflowing index, while it holds only 10 'int' elements}}
31- int b = TenElements [arg ]; // expected-warning{{Out of bound access to memory after the end of 'TenElements'}}
32- // expected-note@-1 {{Access of 'TenElements' at an overflowing index, while it holds only 10 'int' elements}}
29+ // expected-note@-1 {{Assuming index is non-negative and less than 10, the number of 'int' elements in 'TenElements'}}
30+ int b = TenElements [arg ]; // no additional note, we already assumed that 'arg' is in bounds
3331 int c = TenElements [arg + 10 ];
3432 // expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
3533 // expected-note@-2 {{Access of 'TenElements' at an overflowing index, while it holds only 10 'int' elements}}
@@ -41,11 +39,9 @@ int assumingBothPointerToMiddle(int arg) {
4139 // will speak about the "byte offset" measured from the beginning of the TenElements.
4240 int * p = TenElements + 2 ;
4341 int a = p [arg ];
44- // expected-warning@-1 {{Out of bound access to memory around 'TenElements'}}
45- // expected-note@-2 {{Access of 'TenElements' at a negative or overflowing index, while it holds only 10 'int' elements}}
42+ // expected-note@-1 {{Assuming byte offset is non-negative and less than 40, the extent of 'TenElements'}}
4643
47- int b = TenElements [arg ]; // expected-warning{{Out of bound access to memory after the end of 'TenElements'}}
48- // expected-note@-1 {{Access of 'TenElements' at an overflowing index, while it holds only 10 'int' elements}}
44+ int b = TenElements [arg ]; // This is normal access, and only the lower bound is new.
4945 int c = TenElements [arg + 10 ];
5046 // expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
5147 // expected-note@-2 {{Access of 'TenElements' at an overflowing index, while it holds only 10 'int' elements}}
@@ -66,16 +62,15 @@ int assumingLower(int arg) {
6662}
6763
6864int assumingUpper (int arg ) {
69- // expected-note@+2 2 {{Assuming 'arg' is >= 0}}
70- // expected-note@+1 2 {{Taking false branch}}
65+ // expected-note@+2 {{Assuming 'arg' is >= 0}}
66+ // expected-note@+1 {{Taking false branch}}
7167 if (arg < 0 )
7268 return 0 ;
7369 int a = TenElements [arg ];
74- // expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
75- // expected-note@-2 {{Access of 'TenElements' at an overflowing index, while it holds only 10 'int' elements}}
70+ // expected-note@-1 {{Assuming index is less than 10, the number of 'int' elements in 'TenElements'}}
7671 int b = TenElements [arg - 10 ];
77- // expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
78- // expected-note@-2 {{Access of 'TenElements' at an overflowing index, while it holds only 10 'int' elements }}
72+ // expected-warning@-1 {{Out of bound access to memory preceding 'TenElements'}}
73+ // expected-note@-2 {{Access of 'TenElements' at a negative index}}
7974 return a + b ;
8075}
8176
@@ -87,13 +82,12 @@ int assumingUpperIrrelevant(int arg) {
8782 // filter out assumptions that are logically irrelevant but "touch"
8883 // interesting symbols; eventually it would be good to add support for this.
8984
90- // expected-note@+2 2 {{Assuming 'arg' is >= 0}}
91- // expected-note@+1 2 {{Taking false branch}}
85+ // expected-note@+2 {{Assuming 'arg' is >= 0}}
86+ // expected-note@+1 {{Taking false branch}}
9287 if (arg < 0 )
9388 return 0 ;
9489 int a = TenElements [arg ];
95- // expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
96- // expected-note@-2 {{Access of 'TenElements' at an overflowing index, while it holds only 10 'int' elements}}
90+ // expected-note@-1 {{Assuming index is less than 10, the number of 'int' elements in 'TenElements'}}
9791 int b = TenElements [arg + 10 ];
9892 // expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
9993 // expected-note@-2 {{Access of 'TenElements' at an overflowing index, while it holds only 10 'int' elements}}
@@ -102,11 +96,10 @@ int assumingUpperIrrelevant(int arg) {
10296
10397int assumingUpperUnsigned (unsigned arg ) {
10498 int a = TenElements [arg ];
105- // expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
106- // expected-note@-2 {{Access of 'TenElements' at an overflowing index, while it holds only 10 'int' elements}}
99+ // expected-note@-1 {{Assuming index is less than 10, the number of 'int' elements in 'TenElements'}}
107100 int b = TenElements [(int )arg - 10 ];
108- // expected-warning@-1 {{Out of bound access to memory around 'TenElements'}}
109- // expected-note@-2 {{Access of 'TenElements' at a negative or overflowing index, while it holds only 10 'int' elements }}
101+ // expected-warning@-1 {{Out of bound access to memory preceding 'TenElements'}}
102+ // expected-note@-2 {{Access of 'TenElements' at a negative index}}
110103 return a + b ;
111104}
112105
@@ -127,10 +120,8 @@ short assumingConvertedToCharP(int arg) {
127120 // result type of the subscript operator.
128121 char * cp = (char * )TenElements ;
129122 char a = cp [arg ];
130- // expected-warning@-1 {{Out of bound access to memory around 'TenElements'}}
131- // expected-note@-2 {{Access of 'TenElements' at a negative or overflowing index, while it holds only 40 'char' elements}}
132- char b = cp [arg ]; // expected-warning{{Out of bound access to memory after the end of 'TenElements'}}
133- // expected-note@-1 {{Access of 'TenElements' at an overflowing index, while it holds only 40 'char' elements}}
123+ // expected-note@-1 {{Assuming index is non-negative and less than 40, the number of 'char' elements in 'TenElements'}}
124+ char b = cp [arg ]; // no additional note, we already assumed that 'arg' is in bounds
134125 char c = cp [arg + 40 ];
135126 // expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
136127 // expected-note@-2 {{Access of 'TenElements' at an overflowing index, while it holds only 40 'char' elements}}
@@ -147,14 +138,14 @@ int assumingConvertedToIntP(struct foo f, int arg) {
147138 // When indices are reported, the note will use the element type that's the
148139 // result type of the subscript operator.
149140 int a = ((int * )(f .a ))[arg ];
150- // expected-warning@-1 {{Out of bound access to memory around 'f.a'}}
151- // expected-note@-2 {{Access of 'f.a' at a negative or overflowing index, while it holds only 2 'int' elements}}
141+ // expected-note@-1 {{Assuming index is non-negative and less than 2, the number of 'int' elements in 'f.a'}}
142+ // However, if the extent of the memory region is not divisible by the
143+ // element size, the checker measures the offset and extent in bytes.
152144 int b = ((int * )(f .b ))[arg ];
153- // expected-warning@-1 {{Out of bound access to memory after the end of 'f.b'}}
154- // expected-note@-2 {{Access of 'f.b' at an overflowing byte offset, while it holds only 5 bytes}}
145+ // expected-note@-1 {{Assuming byte offset is less than 5, the extent of 'f.b'}}
155146 int c = TenElements [arg - 2 ];
156- // expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
157- // expected-note@-2 {{Access of 'TenElements' at an overflowing index, while it holds only 10 'int' elements }}
147+ // expected-warning@-1 {{Out of bound access to memory preceding 'TenElements'}}
148+ // expected-note@-2 {{Access of 'TenElements' at a negative index}}
158149 return a + b + c ;
159150}
160151
@@ -163,14 +154,16 @@ int assumingPlainOffset(struct foo f, int arg) {
163154 // shorter "offset" instead of "byte offset" when it's irrelevant that the
164155 // offset is measured in bytes.
165156
166- // expected-note@+2 2 {{Assuming 'arg' is < 2}}
167- // expected-note@+1 2 {{Taking false branch}}
157+ // expected-note@+2 {{Assuming 'arg' is < 2}}
158+ // expected-note@+1 {{Taking false branch}}
168159 if (arg >= 2 )
169160 return 0 ;
170161
171162 int b = ((int * )(f .b ))[arg ];
172- // expected-warning@-1 {{Out of bound access to memory around 'f.b'}}
173- // expected-note@-2 {{Access of 'f.b' at a negative or overflowing byte offset, while it holds only 5 bytes}}
163+ // expected-note@-1 {{Assuming byte offset is non-negative and less than 5, the extent of 'f.b'}}
164+ // FIXME: this should be {{Assuming offset is non-negative}}
165+ // but the current simplification algorithm doesn't realize that arg <= 1
166+ // implies that the byte offset arg*4 will be less than 5.
174167
175168 int c = TenElements [arg + 10 ];
176169 // expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
@@ -188,14 +181,13 @@ int assumingExtent(int arg) {
188181 int * mem = (int * )malloc (arg );
189182
190183 mem [12 ] = 123 ;
191- // expected-warning@-1 {{Out of bound access to memory after the end of the heap area}}
192- // expected-note@-2 {{Access of 'int' element in the heap area at index 12}}
184+ // expected-note@-1 {{Assuming index '12' is less than the number of 'int' elements in the heap area}}
193185
194186 free (mem );
195187
196188 return TenElements [arg ];
197- // expected-warning@-1 {{Out of bound access to memory around 'TenElements'}}
198- // expected-note@-2 {{Access of 'TenElements' at a negative or overflowing index, while it holds only 10 'int' elements}}
189+ // expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
190+ // expected-note@-2 {{Access of 'TenElements' at an overflowing index, while it holds only 10 'int' elements}}
199191}
200192
201193int * extentInterestingness (int arg ) {
@@ -204,8 +196,7 @@ int *extentInterestingness(int arg) {
204196 int * mem = (int * )malloc (arg );
205197
206198 TenElements [arg ] = 123 ;
207- // expected-warning@-1 {{Out of bound access to memory around 'TenElements'}}
208- // expected-note@-2 {{Access of 'TenElements' at a negative or overflowing index, while it holds only 10 'int' elements}}
199+ // expected-note@-1 {{Assuming index is non-negative and less than 10, the number of 'int' elements in 'TenElements'}}
209200
210201 return & mem [12 ];
211202 // expected-warning@-1 {{Out of bound access to memory after the end of the heap area}}
@@ -217,7 +208,8 @@ int triggeredByAnyReport(int arg) {
217208 // not limited to ArrayBound reports but will appear on any bug report (that
218209 // marks the relevant symbol as interesting).
219210 TenElements [arg + 10 ] = 8 ;
220- // expected-warning@-1 {{Out of bound access to memory around 'TenElements'}}
221- // expected-note@-2 {{Access of 'TenElements' at a negative or overflowing index, while it holds only 10 'int' elements}}
211+ // expected-note@-1 {{Assuming index is non-negative and less than 10, the number of 'int' elements in 'TenElements'}}
222212 return 1024 >> arg ;
213+ // expected-warning@-1 {{Right operand is negative in right shift}}
214+ // expected-note@-2 {{The result of right shift is undefined because the right operand is negative}}
223215}
0 commit comments