diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-09-22 01:24:33 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-09-22 01:24:33 +0000 |
commit | dd1d7d88f1fe6d7d7e79acaec3f83bc10d9f7b97 (patch) | |
tree | 361d11291b72644e05fcbd9d2c04958809d0d060 /test/Analysis/nullptr.cpp | |
parent | 5d99a252c63a7745bcd71231ca5240d2a65e4f1d (diff) |
[analyzer] Check that a member expr is valid even when the result is an lvalue.
We want to catch cases like this early, so that we can produce better
diagnostics and path notes:
Point *p = 0;
int *px = &p->x; // should warn here
*px = 1;
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164441 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis/nullptr.cpp')
-rw-r--r-- | test/Analysis/nullptr.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/test/Analysis/nullptr.cpp b/test/Analysis/nullptr.cpp index 050c3f8dc5..80ef5fbf6d 100644 --- a/test/Analysis/nullptr.cpp +++ b/test/Analysis/nullptr.cpp @@ -23,10 +23,11 @@ void foo3(void) { }; 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; + int *ip = &(((struct foo *)np)->f); // expected-warning{{Access to field 'f' results in a dereference of a null pointer (loaded from variable 'np')}} + + // Analysis stops at the first problem case, so we won't actually warn here. + *ip = 0; + *np = 0; } // nullptr is implemented as a zero integer value, so should be able to compare |