aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis/reference.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/Analysis/reference.cpp')
-rw-r--r--test/Analysis/reference.cpp70
1 files changed, 66 insertions, 4 deletions
diff --git a/test/Analysis/reference.cpp b/test/Analysis/reference.cpp
index ed05720fe6..8dd0baf8c3 100644
--- a/test/Analysis/reference.cpp
+++ b/test/Analysis/reference.cpp
@@ -149,16 +149,78 @@ void testReturnReference() {
clang_analyzer_eval(&refFromPointer() == 0); // expected-warning{{FALSE}}
}
+void intRefParam(int &r) {
+ ;
+}
+
+void test(int *ptr) {
+ clang_analyzer_eval(ptr == 0); // expected-warning{{UNKNOWN}}
+
+ extern void use(int &ref);
+ use(*ptr);
+
+ clang_analyzer_eval(ptr == 0); // expected-warning{{FALSE}}
+}
+
+void testIntRefParam() {
+ int i = 0;
+ intRefParam(i); // no-warning
+}
-// ------------------------------------
-// False negatives
-// ------------------------------------
+int refParam(int &byteIndex) {
+ return byteIndex;
+}
+
+void testRefParam(int *p) {
+ if (p)
+ ;
+ refParam(*p); // expected-warning {{Forming reference to null pointer}}
+}
+
+int ptrRefParam(int *&byteIndex) {
+ return *byteIndex; // expected-warning {{Dereference of null pointer}}
+}
+void testRefParam2() {
+ int *p = 0;
+ int *&rp = p;
+ ptrRefParam(rp);
+}
+
+int *maybeNull() {
+ extern bool coin();
+ static int x;
+ return coin() ? &x : 0;
+}
+
+void use(int &x) {
+ x = 1; // no-warning
+}
+
+void testSuppression() {
+ use(*maybeNull());
+}
namespace rdar11212286 {
class B{};
B test() {
B *x = 0;
- return *x; // should warn here!
+ return *x; // expected-warning {{Forming reference to null pointer}}
+ }
+
+ B testif(B *x) {
+ if (x)
+ ;
+ return *x; // expected-warning {{Forming reference to null pointer}}
+ }
+
+ void idc(B *x) {
+ if (x)
+ ;
+ }
+
+ B testidc(B *x) {
+ idc(x);
+ return *x; // no-warning
}
}