clang
19.0.0git
|
#include "clang/Analysis/Analyses/UnsafeBufferUsage.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/Expr.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/Preprocessor.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include <memory>
#include <optional>
#include <queue>
#include <sstream>
#include "clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def"
Go to the source code of this file.
Classes | |
class | clang::ast_matchers::MatchDescendantVisitor |
class | UPCPreIncrementGadget |
class | UUCAddAssignGadget |
class | DerefSimplePtrArithFixableGadget |
struct | CompareNode< NodeTy > |
struct | WarningGadgetSets |
struct | FixableGadgetSets |
class | VariableGroupsManagerImpl |
Namespaces | |
clang | |
The JSON file list parser is used to communicate input to InstallAPI. | |
clang::ast_matchers | |
Macros | |
#define | GADGET(x) x, |
#define | GADGET(x) |
#define | NEXT ++numFound |
#define | FIXABLE_GADGET(name) |
#define | WARNING_GADGET(name) |
#define | WARNING_GADGET(x) |
#define | WARNING_CONTAINER_GADGET(x) |
#define | FIXABLE_GADGET(x) x ## Gadget::matcher().bind(#x), |
#define | DEBUG_NOTE_DECL_FAIL(D, Msg) |
Functions | |
static auto | clang::ast_matchers::hasPointerType () |
static auto | clang::ast_matchers::hasArrayType () |
clang::ast_matchers::AST_MATCHER_P (Stmt, forEachDescendantEvaluatedStmt, internal::Matcher< Stmt >, innerMatcher) | |
clang::ast_matchers::AST_MATCHER_P (Stmt, forEachDescendantStmt, internal::Matcher< Stmt >, innerMatcher) | |
clang::ast_matchers::AST_MATCHER_P (Stmt, notInSafeBufferOptOut, const UnsafeBufferUsageHandler *, Handler) | |
clang::ast_matchers::AST_MATCHER_P (Stmt, ignoreUnsafeBufferInContainer, const UnsafeBufferUsageHandler *, Handler) | |
clang::ast_matchers::AST_MATCHER_P (CastExpr, castSubExpr, internal::Matcher< Expr >, innerMatcher) | |
clang::ast_matchers::AST_MATCHER (UnaryOperator, isPreInc) | |
static auto | clang::ast_matchers::isInUnspecifiedLvalueContext (internal::Matcher< Expr > innerMatcher) |
static internal::Matcher< Stmt > | clang::ast_matchers::isInUnspecifiedPointerContext (internal::Matcher< Stmt > InnerMatcher) |
static internal::Matcher< Stmt > | clang::ast_matchers::isInUnspecifiedUntypedContext (internal::Matcher< Stmt > InnerMatcher) |
clang::ast_matchers::AST_MATCHER (CXXConstructExpr, isSafeSpanTwoParamConstruct) | |
clang::ast_matchers::AST_MATCHER (ArraySubscriptExpr, isSafeArraySubscript) | |
static std::tuple< FixableGadgetList, WarningGadgetList, DeclUseTracker > | findGadgets (const Decl *D, const UnsafeBufferUsageHandler &Handler, bool EmitSuggestions) |
Scan the function and return a list of gadgets found with provided kits. More... | |
static WarningGadgetSets | groupWarningGadgetsByVar (const WarningGadgetList &AllUnsafeOperations) |
static FixableGadgetSets | groupFixablesByVar (FixableGadgetList &&AllFixableOperations) |
static std::optional< FixItList > | createDataFixit (const ASTContext &Ctx, const DeclRefExpr *DRE) |
static bool | isNonNegativeIntegerExpr (const Expr *Expr, const VarDecl *VD, const ASTContext &Ctx) |
static std::optional< FixItList > | fixUPCAddressofArraySubscriptWithSpan (const UnaryOperator *Node) |
static StringRef | getEndOfLine () |
std::string | getUserFillPlaceHolder (StringRef HintTextToUser="placeholder") |
template<typename NodeTy > | |
static std::optional< SourceLocation > | getEndCharLoc (const NodeTy *Node, const SourceManager &SM, const LangOptions &LangOpts) |
template<typename NodeTy > | |
static std::optional< SourceLocation > | getPastLoc (const NodeTy *Node, const SourceManager &SM, const LangOptions &LangOpts) |
static std::optional< StringRef > | getExprText (const Expr *E, const SourceManager &SM, const LangOptions &LangOpts) |
static std::optional< StringRef > | getRangeText (SourceRange SR, const SourceManager &SM, const LangOptions &LangOpts) |
static SourceLocation | getVarDeclIdentifierLoc (const VarDecl *VD) |
static std::optional< StringRef > | getVarDeclIdentifierText (const VarDecl *VD, const SourceManager &SM, const LangOptions &LangOpts) |
static bool | hasUnsupportedSpecifiers (const VarDecl *VD, const SourceManager &SM) |
static SourceRange | getSourceRangeToTokenEnd (const Decl *D, const SourceManager &SM, const LangOptions &LangOpts) |
static std::optional< std::string > | getPointeeTypeText (const VarDecl *VD, const SourceManager &SM, const LangOptions &LangOpts, std::optional< Qualifiers > *QualifiersToAppend) |
static std::optional< StringRef > | getFunNameText (const FunctionDecl *FD, const SourceManager &SM, const LangOptions &LangOpts) |
static std::string | getSpanTypeText (StringRef EltTyText, std::optional< Qualifiers > Quals=std::nullopt) |
static std::optional< FixItList > | FixVarInitializerWithSpan (const Expr *Init, ASTContext &Ctx, const StringRef UserFillPlaceHolder) |
static std::optional< std::string > | createSpanTypeForVarDecl (const VarDecl *VD, const ASTContext &Ctx) |
static FixItList | fixLocalVarDeclWithSpan (const VarDecl *D, ASTContext &Ctx, const StringRef UserFillPlaceHolder, UnsafeBufferUsageHandler &Handler) |
static bool | hasConflictingOverload (const FunctionDecl *FD) |
static std::optional< FixItList > | createOverloadsForFixedParams (const FixitStrategy &S, const FunctionDecl *FD, const ASTContext &Ctx, UnsafeBufferUsageHandler &Handler) |
static FixItList | fixParamWithSpan (const ParmVarDecl *PVD, const ASTContext &Ctx, UnsafeBufferUsageHandler &Handler) |
static FixItList | fixVariableWithSpan (const VarDecl *VD, const DeclUseTracker &Tracker, ASTContext &Ctx, UnsafeBufferUsageHandler &Handler) |
static FixItList | fixVarDeclWithArray (const VarDecl *D, const ASTContext &Ctx, UnsafeBufferUsageHandler &Handler) |
static FixItList | fixVariableWithArray (const VarDecl *VD, const DeclUseTracker &Tracker, const ASTContext &Ctx, UnsafeBufferUsageHandler &Handler) |
static FixItList | fixVariable (const VarDecl *VD, FixitStrategy::Kind K, const Decl *D, const DeclUseTracker &Tracker, ASTContext &Ctx, UnsafeBufferUsageHandler &Handler) |
static bool | overlapWithMacro (const FixItList &FixIts) |
static bool | isParameterOf (const VarDecl *VD, const Decl *D) |
static void | eraseVarsForUnfixableGroupMates (std::map< const VarDecl *, FixItList > &FixItsForVariable, const VariableGroupsManager &VarGrpMgr) |
static FixItList | createFunctionOverloadsForParms (std::map< const VarDecl *, FixItList > &FixItsForVariable, const VariableGroupsManager &VarGrpMgr, const FunctionDecl *FD, const FixitStrategy &S, ASTContext &Ctx, UnsafeBufferUsageHandler &Handler) |
static std::map< const VarDecl *, FixItList > | getFixIts (FixableGadgetSets &FixablesForAllVars, const FixitStrategy &S, ASTContext &Ctx, const Decl *D, const DeclUseTracker &Tracker, UnsafeBufferUsageHandler &Handler, const VariableGroupsManager &VarGrpMgr) |
template<typename VarDeclIterTy > | |
static FixitStrategy | getNaiveStrategy (llvm::iterator_range< VarDeclIterTy > UnsafeVars) |
#define DEBUG_NOTE_DECL_FAIL | ( | D, | |
Msg | |||
) |
Definition at line 2289 of file UnsafeBufferUsage.cpp.
#define FIXABLE_GADGET | ( | name | ) |
#define FIXABLE_GADGET | ( | x | ) | x ## Gadget::matcher().bind(#x), |
#define GADGET | ( | x | ) | x, |
Definition at line 469 of file UnsafeBufferUsage.cpp.
#define GADGET | ( | x | ) |
Definition at line 469 of file UnsafeBufferUsage.cpp.
#define NEXT ++numFound |
#define WARNING_CONTAINER_GADGET | ( | x | ) |
#define WARNING_GADGET | ( | name | ) |
#define WARNING_GADGET | ( | x | ) |
|
inlinestatic |
Definition at line 2051 of file UnsafeBufferUsage.cpp.
References clang::ASTContext::getLangOpts(), getPastLoc(), clang::ASTContext::getSourceManager(), and SM.
|
static |
Definition at line 2863 of file UnsafeBufferUsage.cpp.
|
static |
Definition at line 2420 of file UnsafeBufferUsage.cpp.
|
static |
Definition at line 2301 of file UnsafeBufferUsage.cpp.
References clang::ASTContext::getLangOpts(), getPointeeTypeText(), clang::ASTContext::getSourceManager(), clang::ValueDecl::getType(), and clang::Type::isPointerType().
Referenced by fixLocalVarDeclWithSpan(), and fixParamWithSpan().
|
static |
Definition at line 2834 of file UnsafeBufferUsage.cpp.
References clang::VariableGroupsManager::getGroupOfVar(), and clang::Member.
|
static |
Scan the function and return a list of gadgets found with provided kits.
Definition at line 1390 of file UnsafeBufferUsage.cpp.
References clang::ast_matchers::MatchFinder::addMatcher(), clang::ast_matchers::allOf, clang::ast_matchers::anyOf, clang::ast_matchers::bindingDecl, clang::ast_matchers::declRefExpr, clang::ast_matchers::declStmt, clang::ast_matchers::eachOf, FIXABLE_GADGET, clang::Decl::getASTContext(), clang::Decl::getBody(), clang::ast_matchers::hasArrayType(), clang::ast_matchers::hasPointerType(), clang::ast_matchers::MatchFinder::match(), NEXT, clang::transformer::run(), clang::ast_matchers::stmt, clang::ast_matchers::unless, clang::ast_matchers::varDecl, WARNING_CONTAINER_GADGET, and WARNING_GADGET.
Referenced by clang::checkUnsafeBufferUsage().
|
static |
Definition at line 2337 of file UnsafeBufferUsage.cpp.
References createSpanTypeForVarDecl(), DEBUG_NOTE_DECL_FAIL, FixVarInitializerWithSpan(), clang::DeclaratorDecl::getBeginLoc(), clang::VarDecl::getInit(), clang::SourceLocation::getLocWithOffset(), clang::ASTContext::getSourceManager(), clang::DeclaratorDecl::getTypeSpecEndLoc(), getVarDeclIdentifierLoc(), hasUnsupportedSpecifiers(), and clang::SourceLocation::isValid().
Referenced by fixVariableWithSpan().
|
static |
Definition at line 2587 of file UnsafeBufferUsage.cpp.
References createSpanTypeForVarDecl(), DEBUG_NOTE_DECL_FAIL, clang::Qualifiers::getAsString(), clang::NamedDecl::getIdentifier(), clang::ASTContext::getLangOpts(), clang::IdentifierInfo::getName(), getPointeeTypeText(), clang::QualType::getQualifiers(), clang::ASTContext::getSourceManager(), clang::ParmVarDecl::getSourceRange(), getSpanTypeText(), clang::ValueDecl::getType(), clang::ParmVarDecl::hasDefaultArg(), clang::QualType::hasQualifiers(), and hasUnsupportedSpecifiers().
Referenced by fixVariable().
|
static |
Definition at line 2089 of file UnsafeBufferUsage.cpp.
References clang::Decl::getASTContext(), clang::DeclRefExpr::getDecl(), clang::ASTContext::getSourceManager(), Node, and SM.
|
static |
Definition at line 2656 of file UnsafeBufferUsage.cpp.
References DEBUG_NOTE_DECL_FAIL, clang::DeclaratorDecl::getBeginLoc(), clang::QualType::getCanonicalType(), clang::SourceRange::getEnd(), clang::ASTContext::getLangOpts(), clang::SourceLocation::getLocWithOffset(), getRangeText(), clang::ASTContext::getSourceManager(), clang::VarDecl::getSourceRange(), clang::ValueDecl::getType(), clang::DeclaratorDecl::getTypeSpecEndLoc(), getVarDeclIdentifierLoc(), getVarDeclIdentifierText(), and clang::QualType::isNull().
Referenced by fixVariableWithArray().
|
static |
Definition at line 2752 of file UnsafeBufferUsage.cpp.
References DEBUG_NOTE_DECL_FAIL, fixParamWithSpan(), fixVariableWithArray(), fixVariableWithSpan(), clang::QualType::getCanonicalType(), clang::ValueDecl::getType(), clang::VarDecl::isLocalVarDecl(), and clang::Type::isPointerType().
|
static |
Definition at line 2730 of file UnsafeBufferUsage.cpp.
References fixVarDeclWithArray(), and clang::DeclStmt::isSingleDecl().
Referenced by fixVariable().
|
static |
Definition at line 2632 of file UnsafeBufferUsage.cpp.
References DEBUG_NOTE_DECL_FAIL, fixLocalVarDeclWithSpan(), getUserFillPlaceHolder(), and clang::DeclStmt::isSingleDecl().
Referenced by fixVariable().
|
static |
Definition at line 2211 of file UnsafeBufferUsage.cpp.
References clang::ASTContext::getSourceManager(), and SM.
Referenced by fixLocalVarDeclWithSpan().
|
static |
Definition at line 1739 of file UnsafeBufferUsage.cpp.
|
static |
Definition at line 1723 of file UnsafeBufferUsage.cpp.
|
static |
Definition at line 1763 of file UnsafeBufferUsage.cpp.
|
static |
Definition at line 2887 of file UnsafeBufferUsage.cpp.
Referenced by clang::checkUnsafeBufferUsage().
|
static |
Definition at line 1927 of file UnsafeBufferUsage.cpp.
|
static |
Definition at line 2987 of file UnsafeBufferUsage.cpp.
Referenced by clang::checkUnsafeBufferUsage().
|
static |
Definition at line 1752 of file UnsafeBufferUsage.cpp.
Referenced by createDataFixit().
|
static |
Definition at line 1854 of file UnsafeBufferUsage.cpp.
Referenced by createSpanTypeForVarDecl(), and fixParamWithSpan().
|
static |
Definition at line 1777 of file UnsafeBufferUsage.cpp.
Referenced by fixVarDeclWithArray().
|
static |
Definition at line 1836 of file UnsafeBufferUsage.cpp.
|
static |
Definition at line 1948 of file UnsafeBufferUsage.cpp.
Referenced by fixParamWithSpan().
std::string getUserFillPlaceHolder | ( | StringRef | HintTextToUser = "placeholder" | ) |
Definition at line 1729 of file UnsafeBufferUsage.cpp.
References s.
Referenced by fixVariableWithSpan().
|
static |
Definition at line 1791 of file UnsafeBufferUsage.cpp.
References clang::Decl::getLocation().
Referenced by fixLocalVarDeclWithSpan(), and fixVarDeclWithArray().
|
static |
Definition at line 1799 of file UnsafeBufferUsage.cpp.
Referenced by fixVarDeclWithArray().
|
static |
Definition at line 1542 of file UnsafeBufferUsage.cpp.
References FixableGadgetSets::byVar, and clang::DeclRefExpr::getDecl().
Referenced by clang::checkUnsafeBufferUsage().
|
static |
Definition at line 1510 of file UnsafeBufferUsage.cpp.
References WarningGadgetSets::byVar, clang::DeclRefExpr::getDecl(), and WarningGadgetSets::noVar.
Referenced by clang::checkUnsafeBufferUsage().
|
static |
Definition at line 2384 of file UnsafeBufferUsage.cpp.
References clang::Decl::getDeclContext(), clang::NamedDecl::getDeclName(), clang::DeclContextLookupResult::isSingleResult(), and clang::DeclContext::lookup().
|
static |
Definition at line 1817 of file UnsafeBufferUsage.cpp.
References clang::Decl::attrs(), clang::VarDecl::hasConstantInitialization(), clang::VarDecl::hasLocalStorage(), clang::VarDecl::isConstexpr(), and clang::VarDecl::isInlineSpecified().
Referenced by fixLocalVarDeclWithSpan(), and fixParamWithSpan().
|
static |
Definition at line 1663 of file UnsafeBufferUsage.cpp.
References clang::Expr::getIntegerConstantExpr(), clang::Expr::getType(), and clang::Type::isUnsignedIntegerType().
Definition at line 2826 of file UnsafeBufferUsage.cpp.
References clang::Decl::getDeclContext().
Referenced by clang::checkUnsafeBufferUsage().
|
static |
Definition at line 2813 of file UnsafeBufferUsage.cpp.
References clang::SourceRange::getBegin(), clang::SourceRange::getEnd(), clang::SourceLocation::isMacroID(), Range, and clang::FixItHint::RemoveRange.