File indexing completed on 2026-05-10 08:36:22
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SUSPICIOUSCALLARGUMENTCHECK_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SUSPICIOUSCALLARGUMENTCHECK_H
0011
0012 #include "../ClangTidyCheck.h"
0013 #include "llvm/ADT/StringSet.h"
0014 #include <optional>
0015
0016 namespace clang::tidy::readability {
0017
0018
0019
0020
0021
0022
0023
0024 class SuspiciousCallArgumentCheck : public ClangTidyCheck {
0025 enum class Heuristic {
0026 Equality,
0027 Abbreviation,
0028 Prefix,
0029 Suffix,
0030 Substring,
0031 Levenshtein,
0032 JaroWinkler,
0033 Dice
0034 };
0035
0036
0037
0038
0039 enum class BoundKind {
0040
0041
0042 DissimilarBelow,
0043
0044
0045
0046
0047 SimilarAbove
0048 };
0049
0050 public:
0051 static constexpr std::size_t SmallVectorSize = 8;
0052 static constexpr std::size_t HeuristicCount =
0053 static_cast<std::size_t>(Heuristic::Dice) + 1;
0054
0055 SuspiciousCallArgumentCheck(StringRef Name, ClangTidyContext *Context);
0056 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
0057 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0058 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0059
0060 private:
0061 const std::size_t MinimumIdentifierNameLength;
0062
0063
0064 SmallVector<Heuristic, HeuristicCount> AppliedHeuristics;
0065
0066
0067 SmallVector<std::pair<int8_t, int8_t>, HeuristicCount> ConfiguredBounds;
0068
0069
0070 llvm::StringMap<std::string> AbbreviationDictionary;
0071
0072 bool isHeuristicEnabled(Heuristic H) const;
0073 std::optional<int8_t> getBound(Heuristic H, BoundKind BK) const;
0074
0075
0076 SmallVector<QualType, SmallVectorSize> ArgTypes;
0077 SmallVector<StringRef, SmallVectorSize> ArgNames;
0078 SmallVector<QualType, SmallVectorSize> ParamTypes;
0079 SmallVector<StringRef, SmallVectorSize> ParamNames;
0080
0081 void setParamNamesAndTypes(const FunctionDecl *CalleeFuncDecl);
0082
0083 void setArgNamesAndTypes(const CallExpr *MatchedCallExpr,
0084 std::size_t InitialArgIndex);
0085
0086 bool areParamAndArgComparable(std::size_t Position1, std::size_t Position2,
0087 const ASTContext &Ctx) const;
0088
0089 bool areArgsSwapped(std::size_t Position1, std::size_t Position2) const;
0090
0091 bool areNamesSimilar(StringRef Arg, StringRef Param, Heuristic H,
0092 BoundKind BK) const;
0093 };
0094
0095 }
0096
0097 #endif