@@ -36,7 +36,7 @@ void testIncrement(char *p) { // expected-warning{{'p' is an unsafe pointer used
36
36
void * voidPtrCall (void );
37
37
char * charPtrCall (void );
38
38
39
- void testArraySubscripts (int *p, int **pp) {
39
+ void testArraySubscripts (int idx, int *p, int **pp) {
40
40
// expected-warning@-1{{'p' is an unsafe pointer used for buffer access}}
41
41
// expected-warning@-2{{'pp' is an unsafe pointer used for buffer access}}
42
42
foo (p[1 ], // expected-note{{used in buffer access here}}
@@ -64,13 +64,14 @@ void testArraySubscripts(int *p, int **pp) {
64
64
// expected-note@-1{{change type of 'a' to 'std::array' to label it for hardening}}
65
65
int b[10 ][10 ]; // expected-warning{{'b' is an unsafe buffer that does not perform bounds checks}}
66
66
67
- foo (a[1 ], 1 [a], // expected-note2{{used in buffer access here}}
68
- b[3 ][4 ], // expected-warning{{unsafe buffer access}}
69
- // expected-note@-1{{used in buffer access here}}
70
- 4 [b][3 ], // expected-warning{{unsafe buffer access}}
71
- // expected-note@-1{{used in buffer access here}}
72
- 4 [3 [b]]); // expected-warning{{unsafe buffer access}}
73
- // expected-note@-1{{used in buffer access here}}
67
+ foo (a[idx], idx[a], // expected-note2{{used in buffer access here}}
68
+ b[idx][idx + 1 ], // expected-warning{{unsafe buffer access}}
69
+ // expected-note@-1{{used in buffer access here}}
70
+ (idx + 1 )[b][idx],// expected-warning{{unsafe buffer access}}
71
+ // expected-note@-1{{used in buffer access here}}
72
+ (idx + 1 )[idx[b]]);
73
+ // expected-warning@-1{{unsafe buffer access}}
74
+ // expected-note@-2{{used in buffer access here}}
74
75
75
76
// Not to warn when index is zero
76
77
foo (p[0 ], pp[0 ][0 ], 0 [0 [pp]], 0 [pp][0 ],
@@ -158,9 +159,9 @@ void testLambdaCaptureAndGlobal(int * p) {
158
159
// expected-warning@-1{{'p' is an unsafe pointer used for buffer access}}
159
160
int a[10 ]; // expected-warning{{'a' is an unsafe buffer that does not perform bounds checks}}
160
161
161
- auto Lam = [p, a]() {
162
+ auto Lam = [p, a](int idx ) {
162
163
return p[1 ] // expected-note{{used in buffer access here}}
163
- + a[1 ] + garray[1 ] // expected-note2{{used in buffer access here}}
164
+ + a[idx ] + garray[idx] // expected-note2{{used in buffer access here}}
164
165
+ gp[1 ]; // expected-note{{used in buffer access here}}
165
166
166
167
};
@@ -178,31 +179,31 @@ void testLambdaCapture() {
178
179
// expected-note@-1{{change type of 'b' to 'std::array' to label it for hardening}}
179
180
int c[10 ];
180
181
181
- auto Lam1 = [a]() {
182
- return a[1 ]; // expected-note{{used in buffer access here}}
182
+ auto Lam1 = [a](unsigned idx ) {
183
+ return a[idx ]; // expected-note{{used in buffer access here}}
183
184
};
184
185
185
- auto Lam2 = [x = b[3 ]]() { // expected-note{{used in buffer access here}}
186
+ auto Lam2 = [x = b[c[ 5 ] ]]() { // expected-note{{used in buffer access here}}
186
187
return x;
187
188
};
188
189
189
- auto Lam = [x = c]() { // expected-warning{{'x' is an unsafe pointer used for buffer access}}
190
- return x[3 ]; // expected-note{{used in buffer access here}}
190
+ auto Lam = [x = c](unsigned idx ) { // expected-warning{{'x' is an unsafe pointer used for buffer access}}
191
+ return x[idx ]; // expected-note{{used in buffer access here}}
191
192
};
192
193
}
193
194
194
- void testLambdaImplicitCapture () {
195
+ void testLambdaImplicitCapture (long idx ) {
195
196
int a[10 ]; // expected-warning{{'a' is an unsafe buffer that does not perform bounds checks}}
196
197
// expected-note@-1{{change type of 'a' to 'std::array' to label it for hardening}}
197
198
int b[10 ]; // expected-warning{{'b' is an unsafe buffer that does not perform bounds checks}}
198
199
// expected-note@-1{{change type of 'b' to 'std::array' to label it for hardening}}
199
200
200
201
auto Lam1 = [=]() {
201
- return a[1 ]; // expected-note{{used in buffer access here}}
202
+ return a[idx ]; // expected-note{{used in buffer access here}}
202
203
};
203
204
204
205
auto Lam2 = [&]() {
205
- return b[1 ]; // expected-note{{used in buffer access here}}
206
+ return b[idx ]; // expected-note{{used in buffer access here}}
206
207
};
207
208
}
208
209
@@ -344,38 +345,37 @@ int testVariableDecls(int * p) {
344
345
return p[1 ]; // expected-note{{used in buffer access here}}
345
346
}
346
347
347
- template <typename T> void fArr (T t[]) {
348
+ template <typename T> void fArr (T t[], long long idx ) {
348
349
// expected-warning@-1{{'t' is an unsafe pointer used for buffer access}}
349
350
foo (t[1 ]); // expected-note{{used in buffer access here}}
350
351
T ar[8 ]; // expected-warning{{'ar' is an unsafe buffer that does not perform bounds checks}}
351
352
// expected-note@-1{{change type of 'ar' to 'std::array' to label it for hardening}}
352
- foo (ar[5 ]); // expected-note{{used in buffer access here}}
353
+ foo (ar[idx ]); // expected-note{{used in buffer access here}}
353
354
}
354
355
355
- template void fArr <int >(int t[]); // FIXME: expected note {{in instantiation of}}
356
+ template void fArr <int >(int t[], long long ); // FIXME: expected note {{in instantiation of}}
356
357
357
358
int testReturn (int t[]) {// expected-note{{change type of 't' to 'std::span' to preserve bounds information}}
358
359
// expected-warning@-1{{'t' is an unsafe pointer used for buffer access}}
359
360
return t[1 ]; // expected-note{{used in buffer access here}}
360
361
}
361
362
362
- int testArrayAccesses (int n) {
363
+ int testArrayAccesses (int n, int idx ) {
363
364
// auto deduced array type
364
365
int cArr[2 ][3 ] = {{1 , 2 , 3 }, {4 , 5 , 6 }};
365
366
// expected-warning@-1{{'cArr' is an unsafe buffer that does not perform bounds checks}}
366
367
int d = cArr[0 ][0 ];
367
368
foo (cArr[0 ][0 ]);
368
- foo (cArr[1 ][ 2 ]); // expected-note{{used in buffer access here}}
369
- // expected-warning@-1{{unsafe buffer access}}
370
- auto cPtr = cArr[1 ][ 2 ]; // expected-note{{used in buffer access here}}
371
- // expected-warning@-1{{unsafe buffer access}}
369
+ foo (cArr[idx][idx + 1 ]); // expected-note{{used in buffer access here}}
370
+ // expected-warning@-1{{unsafe buffer access}}
371
+ auto cPtr = cArr[idx][idx * 2 ]; // expected-note{{used in buffer access here}}
372
+ // expected-warning@-1{{unsafe buffer access}}
372
373
foo (cPtr);
373
374
374
375
// Typdefs
375
376
typedef int A[3 ];
376
377
const A tArr = {4 , 5 , 6 };
377
- // expected-warning@-1{{'tArr' is an unsafe buffer that does not perform bounds checks}}
378
- foo (tArr[0 ], tArr[1 ]); // expected-note{{used in buffer access here}}
378
+ foo (tArr[0 ], tArr[1 ]);
379
379
return cArr[0 ][1 ]; // expected-warning{{unsafe buffer access}}
380
380
}
381
381
0 commit comments