[PATCH] D12725: [analyzer] A fix for substraction of an integer from a pointer.
Artem Dergachev via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 10 02:58:08 PDT 2015
NoQ updated this revision to Diff 34423.
NoQ added a comment.
Make the tests easier to understand.
http://reviews.llvm.org/D12725
Files:
lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
test/Analysis/ptr-arith.c
Index: test/Analysis/ptr-arith.c
===================================================================
--- test/Analysis/ptr-arith.c
+++ 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: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===================================================================
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ 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.34423.patch
Type: text/x-patch
Size: 1354 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150910/b846a2f8/attachment-0001.bin>
More information about the cfe-commits
mailing list