Skip to content

Commit 71389e5

Browse files
authored
[NFC][analyzer] OOB test consolidation III: 'outofbound' tests (#128508)
Before commit 6e17ed9 the test files `outofbound.c` and `outofbound-notwork.c` tested the behavior of the old alpha checker `alpha.security.ArrayBound` (V1); then that commit converted them into tests for the checker `security.ArrayBound` which was previously called `alpha.security.ArrayBoundV2`. This commit removes these test files and migrates their useful content to `out-of-bounds.c`. The file `outofbound.c` contained lots of testcases that covered features which are also covered in `out-of-bounds.c` or `out-of-bounds-diagnostics.c`; those redundant cases are discarded during this migration process. This is part of a commit series that reorganizes the tests of `security.ArrayBound` to a system that's easier to understand and maintain.
1 parent 00f5763 commit 71389e5

File tree

3 files changed

+50
-162
lines changed

3 files changed

+50
-162
lines changed

clang/test/Analysis/out-of-bounds.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,53 @@ int test_negative_offset_with_unsigned_idx(void) {
217217
unsigned idx = 2u;
218218
return p[idx]; // expected-warning {{Out of bound access to memory preceding}}
219219
}
220+
221+
struct three_words { int c[3]; };
222+
struct seven_words { int c[7]; };
223+
void partially_in_bounds(void) {
224+
struct seven_words c;
225+
struct three_words a, *p = (struct three_words *)&c;
226+
p[0] = a; // no-warning
227+
p[1] = a; // no-warning
228+
p[2] = a; // should warn
229+
// FIXME: This is an overflow, but currently security.ArrayBound only checks
230+
// that the _beginning_ of the accessed element is within bounds.
231+
}
232+
233+
void vla(int a) {
234+
if (a == 5) {
235+
int x[a];
236+
x[4] = 4; // no-warning
237+
x[5] = 5; // expected-warning{{Out of bound access}}
238+
}
239+
}
240+
241+
void sizeof_vla(int a) {
242+
// FIXME: VLA modeling is not good enough to cover this case.
243+
if (a == 5) {
244+
char x[a];
245+
int y[sizeof(x)];
246+
y[4] = 4; // no-warning
247+
y[5] = 5; // should be {{Out of bounds access}}
248+
}
249+
}
250+
251+
void sizeof_vla_2(int a) {
252+
// FIXME: VLA modeling is not good enough to cover this case.
253+
if (a == 5) {
254+
char x[a];
255+
int y[sizeof(x) / sizeof(char)];
256+
y[4] = 4; // no-warning
257+
y[5] = 5; // should be {{Out of bounds access}}
258+
}
259+
}
260+
261+
void sizeof_vla_3(int a) {
262+
// FIXME: VLA modeling is not good enough to cover this case.
263+
if (a == 5) {
264+
char x[a];
265+
int y[sizeof(*&*&*&x)];
266+
y[4] = 4; // no-warning
267+
y[5] = 5; // should be {{Out of bounds access}}
268+
}
269+
}

clang/test/Analysis/outofbound-notwork.c

Lines changed: 0 additions & 32 deletions
This file was deleted.

clang/test/Analysis/outofbound.c

Lines changed: 0 additions & 130 deletions
This file was deleted.

0 commit comments

Comments
 (0)