diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-10-01 19:07:15 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-10-01 19:07:15 +0000 |
commit | 12024f8776fdfbf2c85e1b366d6709db6e56576f (patch) | |
tree | b859f1b59dd05a8a5facebf3f265491fe9c8e26b /clang/test/Analysis/nullptr.cpp | |
parent | c491c3f27aabda38ff269c36c4de144b6905170b (diff) | |
download | bcm5719-llvm-12024f8776fdfbf2c85e1b366d6709db6e56576f.tar.gz bcm5719-llvm-12024f8776fdfbf2c85e1b366d6709db6e56576f.zip |
Revert "[analyzer] Check that a member expr is valid even when the result is an lvalue."
The original intent of this commit was to catch potential null dereferences
early, but it breaks the common "home-grown offsetof" idiom (PR13927):
(((struct Foo *)0)->member - ((struct foo *)0))
As it turns out, this appears to be legal in C, per a footnote in
C11 6.5.3.2: "Thus, &*E is equivalent to E (even if E is a null pointer)".
In C++ this issue is still open:
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#232
We'll just have to make sure we have good path notes in the future.
This reverts r164441 / 9be016dcd1ca3986873a7b66bd4bc027309ceb59.
llvm-svn: 164958
Diffstat (limited to 'clang/test/Analysis/nullptr.cpp')
-rw-r--r-- | clang/test/Analysis/nullptr.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/clang/test/Analysis/nullptr.cpp b/clang/test/Analysis/nullptr.cpp index 80ef5fbf6d0..050c3f8dc56 100644 --- a/clang/test/Analysis/nullptr.cpp +++ b/clang/test/Analysis/nullptr.cpp @@ -23,11 +23,10 @@ void foo3(void) { }; char *np = nullptr; // casting a nullptr to anything should be caught eventually - 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; + 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 |