Skip to content

Commit 71e0f40

Browse files
Automerge: Revert "[clang-tidy] support query based custom check" (#159380)
Reverts llvm/llvm-project#131804. This breaks a build bot; see discussion in the original PR. I could reproduce this problem locally. The problem is that the original PR makes use of `registerCustomChecks` in `ClangTidy.cpp` but does not add the new custom module to the dependencies of the target that builds that file. Adding the dependency would create a cyclic dependency, so the fix doesn't seem obvious. See details in the PR description.
2 parents f644255 + 6fdecaa commit 71e0f40

35 files changed

+28
-705
lines changed

clang-tools-extra/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ include(GNUInstallDirs)
55

66
option(CLANG_TIDY_ENABLE_STATIC_ANALYZER
77
"Include static analyzer checks in clang-tidy" ON)
8-
option(CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
9-
"Enable query-based custom checks in clang-tidy" ON)
108

119
if(CLANG_INCLUDE_TESTS)
1210
umbrella_lit_testsuite_begin(check-clang-tools)

clang-tools-extra/clang-tidy/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ add_subdirectory(bugprone)
5858
add_subdirectory(cert)
5959
add_subdirectory(concurrency)
6060
add_subdirectory(cppcoreguidelines)
61-
add_subdirectory(custom)
6261
add_subdirectory(darwin)
6362
add_subdirectory(fuchsia)
6463
add_subdirectory(google)
@@ -102,10 +101,6 @@ set(ALL_CLANG_TIDY_CHECKS
102101
clangTidyReadabilityModule
103102
clangTidyZirconModule
104103
)
105-
106-
if(CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS)
107-
list(APPEND ALL_CLANG_TIDY_CHECKS clangTidyCustomModule)
108-
endif()
109104
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
110105
list(APPEND ALL_CLANG_TIDY_CHECKS clangTidyMPIModule)
111106
endif()

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

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ LLVM_INSTANTIATE_REGISTRY(clang::tidy::ClangTidyModuleRegistry)
5353

5454
namespace clang::tidy {
5555

56-
namespace custom {
57-
extern void registerCustomChecks(const ClangTidyOptions &O,
58-
ClangTidyCheckFactories &Factories);
59-
} // namespace custom
60-
6156
namespace {
6257
#if CLANG_TIDY_ENABLE_STATIC_ANALYZER
6358
#define ANALYZER_CHECK_NAME_PREFIX "clang-analyzer-"
@@ -347,10 +342,6 @@ ClangTidyASTConsumerFactory::ClangTidyASTConsumerFactory(
347342
IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS)
348343
: Context(Context), OverlayFS(std::move(OverlayFS)),
349344
CheckFactories(new ClangTidyCheckFactories) {
350-
#if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
351-
if (Context.canExperimentalCustomChecks())
352-
custom::registerCustomChecks(Context.getOptions(), *CheckFactories);
353-
#endif
354345
for (ClangTidyModuleRegistry::entry E : ClangTidyModuleRegistry::entries()) {
355346
std::unique_ptr<ClangTidyModule> Module = E.instantiate();
356347
Module->addCheckFactories(*CheckFactories);
@@ -420,10 +411,7 @@ ClangTidyASTConsumerFactory::createASTConsumer(
420411
.getCurrentWorkingDirectory();
421412
if (WorkingDir)
422413
Context.setCurrentBuildDirectory(WorkingDir.get());
423-
#if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
424-
if (Context.canExperimentalCustomChecks())
425-
custom::registerCustomChecks(Context.getOptions(), *CheckFactories);
426-
#endif
414+
427415
std::vector<std::unique_ptr<ClangTidyCheck>> Checks =
428416
CheckFactories->createChecksForLanguage(&Context);
429417

@@ -509,13 +497,13 @@ ClangTidyOptions::OptionMap ClangTidyASTConsumerFactory::getCheckOptions() {
509497
return Options;
510498
}
511499

512-
std::vector<std::string> getCheckNames(const ClangTidyOptions &Options,
513-
bool AllowEnablingAnalyzerAlphaCheckers,
514-
bool ExperimentalCustomChecks) {
500+
std::vector<std::string>
501+
getCheckNames(const ClangTidyOptions &Options,
502+
bool AllowEnablingAnalyzerAlphaCheckers) {
515503
clang::tidy::ClangTidyContext Context(
516504
std::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions(),
517505
Options),
518-
AllowEnablingAnalyzerAlphaCheckers, false, ExperimentalCustomChecks);
506+
AllowEnablingAnalyzerAlphaCheckers);
519507
ClangTidyASTConsumerFactory Factory(Context);
520508
return Factory.getCheckNames();
521509
}
@@ -536,12 +524,11 @@ void filterCheckOptions(ClangTidyOptions &Options,
536524

537525
ClangTidyOptions::OptionMap
538526
getCheckOptions(const ClangTidyOptions &Options,
539-
bool AllowEnablingAnalyzerAlphaCheckers,
540-
bool ExperimentalCustomChecks) {
527+
bool AllowEnablingAnalyzerAlphaCheckers) {
541528
clang::tidy::ClangTidyContext Context(
542529
std::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions(),
543530
Options),
544-
AllowEnablingAnalyzerAlphaCheckers, false, ExperimentalCustomChecks);
531+
AllowEnablingAnalyzerAlphaCheckers);
545532
ClangTidyDiagnosticConsumer DiagConsumer(Context);
546533
auto DiagOpts = std::make_unique<DiagnosticOptions>();
547534
DiagnosticsEngine DE(llvm::makeIntrusiveRefCnt<DiagnosticIDs>(), *DiagOpts,
@@ -678,19 +665,15 @@ void exportReplacements(const llvm::StringRef MainFilePath,
678665
YAML << TUD;
679666
}
680667

681-
ChecksAndOptions getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers,
682-
bool ExperimentalCustomChecks) {
668+
ChecksAndOptions
669+
getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) {
683670
ChecksAndOptions Result;
684671
ClangTidyOptions Opts;
685672
Opts.Checks = "*";
686673
clang::tidy::ClangTidyContext Context(
687674
std::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions(), Opts),
688-
AllowEnablingAnalyzerAlphaCheckers, false, ExperimentalCustomChecks);
675+
AllowEnablingAnalyzerAlphaCheckers);
689676
ClangTidyCheckFactories Factories;
690-
#if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
691-
if (ExperimentalCustomChecks)
692-
custom::registerCustomChecks(Context.getOptions(), Factories);
693-
#endif
694677
for (const ClangTidyModuleRegistry::entry &Module :
695678
ClangTidyModuleRegistry::entries()) {
696679
Module.instantiate()->addCheckFactories(Factories);

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,15 @@ class ClangTidyASTConsumerFactory {
5656
/// Fills the list of check names that are enabled when the provided
5757
/// filters are applied.
5858
std::vector<std::string> getCheckNames(const ClangTidyOptions &Options,
59-
bool AllowEnablingAnalyzerAlphaCheckers,
60-
bool ExperimentalCustomChecks);
59+
bool AllowEnablingAnalyzerAlphaCheckers);
6160

6261
struct ChecksAndOptions {
6362
llvm::StringSet<> Checks;
6463
llvm::StringSet<> Options;
6564
};
6665

67-
ChecksAndOptions getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers,
68-
bool ExperimentalCustomChecks);
66+
ChecksAndOptions
67+
getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers = true);
6968

7069
/// Returns the effective check-specific options.
7170
///
@@ -75,8 +74,7 @@ ChecksAndOptions getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers,
7574
/// Options.
7675
ClangTidyOptions::OptionMap
7776
getCheckOptions(const ClangTidyOptions &Options,
78-
bool AllowEnablingAnalyzerAlphaCheckers,
79-
bool ExperimentalCustomChecks);
77+
bool AllowEnablingAnalyzerAlphaCheckers);
8078

8179
/// Filters CheckOptions in \p Options to only include options specified in
8280
/// the \p EnabledChecks which is a sorted vector.

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,11 @@ ClangTidyError::ClangTidyError(StringRef CheckName,
160160

161161
ClangTidyContext::ClangTidyContext(
162162
std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider,
163-
bool AllowEnablingAnalyzerAlphaCheckers, bool EnableModuleHeadersParsing,
164-
bool ExperimentalCustomChecks)
163+
bool AllowEnablingAnalyzerAlphaCheckers, bool EnableModuleHeadersParsing)
165164
: OptionsProvider(std::move(OptionsProvider)),
165+
166166
AllowEnablingAnalyzerAlphaCheckers(AllowEnablingAnalyzerAlphaCheckers),
167-
EnableModuleHeadersParsing(EnableModuleHeadersParsing),
168-
ExperimentalCustomChecks(ExperimentalCustomChecks) {
167+
EnableModuleHeadersParsing(EnableModuleHeadersParsing) {
169168
// Before the first translation unit we can get errors related to command-line
170169
// parsing, use dummy string for the file name in this case.
171170
setCurrentFile("dummy");

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "llvm/ADT/StringSet.h"
2020
#include "llvm/Support/Regex.h"
2121
#include <optional>
22-
#include <utility>
2322

2423
namespace clang {
2524

@@ -69,13 +68,10 @@ struct ClangTidyStats {
6968
/// \endcode
7069
class ClangTidyContext {
7170
public:
72-
ClangTidyContext(std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider)
73-
: ClangTidyContext(std::move(OptionsProvider), false, false, false) {}
7471
/// Initializes \c ClangTidyContext instance.
7572
ClangTidyContext(std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider,
76-
bool AllowEnablingAnalyzerAlphaCheckers,
77-
bool EnableModuleHeadersParsing,
78-
bool ExperimentalCustomChecks);
73+
bool AllowEnablingAnalyzerAlphaCheckers = false,
74+
bool EnableModuleHeadersParsing = false);
7975
/// Sets the DiagnosticsEngine that diag() will emit diagnostics to.
8076
// FIXME: this is required initialization, and should be a constructor param.
8177
// Fix the context -> diag engine -> consumer -> context initialization cycle.
@@ -214,10 +210,6 @@ class ClangTidyContext {
214210
return EnableModuleHeadersParsing;
215211
}
216212

217-
// whether experimental custom checks can be enabled.
218-
// enabled with `--experimental-custom-checks`
219-
bool canExperimentalCustomChecks() const { return ExperimentalCustomChecks; }
220-
221213
void setSelfContainedDiags(bool Value) { SelfContainedDiags = Value; }
222214

223215
bool areDiagsSelfContained() const { return SelfContainedDiags; }
@@ -266,7 +258,6 @@ class ClangTidyContext {
266258

267259
bool AllowEnablingAnalyzerAlphaCheckers;
268260
bool EnableModuleHeadersParsing;
269-
bool ExperimentalCustomChecks;
270261

271262
bool SelfContainedDiags = false;
272263

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ extern volatile int CppCoreGuidelinesModuleAnchorSource;
5454
static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination =
5555
CppCoreGuidelinesModuleAnchorSource;
5656

57-
#if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
58-
// This anchor is used to force the linker to link the CustomModule.
59-
extern volatile int CustomModuleAnchorSource;
60-
static int LLVM_ATTRIBUTE_UNUSED CustomModuleAnchorDestination =
61-
CustomModuleAnchorSource;
62-
#endif
63-
6457
// This anchor is used to force the linker to link the DarwinModule.
6558
extern volatile int DarwinModuleAnchorSource;
6659
static int LLVM_ATTRIBUTE_UNUSED DarwinModuleAnchorDestination =

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ class ClangTidyCheckFactories {
6262
});
6363
}
6464

65-
void eraseCheck(llvm::StringRef CheckName) { Factories.erase(CheckName); }
66-
6765
/// Create instances of checks that are enabled.
6866
std::vector<std::unique_ptr<ClangTidyCheck>>
6967
createChecks(ClangTidyContext *Context) const;

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

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88

99
#include "ClangTidyOptions.h"
1010
#include "ClangTidyModuleRegistry.h"
11-
#include "clang/Basic/DiagnosticIDs.h"
1211
#include "clang/Basic/LLVM.h"
1312
#include "llvm/ADT/SmallString.h"
14-
#include "llvm/ADT/StringExtras.h"
1513
#include "llvm/Support/Debug.h"
1614
#include "llvm/Support/ErrorOr.h"
1715
#include "llvm/Support/MemoryBufferRef.h"
@@ -131,51 +129,6 @@ void yamlize(IO &IO, ClangTidyOptions::OptionMap &Val, bool,
131129
}
132130
}
133131

134-
namespace {
135-
struct MultiLineString {
136-
std::string &S;
137-
};
138-
} // namespace
139-
140-
template <> struct BlockScalarTraits<MultiLineString> {
141-
static void output(const MultiLineString &S, void *Ctxt, raw_ostream &OS) {
142-
OS << S.S;
143-
}
144-
static StringRef input(StringRef Str, void *Ctxt, MultiLineString &S) {
145-
S.S = Str;
146-
return "";
147-
}
148-
};
149-
150-
template <> struct ScalarEnumerationTraits<clang::DiagnosticIDs::Level> {
151-
static void enumeration(IO &IO, clang::DiagnosticIDs::Level &Level) {
152-
IO.enumCase(Level, "Warning", clang::DiagnosticIDs::Level::Warning);
153-
IO.enumCase(Level, "Note", clang::DiagnosticIDs::Level::Note);
154-
}
155-
};
156-
template <> struct SequenceElementTraits<ClangTidyOptions::CustomCheckDiag> {
157-
static const bool flow = false;
158-
};
159-
template <> struct MappingTraits<ClangTidyOptions::CustomCheckDiag> {
160-
static void mapping(IO &IO, ClangTidyOptions::CustomCheckDiag &D) {
161-
IO.mapRequired("BindName", D.BindName);
162-
MultiLineString MLS{D.Message};
163-
IO.mapRequired("Message", MLS);
164-
IO.mapOptional("Level", D.Level);
165-
}
166-
};
167-
template <> struct SequenceElementTraits<ClangTidyOptions::CustomCheckValue> {
168-
static const bool flow = false;
169-
};
170-
template <> struct MappingTraits<ClangTidyOptions::CustomCheckValue> {
171-
static void mapping(IO &IO, ClangTidyOptions::CustomCheckValue &V) {
172-
IO.mapRequired("Name", V.Name);
173-
MultiLineString MLS{V.Query};
174-
IO.mapRequired("Query", MLS);
175-
IO.mapRequired("Diagnostic", V.Diags);
176-
}
177-
};
178-
179132
struct ChecksVariant {
180133
std::optional<std::string> AsString;
181134
std::optional<std::vector<std::string>> AsVector;
@@ -231,7 +184,6 @@ template <> struct MappingTraits<ClangTidyOptions> {
231184
IO.mapOptional("InheritParentConfig", Options.InheritParentConfig);
232185
IO.mapOptional("UseColor", Options.UseColor);
233186
IO.mapOptional("SystemHeaders", Options.SystemHeaders);
234-
IO.mapOptional("CustomChecks", Options.CustomChecks);
235187
}
236188
};
237189

@@ -293,8 +245,7 @@ ClangTidyOptions &ClangTidyOptions::mergeWith(const ClangTidyOptions &Other,
293245
overrideValue(UseColor, Other.UseColor);
294246
mergeVectors(ExtraArgs, Other.ExtraArgs);
295247
mergeVectors(ExtraArgsBefore, Other.ExtraArgsBefore);
296-
// FIXME: how to handle duplicate names check?
297-
mergeVectors(CustomChecks, Other.CustomChecks);
248+
298249
for (const auto &KeyValue : Other.CheckOptions) {
299250
CheckOptions.insert_or_assign(
300251
KeyValue.getKey(),

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYOPTIONS_H
1010
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYOPTIONS_H
1111

12-
#include "clang/Basic/DiagnosticIDs.h"
1312
#include "llvm/ADT/IntrusiveRefCntPtr.h"
1413
#include "llvm/ADT/SmallString.h"
1514
#include "llvm/ADT/StringMap.h"
@@ -130,19 +129,6 @@ struct ClangTidyOptions {
130129
/// Key-value mapping used to store check-specific options.
131130
OptionMap CheckOptions;
132131

133-
struct CustomCheckDiag {
134-
std::string BindName;
135-
std::string Message;
136-
std::optional<DiagnosticIDs::Level> Level;
137-
};
138-
struct CustomCheckValue {
139-
std::string Name;
140-
std::string Query;
141-
llvm::SmallVector<CustomCheckDiag> Diags;
142-
};
143-
using CustomCheckValueList = llvm::SmallVector<CustomCheckValue>;
144-
std::optional<CustomCheckValueList> CustomChecks;
145-
146132
using ArgList = std::vector<std::string>;
147133

148134
/// Add extra compilation arguments to the end of the list.

0 commit comments

Comments
 (0)