diff options
author | dim <dim@FreeBSD.org> | 2015-12-30 11:49:41 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2015-12-30 11:49:41 +0000 |
commit | 3176e97f130184ece0e1a21352c8124cc83ff24a (patch) | |
tree | 0a5b74c0b9ca73aded34df95c91fcaf3815230d8 /test/Analysis/nullptr.cpp | |
parent | 1e9b8d38881c3213d1e67b0c47ab9b2c00721a5c (diff) | |
download | FreeBSD-src-3176e97f130184ece0e1a21352c8124cc83ff24a.zip FreeBSD-src-3176e97f130184ece0e1a21352c8124cc83ff24a.tar.gz |
Vendor import of clang trunk r256633:
https://llvm.org/svn/llvm-project/cfe/trunk@256633
Diffstat (limited to 'test/Analysis/nullptr.cpp')
-rw-r--r-- | test/Analysis/nullptr.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/test/Analysis/nullptr.cpp b/test/Analysis/nullptr.cpp index 56151dc..17320f3 100644 --- a/test/Analysis/nullptr.cpp +++ b/test/Analysis/nullptr.cpp @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 -std=c++11 -Wno-conversion-null -analyze -analyzer-checker=core -analyzer-store region -verify %s +// RUN: %clang_cc1 -std=c++11 -Wno-conversion-null -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-store region -verify %s + +void clang_analyzer_eval(int); // test to see if nullptr is detected as a null pointer void foo1(void) { @@ -87,3 +89,40 @@ void testMaterializeTemporaryExprWithNullPtr() { // Create MaterializeTemporaryExpr with a nullptr inside. const nullptr_t &r = nullptr; } + +int getSymbol(); + +struct X { + virtual void f() {} +}; + +void invokeF(X* x) { + x->f(); // expected-warning{{Called C++ object pointer is null}} +} + +struct Type { + decltype(nullptr) x; +}; + +void shouldNotCrash() { + decltype(nullptr) p; + if (getSymbol()) + invokeF(p); // expected-warning{{Function call argument is an uninit}} + if (getSymbol()) + invokeF(nullptr); + if (getSymbol()) { + X *x = Type().x; + x->f(); // expected-warning{{Called C++ object pointer is null}} + } +} + +void f(decltype(nullptr) p) { + int *q = nullptr; + clang_analyzer_eval(p == 0); // expected-warning{{TRUE}} + clang_analyzer_eval(q == 0); // expected-warning{{TRUE}} +} + +decltype(nullptr) returnsNullPtrType(); +void fromReturnType() { + ((X *)returnsNullPtrType())->f(); // expected-warning{{Called C++ object pointer is null}} +} |