diff options
author | Anna Zaks <ganna@apple.com> | 2013-03-02 03:20:52 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2013-03-02 03:20:52 +0000 |
commit | cc5dbdae70c6eb2423921f52a35ba4686d2969cf (patch) | |
tree | 83fe2a6f9d4d350c3a7d2a4838b845cafcf6ae38 /include/clang/StaticAnalyzer | |
parent | 8536fa14ee1048e5e2d62cb3dc11fc640c7dc00d (diff) |
[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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176402 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/StaticAnalyzer')
-rw-r--r-- | include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h | 25 | ||||
-rw-r--r-- | include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h | 10 |
2 files changed, 32 insertions, 3 deletions
diff --git a/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h b/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h index bef4b30a35..c1b5594209 100644 --- a/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h +++ b/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h @@ -280,6 +280,31 @@ public: BugReport &BR); }; +class SuppressInlineDefensiveChecksVisitor +: public BugReporterVisitorImpl<SuppressInlineDefensiveChecksVisitor> +{ + // The symbolic value for which we are tracking constraints. + // This value is constrained to null in the end of path. + DefinedSVal V; + + // Track if we found the node where the constraint was first added. + bool IsSatisfied; + +public: + SuppressInlineDefensiveChecksVisitor(DefinedSVal Val, const ExplodedNode *N); + + void Profile(llvm::FoldingSetNodeID &ID) const; + + /// Return the tag associated with this visitor. This tag will be used + /// to make all PathDiagnosticPieces created by this visitor. + static const char *getTag(); + + PathDiagnosticPiece *VisitNode(const ExplodedNode *N, + const ExplodedNode *PrevN, + BugReporterContext &BRC, + BugReport &BR); +}; + namespace bugreporter { /// Attempts to add visitors to trace a null or undefined value back to its diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h b/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h index eab248bac2..798090735b 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h @@ -173,8 +173,8 @@ public: ProgramStateRef assume(DefinedOrUnknownSVal cond, bool assumption) const; /// This method assumes both "true" and "false" for 'cond', and - /// returns both corresponding states. It's shorthand for doing - /// 'assume' twice. + /// returns both corresponding states. It's shorthand for doing + /// 'assume' twice. std::pair<ProgramStateRef , ProgramStateRef > assume(DefinedOrUnknownSVal cond) const; @@ -182,7 +182,11 @@ public: DefinedOrUnknownSVal upperBound, bool assumption, QualType IndexType = QualType()) const; - + + /// \brief Check if the given SVal is constrained to zero or is a zero + /// constant. + ConditionTruthVal isNull(SVal V) const; + /// Utility method for getting regions. const VarRegion* getRegion(const VarDecl *D, const LocationContext *LC) const; |