diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Analysis/initializer.cpp | 3 | ||||
-rw-r--r-- | test/Analysis/reference.cpp | 70 |
2 files changed, 67 insertions, 6 deletions
diff --git a/test/Analysis/initializer.cpp b/test/Analysis/initializer.cpp index ab2eb90143..3f7802c56d 100644 --- a/test/Analysis/initializer.cpp +++ b/test/Analysis/initializer.cpp @@ -68,8 +68,7 @@ void testReferenceMember() { void testReferenceMember2() { int *p = 0; - // FIXME: We should warn here, since we're creating the reference here. - RefWrapper X(*p); // expected-warning@-12 {{Dereference of null pointer}} + RefWrapper X(*p); // expected-warning {{Forming reference to null pointer}} } 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 } } |