[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>.
llvm-svn: 161214
diff --git a/clang/test/Analysis/reference.cpp b/clang/test/Analysis/reference.cpp
index a12e0bd..c9bfadc 100644
--- a/clang/test/Analysis/reference.cpp
+++ b/clang/test/Analysis/reference.cpp
@@ -90,3 +90,29 @@
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!
+ }
+
+}