12#ifndef LLVM_CLANG_SCALABLESTATICANALYSIS_ANALYSES_SSAFANALYSESCOMMON_H
13#define LLVM_CLANG_SCALABLESTATICANALYSIS_ANALYSES_SSAFANALYSESCOMMON_H
21#include "llvm/ADT/DenseMap.h"
22#include "llvm/ADT/STLFunctionalExtras.h"
23#include "llvm/Support/Debug.h"
24#include "llvm/Support/Error.h"
25#include "llvm/Support/JSON.h"
26#include "llvm/Support/raw_ostream.h"
39template <
typename NodeTy,
typename... Ts>
41 llvm::StringRef Fmt,
const Ts &...Args) {
43 return llvm::createStringError((Fmt +
" at %s").str().c_str(), Args...,
47template <
typename JSONTy,
typename... Ts>
49 const Ts &...ExpectedArgs) {
50 std::string Fmt = (
"saw %s but expected " +
Expected).str();
53 return llvm::createStringError(Fmt.c_str(), SawStr.c_str(), ExpectedArgs...);
58 return llvm::isa<clang::PointerType, clang::ArrayType>(
64 return llvm::isa<clang::PointerType, clang::ArrayType>(
73 DEBUG_WITH_TYPE(
"ssaf-analyses", llvm::errs() << Err);
74 llvm::consumeError(std::move(Err));
89 llvm::DenseMap<
const NamedDecl *, std::vector<const NamedDecl *>>
97 llvm::function_ref<
void(
const DynTypedNode &)> MatchActionRef);
112template <
typename ExtractorFnT>
115 ExtractorFnT ExtractFn,
116 llvm::StringRef ExtractorName =
"") {
117 llvm::DenseMap<const NamedDecl *, std::vector<const NamedDecl *>>
120 for (
const auto &[Cano, Decls] : Contributors) {
121 assert(!Decls.empty() &&
122 "'findContributors' guarantees that 'Decls' are non-empty");
123 assert(!Decls[0]->isImplicit() &&
124 "'findContributors' guarantees that 'Decls' are non-implicit");
129 if (Decls[0]->isTemplated())
132 auto Summary = ExtractFn(Decls);
134 if (Summary->empty())
137 if (
auto Id = Extractor.
addEntity(Decls[0])) {
138 if (!Builder.addSummary(*Id, std::move(Summary)).second)
140 Ctx, Decls[0],
"dropping duplicate %s summary for entity %s",
141 ExtractorName.str().c_str(), Decls[0]->getNameAsString().c_str()));
Defines the clang::ASTContext interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
A dynamically typed AST node container.
This represents one expression.
This represents a decl that may have a name.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getCanonicalType() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
void extractAndAddSummaries(TUSummaryExtractor &Extractor, TUSummaryBuilder &Builder, ASTContext &Ctx, ExtractorFnT ExtractFn, llvm::StringRef ExtractorName="")
The standard contributor-summary extraction procedure:
bool hasPtrOrArrType(const Expr *E)
void logWarningFromError(llvm::Error Err)
Log a warning from an llvm::Error.
llvm::Error makeErrAtNode(clang::ASTContext &Ctx, const NodeTy *N, llvm::StringRef Fmt, const Ts &...Args)
llvm::Error makeEntityNameErr(clang::ASTContext &Ctx, const clang::NamedDecl *D)
void findMatchesIn(const NamedDecl *Contributor, llvm::function_ref< void(const DynTypedNode &)> MatchActionRef)
Perform "MatchAction" on each Stmt and Decl belonging to the Contributor.
llvm::Error makeSawButExpectedError(const JSONTy &Saw, llvm::StringRef Expected, const Ts &...ExpectedArgs)
std::string describeJSONValue(const llvm::json::Value &V)
void findContributors(ASTContext &Ctx, const SSAFOptions &Options, llvm::DenseMap< const NamedDecl *, std::vector< const NamedDecl * > > &Contributors)
Find all contributors in an AST.