diff options
author | dim <dim@FreeBSD.org> | 2011-05-02 19:39:53 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2011-05-02 19:39:53 +0000 |
commit | 110eaaceddcec790f7e6a5e3bf1261c9aa1e73ab (patch) | |
tree | 64a10f4c4154739d4a8191d7e1b52ce497f4ebd6 /test/Analysis/nullptr.cpp | |
parent | a0fb00f9837bd0d2e5948f16f6a6b82a7a628f51 (diff) | |
download | FreeBSD-src-110eaaceddcec790f7e6a5e3bf1261c9aa1e73ab.zip FreeBSD-src-110eaaceddcec790f7e6a5e3bf1261c9aa1e73ab.tar.gz |
Vendor import of clang trunk r130700:
http://llvm.org/svn/llvm-project/cfe/trunk@130700
Diffstat (limited to 'test/Analysis/nullptr.cpp')
-rw-r--r-- | test/Analysis/nullptr.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/Analysis/nullptr.cpp b/test/Analysis/nullptr.cpp new file mode 100644 index 0000000..b74a5ab --- /dev/null +++ b/test/Analysis/nullptr.cpp @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 -std=c++0x -analyze -analyzer-checker=core -analyzer-store region -verify %s + +// test to see if nullptr is detected as a null pointer +void foo1(void) { + char *np = nullptr; + *np = 0; // expected-warning{{Dereference of null pointer}} +} + +// check if comparing nullptr to nullptr is detected properly +void foo2(void) { + char *np1 = nullptr; + char *np2 = np1; + char c; + if (np1 == np2) + np1 = &c; + *np1 = 0; // no-warning +} + +// invoving a nullptr in a more complex operation should be cause a warning +void foo3(void) { + struct foo { + int a, f; + }; + char *np = nullptr; + // casting a nullptr to anything should be caught eventually + int *ip = &(((struct foo *)np)->f); + *ip = 0; // expected-warning{{Dereference of null pointer}} + // should be error here too, but analysis gets stopped +// *np = 0; +} + +// nullptr is implemented as a zero integer value, so should be able to compare +void foo4(void) { + char *np = nullptr; + if (np != 0) + *np = 0; // no-warning + char *cp = 0; + if (np != cp) + *np = 0; // no-warning +} + |