aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-07-05 14:23:59 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-07-05 14:23:59 +0000
commitc192b3dcffd5e672a2b2e1730e2440febb4fb192 (patch)
treeac719b5984165053bf83d71142e4d96b609b9784 /test/Analysis
parent2e645aa5697838f16ec570eb07c2bee7e13d0e0b (diff)
Notes
Diffstat (limited to 'test/Analysis')
-rw-r--r--test/Analysis/division-by-zero.c7
-rw-r--r--test/Analysis/retain-release.m2
-rw-r--r--test/Analysis/test-include-cpp.cpp13
-rw-r--r--test/Analysis/test-include-cpp.h9
-rw-r--r--test/Analysis/test-include.c21
-rw-r--r--test/Analysis/test-include.h2
6 files changed, 53 insertions, 1 deletions
diff --git a/test/Analysis/division-by-zero.c b/test/Analysis/division-by-zero.c
new file mode 100644
index 0000000000000..d3c228e6c97df
--- /dev/null
+++ b/test/Analysis/division-by-zero.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=unix.Malloc %s
+// Do not crash due to division by zero
+
+int f(unsigned int a) {
+ if (a <= 0) return 1 / a;
+ return a;
+}
diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m
index 1dbcda507c174..f0d91e34c1b06 100644
--- a/test/Analysis/retain-release.m
+++ b/test/Analysis/retain-release.m
@@ -2165,7 +2165,7 @@ void testCFReturnsNotRetained() {
}
void testCFReturnsNotRetainedAnnotated() {
- extern void getViaParam2(CFTypeRef * __nonnull CF_RETURNS_NOT_RETAINED outObj);
+ extern void getViaParam2(CFTypeRef * _Nonnull CF_RETURNS_NOT_RETAINED outObj);
CFTypeRef obj;
getViaParam2(&obj);
CFRelease(obj); // // expected-warning {{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}}
diff --git a/test/Analysis/test-include-cpp.cpp b/test/Analysis/test-include-cpp.cpp
new file mode 100644
index 0000000000000..2ac5e11c997e5
--- /dev/null
+++ b/test/Analysis/test-include-cpp.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core -verify %s
+
+#include "test-include-cpp.h"
+
+int TestIncludeClass::test1(int *p) {
+ p = 0;
+ return *p; // expected-warning{{Dereference of null pointer}}
+}
+
+int TestIncludeClass::test2(int *p) {
+ p = 0;
+ return *p; // expected-warning{{Dereference of null pointer}}
+}
diff --git a/test/Analysis/test-include-cpp.h b/test/Analysis/test-include-cpp.h
new file mode 100644
index 0000000000000..90ec27acd5d35
--- /dev/null
+++ b/test/Analysis/test-include-cpp.h
@@ -0,0 +1,9 @@
+#ifndef TEST_INCLUDE_CPP_H
+#define TEST_INCLUDE_CPP_H
+
+class TestIncludeClass {
+ int test1(int *);
+ static int test2(int *);
+};
+
+#endif
diff --git a/test/Analysis/test-include.c b/test/Analysis/test-include.c
new file mode 100644
index 0000000000000..6aa80b96426c1
--- /dev/null
+++ b/test/Analysis/test-include.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core -verify %s
+
+#include "test-include.h"
+#define DIVYX(X,Y) Y/X
+
+void test_01(int *data) {
+ data = 0;
+ *data = 1; // expected-warning{{Dereference of null pointer}}
+}
+
+int test_02() {
+ int res = DIVXY(1,0); // expected-warning{{Division by zero}}
+ // expected-warning@-1{{division by zero is undefined}}
+ return res;
+}
+
+int test_03() {
+ int res = DIVYX(0,1); // expected-warning{{Division by zero}}
+ // expected-warning@-1{{division by zero is undefined}}
+ return res;
+} \ No newline at end of file
diff --git a/test/Analysis/test-include.h b/test/Analysis/test-include.h
new file mode 100644
index 0000000000000..07cd1c9dca1b1
--- /dev/null
+++ b/test/Analysis/test-include.h
@@ -0,0 +1,2 @@
+void test_01(int * data);
+#define DIVXY(X,Y) X/Y