Eugene Zelenko | 0a4f3f4 | 2016-02-10 19:11:58 +0000 | [diff] [blame] | 1 | //===- CheckerDocumentation.cpp - Documentation checker ---------*- C++ -*-===// |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This checker lists all the checker callbacks and provides documentation for |
| 10 | // checker writers. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Kristof Umann | 76a2150 | 2018-12-15 16:23:51 +0000 | [diff] [blame] | 14 | #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 15 | #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 16 | #include "clang/StaticAnalyzer/Core/Checker.h" |
| 17 | #include "clang/StaticAnalyzer/Core/CheckerManager.h" |
| 18 | #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 19 | #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h" |
| 20 | |
| 21 | using namespace clang; |
| 22 | using namespace ento; |
| 23 | |
| 24 | // All checkers should be placed into anonymous namespace. |
| 25 | // We place the CheckerDocumentation inside ento namespace to make the |
| 26 | // it visible in doxygen. |
Jordan Rose | f684db6 | 2012-11-07 02:35:02 +0000 | [diff] [blame] | 27 | namespace clang { |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 28 | namespace ento { |
| 29 | |
| 30 | /// This checker documents the callback functions checkers can use to implement |
| 31 | /// the custom handling of the specific events during path exploration as well |
| 32 | /// as reporting bugs. Most of the callbacks are targeted at path-sensitive |
| 33 | /// checking. |
| 34 | /// |
| 35 | /// \sa CheckerContext |
Jordan Rose | 4080b0c | 2012-11-02 23:49:33 +0000 | [diff] [blame] | 36 | class CheckerDocumentation : public Checker< check::PreStmt<ReturnStmt>, |
| 37 | check::PostStmt<DeclStmt>, |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 38 | check::PreObjCMessage, |
| 39 | check::PostObjCMessage, |
Devin Coughlin | ca5ab2b | 2015-09-15 01:13:53 +0000 | [diff] [blame] | 40 | check::ObjCMessageNil, |
Jordan Rose | afe7c2c | 2012-07-02 19:28:16 +0000 | [diff] [blame] | 41 | check::PreCall, |
| 42 | check::PostCall, |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 43 | check::BranchCondition, |
Artem Dergachev | 13b2026 | 2018-01-17 23:46:13 +0000 | [diff] [blame] | 44 | check::NewAllocator, |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 45 | check::Location, |
| 46 | check::Bind, |
| 47 | check::DeadSymbols, |
Devin Coughlin | e434fc4 | 2016-07-28 00:52:10 +0000 | [diff] [blame] | 48 | check::BeginFunction, |
Anna Zaks | 3fdcc0b | 2013-01-03 00:25:29 +0000 | [diff] [blame] | 49 | check::EndFunction, |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 50 | check::EndAnalysis, |
| 51 | check::EndOfTranslationUnit, |
| 52 | eval::Call, |
| 53 | eval::Assume, |
| 54 | check::LiveSymbols, |
| 55 | check::RegionChanges, |
Anna Zaks | dc15415 | 2012-12-20 00:38:25 +0000 | [diff] [blame] | 56 | check::PointerEscape, |
Anna Zaks | 4b04e66 | 2013-03-28 23:15:32 +0000 | [diff] [blame] | 57 | check::ConstPointerEscape, |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 58 | check::Event<ImplicitNullDerefEvent>, |
| 59 | check::ASTDecl<FunctionDecl> > { |
| 60 | public: |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 61 | /// Pre-visit the Statement. |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 62 | /// |
| 63 | /// The method will be called before the analyzer core processes the |
| 64 | /// statement. The notification is performed for every explored CFGElement, |
| 65 | /// which does not include the control flow statements such as IfStmt. The |
| 66 | /// callback can be specialized to be called with any subclass of Stmt. |
| 67 | /// |
| 68 | /// See checkBranchCondition() callback for performing custom processing of |
| 69 | /// the branching statements. |
| 70 | /// |
Jordan Rose | 4080b0c | 2012-11-02 23:49:33 +0000 | [diff] [blame] | 71 | /// check::PreStmt<ReturnStmt> |
| 72 | void checkPreStmt(const ReturnStmt *DS, CheckerContext &C) const {} |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 73 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 74 | /// Post-visit the Statement. |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 75 | /// |
| 76 | /// The method will be called after the analyzer core processes the |
| 77 | /// statement. The notification is performed for every explored CFGElement, |
| 78 | /// which does not include the control flow statements such as IfStmt. The |
| 79 | /// callback can be specialized to be called with any subclass of Stmt. |
| 80 | /// |
Jordan Rose | 4080b0c | 2012-11-02 23:49:33 +0000 | [diff] [blame] | 81 | /// check::PostStmt<DeclStmt> |
| 82 | void checkPostStmt(const DeclStmt *DS, CheckerContext &C) const; |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 83 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 84 | /// Pre-visit the Objective C message. |
Jordan Rose | afe7c2c | 2012-07-02 19:28:16 +0000 | [diff] [blame] | 85 | /// |
| 86 | /// This will be called before the analyzer core processes the method call. |
| 87 | /// This is called for any action which produces an Objective-C message send, |
Jordan Rose | 627b046 | 2012-07-18 21:59:51 +0000 | [diff] [blame] | 88 | /// including explicit message syntax and property access. |
Jordan Rose | afe7c2c | 2012-07-02 19:28:16 +0000 | [diff] [blame] | 89 | /// |
| 90 | /// check::PreObjCMessage |
Jordan Rose | 547060b | 2012-07-02 19:28:04 +0000 | [diff] [blame] | 91 | void checkPreObjCMessage(const ObjCMethodCall &M, CheckerContext &C) const {} |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 92 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 93 | /// Post-visit the Objective C message. |
Jordan Rose | afe7c2c | 2012-07-02 19:28:16 +0000 | [diff] [blame] | 94 | /// \sa checkPreObjCMessage() |
| 95 | /// |
| 96 | /// check::PostObjCMessage |
Jordan Rose | 547060b | 2012-07-02 19:28:04 +0000 | [diff] [blame] | 97 | void checkPostObjCMessage(const ObjCMethodCall &M, CheckerContext &C) const {} |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 98 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 99 | /// Visit an Objective-C message whose receiver is nil. |
Devin Coughlin | ca5ab2b | 2015-09-15 01:13:53 +0000 | [diff] [blame] | 100 | /// |
| 101 | /// This will be called when the analyzer core processes a method call whose |
| 102 | /// receiver is definitely nil. In this case, check{Pre/Post}ObjCMessage and |
| 103 | /// check{Pre/Post}Call will not be called. |
| 104 | /// |
| 105 | /// check::ObjCMessageNil |
| 106 | void checkObjCMessageNil(const ObjCMethodCall &M, CheckerContext &C) const {} |
| 107 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 108 | /// Pre-visit an abstract "call" event. |
Jordan Rose | afe7c2c | 2012-07-02 19:28:16 +0000 | [diff] [blame] | 109 | /// |
| 110 | /// This is used for checkers that want to check arguments or attributed |
| 111 | /// behavior for functions and methods no matter how they are being invoked. |
| 112 | /// |
| 113 | /// Note that this includes ALL cross-body invocations, so if you want to |
Jordan Rose | 4080b0c | 2012-11-02 23:49:33 +0000 | [diff] [blame] | 114 | /// limit your checks to, say, function calls, you should test for that at the |
| 115 | /// beginning of your callback function. |
Jordan Rose | afe7c2c | 2012-07-02 19:28:16 +0000 | [diff] [blame] | 116 | /// |
| 117 | /// check::PreCall |
| 118 | void checkPreCall(const CallEvent &Call, CheckerContext &C) const {} |
| 119 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 120 | /// Post-visit an abstract "call" event. |
Jordan Rose | afe7c2c | 2012-07-02 19:28:16 +0000 | [diff] [blame] | 121 | /// \sa checkPreObjCMessage() |
| 122 | /// |
| 123 | /// check::PostCall |
| 124 | void checkPostCall(const CallEvent &Call, CheckerContext &C) const {} |
| 125 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 126 | /// Pre-visit of the condition statement of a branch (such as IfStmt). |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 127 | void checkBranchCondition(const Stmt *Condition, CheckerContext &Ctx) const {} |
| 128 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 129 | /// Post-visit the C++ operator new's allocation call. |
Artem Dergachev | 13b2026 | 2018-01-17 23:46:13 +0000 | [diff] [blame] | 130 | /// |
| 131 | /// Execution of C++ operator new consists of the following phases: (1) call |
| 132 | /// default or overridden operator new() to allocate memory (2) cast the |
| 133 | /// return value of operator new() from void pointer type to class pointer |
| 134 | /// type, (3) assuming that the value is non-null, call the object's |
| 135 | /// constructor over this pointer, (4) declare that the value of the |
| 136 | /// new-expression is this pointer. This callback is called between steps |
| 137 | /// (2) and (3). Post-call for the allocator is called after step (1). |
| 138 | /// Pre-statement for the new-expression is called on step (4) when the value |
| 139 | /// of the expression is evaluated. |
| 140 | /// \param NE The C++ new-expression that triggered the allocation. |
| 141 | /// \param Target The allocated region, casted to the class type. |
| 142 | void checkNewAllocator(const CXXNewExpr *NE, SVal Target, |
| 143 | CheckerContext &) const {} |
| 144 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 145 | /// Called on a load from and a store to a location. |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 146 | /// |
| 147 | /// The method will be called each time a location (pointer) value is |
| 148 | /// accessed. |
| 149 | /// \param Loc The value of the location (pointer). |
| 150 | /// \param IsLoad The flag specifying if the location is a store or a load. |
| 151 | /// \param S The load is performed while processing the statement. |
| 152 | /// |
| 153 | /// check::Location |
| 154 | void checkLocation(SVal Loc, bool IsLoad, const Stmt *S, |
James Dennett | 845619a | 2012-06-15 07:41:35 +0000 | [diff] [blame] | 155 | CheckerContext &) const {} |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 156 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 157 | /// Called on binding of a value to a location. |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 158 | /// |
| 159 | /// \param Loc The value of the location (pointer). |
| 160 | /// \param Val The value which will be stored at the location Loc. |
| 161 | /// \param S The bind is performed while processing the statement S. |
| 162 | /// |
| 163 | /// check::Bind |
James Dennett | 845619a | 2012-06-15 07:41:35 +0000 | [diff] [blame] | 164 | void checkBind(SVal Loc, SVal Val, const Stmt *S, CheckerContext &) const {} |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 165 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 166 | /// Called whenever a symbol becomes dead. |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 167 | /// |
| 168 | /// This callback should be used by the checkers to aggressively clean |
| 169 | /// up/reduce the checker state, which is important for reducing the overall |
| 170 | /// memory usage. Specifically, if a checker keeps symbol specific information |
Raphael Isemann | b23ccec | 2018-12-10 12:37:46 +0000 | [diff] [blame] | 171 | /// in the state, it can and should be dropped after the symbol becomes dead. |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 172 | /// In addition, reporting a bug as soon as the checker becomes dead leads to |
| 173 | /// more precise diagnostics. (For example, one should report that a malloced |
| 174 | /// variable is not freed right after it goes out of scope.) |
| 175 | /// |
| 176 | /// \param SR The SymbolReaper object can be queried to determine which |
| 177 | /// symbols are dead. |
| 178 | /// |
| 179 | /// check::DeadSymbols |
| 180 | void checkDeadSymbols(SymbolReaper &SR, CheckerContext &C) const {} |
| 181 | |
Devin Coughlin | 8d922aa | 2016-02-19 01:35:10 +0000 | [diff] [blame] | 182 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 183 | /// Called when the analyzer core starts analyzing a function, |
Devin Coughlin | 8d922aa | 2016-02-19 01:35:10 +0000 | [diff] [blame] | 184 | /// regardless of whether it is analyzed at the top level or is inlined. |
| 185 | /// |
| 186 | /// check::BeginFunction |
| 187 | void checkBeginFunction(CheckerContext &Ctx) const {} |
| 188 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 189 | /// Called when the analyzer core reaches the end of a |
Devin Coughlin | 8d922aa | 2016-02-19 01:35:10 +0000 | [diff] [blame] | 190 | /// function being analyzed regardless of whether it is analyzed at the top |
| 191 | /// level or is inlined. |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 192 | /// |
Anna Zaks | 3fdcc0b | 2013-01-03 00:25:29 +0000 | [diff] [blame] | 193 | /// check::EndFunction |
Reka Kovacs | ed8c05c | 2018-07-16 20:47:45 +0000 | [diff] [blame] | 194 | void checkEndFunction(const ReturnStmt *RS, CheckerContext &Ctx) const {} |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 195 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 196 | /// Called after all the paths in the ExplodedGraph reach end of path |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 197 | /// - the symbolic execution graph is fully explored. |
| 198 | /// |
| 199 | /// This callback should be used in cases when a checker needs to have a |
| 200 | /// global view of the information generated on all paths. For example, to |
| 201 | /// compare execution summary/result several paths. |
| 202 | /// See IdempotentOperationChecker for a usage example. |
| 203 | /// |
| 204 | /// check::EndAnalysis |
| 205 | void checkEndAnalysis(ExplodedGraph &G, |
| 206 | BugReporter &BR, |
| 207 | ExprEngine &Eng) const {} |
| 208 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 209 | /// Called after analysis of a TranslationUnit is complete. |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 210 | /// |
| 211 | /// check::EndOfTranslationUnit |
Anton Yartsev | edb0628 | 2012-03-23 02:43:24 +0000 | [diff] [blame] | 212 | void checkEndOfTranslationUnit(const TranslationUnitDecl *TU, |
| 213 | AnalysisManager &Mgr, |
| 214 | BugReporter &BR) const {} |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 215 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 216 | /// Evaluates function call. |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 217 | /// |
Gabor Horvath | 2c3d49b | 2019-01-29 10:15:52 +0000 | [diff] [blame] | 218 | /// The analysis core treats all function calls in the same way. However, some |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 219 | /// functions have special meaning, which should be reflected in the program |
| 220 | /// state. This callback allows a checker to provide domain specific knowledge |
| 221 | /// about the particular functions it knows about. |
| 222 | /// |
| 223 | /// \returns true if the call has been successfully evaluated |
| 224 | /// and false otherwise. Note, that only one checker can evaluate a call. If |
Duncan Sands | f3dcb68 | 2013-05-25 02:22:10 +0000 | [diff] [blame] | 225 | /// more than one checker claims that they can evaluate the same call the |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 226 | /// first one wins. |
| 227 | /// |
| 228 | /// eval::Call |
| 229 | bool evalCall(const CallExpr *CE, CheckerContext &C) const { return true; } |
| 230 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 231 | /// Handles assumptions on symbolic values. |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 232 | /// |
| 233 | /// This method is called when a symbolic expression is assumed to be true or |
| 234 | /// false. For example, the assumptions are performed when evaluating a |
| 235 | /// condition at a branch. The callback allows checkers track the assumptions |
| 236 | /// performed on the symbols of interest and change the state accordingly. |
| 237 | /// |
| 238 | /// eval::Assume |
Ted Kremenek | 49b1e38 | 2012-01-26 21:29:00 +0000 | [diff] [blame] | 239 | ProgramStateRef evalAssume(ProgramStateRef State, |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 240 | SVal Cond, |
| 241 | bool Assumption) const { return State; } |
| 242 | |
| 243 | /// Allows modifying SymbolReaper object. For example, checkers can explicitly |
| 244 | /// register symbols of interest as live. These symbols will not be marked |
| 245 | /// dead and removed. |
| 246 | /// |
| 247 | /// check::LiveSymbols |
Ted Kremenek | 49b1e38 | 2012-01-26 21:29:00 +0000 | [diff] [blame] | 248 | void checkLiveSymbols(ProgramStateRef State, SymbolReaper &SR) const {} |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 249 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 250 | /// Called when the contents of one or more regions change. |
Jordan Rose | f684db6 | 2012-11-07 02:35:02 +0000 | [diff] [blame] | 251 | /// |
| 252 | /// This can occur in many different ways: an explicit bind, a blanket |
| 253 | /// invalidation of the region contents, or by passing a region to a function |
| 254 | /// call whose behavior the analyzer cannot model perfectly. |
James Dennett | 845619a | 2012-06-15 07:41:35 +0000 | [diff] [blame] | 255 | /// |
| 256 | /// \param State The current program state. |
| 257 | /// \param Invalidated A set of all symbols potentially touched by the change. |
Anna Zaks | 3d34834 | 2012-02-14 21:55:24 +0000 | [diff] [blame] | 258 | /// \param ExplicitRegions The regions explicitly requested for invalidation. |
Jordan Rose | f684db6 | 2012-11-07 02:35:02 +0000 | [diff] [blame] | 259 | /// For a function call, this would be the arguments. For a bind, this |
| 260 | /// would be the region being bound to. |
| 261 | /// \param Regions The transitive closure of regions accessible from, |
| 262 | /// \p ExplicitRegions, i.e. all regions that may have been touched |
| 263 | /// by this change. For a simple bind, this list will be the same as |
| 264 | /// \p ExplicitRegions, since a bind does not affect the contents of |
| 265 | /// anything accessible through the base region. |
Anna Zaks | b570195 | 2017-01-13 00:50:57 +0000 | [diff] [blame] | 266 | /// \param LCtx LocationContext that is useful for getting various contextual |
| 267 | /// info, like callstack, CFG etc. |
Jordan Rose | f684db6 | 2012-11-07 02:35:02 +0000 | [diff] [blame] | 268 | /// \param Call The opaque call triggering this invalidation. Will be 0 if the |
| 269 | /// change was not triggered by a call. |
| 270 | /// |
James Dennett | 845619a | 2012-06-15 07:41:35 +0000 | [diff] [blame] | 271 | /// check::RegionChanges |
Ted Kremenek | 3a0678e | 2015-09-08 03:50:52 +0000 | [diff] [blame] | 272 | ProgramStateRef |
Ted Kremenek | 49b1e38 | 2012-01-26 21:29:00 +0000 | [diff] [blame] | 273 | checkRegionChanges(ProgramStateRef State, |
Anna Zaks | dc15415 | 2012-12-20 00:38:25 +0000 | [diff] [blame] | 274 | const InvalidatedSymbols *Invalidated, |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 275 | ArrayRef<const MemRegion *> ExplicitRegions, |
Anna Zaks | 3d34834 | 2012-02-14 21:55:24 +0000 | [diff] [blame] | 276 | ArrayRef<const MemRegion *> Regions, |
Anna Zaks | b570195 | 2017-01-13 00:50:57 +0000 | [diff] [blame] | 277 | const LocationContext *LCtx, |
Jordan Rose | 742920c | 2012-07-02 19:27:35 +0000 | [diff] [blame] | 278 | const CallEvent *Call) const { |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 279 | return State; |
| 280 | } |
| 281 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 282 | /// Called when pointers escape. |
Anna Zaks | dc15415 | 2012-12-20 00:38:25 +0000 | [diff] [blame] | 283 | /// |
| 284 | /// This notifies the checkers about pointer escape, which occurs whenever |
Anna Zaks | 9747feb | 2012-12-21 01:50:14 +0000 | [diff] [blame] | 285 | /// the analyzer cannot track the symbol any more. For example, as a |
Ted Kremenek | 3a0678e | 2015-09-08 03:50:52 +0000 | [diff] [blame] | 286 | /// result of assigning a pointer into a global or when it's passed to a |
Anna Zaks | dc15415 | 2012-12-20 00:38:25 +0000 | [diff] [blame] | 287 | /// function call the analyzer cannot model. |
Ted Kremenek | 3a0678e | 2015-09-08 03:50:52 +0000 | [diff] [blame] | 288 | /// |
Anna Zaks | dc15415 | 2012-12-20 00:38:25 +0000 | [diff] [blame] | 289 | /// \param State The state at the point of escape. |
| 290 | /// \param Escaped The list of escaped symbols. |
Ted Kremenek | 3a0678e | 2015-09-08 03:50:52 +0000 | [diff] [blame] | 291 | /// \param Call The corresponding CallEvent, if the symbols escape as |
Anna Zaks | dc15415 | 2012-12-20 00:38:25 +0000 | [diff] [blame] | 292 | /// parameters to the given call. |
Anna Zaks | acdc13c | 2013-02-07 23:05:43 +0000 | [diff] [blame] | 293 | /// \param Kind How the symbols have escaped. |
Anna Zaks | dc15415 | 2012-12-20 00:38:25 +0000 | [diff] [blame] | 294 | /// \returns Checkers can modify the state by returning a new state. |
| 295 | ProgramStateRef checkPointerEscape(ProgramStateRef State, |
| 296 | const InvalidatedSymbols &Escaped, |
Anna Zaks | acdc13c | 2013-02-07 23:05:43 +0000 | [diff] [blame] | 297 | const CallEvent *Call, |
| 298 | PointerEscapeKind Kind) const { |
Anna Zaks | dc15415 | 2012-12-20 00:38:25 +0000 | [diff] [blame] | 299 | return State; |
| 300 | } |
| 301 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 302 | /// Called when const pointers escape. |
Anna Zaks | 4b04e66 | 2013-03-28 23:15:32 +0000 | [diff] [blame] | 303 | /// |
| 304 | /// Note: in most cases checkPointerEscape callback is sufficient. |
| 305 | /// \sa checkPointerEscape |
| 306 | ProgramStateRef checkConstPointerEscape(ProgramStateRef State, |
| 307 | const InvalidatedSymbols &Escaped, |
| 308 | const CallEvent *Call, |
| 309 | PointerEscapeKind Kind) const { |
| 310 | return State; |
| 311 | } |
Ted Kremenek | 3a0678e | 2015-09-08 03:50:52 +0000 | [diff] [blame] | 312 | |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 313 | /// check::Event<ImplicitNullDerefEvent> |
| 314 | void checkEvent(ImplicitNullDerefEvent Event) const {} |
| 315 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 316 | /// Check every declaration in the AST. |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 317 | /// |
| 318 | /// An AST traversal callback, which should only be used when the checker is |
| 319 | /// not path sensitive. It will be called for every Declaration in the AST and |
| 320 | /// can be specialized to only be called on subclasses of Decl, for example, |
| 321 | /// FunctionDecl. |
| 322 | /// |
| 323 | /// check::ASTDecl<FunctionDecl> |
| 324 | void checkASTDecl(const FunctionDecl *D, |
| 325 | AnalysisManager &Mgr, |
| 326 | BugReporter &BR) const {} |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 327 | }; |
| 328 | |
Jordan Rose | 4080b0c | 2012-11-02 23:49:33 +0000 | [diff] [blame] | 329 | void CheckerDocumentation::checkPostStmt(const DeclStmt *DS, |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 330 | CheckerContext &C) const { |
Anna Zaks | 92297f9 | 2011-11-30 17:12:52 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Jordan Rose | f684db6 | 2012-11-07 02:35:02 +0000 | [diff] [blame] | 333 | } // end namespace ento |
| 334 | } // end namespace clang |