summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhongxing Xu <xuzhongxing@gmail.com>2010-04-20 05:48:57 +0000
committerZhongxing Xu <xuzhongxing@gmail.com>2010-04-20 05:48:57 +0000
commit52c28fe61a6e58e158b360607ea76069a7a9ba60 (patch)
treea515eca186c007b54c91c2dfcd7a67095806ddaa
parent9cffdf133127eb3efd281cfff7e78755312da55f (diff)
downloadbcm5719-llvm-52c28fe61a6e58e158b360607ea76069a7a9ba60.tar.gz
bcm5719-llvm-52c28fe61a6e58e158b360607ea76069a7a9ba60.zip
Add test cases.
llvm-svn: 101878
-rw-r--r--clang/test/Analysis/method-call.cpp18
-rw-r--r--clang/test/Analysis/new.cpp12
2 files changed, 30 insertions, 0 deletions
diff --git a/clang/test/Analysis/method-call.cpp b/clang/test/Analysis/method-call.cpp
new file mode 100644
index 00000000000..dd891596c5d
--- /dev/null
+++ b/clang/test/Analysis/method-call.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store region -verify %s
+struct A {
+ int x;
+ A(int a) { x = a; }
+ int getx() { return x; }
+};
+
+void f1() {
+ A x(3);
+ if (x.getx() == 3) {
+ int *p = 0;
+ *p = 3; // expected-warning{{Dereference of null pointer}}
+ } else {
+ int *p = 0;
+ *p = 3; // no-warning
+ }
+}
+
diff --git a/clang/test/Analysis/new.cpp b/clang/test/Analysis/new.cpp
new file mode 100644
index 00000000000..95bd966cb02
--- /dev/null
+++ b/clang/test/Analysis/new.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store region -verify %s
+
+void f1() {
+ int *n1 = new int;
+ if (*n1) { // expected-warning {{Branch condition evaluates to a garbage value}}
+ }
+
+ int *n2 = new int(3);
+ if (*n2) { // no-warning
+ }
+}
+
OpenPOWER on IntegriCloud