clang 17.0.0git
|
#include "clang/Analysis/Analyses/UnsafeBufferUsage.h"
#include "clang/AST/Decl.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/Preprocessor.h"
#include "llvm/ADT/SmallVector.h"
#include <memory>
#include <optional>
#include "clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def"
Go to the source code of this file.
Classes | |
class | clang::ast_matchers::MatchDescendantVisitor |
class | DerefSimplePtrArithFixableGadget |
struct | CompareNode< NodeTy > |
struct | WarningGadgetSets |
struct | FixableGadgetSets |
Namespaces | |
namespace | clang |
namespace | clang::ast_matchers |
Macros | |
#define | GADGET(x) x, |
#define | NEXT ++numFound |
#define | FIXABLE_GADGET(name) |
#define | WARNING_GADGET(name) |
#define | FIXABLE_GADGET(x) x ## Gadget::matcher().bind(#x), |
#define | WARNING_GADGET(x) allOf(x ## Gadget::matcher().bind(#x), notInSafeBufferOptOut(&Handler)), |
Functions | |
clang::ast_matchers::AST_MATCHER_P (Stmt, forEveryDescendant, internal::Matcher< Stmt >, innerMatcher) | |
clang::ast_matchers::AST_MATCHER_P (Stmt, notInSafeBufferOptOut, const UnsafeBufferUsageHandler *, Handler) | |
clang::ast_matchers::AST_MATCHER_P (CastExpr, castSubExpr, internal::Matcher< Expr >, innerMatcher) | |
static auto | clang::ast_matchers::isInUnspecifiedLvalueContext (internal::Matcher< Expr > innerMatcher) |
static auto | hasPointerType () |
static auto | hasArrayType () |
static std::tuple< FixableGadgetList, WarningGadgetList, DeclUseTracker > | findGadgets (const Decl *D, const UnsafeBufferUsageHandler &Handler) |
Scan the function and return a list of gadgets found with provided kits. | |
static WarningGadgetSets | groupWarningGadgetsByVar (WarningGadgetList &&AllUnsafeOperations) |
static FixableGadgetSets | groupFixablesByVar (FixableGadgetList &&AllFixableOperations) |
static std::string | getAPIntText (APInt Val) |
template<typename NodeTy > | |
static SourceLocation | getEndCharLoc (const NodeTy *Node, const SourceManager &SM, const LangOptions &LangOpts) |
template<typename NodeTy > | |
static SourceLocation | getPastLoc (const NodeTy *Node, const SourceManager &SM, const LangOptions &LangOpts) |
static StringRef | getExprText (const Expr *E, const SourceManager &SM, const LangOptions &LangOpts) |
static FixItList | populateInitializerFixItWithSpan (const Expr *Init, const ASTContext &Ctx, const StringRef UserFillPlaceHolder) |
static FixItList | fixVarDeclWithSpan (const VarDecl *D, const ASTContext &Ctx, const StringRef UserFillPlaceHolder) |
static FixItList | fixVariableWithSpan (const VarDecl *VD, const DeclUseTracker &Tracker, const ASTContext &Ctx, UnsafeBufferUsageHandler &Handler) |
static FixItList | fixVariable (const VarDecl *VD, Strategy::Kind K, const DeclUseTracker &Tracker, const ASTContext &Ctx, UnsafeBufferUsageHandler &Handler) |
static bool | overlapWithMacro (const FixItList &FixIts) |
static std::map< const VarDecl *, FixItList > | getFixIts (FixableGadgetSets &FixablesForUnsafeVars, const Strategy &S, const DeclUseTracker &Tracker, const ASTContext &Ctx, UnsafeBufferUsageHandler &Handler) |
static Strategy | getNaiveStrategy (const llvm::SmallVectorImpl< const VarDecl * > &UnsafeVars) |
#define FIXABLE_GADGET | ( | name | ) |
#define FIXABLE_GADGET | ( | x | ) | x ## Gadget::matcher().bind(#x), |
#define GADGET | ( | x | ) | x, |
Definition at line 183 of file UnsafeBufferUsage.cpp.
#define NEXT ++numFound |
#define WARNING_GADGET | ( | name | ) |
#define WARNING_GADGET | ( | x | ) | allOf(x ## Gadget::matcher().bind(#x), notInSafeBufferOptOut(&Handler)), |
|
static |
Scan the function and return a list of gadgets found with provided kits.
Definition at line 614 of file UnsafeBufferUsage.cpp.
References clang::ast_matchers::MatchFinder::addMatcher(), clang::ast_matchers::allOf, clang::ast_matchers::anyOf, clang::ast_matchers::declRefExpr, clang::ast_matchers::declStmt, clang::ast_matchers::eachOf, FIXABLE_GADGET, clang::Decl::getASTContext(), clang::Decl::getBody(), hasArrayType(), hasPointerType(), clang::ast_matchers::MatchFinder::match(), NEXT, clang::ast_matchers::MatchFinder::MatchCallback::run(), clang::ast_matchers::stmt, clang::ast_matchers::varDecl, and WARNING_GADGET.
Referenced by clang::checkUnsafeBufferUsage().
|
static |
Definition at line 993 of file UnsafeBufferUsage.cpp.
References clang::FixItHint::CreateReplacement(), clang::QualType::getAsString(), clang::DeclaratorDecl::getBeginLoc(), getEndCharLoc(), clang::VarDecl::getInit(), clang::ASTContext::getLangOpts(), clang::NamedDecl::getName(), clang::Type::getPointeeType(), clang::ASTContext::getSourceManager(), clang::ValueDecl::getType(), clang::QualType::isNull(), populateInitializerFixItWithSpan(), and SM.
Referenced by fixVariableWithSpan().
|
static |
Definition at line 1045 of file UnsafeBufferUsage.cpp.
References fixVariableWithSpan(), clang::ValueDecl::getType(), clang::VarDecl::isLocalVarDecl(), and clang::Type::isPointerType().
Referenced by getFixIts().
|
static |
Definition at line 1026 of file UnsafeBufferUsage.cpp.
References fixVarDeclWithSpan(), clang::UnsafeBufferUsageHandler::getUserFillPlaceHolder(), and clang::DeclStmt::isSingleDecl().
Referenced by fixVariable().
|
static |
Definition at line 834 of file UnsafeBufferUsage.cpp.
Referenced by populateInitializerFixItWithSpan().
|
static |
Definition at line 844 of file UnsafeBufferUsage.cpp.
References clang::Lexer::getLocForEndOfToken(), Node, and SM.
Referenced by fixVarDeclWithSpan().
|
static |
Definition at line 857 of file UnsafeBufferUsage.cpp.
References clang::Stmt::getBeginLoc(), clang::CharSourceRange::getCharRange(), getPastLoc(), clang::Lexer::getSourceText(), and SM.
Referenced by populateInitializerFixItWithSpan().
|
static |
Definition at line 1080 of file UnsafeBufferUsage.cpp.
References clang::internal::anyConflict(), FixableGadgetSets::byVar, fixVariable(), clang::ASTContext::getSourceManager(), and overlapWithMacro().
Referenced by clang::checkUnsafeBufferUsage().
|
static |
Definition at line 1124 of file UnsafeBufferUsage.cpp.
Referenced by clang::checkUnsafeBufferUsage().
|
static |
Definition at line 851 of file UnsafeBufferUsage.cpp.
References clang::Lexer::getLocForEndOfToken(), Node, and SM.
Referenced by getExprText(), DerefSimplePtrArithFixableGadget::getFixits(), and populateInitializerFixItWithSpan().
|
static |
Definition at line 759 of file UnsafeBufferUsage.cpp.
References FixableGadgetSets::byVar, and clang::DeclRefExpr::getDecl().
Referenced by clang::checkUnsafeBufferUsage().
|
static |
Definition at line 731 of file UnsafeBufferUsage.cpp.
References WarningGadgetSets::byVar, clang::DeclRefExpr::getDecl(), and WarningGadgetSets::noVar.
Referenced by clang::checkUnsafeBufferUsage().
|
static |
Definition at line 167 of file UnsafeBufferUsage.cpp.
References clang::ast_matchers::arrayType.
Referenced by findGadgets().
|
static |
Definition at line 163 of file UnsafeBufferUsage.cpp.
References clang::ast_matchers::pointerType.
Referenced by findGadgets(), and DerefSimplePtrArithFixableGadget::matcher().
|
static |
Definition at line 1067 of file UnsafeBufferUsage.cpp.
References clang::CharSourceRange::getBegin(), and clang::FixItHint::RemoveRange.
Referenced by getFixIts().
|
static |
Definition at line 930 of file UnsafeBufferUsage.cpp.
References clang::FixItHint::CreateInsertion(), getAPIntText(), clang::ASTContext::getAsConstantArrayType(), getExprText(), clang::ASTContext::getLangOpts(), getPastLoc(), clang::ASTContext::getSourceManager(), and SM.
Referenced by fixVarDeclWithSpan().