summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorGabor Horvath <xazax.hun@gmail.com>2016-08-22 10:07:32 +0000
committerGabor Horvath <xazax.hun@gmail.com>2016-08-22 10:07:32 +0000
commit855ad82e05247498ebd0e28d8e6c244937a914db (patch)
tree3aa1b0fbba0b4134ad0dbe6763fc2ae813447c47 /clang/test
parent5f8419da34393de830e8d53c93253159cc9a2e3f (diff)
downloadbcm5719-llvm-855ad82e05247498ebd0e28d8e6c244937a914db.tar.gz
bcm5719-llvm-855ad82e05247498ebd0e28d8e6c244937a914db.zip
[analyzer] Correctly add assumptions based on array bounds.
Also simplify the constraints generated by the checker. Differential Revision: https://reviews.llvm.org/D23112 llvm-svn: 279425
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Analysis/out-of-bounds.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/clang/test/Analysis/out-of-bounds.c b/clang/test/Analysis/out-of-bounds.c
index d89a2396190..ca1e0d05006 100644
--- a/clang/test/Analysis/out-of-bounds.c
+++ b/clang/test/Analysis/out-of-bounds.c
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -Wno-array-bounds -analyze -analyzer-checker=core,alpha.security.ArrayBoundV2 -verify %s
+// RUN: %clang_cc1 -Wno-array-bounds -analyze -analyzer-checker=core,alpha.security.ArrayBoundV2,debug.ExprInspection -verify %s
+
+void clang_analyzer_eval(int);
// Tests doing an out-of-bounds access after the end of an array using:
// - constant integer index
@@ -128,22 +130,22 @@ void test2_multi_ok(int x) {
buf[0][0] = 1; // no-warning
}
-// *** FIXME ***
-// We don't get a warning here yet because our symbolic constraint solving
-// doesn't handle: (symbol * constant) < constant
void test3(int x) {
int buf[100];
if (x < 0)
- buf[x] = 1;
+ buf[x] = 1; // expected-warning{{Out of bound memory access}}
}
-// *** FIXME ***
-// We don't get a warning here yet because our symbolic constraint solving
-// doesn't handle: (symbol * constant) < constant
void test4(int x) {
int buf[100];
if (x > 99)
- buf[x] = 1;
+ buf[x] = 1; // expected-warning{{Out of bound memory access}}
+}
+
+void test_assume_after_access(unsigned long x) {
+ int buf[100];
+ buf[x] = 1;
+ clang_analyzer_eval(x <= 99); // expected-warning{{TRUE}}
}
// Don't warn when indexing below the start of a symbolic region's whose
@@ -166,3 +168,9 @@ void test_extern_void() {
p[1] = 42; // no-warning
}
+void test_assume_after_access2(unsigned long x) {
+ char buf[100];
+ buf[x] = 1;
+ clang_analyzer_eval(x <= 99); // expected-warning{{TRUE}}
+}
+
OpenPOWER on IntegriCloud