Skip to content

Commit 5500699

Browse files
committed
fix review
1 parent 190ad52 commit 5500699

File tree

9 files changed

+75
-37
lines changed

9 files changed

+75
-37
lines changed

clang-tools-extra/clang-tidy/ClangTidy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ LLVM_INSTANTIATE_REGISTRY(clang::tidy::ClangTidyModuleRegistry)
5454
namespace clang::tidy {
5555

5656
namespace custom {
57-
extern void registerCustomChecks(ClangTidyOptions const &O,
57+
extern void registerCustomChecks(const ClangTidyOptions &O,
5858
ClangTidyCheckFactories &Factories);
5959
} // namespace custom
6060

clang-tools-extra/clang-tidy/ClangTidyModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class ClangTidyCheckFactories {
6262
});
6363
}
6464

65-
void erase(llvm::StringRef CheckName) { Factories.erase(CheckName); }
65+
void eraseCheck(llvm::StringRef CheckName) { Factories.erase(CheckName); }
6666

6767
/// Create instances of checks that are enabled.
6868
std::vector<std::unique_ptr<ClangTidyCheck>>

clang-tools-extra/clang-tidy/ClangTidyOptions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "llvm/Support/MemoryBufferRef.h"
1919
#include "llvm/Support/VirtualFileSystem.h"
2020
#include <functional>
21-
#include <map>
2221
#include <optional>
2322
#include <string>
2423
#include <system_error>

clang-tools-extra/clang-tidy/custom/CustomTidyModule.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ class CustomModule : public ClangTidyModule {
1818

1919
// We need to register the checks more flexibly than builtin modules. The checks
2020
// will changed dynamically when switching to different source file.
21-
extern void registerCustomChecks(ClangTidyOptions const &Options,
21+
extern void registerCustomChecks(const ClangTidyOptions &Options,
2222
ClangTidyCheckFactories &Factories) {
2323
static llvm::SmallSet<llvm::SmallString<32>, 8> CustomCheckNames{};
2424
if (!Options.CustomChecks.has_value() || Options.CustomChecks->empty())
2525
return;
26-
for (llvm::SmallString<32> const &Name : CustomCheckNames)
27-
Factories.erase(Name);
26+
for (const llvm::SmallString<32> &Name : CustomCheckNames)
27+
Factories.eraseCheck(Name);
2828
for (const ClangTidyOptions::CustomCheckValue &V :
2929
Options.CustomChecks.value()) {
3030
llvm::SmallString<32> Name = llvm::StringRef{"custom-" + V.Name};
@@ -45,6 +45,6 @@ static ClangTidyModuleRegistry::Add<custom::CustomModule>
4545

4646
// This anchor is used to force the linker to link in the generated object file
4747
// and thus register the AlteraModule.
48-
volatile int CustomModuleAnchorSource = 0;
48+
volatile int CustomModuleAnchorSource = 0; // NOLINT (misc-use-internal-linkage)
4949

5050
} // namespace clang::tidy

clang-tools-extra/clang-tidy/custom/QueryCheck.cpp

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ using namespace clang::ast_matchers;
2020

2121
namespace clang::tidy::custom {
2222

23+
static void emitConfigurationDiag(ClangTidyContext *Context, StringRef Message,
24+
StringRef CheckName) {
25+
Context->configurationDiag("%0 in '%1'", DiagnosticIDs::Warning)
26+
<< Message << CheckName;
27+
}
28+
2329
static SmallVector<ast_matchers::dynamic::DynTypedMatcher>
2430
parseQuery(const ClangTidyOptions::CustomCheckValue &V,
2531
ClangTidyContext *Context) {
@@ -39,23 +45,52 @@ parseQuery(const ClangTidyOptions::CustomCheckValue &V,
3945
LetQuery.run(llvm::errs(), QS);
4046
break;
4147
}
48+
case query::QK_NoOp: {
49+
const auto &NoOpQuery = llvm::cast<query::NoOpQuery>(*Q);
50+
NoOpQuery.run(llvm::errs(), QS);
51+
break;
52+
}
4253
case query::QK_Invalid: {
4354
const auto &InvalidQuery = llvm::cast<query::InvalidQuery>(*Q);
44-
Context->configurationDiag(InvalidQuery.ErrStr, DiagnosticIDs::Error);
55+
emitConfigurationDiag(Context, InvalidQuery.ErrStr, V.Name);
4556
return {};
4657
}
4758
// FIXME: TODO
48-
case query::QK_File:
49-
case query::QK_DisableOutputKind:
50-
case query::QK_EnableOutputKind:
51-
case query::QK_SetOutputKind:
52-
case query::QK_SetTraversalKind:
53-
case query::QK_Help:
54-
case query::QK_NoOp:
55-
case query::QK_Quit:
59+
case query::QK_File: {
60+
emitConfigurationDiag(Context, "unsupported query kind 'File'", V.Name);
61+
return {};
62+
}
63+
case query::QK_DisableOutputKind: {
64+
emitConfigurationDiag(
65+
Context, "unsupported query kind 'DisableOutputKind'", V.Name);
66+
return {};
67+
}
68+
case query::QK_EnableOutputKind: {
69+
emitConfigurationDiag(
70+
Context, "unsupported query kind 'EnableOutputKind'", V.Name);
71+
return {};
72+
}
73+
case query::QK_SetOutputKind: {
74+
emitConfigurationDiag(Context, "unsupported query kind 'SetOutputKind'",
75+
V.Name);
76+
return {};
77+
}
78+
case query::QK_SetTraversalKind: {
79+
emitConfigurationDiag(
80+
Context, "unsupported query kind 'SetTraversalKind'", V.Name);
81+
return {};
82+
}
5683
case query::QK_SetBool: {
57-
Context->configurationDiag("unsupported query kind",
58-
DiagnosticIDs::Error);
84+
emitConfigurationDiag(Context, "unsupported query kind 'SetBool'",
85+
V.Name);
86+
return {};
87+
}
88+
case query::QK_Help: {
89+
emitConfigurationDiag(Context, "unsupported query kind 'Help'", V.Name);
90+
return {};
91+
}
92+
case query::QK_Quit: {
93+
emitConfigurationDiag(Context, "unsupported query kind 'Quit'", V.Name);
5994
return {};
6095
}
6196
}
@@ -89,19 +124,19 @@ void QueryCheck::registerMatchers(MatchFinder *Finder) {
89124
}
90125

91126
void QueryCheck::check(const MatchFinder::MatchResult &Result) {
92-
auto Emit = [this](DiagMaps const &DiagMaps, std::string const &BindName,
93-
DynTypedNode const &Node, DiagnosticIDs::Level Level) {
94-
if (!DiagMaps.contains(Level))
127+
auto Emit = [this](const DiagMaps &DiagMaps, const std::string &BindName,
128+
const DynTypedNode &Node, DiagnosticIDs::Level Level) {
129+
DiagMaps::const_iterator DiagMapIt = DiagMaps.find(Level);
130+
if (DiagMapIt == DiagMaps.end())
95131
return;
96-
auto &DiagMap = DiagMaps.at(Level);
97-
if (!DiagMap.contains(BindName))
132+
const BindNameMapToDiagMessage &BindNameMap = DiagMapIt->second;
133+
BindNameMapToDiagMessage::const_iterator BindNameMapIt =
134+
BindNameMap.find(BindName);
135+
if (BindNameMapIt == BindNameMap.end())
98136
return;
99-
for (const std::string &Message : DiagMap.at(BindName)) {
137+
for (const std::string &Message : BindNameMapIt->second)
100138
diag(Node.getSourceRange().getBegin(), Message, Level);
101-
}
102139
};
103-
for (const auto &[Name, Node] : Result.Nodes.getMap())
104-
Emit(Diags, Name, Node, DiagnosticIDs::Error);
105140
for (const auto &[Name, Node] : Result.Nodes.getMap())
106141
Emit(Diags, Name, Node, DiagnosticIDs::Warning);
107142
// place Note last, otherwise it will not be emitted

clang-tools-extra/clang-tidy/custom/QueryCheck.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ class QueryCheck : public ClangTidyCheck {
2929

3030
private:
3131
llvm::SmallVector<ast_matchers::dynamic::DynTypedMatcher> Matchers{};
32+
using BindNameMapToDiagMessage =
33+
llvm::StringMap<llvm::SmallVector<std::string>>;
3234
using DiagMaps =
33-
llvm::DenseMap<DiagnosticIDs::Level,
34-
llvm::StringMap<llvm::SmallVector<std::string>>>;
35+
llvm::DenseMap<DiagnosticIDs::Level, BindNameMapToDiagMessage>;
3536
DiagMaps Diags;
3637
};
3738

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,6 @@ Improvements to clang-tidy
104104
clauses. Added a ``--match-partial-fixes`` option to keep previous behavior on
105105
specific tests. This may break tests for users with custom out-of-tree checks
106106
who use :program:`check_clang_tidy.py` as-is.
107-
- :program:`clang-tidy` no longer processes declarations from system headers
108-
by default, greatly improving performance. This behavior is disabled if the
109-
`SystemHeaders` option is enabled.
110-
Note: this may lead to false negatives; downstream users may need to adjust
111-
their checks to preserve existing behavior.
112107
- :program:`clang-tidy` now supports query based custom checks by `CustomChecks`
113108
configuration option.
114109
:doc:`Query Based Custom Check Document <clang-tidy/QueryBasedCustomChecks>`

clang-tools-extra/test/clang-tidy/checkers/custom/Inputs/incorrect-clang-tidy.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CustomChecks:
2-
- Name: test-let-bind-invalid
2+
- Name: test-let-bind-invalid-1
33
Query: |
44
let expr varDecl(isStaticStorageClass()).bind("vd")
55
match expr
@@ -8,6 +8,13 @@ CustomChecks:
88
- BindName: vd
99
Message: find static variable
1010
Level: Warning
11+
- Name: test-let-bind-invalid-2
12+
Query: |
13+
match varDeclInvalid(isStaticStorageClass()).bind("vd")
14+
Diagnostic:
15+
- BindName: vd
16+
Message: find static variable
17+
Level: Warning
1118
- Name: test-let-bind-valid
1219
Query: |
1320
let expr varDecl(isStaticStorageClass()).bind("vd")
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// RUN: not %check_clang_tidy %s custom-* %t --config-file=%S/Inputs/incorrect-clang-tidy.yml
1+
// RUN: %check_clang_tidy %s custom-* %t --config-file=%S/Inputs/incorrect-clang-tidy.yml
22

3-
// CHECK-MESSAGES: error: unsupported query kind [clang-tidy-config]
3+
// CHECK-MESSAGES: warning: 1:1: Matcher not found: varDeclInvalid in 'test-let-bind-invalid-2' [clang-tidy-config]
4+
// CHECK-MESSAGES: warning: unsupported query kind 'SetOutputKind' in 'test-let-bind-invalid-1' [clang-tidy-config]
45

56
static int S;
67
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: find static variable [custom-test-let-bind-valid]

0 commit comments

Comments
 (0)