[PATCH] D12725: [analyzer] A fix for substraction of an integer from a pointer.
Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 18 12:14:54 PDT 2015
This revision was automatically updated to reflect the committed changes.
Closed by commit rL248021: [analyzer] A fix for substraction of an integer from a pointer. (authored by xazax).
Changed prior to commit:
http://reviews.llvm.org/D12725?vs=34423&id=35122#toc
Repository:
rL LLVM
http://reviews.llvm.org/D12725
Files:
cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
cfe/trunk/test/Analysis/ptr-arith.c
Index: cfe/trunk/test/Analysis/ptr-arith.c
===================================================================
--- cfe/trunk/test/Analysis/ptr-arith.c
+++ cfe/trunk/test/Analysis/ptr-arith.c
@@ -296,3 +296,20 @@
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}}
+}
+
Index: cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -911,8 +911,9 @@
elementType = elemReg->getElementType();
}
else if (isa<SubRegion>(region)) {
+ assert(op == BO_Add || op == BO_Sub);
+ index = (op == BO_Add) ? rhs : evalMinus(rhs);
superR = region;
- index = rhs;
if (resultTy->isAnyPointerType())
elementType = resultTy->getPointeeType();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12725.35122.patch
Type: text/x-patch
Size: 1414 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150918/6a6c6833/attachment.bin>
More information about the cfe-commits
mailing list