Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class IdDependentBackwardBranchCheck : public ClangTidyCheck {
std::string Message;
};
// Stores the locations where ID-dependent variables are created.
std::map<const VarDecl *, IdDependencyRecord> IdDepVarsMap;
llvm::DenseMap<const VarDecl *, IdDependencyRecord> IdDepVarsMap;
// Stores the locations where ID-dependent fields are created.
std::map<const FieldDecl *, IdDependencyRecord> IdDepFieldsMap;
llvm::DenseMap<const FieldDecl *, IdDependencyRecord> IdDepFieldsMap;
/// Returns an IdDependencyRecord if the Expression contains an ID-dependent
/// variable, returns a nullptr otherwise.
const IdDependencyRecord *hasIdDepVar(const Expr *Expression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ static constexpr bool DefaultIgnoreMacros = false;
// either a function body or a lambda body.
class MacroExpansionsWithFileAndLine : public PPCallbacks {
public:
explicit MacroExpansionsWithFileAndLine(
LambdaFunctionNameCheck::SourceRangeSet *SME)
explicit MacroExpansionsWithFileAndLine(llvm::DenseSet<SourceRange> *SME)
: SuppressMacroExpansions(SME) {}

void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
Expand All @@ -52,7 +51,7 @@ class MacroExpansionsWithFileAndLine : public PPCallbacks {
}

private:
LambdaFunctionNameCheck::SourceRangeSet *SuppressMacroExpansions;
llvm::DenseSet<SourceRange> *SuppressMacroExpansions;
};

AST_MATCHER(CXXMethodDecl, isInLambda) { return Node.getParent()->isLambda(); }
Expand Down Expand Up @@ -97,8 +96,7 @@ void LambdaFunctionNameCheck::check(const MatchFinder::MatchResult &Result) {

auto ER =
Result.SourceManager->getImmediateExpansionRange(E->getLocation());
if (SuppressMacroExpansions.find(ER.getAsRange()) !=
SuppressMacroExpansions.end()) {
if (SuppressMacroExpansions.contains(ER.getAsRange())) {
// This is a macro expansion for which we should not warn.
return;
}
Expand Down
11 changes: 1 addition & 10 deletions clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ namespace clang::tidy::bugprone {
/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/lambda-function-name.html
class LambdaFunctionNameCheck : public ClangTidyCheck {
public:
struct SourceRangeLessThan {
bool operator()(const SourceRange &L, const SourceRange &R) const {
if (L.getBegin() == R.getBegin())
return L.getEnd() < R.getEnd();
return L.getBegin() < R.getBegin();
}
};
using SourceRangeSet = std::set<SourceRange, SourceRangeLessThan>;

LambdaFunctionNameCheck(StringRef Name, ClangTidyContext *Context);
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus11;
Expand All @@ -42,7 +33,7 @@ class LambdaFunctionNameCheck : public ClangTidyCheck {
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;

private:
SourceRangeSet SuppressMacroExpansions;
llvm::DenseSet<SourceRange> SuppressMacroExpansions;
bool IgnoreMacros;
};

Expand Down
15 changes: 8 additions & 7 deletions clang-tools-extra/clang-tidy/google/AvoidNSObjectNewCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"
#include "llvm/Support/FormatVariadic.h"
#include <map>
#include <string>
#include <utility>

using namespace clang::ast_matchers;

Expand Down Expand Up @@ -70,12 +70,13 @@ static FixItHint getCallFixItHint(const ObjCMessageExpr *Expr,
StringRef Receiver =
getReceiverString(Expr->getReceiverRange(), SM, LangOpts);
// Some classes should use standard factory methods instead of alloc/init.
std::map<StringRef, StringRef> ClassToFactoryMethodMap = {{"NSDate", "date"},
{"NSNull", "null"}};
auto FoundClassFactory = ClassToFactoryMethodMap.find(Receiver);
if (FoundClassFactory != ClassToFactoryMethodMap.end()) {
StringRef ClassName = FoundClassFactory->first;
StringRef FactorySelector = FoundClassFactory->second;
static constexpr std::pair<StringRef, StringRef> ClassToFactoryMethodMap[] = {
{"NSDate", "date"}, {"NSNull", "null"}};
const auto *FoundClassFactory =
llvm::find_if(ClassToFactoryMethodMap,
[&](const auto &Entry) { return Entry.first == Receiver; });
if (FoundClassFactory != std::end(ClassToFactoryMethodMap)) {
const auto &[ClassName, FactorySelector] = *FoundClassFactory;
const std::string NewCall =
std::string(llvm::formatv("[{0} {1}]", ClassName, FactorySelector));
return FixItHint::CreateReplacement(Expr->getSourceRange(), NewCall);
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class IncludeOrderPPCallbacks : public PPCallbacks {
};

using FileIncludes = std::vector<IncludeDirective>;
std::map<clang::FileID, FileIncludes> IncludeDirectives;
llvm::DenseMap<FileID, FileIncludes> IncludeDirectives;
bool LookForMainModule = true;

ClangTidyCheck &Check;
Expand Down
6 changes: 2 additions & 4 deletions clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NEWDELETEOVERLOADSCHECK_H

#include "../ClangTidyCheck.h"
#include "llvm/ADT/SmallVector.h"
#include <map>

namespace clang::tidy::misc {

class NewDeleteOverloadsCheck : public ClangTidyCheck {
std::map<const clang::CXXRecordDecl *,
llvm::SmallVector<const clang::FunctionDecl *, 4>>
llvm::DenseMap<const CXXRecordDecl *,
llvm::SmallVector<const FunctionDecl *, 4>>
Overloads;

public:
Expand Down
12 changes: 5 additions & 7 deletions clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"
#include <unordered_map>
#include <unordered_set>

using namespace clang::ast_matchers;

Expand Down Expand Up @@ -84,12 +82,12 @@ class UnusedParametersCheck::IndexerVisitor
public:
IndexerVisitor(ASTContext &Ctx) { TraverseAST(Ctx); }

const std::unordered_set<const CallExpr *> &
const llvm::SmallPtrSetImpl<const CallExpr *> &
getFnCalls(const FunctionDecl *Fn) {
return Index[Fn->getCanonicalDecl()].Calls;
}

const std::unordered_set<const DeclRefExpr *> &
const llvm::SmallPtrSetImpl<const DeclRefExpr *> &
getOtherRefs(const FunctionDecl *Fn) {
return Index[Fn->getCanonicalDecl()].OtherRefs;
}
Expand Down Expand Up @@ -119,11 +117,11 @@ class UnusedParametersCheck::IndexerVisitor

private:
struct IndexEntry {
std::unordered_set<const CallExpr *> Calls;
std::unordered_set<const DeclRefExpr *> OtherRefs;
llvm::SmallPtrSet<const CallExpr *, 2> Calls;
llvm::SmallPtrSet<const DeclRefExpr *, 2> OtherRefs;
};

std::unordered_map<const FunctionDecl *, IndexEntry> Index;
llvm::DenseMap<const FunctionDecl *, IndexEntry> Index;
};

UnusedParametersCheck::~UnusedParametersCheck() = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ namespace clang::tidy::modernize {
static constexpr char SpecialFunction[] = "SpecialFunction";

/// Finds all the named non-static fields of \p Record.
static std::set<const FieldDecl *>
static llvm::SmallPtrSet<const FieldDecl *, 0>
getAllNamedFields(const CXXRecordDecl *Record) {
std::set<const FieldDecl *> Result;
llvm::SmallPtrSet<const FieldDecl *, 0> Result;
for (const auto *Field : Record->fields()) {
// Static data members are not in this range.
if (Field->isUnnamedBitField())
Expand All @@ -35,8 +35,9 @@ getAllNamedFields(const CXXRecordDecl *Record) {

/// Returns the names of the direct bases of \p Record, both virtual and
/// non-virtual.
static std::set<const Type *> getAllDirectBases(const CXXRecordDecl *Record) {
std::set<const Type *> Result;
static llvm::SmallPtrSet<const Type *, 0>
getAllDirectBases(const CXXRecordDecl *Record) {
llvm::SmallPtrSet<const Type *, 0> Result;
for (auto Base : Record->bases()) {
// CXXBaseSpecifier.
const auto *BaseType = Base.getTypeSourceInfo()->getType().getTypePtr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class BracesAroundStatementsCheck : public ClangTidyCheck {
return TK_IgnoreUnlessSpelledInSource;
}

std::set<const Stmt *> ForceBracesStmts;
llvm::SmallPtrSet<const Stmt *, 0> ForceBracesStmts;
const unsigned ShortStatementLines;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class NonConstParameterCheck : public ClangTidyCheck {
};

/// Track all nonconst integer/float parameters.
std::map<const ParmVarDecl *, ParmInfo> Parameters;
llvm::DenseMap<const ParmVarDecl *, ParmInfo> Parameters;

/// Add function parameter.
void addParm(const ParmVarDecl *Parm);
Expand Down
5 changes: 3 additions & 2 deletions clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,10 @@ class HeaderGuardPPCallbacks : public PPCallbacks {

std::vector<std::pair<Token, const MacroInfo *>> Macros;
llvm::StringMap<const FileEntry *> Files;
std::map<const IdentifierInfo *, std::pair<SourceLocation, SourceLocation>>
llvm::DenseMap<const IdentifierInfo *,
std::pair<SourceLocation, SourceLocation>>
Ifndefs;
std::map<SourceLocation, SourceLocation> EndIfs;
llvm::DenseMap<SourceLocation, SourceLocation> EndIfs;

Preprocessor *PP;
HeaderGuardCheck *Check;
Expand Down