[analyzer] A fix for substraction of an integer from a pointer.

Patch by Artem Dergachev!

Differential Revision: http://reviews.llvm.org/D12725

llvm-svn: 248021
This commit is contained in:
Gabor Horvath 2015-09-18 19:13:22 +00:00
parent e72b0dbf97
commit c4b28a8f74
2 changed files with 19 additions and 1 deletions

View File

@ -911,8 +911,9 @@ SVal SimpleSValBuilder::evalBinOpLN(ProgramStateRef state,
elementType = elemReg->getElementType(); elementType = elemReg->getElementType();
} }
else if (isa<SubRegion>(region)) { else if (isa<SubRegion>(region)) {
assert(op == BO_Add || op == BO_Sub);
index = (op == BO_Add) ? rhs : evalMinus(rhs);
superR = region; superR = region;
index = rhs;
if (resultTy->isAnyPointerType()) if (resultTy->isAnyPointerType())
elementType = resultTy->getPointeeType(); elementType = resultTy->getPointeeType();
} }

View File

@ -296,3 +296,20 @@ void symbolicFieldRegion(struct Point *points, int i, int j) {
clang_analyzer_eval(&points[i].x < &points[i].y);// expected-warning{{TRUE}} clang_analyzer_eval(&points[i].x < &points[i].y);// expected-warning{{TRUE}}
} }
void negativeIndex(char *str) {
*(str + 1) = 'a';
clang_analyzer_eval(*(str + 1) == 'a'); // expected-warning{{TRUE}}
clang_analyzer_eval(*(str - 1) == 'a'); // expected-warning{{UNKNOWN}}
char *ptr1 = str - 1;
clang_analyzer_eval(*ptr1 == 'a'); // expected-warning{{UNKNOWN}}
char *ptr2 = str;
ptr2 -= 1;
clang_analyzer_eval(*ptr2 == 'a'); // expected-warning{{UNKNOWN}}
char *ptr3 = str;
--ptr3;
clang_analyzer_eval(*ptr3 == 'a'); // expected-warning{{UNKNOWN}}
}