Skip to content

Commit a7d7db7

Browse files
authored
[NFC][analyzer] OOB test consolidation IV: rename files (#129697)
This commit finishes the reorganization of the tests for the checker `security.ArrayBound`. Previously these tests were all named `out-of-bounds-*` which was only weakly connected to the checker name; this commit moves them to a directory named after the checker (`ArrayBound`). I decided to use a directory instead of the more common filename prefix ("poor man's directory") system because it seems to be a more natural use of the filesystem and there are already a few precedents for it. I also added (or edited) comments at the beginning of each test file to describe their purpose; and I added a single new testcase to highlight that the assumption note tags can be added to reports by any checker. (Previously all tests in the file triggered out-of-bounds reports to reveal the note tags; but that was just for convenience.)
1 parent 405c28b commit a7d7db7

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

clang/test/Analysis/out-of-bounds-notes.c renamed to clang/test/Analysis/ArrayBound/assumption-reporting.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
// RUN: %clang_analyze_cc1 -Wno-array-bounds -analyzer-output=text \
22
// RUN: -analyzer-checker=core,security.ArrayBound,unix.Malloc,optin.taint -verify %s
33

4+
// When the checker security.ArrayBound encounters an array subscript operation
5+
// that _may be_ in bounds, it assumes that indexing _is_ in bound. These
6+
// assumptions will be reported to the user if the execution path leads to a
7+
// bug report (made by any checker) and the symbol which was constrainted by
8+
// the assumption is marked as interesting (with `markInteresting` or
9+
// indirectly via `trackExpressionValue`) in that bug report.
10+
//
11+
// This test file validates the content of these note tags which describe the
12+
// assumptions for the user.
13+
414
int TenElements[10];
515

616
int irrelevantAssumptions(int arg) {
@@ -197,3 +207,14 @@ int *extentInterestingness(int arg) {
197207
// expected-warning@-1 {{Out of bound access to memory after the end of the heap area}}
198208
// expected-note@-2 {{Access of 'int' element in the heap area at index 12}}
199209
}
210+
211+
int triggeredByAnyReport(int arg) {
212+
// Verify that note tags explaining the assumptions made by ArrayBound are
213+
// not limited to ArrayBound reports but will appear on any bug report (that
214+
// marks the relevant symbol as interesting).
215+
TenElements[arg + 10] = 8;
216+
// expected-note@-1 {{Assuming index is non-negative and less than 10, the number of 'int' elements in 'TenElements'}}
217+
return 1024 >> arg;
218+
// expected-warning@-1 {{Right operand is negative in right shift}}
219+
// expected-note@-2 {{The result of right shift is undefined because the right operand is negative}}
220+
}

clang/test/Analysis/out-of-bounds.c renamed to clang/test/Analysis/ArrayBound/brief-tests.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
// RUN: %clang_analyze_cc1 -Wno-array-bounds -analyzer-checker=core,security.ArrayBound,debug.ExprInspection -verify %s
22

3+
// Miscellaneous tests for `security.ArrayBound` where we only test the
4+
// presence or absence of a bug report. If a test doesn't fit in a more
5+
// specific file and doesn't need to verify the details of 'note' diagnostics,
6+
// then it should be placed here.
7+
38
void clang_analyzer_value(int);
49

510
// Tests doing an out-of-bounds access after the end of an array using:

clang/test/Analysis/out-of-bounds-new.cpp renamed to clang/test/Analysis/ArrayBound/cplusplus.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %clang_analyze_cc1 -std=c++11 -Wno-array-bounds -analyzer-checker=unix,core,security.ArrayBound -verify %s
22

3+
// Test the interactions of `security.ArrayBound` with C++ features.
4+
35
// Tests doing an out-of-bounds access after the end of an array using:
46
// - constant integer index
57
// - constant integer size for buffer
@@ -150,15 +152,13 @@ void test_dynamic_size(int s) {
150152
}
151153
//Tests complex arithmetic
152154
//in new expression
153-
void test_dynamic_size2(unsigned m,unsigned n){
155+
void test_dynamic_size2(unsigned m, unsigned n){
154156
unsigned *U = nullptr;
155157
U = new unsigned[m + n + 1];
156158
}
157159

158160
//Test creating invalid references, which break the invariant that a reference
159161
//is always holding a value, and could lead to nasty runtime errors.
160-
//(This is not related to operator new, but placed in this file because the
161-
//other test files are not C++.)
162162
int array[10] = {0};
163163

164164
void test_after_the_end_reference() {
@@ -179,4 +179,3 @@ int test_reference_that_might_be_after_the_end(int idx) {
179179
return -1;
180180
return ref;
181181
}
182-

clang/test/Analysis/out-of-bounds-diagnostics.c renamed to clang/test/Analysis/ArrayBound/verbose-tests.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// RUN: %clang_analyze_cc1 -Wno-array-bounds -analyzer-output=text \
22
// RUN: -analyzer-checker=core,security.ArrayBound,unix.Malloc,optin.taint -verify %s
33

4+
// Miscellaneous tests for `security.ArrayBound` where we also verify the
5+
// content of the 'note' diagnostics. This makes the tests sensitive to textual
6+
// changes in the diagnostics, so prefer adding new tests to `brief-tests.c`
7+
// unless they need to verify the correctness of 'note' diagnostics.
8+
49
int TenElements[10];
510

611
void arrayUnderflow(void) {

0 commit comments

Comments
 (0)