Skip to content

Commit 8163c8e

Browse files
committed
Fix tests after removing taint assumptions
1 parent 5fe8a24 commit 8163c8e

File tree

6 files changed

+127
-147
lines changed

6 files changed

+127
-147
lines changed

clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,8 @@ void ArrayBoundChecker::performCheck(const Expr *E, CheckerContext &C) const {
680680
BadOffsetKind Problem = AlsoMentionUnderflow
681681
? BadOffsetKind::Indeterminate
682682
: BadOffsetKind::Overflowing;
683-
Messages Msgs =
684-
getNonTaintMsgs(C.getASTContext(), Space, Reg, ByteOffset,
685-
*KnownSize, Location, Problem);
683+
Messages Msgs = getNonTaintMsgs(C.getASTContext(), Space, Reg, ByteOffset,
684+
*KnownSize, Location, Problem);
686685
reportOOB(C, ExceedsUpperBound, Msgs, ByteOffset, KnownSize);
687686
return;
688687
}

clang/test/Analysis/ArrayBound/assumption-reporting.c

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ int TenElements[10];
1515

1616
int irrelevantAssumptions(int arg) {
1717
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}}
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,8 +26,10 @@ int irrelevantAssumptions(int arg) {
2626

2727
int assumingBoth(int arg) {
2828
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}}
3133
int c = TenElements[arg + 10];
3234
// expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
3335
// 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) {
3941
// will speak about the "byte offset" measured from the beginning of the TenElements.
4042
int *p = TenElements + 2;
4143
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}}
4346

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}}
4549
int c = TenElements[arg + 10];
4650
// expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
4751
// 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) {
6266
}
6367

6468
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}}
6771
if (arg < 0)
6872
return 0;
6973
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}}
7176
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}}
7479
return a + b;
7580
}
7681

@@ -82,12 +87,13 @@ int assumingUpperIrrelevant(int arg) {
8287
// filter out assumptions that are logically irrelevant but "touch"
8388
// interesting symbols; eventually it would be good to add support for this.
8489

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}}
8792
if (arg < 0)
8893
return 0;
8994
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}}
9197
int b = TenElements[arg + 10];
9298
// expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
9399
// 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) {
96102

97103
int assumingUpperUnsigned(unsigned arg) {
98104
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}}
100107
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}}
103110
return a + b;
104111
}
105112

@@ -120,8 +127,10 @@ short assumingConvertedToCharP(int arg) {
120127
// result type of the subscript operator.
121128
char *cp = (char*)TenElements;
122129
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}}
125134
char c = cp[arg + 40];
126135
// expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
127136
// 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) {
138147
// When indices are reported, the note will use the element type that's the
139148
// result type of the subscript operator.
140149
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}}
144152
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}}
146155
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}}
149158
return a + b + c;
150159
}
151160

@@ -154,16 +163,14 @@ int assumingPlainOffset(struct foo f, int arg) {
154163
// shorter "offset" instead of "byte offset" when it's irrelevant that the
155164
// offset is measured in bytes.
156165

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}}
159168
if (arg >= 2)
160169
return 0;
161170

162171
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}}
167174

168175
int c = TenElements[arg+10];
169176
// expected-warning@-1 {{Out of bound access to memory after the end of 'TenElements'}}
@@ -181,13 +188,14 @@ int assumingExtent(int arg) {
181188
int *mem = (int*)malloc(arg);
182189

183190
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}}
185193

186194
free(mem);
187195

188196
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}}
191199
}
192200

193201
int *extentInterestingness(int arg) {
@@ -196,7 +204,8 @@ int *extentInterestingness(int arg) {
196204
int *mem = (int*)malloc(arg);
197205

198206
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}}
200209

201210
return &mem[12];
202211
// expected-warning@-1 {{Out of bound access to memory after the end of the heap area}}
@@ -208,8 +217,7 @@ int triggeredByAnyReport(int arg) {
208217
// not limited to ArrayBound reports but will appear on any bug report (that
209218
// marks the relevant symbol as interesting).
210219
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}}
212222
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}}
215223
}

0 commit comments

Comments
 (0)