clang 18.0.0git
Public Member Functions | Friends | List of all members
clang::ento::CallDescription Class Reference

This class represents a description of a function call using the number of arguments and the name of the function. More...

#include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"

Public Member Functions

 CallDescription (CallDescriptionFlags Flags, ArrayRef< StringRef > QualifiedName, MaybeCount RequiredArgs=std::nullopt, MaybeCount RequiredParams=std::nullopt)
 Constructs a CallDescription object.
 
 CallDescription (ArrayRef< StringRef > QualifiedName, MaybeCount RequiredArgs=std::nullopt, MaybeCount RequiredParams=std::nullopt)
 Construct a CallDescription with default flags.
 
 CallDescription (std::nullptr_t)=delete
 
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.
 

Detailed Description

This class represents a description of a function call using the number of arguments and the name of the function.

Definition at line 43 of file CallDescription.h.

Constructor & Destructor Documentation

◆ CallDescription() [1/3]

ento::CallDescription::CallDescription ( CallDescriptionFlags  Flags,
ArrayRef< StringRef >  QualifiedName,
MaybeCount  RequiredArgs = std::nullopt,
MaybeCount  RequiredParams = std::nullopt 
)

Constructs a CallDescription object.

Parameters
QualifiedNameThe 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().
RequiredArgsThe number of arguments that is expected to match a call. Omit this parameter to match every occurrence of call with a given name regardless the number of arguments.

Definition at line 38 of file CallDescription.cpp.

◆ CallDescription() [2/3]

ento::CallDescription::CallDescription ( ArrayRef< StringRef >  QualifiedName,
MaybeCount  RequiredArgs = std::nullopt,
MaybeCount  RequiredParams = std::nullopt 
)

Construct a CallDescription with default flags.

Definition at line 52 of file CallDescription.cpp.

◆ CallDescription() [3/3]

clang::ento::CallDescription::CallDescription ( std::nullptr_t  )
delete

Member Function Documentation

◆ begin_qualified_name_parts()

auto clang::ento::CallDescription::begin_qualified_name_parts ( ) const
inline

Get the qualified name parts in reversed order.

E.g. { "std", "vector", "data" } -> "vector", "std"

Definition at line 82 of file CallDescription.h.

◆ end_qualified_name_parts()

auto clang::ento::CallDescription::end_qualified_name_parts ( ) const
inline

Definition at line 85 of file CallDescription.h.

◆ getFunctionName()

StringRef clang::ento::CallDescription::getFunctionName ( ) const
inline

Get the name of the function that this object matches.

Definition at line 78 of file CallDescription.h.

◆ hasQualifiedNameParts()

bool clang::ento::CallDescription::hasQualifiedNameParts ( ) const
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 89 of file CallDescription.h.

◆ matches()

bool ento::CallDescription::matches ( const CallEvent Call) const

Returns true if the CallEvent is a call to a function that matches the CallDescription.

Note
This function is not intended to be used to match Obj-C method calls.

Definition at line 57 of file CallDescription.cpp.

References clang::ento::CE_ObjCMessage.

◆ matchesAsWritten()

bool ento::CallDescription::matchesAsWritten ( const CallExpr CE) const

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 candicade 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 69 of file CallDescription.cpp.

References clang::CallExpr::getCalleeDecl(), and clang::CallExpr::getNumArgs().

Friends And Related Function Documentation

◆ CallEvent

friend class CallEvent
friend

Definition at line 44 of file CallDescription.h.

◆ matchesAny [1/2]

bool matchesAny ( const CallEvent Call,
const CallDescription CD1 
)
friend

Returns true whether the CallEvent matches on any of the CallDescriptions supplied.

Note
This function is not intended to be used to match Obj-C method calls.

Definition at line 106 of file CallDescription.h.

◆ matchesAny [2/2]

template<typename... Ts>
bool matchesAny ( const CallEvent Call,
const CallDescription CD1,
const Ts &...  CDs 
)
friend

Returns true whether the CallEvent matches on any of the CallDescriptions supplied.

Note
This function is not intended to be used to match Obj-C method calls.

Definition at line 112 of file CallDescription.h.

◆ matchesAnyAsWritten [1/2]

bool matchesAnyAsWritten ( const CallExpr CE,
const CallDescription CD1 
)
friend

Returns true whether the CallExpr matches on any of the CallDescriptions supplied.

Note
This function is not intended to be used to match Obj-C method calls.

Definition at line 143 of file CallDescription.h.

◆ matchesAnyAsWritten [2/2]

template<typename... Ts>
bool matchesAnyAsWritten ( const CallExpr CE,
const CallDescription CD1,
const Ts &...  CDs 
)
friend

Returns true whether the CallExpr matches on any of the CallDescriptions supplied.

Note
This function is not intended to be used to match Obj-C method calls.

Definition at line 150 of file CallDescription.h.


The documentation for this class was generated from the following files: