18#include "llvm/ADT/STLExtras.h"
19#include "llvm/ADT/iterator_range.h"
20#include "llvm/Support/Error.h"
31 return llvm::createStringError(
32 "failed to create entity name for %s declared at %s",
36static llvm::Error makeAddEntitySummaryError(
const NamedDecl *FailedContributor,
41 return llvm::createStringError(
42 "failed to add entity summary for contributor %s declared at %s",
47buildEntityPointerLevels(std::set<const Expr *> &&UnsafePointers,
51 EntityPointerLevelSet Result{};
52 llvm::Error AllErrors = llvm::ErrorSuccess();
54 for (
const Expr *Ptr : UnsafePointers) {
61 auto FilteredTranslation = llvm::make_filter_range(
62 *Translation, [](
const EntityPointerLevel &E) ->
bool {
63 return E.getPointerLevel() > 0;
65 Result.insert(FilteredTranslation.begin(), FilteredTranslation.end());
68 AllErrors = llvm::joinErrors(std::move(AllErrors), Translation.takeError());
79 if (
auto *RD = dyn_cast<RecordDecl>(D)) {
80 std::set<const Expr *> Result;
82 for (
const FieldDecl *FD : RD->fields()) {
90std::unique_ptr<UnsafeBufferUsageEntitySummary>
98 return std::make_unique<UnsafeBufferUsageEntitySummary>(
100 Error = EPLs.takeError();
111 std::vector<const NamedDecl *> Contributors;
114 Contributors.push_back(D);
118 bool VisitRecordDecl(
RecordDecl *D)
override {
119 Contributors.push_back(D);
123 bool VisitVarDecl(
VarDecl *D)
override {
127 Contributors.push_back(D);
134 llvm::Error Errors = llvm::ErrorSuccess();
135 auto addError = [&Errors](llvm::Error Err) {
136 Errors = llvm::joinErrors(std::move(Errors), std::move(Err));
139 for (
auto *CD : ContributorFinder.Contributors) {
140 llvm::Error
Error = llvm::ErrorSuccess();
144 addError(std::move(
Error));
150 if (!ContributorName) {
159 addError(makeAddEntitySummaryError(CD, Ctx));
162 llvm::consumeError(std::move(Errors));
Defines the clang::ASTContext interface.
static llvm::Error makeCreateEntityNameError(const NamedDecl *FailedDecl, ASTContext &Ctx)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
TranslationUnitDecl * getTranslationUnitDecl() const
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
bool isFileContext() const
Decl - This represents one declaration (or definition), e.g.
DeclContext * getDeclContext()
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
This represents one expression.
Represents a member of a struct/union/class.
Represents a function declaration or definition.
This represents a decl that may have a name.
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
Represents a struct/union/class.
std::string printToString(const SourceManager &SM) const
SourceLocation getBegin() const
Represents a variable declaration or definition.
Lightweight opaque handle representing an entity in an EntityIdTable.
Uniquely identifies an entity in a program.
Base class for analysis-specific summary data.
An UnsafeBufferUsageEntitySummary is an immutable set of unsafe buffers, in the form of EntityPointer...
llvm::Expected< EntityPointerLevelSet > translateEntityPointerLevel(const Expr *E, ASTContext &Ctx, std::function< EntityId(EntityName EN)> AddEntity)
An EntityPointerLevel represents a level of the declared pointer/array type of an entity.
std::optional< EntityName > getEntityName(const Decl *D)
Maps a declaration to an EntityName.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
@ Success
Annotation was successful.
DynamicRecursiveASTVisitorBase< false > DynamicRecursiveASTVisitor
std::set< const Expr * > findUnsafePointers(const Decl *D)
Find unsafe pointers in body/initializer of D, if D is one of the followings: VarDecl FieldDecl Funct...
int const char * function