summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-08-04 01:04:52 +0000
committerJordan Rose <jordan_rose@apple.com>2012-08-04 01:04:52 +0000
commita01741fce4d1f62bae55e3995601e05c9e8ba5cd (patch)
tree5311a4b533483308fe98b7044ba1b5c81e8d77ac /clang
parentc51171e0e96eac694a18855ca7a504b4a77ed6ca (diff)
downloadbcm5719-llvm-a01741fce4d1f62bae55e3995601e05c9e8ba5cd.tar.gz
bcm5719-llvm-a01741fce4d1f62bae55e3995601e05c9e8ba5cd.zip
[analyzer] Use a more robust check for null in CallAndMessageChecker.
This should fix the failing test on the buildbot as well. llvm-svn: 161290
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp14
-rw-r--r--clang/test/Analysis/misc-ps-region-store.cpp8
2 files changed, 16 insertions, 6 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
index e09d6885a98..30f45c7685b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
@@ -232,7 +232,11 @@ void CallAndMessageChecker::checkPreStmt(const CallExpr *CE,
return;
}
- if (L.isZeroConstant()) {
+ ProgramStateRef StNonNull, StNull;
+ llvm::tie(StNonNull, StNull) = State->assume(cast<DefinedOrUnknownSVal>(L));
+
+ // FIXME: Do we want to record the non-null assumption here?
+ if (StNull && !StNonNull) {
if (!BT_call_null)
BT_call_null.reset(
new BuiltinBug("Called function pointer is null (null dereference)"));
@@ -253,7 +257,13 @@ void CallAndMessageChecker::checkPreCall(const CallEvent &Call,
emitBadCall(BT_cxx_call_undef.get(), C, CC->getCXXThisExpr());
return;
}
- if (V.isZeroConstant()) {
+
+ ProgramStateRef State = C.getState();
+ ProgramStateRef StNonNull, StNull;
+ llvm::tie(StNonNull, StNull) = State->assume(cast<DefinedOrUnknownSVal>(V));
+
+ // FIXME: Do we want to record the non-null assumption here?
+ if (StNull && !StNonNull) {
if (!BT_cxx_call_null)
BT_cxx_call_null.reset(new BuiltinBug("Called C++ object pointer "
"is null"));
diff --git a/clang/test/Analysis/misc-ps-region-store.cpp b/clang/test/Analysis/misc-ps-region-store.cpp
index fcffe075360..e30cedb9118 100644
--- a/clang/test/Analysis/misc-ps-region-store.cpp
+++ b/clang/test/Analysis/misc-ps-region-store.cpp
@@ -272,11 +272,11 @@ const Rdar9212495_A& rdar9212495(const Rdar9212495_C* ptr) {
const Rdar9212495_A& val = dynamic_cast<const Rdar9212495_A&>(*ptr);
// This is not valid C++; dynamic_cast with a reference type will throw an
- // exception if the pointer does not match the expected type.
+ // exception if the pointer does not match the expected type. However, our
+ // implementation of dynamic_cast will pass through a null pointer...or a
+ // "null reference"! So this branch is actually possible.
if (&val == 0) {
- val.bar(); // no warning (unreachable)
- int *p = 0;
- *p = 0xDEAD; // no warning (unreachable)
+ val.bar(); // expected-warning{{Called C++ object pointer is null}}
}
return val;
OpenPOWER on IntegriCloud