31 return RequiredParams;
39 MaybeCount RequiredArgs ,
40 MaybeCount RequiredParams )
41 : RequiredArgs(RequiredArgs),
44 assert(!QualifiedName.empty());
45 this->QualifiedName.reserve(QualifiedName.size());
46 llvm::transform(QualifiedName, std::back_inserter(this->QualifiedName),
47 [](StringRef From) {
return From.str(); });
55 const auto *FD = dyn_cast_or_null<FunctionDecl>(
Call.getDecl());
59 return matchesImpl(FD,
Call.getNumArgs(),
Call.parameters().size());
63 const auto *FD = dyn_cast_or_null<FunctionDecl>(CE.
getCalleeDecl());
67 return matchesImpl(FD, CE.
getNumArgs(), FD->param_size());
70bool ento::CallDescription::matchNameOnly(
const NamedDecl *ND)
const {
86bool ento::CallDescription::matchQualifiedNameParts(
const Decl *D)
const {
87 const auto FindNextNamespaceOrRecord =
90 Ctx = Ctx->getParent();
94 auto QualifierPartsIt = begin_qualified_name_parts();
95 const auto QualifierPartsEndIt = end_qualified_name_parts();
99 const DeclContext *Ctx = FindNextNamespaceOrRecord(D->
getDeclContext());
100 for (; Ctx && QualifierPartsIt != QualifierPartsEndIt;
101 Ctx = FindNextNamespaceOrRecord(Ctx->
getParent())) {
109 return QualifierPartsIt == QualifierPartsEndIt;
112bool ento::CallDescription::matchesImpl(
const FunctionDecl *FD,
size_t ArgCount,
113 size_t ParamCount)
const {
119 if (MatchAs == Mode::SimpleFunc && isMethod)
122 if (MatchAs == Mode::CXXMethod && !isMethod)
125 if (MatchAs == Mode::CLibraryMaybeHardened) {
134 return (RequiredArgs.value_or(ArgCount) <= ArgCount &&
135 RequiredParams.value_or(ParamCount) <= ParamCount);
139 if (RequiredArgs.value_or(ArgCount) != ArgCount ||
140 RequiredParams.value_or(ParamCount) != ParamCount)
143 if (MatchAs == Mode::CLibrary || MatchAs == Mode::CLibraryMaybeHardened)
146 if (!matchNameOnly(FD))
149 if (!hasQualifiedNameParts())
152 return matchQualifiedNameParts(FD);
156 std::initializer_list<CallDescription> &&List) {
157 Impl.LinearMap.reserve(List.size());
159 Impl.LinearMap.push_back({CD,
true});
163 return static_cast<bool>(Impl.lookup(
Call));
167 return static_cast<bool>(Impl.lookupAsWritten(CE));
static MaybeCount readRequiredParams(MaybeCount RequiredArgs, MaybeCount RequiredParams)
std::optional< unsigned > MaybeCount
static std::string getFunctionName(const CallEvent &Call)
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Decl - This represents one declaration (or definition), e.g.
ASTContext & getASTContext() const LLVM_READONLY
DeclContext * getDeclContext()
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
std::string getAsString() const
Retrieve the human-readable string for this name.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
CallDescriptionSet(std::initializer_list< CallDescription > &&List)
bool containsAsWritten(const CallExpr &CE) const
When available, always prefer lookup with a CallEvent!
bool contains(const CallEvent &Call) const
A CallDescription is a pattern that can be used to match calls based on the qualified name and the ar...
CallDescription(Mode MatchAs, ArrayRef< StringRef > QualifiedName, MaybeCount RequiredArgs=std::nullopt, MaybeCount RequiredParams=std::nullopt)
Constructs a CallDescription object.
bool matches(const CallEvent &Call) const
Returns true if the CallEvent is a call to a function that matches the CallDescription.
bool matchesAsWritten(const CallExpr &CE) const
Returns true if the CallExpr is a call to a function that matches the CallDescription.
Represents an abstract call to a function or method along a particular path.
static bool isCLibraryFunction(const FunctionDecl *FD, StringRef Name=StringRef())
Returns true if the given function is an externally-visible function in the top-level namespace,...
static bool isHardenedVariantOf(const FunctionDecl *FD, StringRef Name)
In builds that use source hardening (-D_FORTIFY_SOURCE), many standard functions are implemented as m...
StringRef getName(const HeaderType T)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
U cast(CodeGen::Address addr)
Diagnostic wrappers for TextAPI types for error reporting.