summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2013-03-02 03:20:52 +0000
committerAnna Zaks <ganna@apple.com>2013-03-02 03:20:52 +0000
commit8d7c8a4dd6ef965e9f6b358c7005195e635ca7c1 (patch)
treecedacc3aeb89371513adac93e2c9695f21b91ce9 /clang/lib/StaticAnalyzer/Core/ProgramState.cpp
parente400cb70d4c37e8ae9c96ebf1f412eaa329d2850 (diff)
downloadbcm5719-llvm-8d7c8a4dd6ef965e9f6b358c7005195e635ca7c1.tar.gz
bcm5719-llvm-8d7c8a4dd6ef965e9f6b358c7005195e635ca7c1.zip
[analyzer] Simple inline defensive checks suppression
Inlining brought a few "null pointer use" false positives, which occur because the callee defensively checks if a pointer is NULL, whereas the caller knows that the pointer cannot be NULL in the context of the given call. This is a first attempt to silence these warnings by tracking the symbolic value along the execution path in the BugReporter. The new visitor finds the node in which the symbol was first constrained to NULL. If the node belongs to a function on the active stack, the warning is reported, otherwise, it is suppressed. There are several areas for follow up work, for example: - How do we differentiate the cases where the first check is followed by another one, which does happen on the active stack? Also, this only silences a fraction of null pointer use warnings. For example, it does not do anything for the cases where NULL was assigned inside a callee. llvm-svn: 176402
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/ProgramState.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Core/ProgramState.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
index 400569e49a5..64205f8d998 100644
--- a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -324,6 +324,16 @@ ProgramStateRef ProgramState::assumeInBound(DefinedOrUnknownSVal Idx,
return CM.assume(this, inBound.castAs<DefinedSVal>(), Assumption);
}
+ConditionTruthVal ProgramState::isNull(SVal V) const {
+ if (V.isZeroConstant())
+ return true;
+
+ SymbolRef Sym = V.getAsSymbol();
+ if (!Sym)
+ return false;
+ return getStateManager().ConstraintMgr->isNull(this, Sym);
+}
+
ProgramStateRef ProgramStateManager::getInitialState(const LocationContext *InitLoc) {
ProgramState State(this,
EnvMgr.getInitialEnvironment(),
OpenPOWER on IntegriCloud