Skip to content

Commit b162a47

Browse files
Merge branch 'llvm:main' into cfi-show
2 parents 3079588 + 07a7928 commit b162a47

File tree

680 files changed

+25508
-16220
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

680 files changed

+25508
-16220
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@
132132
/mlir/**/Transforms/Mem2Reg.* @moxinilian
133133
/mlir/**/Transforms/SROA.* @moxinilian
134134

135+
# MLIR IRDL-related
136+
/mlir/**/*IRDL* @moxinilian
137+
135138
# BOLT
136139
/bolt/ @aaupov @maksfb @rafaelauler @ayermolo @yota9 @paschalis-mpeis @yozhu
137140

clang-tools-extra/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ 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)
810

911
if(CLANG_INCLUDE_TESTS)
1012
umbrella_lit_testsuite_begin(check-clang-tools)

clang-tools-extra/clang-include-fixer/IncludeFixer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ bool IncludeFixerActionFactory::runInvocation(
9494

9595
// Create the compiler's actual diagnostics engine. We want to drop all
9696
// diagnostics here.
97-
Compiler.createDiagnostics(Files->getVirtualFileSystem(),
98-
new clang::IgnoringDiagConsumer,
97+
Compiler.createDiagnostics(new clang::IgnoringDiagConsumer,
9998
/*ShouldOwnClient=*/true);
10099
Compiler.createSourceManager(*Files);
101100

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ add_subdirectory(bugprone)
5858
add_subdirectory(cert)
5959
add_subdirectory(concurrency)
6060
add_subdirectory(cppcoreguidelines)
61+
add_subdirectory(custom)
6162
add_subdirectory(darwin)
6263
add_subdirectory(fuchsia)
6364
add_subdirectory(google)
@@ -101,6 +102,10 @@ set(ALL_CLANG_TIDY_CHECKS
101102
clangTidyReadabilityModule
102103
clangTidyZirconModule
103104
)
105+
106+
if(CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS)
107+
list(APPEND ALL_CLANG_TIDY_CHECKS clangTidyCustomModule)
108+
endif()
104109
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
105110
list(APPEND ALL_CLANG_TIDY_CHECKS clangTidyMPIModule)
106111
endif()

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

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ 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+
5661
namespace {
5762
#if CLANG_TIDY_ENABLE_STATIC_ANALYZER
5863
#define ANALYZER_CHECK_NAME_PREFIX "clang-analyzer-"
@@ -342,6 +347,10 @@ ClangTidyASTConsumerFactory::ClangTidyASTConsumerFactory(
342347
IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS)
343348
: Context(Context), OverlayFS(std::move(OverlayFS)),
344349
CheckFactories(new ClangTidyCheckFactories) {
350+
#if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
351+
if (Context.canExperimentalCustomChecks())
352+
custom::registerCustomChecks(Context.getOptions(), *CheckFactories);
353+
#endif
345354
for (ClangTidyModuleRegistry::entry E : ClangTidyModuleRegistry::entries()) {
346355
std::unique_ptr<ClangTidyModule> Module = E.instantiate();
347356
Module->addCheckFactories(*CheckFactories);
@@ -411,7 +420,10 @@ ClangTidyASTConsumerFactory::createASTConsumer(
411420
.getCurrentWorkingDirectory();
412421
if (WorkingDir)
413422
Context.setCurrentBuildDirectory(WorkingDir.get());
414-
423+
#if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
424+
if (Context.canExperimentalCustomChecks())
425+
custom::registerCustomChecks(Context.getOptions(), *CheckFactories);
426+
#endif
415427
std::vector<std::unique_ptr<ClangTidyCheck>> Checks =
416428
CheckFactories->createChecksForLanguage(&Context);
417429

@@ -497,13 +509,13 @@ ClangTidyOptions::OptionMap ClangTidyASTConsumerFactory::getCheckOptions() {
497509
return Options;
498510
}
499511

500-
std::vector<std::string>
501-
getCheckNames(const ClangTidyOptions &Options,
502-
bool AllowEnablingAnalyzerAlphaCheckers) {
512+
std::vector<std::string> getCheckNames(const ClangTidyOptions &Options,
513+
bool AllowEnablingAnalyzerAlphaCheckers,
514+
bool ExperimentalCustomChecks) {
503515
clang::tidy::ClangTidyContext Context(
504516
std::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions(),
505517
Options),
506-
AllowEnablingAnalyzerAlphaCheckers);
518+
AllowEnablingAnalyzerAlphaCheckers, false, ExperimentalCustomChecks);
507519
ClangTidyASTConsumerFactory Factory(Context);
508520
return Factory.getCheckNames();
509521
}
@@ -524,11 +536,12 @@ void filterCheckOptions(ClangTidyOptions &Options,
524536

525537
ClangTidyOptions::OptionMap
526538
getCheckOptions(const ClangTidyOptions &Options,
527-
bool AllowEnablingAnalyzerAlphaCheckers) {
539+
bool AllowEnablingAnalyzerAlphaCheckers,
540+
bool ExperimentalCustomChecks) {
528541
clang::tidy::ClangTidyContext Context(
529542
std::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions(),
530543
Options),
531-
AllowEnablingAnalyzerAlphaCheckers);
544+
AllowEnablingAnalyzerAlphaCheckers, false, ExperimentalCustomChecks);
532545
ClangTidyDiagnosticConsumer DiagConsumer(Context);
533546
auto DiagOpts = std::make_unique<DiagnosticOptions>();
534547
DiagnosticsEngine DE(llvm::makeIntrusiveRefCnt<DiagnosticIDs>(), *DiagOpts,
@@ -665,15 +678,19 @@ void exportReplacements(const llvm::StringRef MainFilePath,
665678
YAML << TUD;
666679
}
667680

668-
ChecksAndOptions
669-
getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) {
681+
ChecksAndOptions getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers,
682+
bool ExperimentalCustomChecks) {
670683
ChecksAndOptions Result;
671684
ClangTidyOptions Opts;
672685
Opts.Checks = "*";
673686
clang::tidy::ClangTidyContext Context(
674687
std::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions(), Opts),
675-
AllowEnablingAnalyzerAlphaCheckers);
688+
AllowEnablingAnalyzerAlphaCheckers, false, ExperimentalCustomChecks);
676689
ClangTidyCheckFactories Factories;
690+
#if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
691+
if (ExperimentalCustomChecks)
692+
custom::registerCustomChecks(Context.getOptions(), Factories);
693+
#endif
677694
for (const ClangTidyModuleRegistry::entry &Module :
678695
ClangTidyModuleRegistry::entries()) {
679696
Module.instantiate()->addCheckFactories(Factories);

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,16 @@ 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);
59+
bool AllowEnablingAnalyzerAlphaCheckers,
60+
bool ExperimentalCustomChecks);
6061

6162
struct ChecksAndOptions {
6263
llvm::StringSet<> Checks;
6364
llvm::StringSet<> Options;
6465
};
6566

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

6970
/// Returns the effective check-specific options.
7071
///
@@ -74,7 +75,8 @@ getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers = true);
7475
/// Options.
7576
ClangTidyOptions::OptionMap
7677
getCheckOptions(const ClangTidyOptions &Options,
77-
bool AllowEnablingAnalyzerAlphaCheckers);
78+
bool AllowEnablingAnalyzerAlphaCheckers,
79+
bool ExperimentalCustomChecks);
7880

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

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

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

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

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

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

2324
namespace clang {
2425

@@ -68,10 +69,13 @@ struct ClangTidyStats {
6869
/// \endcode
6970
class ClangTidyContext {
7071
public:
72+
ClangTidyContext(std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider)
73+
: ClangTidyContext(std::move(OptionsProvider), false, false, false) {}
7174
/// Initializes \c ClangTidyContext instance.
7275
ClangTidyContext(std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider,
73-
bool AllowEnablingAnalyzerAlphaCheckers = false,
74-
bool EnableModuleHeadersParsing = false);
76+
bool AllowEnablingAnalyzerAlphaCheckers,
77+
bool EnableModuleHeadersParsing,
78+
bool ExperimentalCustomChecks);
7579
/// Sets the DiagnosticsEngine that diag() will emit diagnostics to.
7680
// FIXME: this is required initialization, and should be a constructor param.
7781
// Fix the context -> diag engine -> consumer -> context initialization cycle.
@@ -210,6 +214,10 @@ class ClangTidyContext {
210214
return EnableModuleHeadersParsing;
211215
}
212216

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

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

259267
bool AllowEnablingAnalyzerAlphaCheckers;
260268
bool EnableModuleHeadersParsing;
269+
bool ExperimentalCustomChecks;
261270

262271
bool SelfContainedDiags = false;
263272

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ 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+
5764
// This anchor is used to force the linker to link the DarwinModule.
5865
extern volatile int DarwinModuleAnchorSource;
5966
static int LLVM_ATTRIBUTE_UNUSED DarwinModuleAnchorDestination =

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

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

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

0 commit comments

Comments
 (0)