aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis/reference.cpp
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-08-02 21:33:42 +0000
committerJordan Rose <jordan_rose@apple.com>2012-08-02 21:33:42 +0000
commit9f3b9d54ccbbf212591602f389ebde7923627490 (patch)
treebcbcdb69c5cc0b5c12f7e4d52cf4cce11b7485d0 /test/Analysis/reference.cpp
parentc27bc80a98b9558513b50956c930eedc9e461ae0 (diff)
[analyzer] Add a simple check for initializing reference variables with null.
There's still more work to be done here; this doesn't catch reference parameters or return values. But it's a step in the right direction. Part of <rdar://problem/11212286>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161214 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis/reference.cpp')
-rw-r--r--test/Analysis/reference.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/Analysis/reference.cpp b/test/Analysis/reference.cpp
index a12e0bd41c..c9bfadced7 100644
--- a/test/Analysis/reference.cpp
+++ b/test/Analysis/reference.cpp
@@ -90,3 +90,29 @@ namespace PR13440 {
clang_analyzer_eval(s2.x[0] == 42); // expected-warning{{TRUE}}
}
}
+
+void testRef() {
+ int *x = 0;
+ int &y = *x; // expected-warning{{Dereference of null pointer}}
+ y = 5;
+}
+
+
+// ------------------------------------
+// False negatives
+// ------------------------------------
+
+namespace rdar11212286 {
+ class B{};
+
+ B test() {
+ B *x = 0;
+ return *x; // should warn here!
+ }
+
+ B &testRef() {
+ B *x = 0;
+ return *x; // should warn here!
+ }
+
+}