clang-tools  14.0.0git
Classes | Namespaces | Macros | Typedefs | Enumerations | Functions | Variables
EasilySwappableParametersCheck.cpp File Reference
#include "EasilySwappableParametersCheck.h"
#include "../utils/OptionsUtils.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Lex/Lexer.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/Support/Debug.h"
Include dependency graph for EasilySwappableParametersCheck.cpp:

Go to the source code of this file.

Classes

struct  clang::tidy::bugprone::model::ConversionSequence
 The results of the steps of an Implicit Conversion Sequence is saved in an instance of this record. More...
 
struct  clang::tidy::bugprone::model::ConversionSequence::UserDefinedConvertingConstructor
 
struct  clang::tidy::bugprone::model::ConversionSequence::UserDefinedConversionOperator
 
struct  clang::tidy::bugprone::model::MixData
 Contains the metadata for the mixability result between two types, independently of which parameters they were calculated from. More...
 
struct  clang::tidy::bugprone::model::Mix
 A named tuple that contains the information for a mix between two concrete parameters. More...
 
struct  clang::tidy::bugprone::model::MixableParameterRange
 
class  clang::tidy::bugprone::filter::relatedness_heuristic::AppearsInSameExpr
 Implements the heuristic that marks two parameters related if there is a usage for both in the same strict expression subtree. More...
 
class  clang::tidy::bugprone::filter::relatedness_heuristic::PassedToSameFunction
 Implements the heuristic that marks two parameters related if there are two separate calls to the same function (overload) and the parameters are passed to the same index in both calls, i.e f(a, b) and f(a, c) passes b and c to the same index (2) of f(), marking them related. More...
 
class  clang::tidy::bugprone::filter::relatedness_heuristic::AccessedSameMemberOf
 Implements the heuristic that marks two parameters related if the same member is accessed (referred to) inside the current function's body. More...
 
class  clang::tidy::bugprone::filter::relatedness_heuristic::Returned
 Implements the heuristic that marks two parameters related if different ReturnStmts return them from the function. More...
 
class  clang::tidy::bugprone::filter::SimilarlyUsedParameterPairSuppressor
 Helper class that is used to detect if two parameters of the same function are used in a similar fashion, to suppress the result. More...
 

Namespaces

 clang
 ===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
 
 clang::tidy
 
 clang::tidy::bugprone
 
 clang::tidy::bugprone::filter
 
 clang::tidy::bugprone::model
 
 clang::tidy::bugprone::filter::relatedness_heuristic
 This namespace contains the implementations for the suppression of diagnostics from similaly used ("related") parameters.
 

Macros

#define DEBUG_TYPE   "EasilySwappableParametersCheck"
 

Typedefs

using clang::tidy::bugprone::TheCheck = EasilySwappableParametersCheck
 
template<typename T , std::size_t N = SmallDataStructureSize>
using clang::tidy::bugprone::filter::relatedness_heuristic::ParamToSmallSetMap = llvm::DenseMap< const ParmVarDecl *, llvm::SmallSet< T, N > >
 

Enumerations

enum  clang::tidy::bugprone::model::MixFlags : unsigned char {
  clang::tidy::bugprone::model::MixFlags::Invalid = 0, clang::tidy::bugprone::model::MixFlags::WorkaroundDisableCanonicalEquivalence = 1, clang::tidy::bugprone::model::MixFlags::None = 2, clang::tidy::bugprone::model::MixFlags::Trivial = 4,
  clang::tidy::bugprone::model::MixFlags::Canonical = 8, clang::tidy::bugprone::model::MixFlags::TypeAlias = 16, clang::tidy::bugprone::model::MixFlags::ReferenceBind = 32, clang::tidy::bugprone::model::MixFlags::Qualifiers = 64,
  clang::tidy::bugprone::model::MixFlags::ImplicitConversion = 128
}
 The language features involved in allowing the mix between two parameters. More...
 
enum  clang::tidy::bugprone::model::ImplicitConversionModellingMode : unsigned char { clang::tidy::bugprone::model::ImplicitConversionModellingMode::None, clang::tidy::bugprone::model::ImplicitConversionModellingMode::All, clang::tidy::bugprone::model::ImplicitConversionModellingMode::OneWaySingleStandardOnly }
 Helper enum for the recursive calls in the modelling that toggle what kinds of implicit conversions are to be modelled. More...
 

Functions

static bool clang::tidy::bugprone::filter::isIgnoredParameter (const TheCheck &Check, const ParmVarDecl *Node)
 Returns whether the parameter's name or the parameter's type's name is configured by the user to be ignored from analysis and diagnostic. More...
 
static bool clang::tidy::bugprone::filter::isSimilarlyUsedParameter (const SimilarlyUsedParameterPairSuppressor &Suppressor, const ParmVarDecl *Param1, const ParmVarDecl *Param2)
 
static bool clang::tidy::bugprone::filter::prefixSuffixCoverUnderThreshold (std::size_t Threshold, StringRef Str1, StringRef Str2)
 Returns whether the two strings are prefixes or suffixes of each other with at most Threshold characters differing on the non-common end. More...
 
 clang::tidy::bugprone::model::LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE ()
 
static bool clang::tidy::bugprone::model::hasFlag (MixFlags Data, MixFlags SearchedFlag)
 Returns whether the SearchedFlag is turned on in the Data. More...
 
static std::string clang::tidy::bugprone::model::formatMixFlags (MixFlags F)
 Formats the MixFlags enum into a useful, user-readable representation. More...
 
static MixData clang::tidy::bugprone::model::isLRefEquallyBindingToType (const TheCheck &Check, const LValueReferenceType *LRef, QualType Ty, const ASTContext &Ctx, bool IsRefRHS, ImplicitConversionModellingMode ImplicitMode)
 Calculates if the reference binds an expression of the given type. More...
 
static MixData clang::tidy::bugprone::model::approximateImplicitConversion (const TheCheck &Check, QualType LType, QualType RType, const ASTContext &Ctx, ImplicitConversionModellingMode ImplicitMode)
 Returns whether an expression of LType can be used in an RType context, as per the implicit conversion rules. More...
 
static bool clang::tidy::bugprone::model::isUselessSugar (const Type *T)
 
static NonCVRQualifiersResult clang::tidy::bugprone::model::getNonCVRQualifiers (const ASTContext &Ctx, QualType LType, QualType RType)
 Returns if the two types are qualified in a way that ever after equating or removing local CVR qualification, even if the unqualified types would mix, the qualified ones don't, because there are some other local qualifiers that aren't equal. More...
 
static MixData clang::tidy::bugprone::model::calculateMixability (const TheCheck &Check, QualType LType, QualType RType, const ASTContext &Ctx, ImplicitConversionModellingMode ImplicitMode)
 Approximate the way how LType and RType might refer to "essentially the same" type, in a sense that at a particular call site, an expression of type LType and RType might be successfully passed to a variable (in our specific case, a parameter) of type RType and LType, respectively. More...
 
static bool clang::tidy::bugprone::model::isDerivedToBase (const CXXRecordDecl *Derived, const CXXRecordDecl *Base)
 
static Optional< QualType > clang::tidy::bugprone::model::approximateStandardConversionSequence (const TheCheck &Check, QualType From, QualType To, const ASTContext &Ctx)
 
static Optional< ConversionSequence > clang::tidy::bugprone::model::tryConversionOperators (const TheCheck &Check, const CXXRecordDecl *RD, QualType ToType)
 
static Optional< ConversionSequence > clang::tidy::bugprone::model::tryConvertingConstructors (const TheCheck &Check, QualType FromType, const CXXRecordDecl *RD)
 
static MixableParameterRange clang::tidy::bugprone::model::modelMixingRange (const TheCheck &Check, const FunctionDecl *FD, std::size_t StartIndex, const filter::SimilarlyUsedParameterPairSuppressor &UsageBasedSuppressor)
 
 clang::tidy::bugprone::AST_MATCHER_FUNCTION (ast_matchers::internal::Matcher< Stmt >, paramRefExpr)
 Matches DeclRefExprs and their ignorable wrappers to ParmVarDecls. More...
 
template<typename MapTy , typename ElemTy >
bool clang::tidy::bugprone::filter::relatedness_heuristic::lazyMapOfSetsIntersectionExists (const MapTy &Map, const ElemTy &E1, const ElemTy &E2)
 Returns whether the sets mapped to the two elements in the map have at least one element in common. More...
 
static void clang::tidy::bugprone::filter::padStringAtEnd (SmallVectorImpl< char > &Str, std::size_t ToLen)
 
static void clang::tidy::bugprone::filter::padStringAtBegin (SmallVectorImpl< char > &Str, std::size_t ToLen)
 
static bool clang::tidy::bugprone::filter::isCommonPrefixWithoutSomeCharacters (std::size_t N, StringRef S1, StringRef S2)
 
static bool clang::tidy::bugprone::filter::isCommonSuffixWithoutSomeCharacters (std::size_t N, StringRef S1, StringRef S2)
 
 clang::tidy::bugprone::AST_MATCHER_P (FunctionDecl, parameterCountGE, unsigned, N)
 Matches functions that have at least the specified amount of parameters. More...
 
 clang::tidy::bugprone::AST_MATCHER (FunctionDecl, isOverloadedUnaryOrBinaryOperator)
 Matches any overloaded unary and binary operators. More...
 
static unsigned clang::tidy::bugprone::clampMinimumLength (const unsigned Value)
 Returns the DefaultMinimumLength if the Value of requested minimum length is less than 2. More...
 
static SmallString< 64 > clang::tidy::bugprone::getName (const NamedDecl *ND)
 Returns the diagnostic-friendly name of the node, or empty string. More...
 
static SmallString< 64 > clang::tidy::bugprone::getNameOrUnnamed (const NamedDecl *ND)
 Returns the diagnostic-friendly name of the node, or a constant value. More...
 
static bool clang::tidy::bugprone::needsToPrintTypeInDiagnostic (const model::Mix &M)
 Returns whether a particular Mix between two parameters should have the types involved diagnosed to the user. More...
 
static bool clang::tidy::bugprone::needsToElaborateImplicitConversion (const model::Mix &M)
 Returns whether a particular Mix between the two parameters should have implicit conversions elaborated. More...
 

Variables

static constexpr std::size_t DefaultMinimumLength = 2
 The default value for the MinimumLength check option. More...
 
static const std::string DefaultIgnoredParameterNames
 The default value for ignored parameter names. More...
 
static const std::string DefaultIgnoredParameterTypeSuffixes
 The default value for ignored parameter type suffixes. More...
 
static constexpr bool DefaultQualifiersMix = false
 The default value for the QualifiersMix check option. More...
 
static constexpr bool DefaultModelImplicitConversions = true
 The default value for the ModelImplicitConversions check option. More...
 
static constexpr bool DefaultSuppressParametersUsedTogether = true
 The default value for suppressing diagnostics about parameters that are used together. More...
 
static constexpr std::size_t DefaultNamePrefixSuffixSilenceDissimilarityTreshold = 1
 The default value for the NamePrefixSuffixSilenceDissimilarityTreshold check option. More...
 
static constexpr std::size_t clang::tidy::bugprone::filter::relatedness_heuristic::SmallDataStructureSize = 4
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "EasilySwappableParametersCheck"

Definition at line 17 of file EasilySwappableParametersCheck.cpp.

Variable Documentation

◆ CommonQualifiers

Qualifiers CommonQualifiers

The set of equal qualifiers between the two types.

Definition at line 583 of file EasilySwappableParametersCheck.cpp.

◆ CommonType

QualType CommonType

◆ ConversionFun

const CXXMethodDecl* ConversionFun

Definition at line 1085 of file EasilySwappableParametersCheck.cpp.

◆ DefaultIgnoredParameterNames

const std::string DefaultIgnoredParameterNames
static
Initial value:
=
optutils::serializeStringList({"\"\"", "iterator", "Iterator", "begin",
"Begin", "end", "End", "first", "First",
"last", "Last", "lhs", "LHS", "rhs", "RHS"})

The default value for ignored parameter names.

Definition at line 26 of file EasilySwappableParametersCheck.cpp.

◆ DefaultIgnoredParameterTypeSuffixes

const std::string DefaultIgnoredParameterTypeSuffixes
static
Initial value:
=
"Bool",
"_Bool",
"it",
"It",
"iterator",
"Iterator",
"inputit",
"InputIt",
"forwardit",
"ForwardIt",
"bidirit",
"BidirIt",
"constiterator",
"const_iterator",
"Const_Iterator",
"Constiterator",
"ConstIterator",
"RandomIt",
"randomit",
"random_iterator",
"ReverseIt",
"reverse_iterator",
"reverse_const_iterator",
"ConstReverseIterator",
"Const_Reverse_Iterator",
"const_reverse_iterator",
"Constreverseiterator",
"constreverseiterator"})

The default value for ignored parameter type suffixes.

Definition at line 32 of file EasilySwappableParametersCheck.cpp.

◆ DefaultMinimumLength

constexpr std::size_t DefaultMinimumLength = 2
staticconstexpr

The default value for the MinimumLength check option.

Definition at line 23 of file EasilySwappableParametersCheck.cpp.

Referenced by clang::tidy::bugprone::clampMinimumLength().

◆ DefaultModelImplicitConversions

constexpr bool DefaultModelImplicitConversions = true
staticconstexpr

The default value for the ModelImplicitConversions check option.

Definition at line 67 of file EasilySwappableParametersCheck.cpp.

◆ DefaultNamePrefixSuffixSilenceDissimilarityTreshold

constexpr std::size_t DefaultNamePrefixSuffixSilenceDissimilarityTreshold = 1
staticconstexpr

The default value for the NamePrefixSuffixSilenceDissimilarityTreshold check option.

Definition at line 76 of file EasilySwappableParametersCheck.cpp.

◆ DefaultQualifiersMix

constexpr bool DefaultQualifiersMix = false
staticconstexpr

The default value for the QualifiersMix check option.

Definition at line 64 of file EasilySwappableParametersCheck.cpp.

◆ DefaultSuppressParametersUsedTogether

constexpr bool DefaultSuppressParametersUsedTogether = true
staticconstexpr

The default value for suppressing diagnostics about parameters that are used together.

Definition at line 71 of file EasilySwappableParametersCheck.cpp.

◆ DiagnosticText

std::string DiagnosticText

Definition at line 1942 of file EasilySwappableParametersCheck.cpp.

◆ Flags

MixFlags Flags

◆ HasMixabilityBreakingQualifiers

bool HasMixabilityBreakingQualifiers

True if the types are qualified in a way that even after equating or removing local CVR qualification, even if the unqualified types themselves would mix, the qualified ones don't, because there are some other local qualifiers that are not equal.

Definition at line 580 of file EasilySwappableParametersCheck.cpp.

◆ LHSType

QualType LHSType

Definition at line 2017 of file EasilySwappableParametersCheck.cpp.

◆ RHSType

QualType RHSType

Definition at line 2017 of file EasilySwappableParametersCheck.cpp.

◆ Seq

ConversionSequence Seq

Definition at line 1087 of file EasilySwappableParametersCheck.cpp.

◆ Trivial

bool Trivial

The formatted sequence is trivial if it is "Ty1 -> Ty2", but Ty1 and Ty2 are the types that are shown in the code.

A trivial diagnostic does not need to be printed.

Definition at line 1947 of file EasilySwappableParametersCheck.cpp.

Referenced by clang::tidy::bugprone::model::MixData::sanitize().

clang::tidy::utils::options::serializeStringList
std::string serializeStringList(ArrayRef< std::string > Strings)
Serialize a sequence of names that can be parsed by parseStringList.
Definition: OptionsUtils.cpp:30