clang-tools 22.0.0git
clang::tidy::performance Namespace Reference

Classes

class  AvoidEndlCheck
 ClangTidyCheck Checks to flag for uses of 'std::endl' on streams and suggests using the newline character '"\n"' instead. More...
class  EnumSizeCheck
 Finds enum type definitions that could use smaller integral type as a base. More...
class  FasterStringFindCheck
 Optimize calls to std::string::find() and friends when the needle passed is a single character string literal. More...
class  ForRangeCopyCheck
 A check that detects copied loop variables and suggests using const references. More...
class  ImplicitConversionInLoopCheck
class  InefficientAlgorithmCheck
 Warns on inefficient use of STL algorithms on associative containers. More...
class  InefficientStringConcatenationCheck
 This check is to warn about the performance overhead arising from concatenating strings, using the operator+, instead of operator+=. More...
class  InefficientVectorOperationCheck
 Finds possible inefficient std::vector operations (e.g. More...
class  MoveConstArgCheck
 Find casts of calculation results to bigger type. More...
class  MoveConstructorInitCheck
 The check flags user-defined move constructors that have a ctor-initializer initializing a member or base class through a copy constructor instead of a move constructor. More...
class  NoAutomaticMoveCheck
 Finds local variables that cannot be automatically moved due to constness. More...
class  NoexceptDestructorCheck
 The check flags destructors not marked with noexcept or marked with noexcept(expr) where expr evaluates to false (but is not a false literal itself). More...
class  NoexceptFunctionBaseCheck
 Generic check which checks if the bound function decl is marked with noexcept or noexcept(expr) where expr evaluates to false. More...
class  NoexceptMoveConstructorCheck
 The check flags user-defined move constructors and assignment operators not marked with noexcept or marked with noexcept(expr) where expr evaluates to false (but is not a false literal itself). More...
class  NoexceptSwapCheck
 The check flags swap functions not marked with noexcept or marked with noexcept(expr) where expr evaluates to false (but is not a false literal itself). More...
class  NoIntToPtrCheck
 Diagnoses every integer to pointer cast. More...
class  PerformanceModule
class  TriviallyDestructibleCheck
 A check that finds classes that would be trivial if not for the defaulted destructors declared out-of-line: struct A: TrivialClass { ~A(); TrivialClass trivial_fields; }; A::~A() = default;. More...
class  TypePromotionInMathFnCheck
 Finds calls to C math library functions with implicit float to double promotions. More...
class  UnnecessaryCopyInitialization
class  UnnecessaryValueParamCheck
 A check that flags value parameters of expensive to copy types that can safely be converted to const references. More...

Functions

static std::pair< const char *, std::uint32_t > getNewType (std::size_t Size, std::uint64_t Min, std::uint64_t Max) noexcept
static std::optional< std::string > makeCharacterLiteral (const StringLiteral *Literal)
static bool isReferenced (const VarDecl &LoopVar, const Stmt &Stmt, ASTContext &Context)
static bool isNonTrivialImplicitCast (const Stmt *ST)
static bool areTypesCompatible (QualType Left, QualType Right)
static ast_matchers::internal::Matcher< Expr > supportedContainerTypesMatcher ()
static void replaceCallWithArg (const CallExpr *Call, DiagnosticBuilder &Diag, const SourceManager &SM, const LangOptions &LangOpts)
static bool isRValueReferenceParam (const Expr *Invocation, const QualType *InvocationParmType, const Expr *Arg)
static ClangTidyModuleRegistry::Add< PerformanceModuleX ("performance-module", "Adds performance checks.")
static void recordFixes (const VarDecl &Var, ASTContext &Context, DiagnosticBuilder &Diagnostic)
static std::optional< SourceLocation > firstLocAfterNewLine (SourceLocation Loc, SourceManager &SM)
static void recordRemoval (const DeclStmt &Stmt, ASTContext &Context, DiagnosticBuilder &Diagnostic)
static bool isInitializingVariableImmutable (const VarDecl &InitializingVar, const Stmt &BlockStmt, ASTContext &Context, const std::vector< StringRef > &ExcludedContainerTypes)
static bool isVariableUnused (const VarDecl &Var, const Stmt &BlockStmt, ASTContext &Context)
static const SubstTemplateTypeParmType * getSubstitutedType (const QualType &Type, ASTContext &Context)
static bool differentReplacedTemplateParams (const QualType &VarType, const QualType &InitializerType, ASTContext &Context)
static QualType constructorArgumentType (const VarDecl *OldVar, const BoundNodes &Nodes)
static std::string paramNameOrIndex (StringRef Name, size_t Index)
static bool hasLoopStmtAncestor (const DeclRefExpr &DeclRef, const Decl &Decl, ASTContext &Context)
SmallPtrSet< const DeclRefExpr *, 16 > allDeclRefExprs (const VarDecl &VarDecl, const Stmt &Stmt, ASTContext &Context)
 Returns set of all DeclRefExprs to VarDecl within Stmt.
bool isOnlyUsedAsConst (const VarDecl &Var, const Stmt &Stmt, ASTContext &Context, int Indirections)
 Returns true if all DeclRefExpr to the variable within Stmt do not modify it. See constReferenceDeclRefExprs for the meaning of Indirections.

Variables

static const char LoopCounterName [] = "for_loop_counter"
static const char LoopParentName [] = "loop_parent"
static const char VectorVarDeclName [] = "vector_var_decl"
static const char VectorVarDeclStmtName [] = "vector_var_decl_stmt"
static const char PushBackOrEmplaceBackCallName [] = "append_call"
static const char ProtoVarDeclName [] = "proto_var_decl"
static const char ProtoVarDeclStmtName [] = "proto_var_decl_stmt"
static const char ProtoAddFieldCallName [] = "proto_add_field"
static const char LoopInitVarName [] = "loop_init_var"
static const char LoopEndExprName [] = "loop_end_expr"
static const char RangeLoopName [] = "for_range_loop"
static constexpr StringRef ObjectArgId = "objectArg"
static constexpr StringRef InitFunctionCallId = "initFunctionCall"
static constexpr StringRef MethodDeclId = "methodDecl"
static constexpr StringRef FunctionDeclId = "functionDecl"
static constexpr StringRef OldVarDeclId = "oldVarDecl"

Function Documentation

◆ allDeclRefExprs()

llvm::SmallPtrSet< const DeclRefExpr *, 16 > clang::tidy::utils::decl_ref_expr::allDeclRefExprs ( const VarDecl & VarDecl,
const Stmt & Stmt,
ASTContext & Context )

Returns set of all DeclRefExprs to VarDecl within Stmt.

Definition at line 377 of file DeclRefExprUtils.cpp.

Referenced by isVariableUnused().

◆ areTypesCompatible()

bool clang::tidy::performance::areTypesCompatible ( QualType Left,
QualType Right )
static

◆ constructorArgumentType()

QualType clang::tidy::performance::constructorArgumentType ( const VarDecl * OldVar,
const BoundNodes & Nodes )
static

◆ differentReplacedTemplateParams()

bool clang::tidy::performance::differentReplacedTemplateParams ( const QualType & VarType,
const QualType & InitializerType,
ASTContext & Context )
static

◆ firstLocAfterNewLine()

std::optional< SourceLocation > clang::tidy::performance::firstLocAfterNewLine ( SourceLocation Loc,
SourceManager & SM )
static

Definition at line 42 of file UnnecessaryCopyInitialization.cpp.

Referenced by recordRemoval().

◆ getNewType()

std::pair< const char *, std::uint32_t > clang::tidy::performance::getNewType ( std::size_t Size,
std::uint64_t Min,
std::uint64_t Max )
staticnoexcept

Definition at line 40 of file EnumSizeCheck.cpp.

Referenced by clang::tidy::performance::EnumSizeCheck::check().

◆ getSubstitutedType()

const SubstTemplateTypeParmType * clang::tidy::performance::getSubstitutedType ( const QualType & Type,
ASTContext & Context )
static

Definition at line 192 of file UnnecessaryCopyInitialization.cpp.

Referenced by differentReplacedTemplateParams().

◆ hasLoopStmtAncestor()

bool clang::tidy::performance::hasLoopStmtAncestor ( const DeclRefExpr & DeclRef,
const Decl & Decl,
ASTContext & Context )
static

◆ isInitializingVariableImmutable()

bool clang::tidy::performance::isInitializingVariableImmutable ( const VarDecl & InitializingVar,
const Stmt & BlockStmt,
ASTContext & Context,
const std::vector< StringRef > & ExcludedContainerTypes )
static

◆ isNonTrivialImplicitCast()

bool clang::tidy::performance::isNonTrivialImplicitCast ( const Stmt * ST)
static

◆ isOnlyUsedAsConst()

bool clang::tidy::utils::decl_ref_expr::isOnlyUsedAsConst ( const VarDecl & Var,
const Stmt & Stmt,
ASTContext & Context,
int Indirections )

Returns true if all DeclRefExpr to the variable within Stmt do not modify it. See constReferenceDeclRefExprs for the meaning of Indirections.

Definition at line 363 of file DeclRefExprUtils.cpp.

Referenced by clang::tidy::performance::UnnecessaryCopyInitialization::check(), and isInitializingVariableImmutable().

◆ isReferenced()

bool clang::tidy::performance::isReferenced ( const VarDecl & LoopVar,
const Stmt & Stmt,
ASTContext & Context )
static

Definition at line 99 of file ForRangeCopyCheck.cpp.

◆ isRValueReferenceParam()

bool clang::tidy::performance::isRValueReferenceParam ( const Expr * Invocation,
const QualType * InvocationParmType,
const Expr * Arg )
static

◆ isVariableUnused()

bool clang::tidy::performance::isVariableUnused ( const VarDecl & Var,
const Stmt & BlockStmt,
ASTContext & Context )
static

◆ makeCharacterLiteral()

std::optional< std::string > clang::tidy::performance::makeCharacterLiteral ( const StringLiteral * Literal)
static

◆ paramNameOrIndex()

std::string clang::tidy::performance::paramNameOrIndex ( StringRef Name,
size_t Index )
static

◆ recordFixes()

void clang::tidy::performance::recordFixes ( const VarDecl & Var,
ASTContext & Context,
DiagnosticBuilder & Diagnostic )
static

◆ recordRemoval()

void clang::tidy::performance::recordRemoval ( const DeclStmt & Stmt,
ASTContext & Context,
DiagnosticBuilder & Diagnostic )
static

◆ replaceCallWithArg()

void clang::tidy::performance::replaceCallWithArg ( const CallExpr * Call,
DiagnosticBuilder & Diag,
const SourceManager & SM,
const LangOptions & LangOpts )
static

◆ supportedContainerTypesMatcher()

ast_matchers::internal::Matcher< Expr > clang::tidy::performance::supportedContainerTypesMatcher ( )
static

Definition at line 61 of file InefficientVectorOperationCheck.cpp.

◆ X()

ClangTidyModuleRegistry::Add< PerformanceModule > clang::tidy::performance::X ( "performance-module" ,
"Adds performance checks."  )
static

Variable Documentation

◆ FunctionDeclId

StringRef clang::tidy::performance::FunctionDeclId = "functionDecl"
staticconstexpr

Definition at line 29 of file UnnecessaryCopyInitialization.cpp.

Referenced by constructorArgumentType().

◆ InitFunctionCallId

StringRef clang::tidy::performance::InitFunctionCallId = "initFunctionCall"
staticconstexpr

Definition at line 27 of file UnnecessaryCopyInitialization.cpp.

Referenced by isInitializingVariableImmutable().

◆ LoopCounterName

const char clang::tidy::performance::LoopCounterName[] = "for_loop_counter"
static

◆ LoopEndExprName

const char clang::tidy::performance::LoopEndExprName[] = "loop_end_expr"
static

◆ LoopInitVarName

const char clang::tidy::performance::LoopInitVarName[] = "loop_init_var"
static

Definition at line 57 of file InefficientVectorOperationCheck.cpp.

◆ LoopParentName

const char clang::tidy::performance::LoopParentName[] = "loop_parent"
static

◆ MethodDeclId

StringRef clang::tidy::performance::MethodDeclId = "methodDecl"
staticconstexpr

Definition at line 28 of file UnnecessaryCopyInitialization.cpp.

Referenced by constructorArgumentType().

◆ ObjectArgId

StringRef clang::tidy::performance::ObjectArgId = "objectArg"
staticconstexpr

◆ OldVarDeclId

◆ ProtoAddFieldCallName

const char clang::tidy::performance::ProtoAddFieldCallName[] = "proto_add_field"
static

◆ ProtoVarDeclName

const char clang::tidy::performance::ProtoVarDeclName[] = "proto_var_decl"
static

◆ ProtoVarDeclStmtName

const char clang::tidy::performance::ProtoVarDeclStmtName[] = "proto_var_decl_stmt"
static

◆ PushBackOrEmplaceBackCallName

const char clang::tidy::performance::PushBackOrEmplaceBackCallName[] = "append_call"
static

◆ RangeLoopName

const char clang::tidy::performance::RangeLoopName[] = "for_range_loop"
static

◆ VectorVarDeclName

const char clang::tidy::performance::VectorVarDeclName[] = "vector_var_decl"
static

◆ VectorVarDeclStmtName

const char clang::tidy::performance::VectorVarDeclStmtName[] = "vector_var_decl_stmt"
static