@@ -15,8 +15,8 @@ int TenElements[10];
15
15
16
16
int irrelevantAssumptions (int arg ) {
17
17
int a = TenElements [arg ];
18
- // Here the analyzer assumes that `arg` is in bounds, but doesn't report this
19
- // because `arg` is not interesting for the bug.
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}}
20
20
int b = TenElements [13 ];
21
21
// expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
22
22
// expected-note@-2 {{Access of 'TenElements' at index 13, while it holds only 10 'int' elements}}
@@ -26,8 +26,10 @@ int irrelevantAssumptions(int arg) {
26
26
27
27
int assumingBoth (int arg ) {
28
28
int a = TenElements [arg ];
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
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}}
31
33
int c = TenElements [arg + 10 ];
32
34
// expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
33
35
// expected-note@-2 {{Access of 'TenElements' at an overflowing index, while it holds only 10 'int' elements}}
@@ -39,9 +41,11 @@ int assumingBothPointerToMiddle(int arg) {
39
41
// will speak about the "byte offset" measured from the beginning of the TenElements.
40
42
int * p = TenElements + 2 ;
41
43
int a = p [arg ];
42
- // expected-note@-1 {{Assuming byte offset is non-negative and less than 40, the extent of 'TenElements'}}
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}}
43
46
44
- int b = TenElements [arg ]; // This is normal access, and only the lower bound is new.
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}}
45
49
int c = TenElements [arg + 10 ];
46
50
// expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
47
51
// expected-note@-2 {{Access of 'TenElements' at an overflowing index, while it holds only 10 'int' elements}}
@@ -62,15 +66,16 @@ int assumingLower(int arg) {
62
66
}
63
67
64
68
int assumingUpper (int arg ) {
65
- // expected-note@+2 {{Assuming 'arg' is >= 0}}
66
- // expected-note@+1 {{Taking false branch}}
69
+ // expected-note@+2 2 {{Assuming 'arg' is >= 0}}
70
+ // expected-note@+1 2 {{Taking false branch}}
67
71
if (arg < 0 )
68
72
return 0 ;
69
73
int a = TenElements [arg ];
70
- // expected-note@-1 {{Assuming index is less than 10, the number of 'int' elements in 'TenElements'}}
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}}
71
76
int b = TenElements [arg - 10 ];
72
- // expected-warning@-1 {{Out of bound access to memory preceding 'TenElements'}}
73
- // expected-note@-2 {{Access of 'TenElements' at a negative index}}
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 }}
74
79
return a + b ;
75
80
}
76
81
@@ -82,12 +87,13 @@ int assumingUpperIrrelevant(int arg) {
82
87
// filter out assumptions that are logically irrelevant but "touch"
83
88
// interesting symbols; eventually it would be good to add support for this.
84
89
85
- // expected-note@+2 {{Assuming 'arg' is >= 0}}
86
- // expected-note@+1 {{Taking false branch}}
90
+ // expected-note@+2 2 {{Assuming 'arg' is >= 0}}
91
+ // expected-note@+1 2 {{Taking false branch}}
87
92
if (arg < 0 )
88
93
return 0 ;
89
94
int a = TenElements [arg ];
90
- // expected-note@-1 {{Assuming index is less than 10, the number of 'int' elements in 'TenElements'}}
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}}
91
97
int b = TenElements [arg + 10 ];
92
98
// expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
93
99
// expected-note@-2 {{Access of 'TenElements' at an overflowing index, while it holds only 10 'int' elements}}
@@ -96,10 +102,11 @@ int assumingUpperIrrelevant(int arg) {
96
102
97
103
int assumingUpperUnsigned (unsigned arg ) {
98
104
int a = TenElements [arg ];
99
- // expected-note@-1 {{Assuming index is less than 10, the number of 'int' elements in 'TenElements'}}
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}}
100
107
int b = TenElements [(int )arg - 10 ];
101
- // expected-warning@-1 {{Out of bound access to memory preceding 'TenElements'}}
102
- // expected-note@-2 {{Access of 'TenElements' at a negative index}}
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 }}
103
110
return a + b ;
104
111
}
105
112
@@ -120,8 +127,10 @@ short assumingConvertedToCharP(int arg) {
120
127
// result type of the subscript operator.
121
128
char * cp = (char * )TenElements ;
122
129
char a = cp [arg ];
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
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}}
125
134
char c = cp [arg + 40 ];
126
135
// expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
127
136
// expected-note@-2 {{Access of 'TenElements' at an overflowing index, while it holds only 40 'char' elements}}
@@ -138,14 +147,14 @@ int assumingConvertedToIntP(struct foo f, int arg) {
138
147
// When indices are reported, the note will use the element type that's the
139
148
// result type of the subscript operator.
140
149
int a = ((int * )(f .a ))[arg ];
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.
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}}
144
152
int b = ((int * )(f .b ))[arg ];
145
- // expected-note@-1 {{Assuming byte offset is less than 5, the extent of 'f.b'}}
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}}
146
155
int c = TenElements [arg - 2 ];
147
- // expected-warning@-1 {{Out of bound access to memory preceding 'TenElements'}}
148
- // expected-note@-2 {{Access of 'TenElements' at a negative index}}
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 }}
149
158
return a + b + c ;
150
159
}
151
160
@@ -154,16 +163,14 @@ int assumingPlainOffset(struct foo f, int arg) {
154
163
// shorter "offset" instead of "byte offset" when it's irrelevant that the
155
164
// offset is measured in bytes.
156
165
157
- // expected-note@+2 {{Assuming 'arg' is < 2}}
158
- // expected-note@+1 {{Taking false branch}}
166
+ // expected-note@+2 2 {{Assuming 'arg' is < 2}}
167
+ // expected-note@+1 2 {{Taking false branch}}
159
168
if (arg >= 2 )
160
169
return 0 ;
161
170
162
171
int b = ((int * )(f .b ))[arg ];
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.
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}}
167
174
168
175
int c = TenElements [arg + 10 ];
169
176
// expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
@@ -181,13 +188,14 @@ int assumingExtent(int arg) {
181
188
int * mem = (int * )malloc (arg );
182
189
183
190
mem [12 ] = 123 ;
184
- // expected-note@-1 {{Assuming index '12' is less than the number of 'int' elements in the heap area}}
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}}
185
193
186
194
free (mem );
187
195
188
196
return TenElements [arg ];
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}}
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}}
191
199
}
192
200
193
201
int * extentInterestingness (int arg ) {
@@ -196,7 +204,8 @@ int *extentInterestingness(int arg) {
196
204
int * mem = (int * )malloc (arg );
197
205
198
206
TenElements [arg ] = 123 ;
199
- // expected-note@-1 {{Assuming index is non-negative and less than 10, the number of 'int' elements in 'TenElements'}}
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}}
200
209
201
210
return & mem [12 ];
202
211
// expected-warning@-1 {{Out of bound access to memory after the end of the heap area}}
@@ -208,8 +217,7 @@ int triggeredByAnyReport(int arg) {
208
217
// not limited to ArrayBound reports but will appear on any bug report (that
209
218
// marks the relevant symbol as interesting).
210
219
TenElements [arg + 10 ] = 8 ;
211
- // expected-note@-1 {{Assuming index is non-negative and less than 10, the number of 'int' elements in 'TenElements'}}
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}}
212
222
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}}
215
223
}
0 commit comments