clang 22.0.0git
|
A CallDescription is a pattern that can be used to match calls based on the qualified name and the argument/parameter counts. More...
#include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
Public Types | |
enum class | Mode { CLibrary , CLibraryMaybeHardened , SimpleFunc , CXXMethod , Unspecified } |
Public Member Functions | |
CallDescription (Mode MatchAs, ArrayRef< StringRef > QualifiedName, MaybeCount RequiredArgs=std::nullopt, MaybeCount RequiredParams=std::nullopt) | |
Constructs a CallDescription object. | |
StringRef | getFunctionName () const |
Get the name of the function that this object matches. | |
auto | begin_qualified_name_parts () const |
Get the qualified name parts in reversed order. | |
auto | end_qualified_name_parts () const |
bool | hasQualifiedNameParts () const |
It's false, if and only if we expect a single identifier, such as getenv. |
Friends | |
class | CallEvent |
Matching CallDescriptions against a CallEvent | |
bool | matchesAny (const CallEvent &Call, const CallDescription &CD1) |
Returns true whether the CallEvent matches on any of the CallDescriptions supplied. | |
template<typename... Ts> | |
bool | matchesAny (const CallEvent &Call, const CallDescription &CD1, const Ts &...CDs) |
Returns true whether the CallEvent matches on any of the CallDescriptions supplied. | |
bool | matches (const CallEvent &Call) const |
Returns true if the CallEvent is a call to a function that matches the CallDescription. |
Matching CallDescriptions against a CallExpr | |
bool | matchesAnyAsWritten (const CallExpr &CE, const CallDescription &CD1) |
Returns true whether the CallExpr matches on any of the CallDescriptions supplied. | |
template<typename... Ts> | |
bool | matchesAnyAsWritten (const CallExpr &CE, const CallDescription &CD1, const Ts &...CDs) |
Returns true whether the CallExpr matches on any of the CallDescriptions supplied. | |
bool | matchesAsWritten (const CallExpr &CE) const |
Returns true if the CallExpr is a call to a function that matches the CallDescription. |
A CallDescription is a pattern that can be used to match calls based on the qualified name and the argument/parameter counts.
Definition at line 32 of file CallDescription.h.
|
strong |
Enumerator | |
---|---|
CLibrary | Match calls to functions from the C standard library. This also recognizes builtin variants whose name is derived by adding "__builtin", "__inline" or similar prefixes or suffixes; but only matches functions that are externally visible and are declared either directly within a TU or in the namespace 'std'. For the exact heuristics, see CheckerContext::isCLibraryFunction(). |
CLibraryMaybeHardened | An extended version of the CLibrary mode that also matches the hardened variants like __FOO_chk() and __builtin__FOO_chk() that take additional arguments compared to the "regular" function FOO(). This is not the default behavior of CLibrary because in this case the checker code must be prepared to handle the different parametrization. For the exact heuristics, see CheckerContext::isHardenedVariantOf(). |
SimpleFunc | Matches "simple" functions that are not methods. (Static methods are methods.) |
CXXMethod | Matches a C++ method (may be static, may be virtual, may be an overloaded operator, a constructor or a destructor). |
Unspecified | Match any CallEvent that is not an ObjCMethodCall. This should not be used when the checker looks for a concrete function (and knows whether it is a method); but GenericTaintChecker uses this mode to match functions whose name was configured by the user. |
Definition at line 34 of file CallDescription.h.
ento::CallDescription::CallDescription | ( | Mode | MatchAs, |
ArrayRef< StringRef > | QualifiedName, | ||
MaybeCount | RequiredArgs = std::nullopt, | ||
MaybeCount | RequiredParams = std::nullopt ) |
Constructs a CallDescription object.
MatchAs | Specifies the kind of the call that should be matched. |
QualifiedName | The list of the name qualifiers of the function that will be matched. The user is allowed to skip any of the qualifiers. For example, {"std", "basic_string", "c_str"} would match both std::basic_string<...>::c_str() and std::__1::basic_string<...>::c_str(). |
RequiredArgs | The expected number of arguments that are passed to the function. Omit this parameter (or pass std::nullopt) to match every occurrence without checking the argument count in the call. |
RequiredParams | The expected number of parameters in the function definition that is called. Omit this parameter to match every occurrence without checking the parameter count in the definition. |
Definition at line 37 of file CallDescription.cpp.
References readRequiredParams().
Referenced by matchesAny, matchesAny, matchesAnyAsWritten, and matchesAnyAsWritten.
|
inline |
Get the qualified name parts in reversed order.
E.g. { "std", "vector", "data" } -> "vector", "std"
Definition at line 109 of file CallDescription.h.
|
inline |
Definition at line 112 of file CallDescription.h.
|
inline |
Get the name of the function that this object matches.
Definition at line 105 of file CallDescription.h.
|
inline |
It's false, if and only if we expect a single identifier, such as getenv.
It's true for std::swap, or my::detail::container::data.
Definition at line 116 of file CallDescription.h.
Returns true if the CallEvent is a call to a function that matches the CallDescription.
Definition at line 50 of file CallDescription.cpp.
References clang::Call, CallEvent, and clang::ento::CE_ObjCMessage.
Referenced by matchesAny, and matchesAny.
Returns true if the CallExpr is a call to a function that matches the CallDescription.
When available, always prefer matching with a CallEvent! This function exists only when that is not available, for example, when only syntactic check is done on a piece of code.
Also, StdLibraryFunctionsChecker::Signature is likely a better candidate for syntactic only matching if you are writing a new checker. This is handy if a CallDescriptionMap is already there.
The function is imprecise because CallEvent may know path sensitive information, such as the precise argument count (see comments for CallEvent::getNumArgs), the called function if it was called through a function pointer, and other information not available syntactically.
Definition at line 62 of file CallDescription.cpp.
References clang::CallExpr::getCalleeDecl(), and clang::CallExpr::getNumArgs().
Referenced by matchesAnyAsWritten, and matchesAnyAsWritten.
|
friend |
Definition at line 72 of file CallDescription.h.
References CallEvent.
Referenced by CallEvent, matches(), matchesAny, and matchesAny.
|
friend |
Returns true whether the CallEvent matches on any of the CallDescriptions supplied.
Definition at line 133 of file CallDescription.h.
References clang::Call, CallDescription(), CallEvent, and matches().
Referenced by matchesAny.
|
friend |
Returns true whether the CallEvent matches on any of the CallDescriptions supplied.
Definition at line 139 of file CallDescription.h.
References clang::Call, CallDescription(), CallEvent, matches(), and matchesAny.
|
friend |
Returns true whether the CallExpr matches on any of the CallDescriptions supplied.
Definition at line 170 of file CallDescription.h.
References CallDescription(), and matchesAsWritten().
Referenced by matchesAnyAsWritten.
|
friend |
Returns true whether the CallExpr matches on any of the CallDescriptions supplied.
Definition at line 177 of file CallDescription.h.
References CallDescription(), matchesAnyAsWritten, and matchesAsWritten().