|
20 | 20 | #include "ClangTidyModuleRegistry.h"
|
21 | 21 | #include "ClangTidyProfiling.h"
|
22 | 22 | #include "ExpandModularHeadersPPCallbacks.h"
|
| 23 | +#include "GlobList.h" |
23 | 24 | #include "clang-tidy-config.h"
|
24 | 25 | #include "clang/AST/ASTConsumer.h"
|
25 | 26 | #include "clang/ASTMatchers/ASTMatchFinder.h"
|
@@ -581,7 +582,32 @@ runClangTidy(clang::tidy::ClangTidyContext &Context,
|
581 | 582 | return AdjustedArgs;
|
582 | 583 | };
|
583 | 584 |
|
| 585 | + // Add extra arguments required by clang-additional-diagnostic-* checks. |
| 586 | + ArgumentsAdjuster ClangAdditionalDiagnosticArgumentsInserter = |
| 587 | + [&Context](const CommandLineArguments &Args, StringRef Filename) { |
| 588 | + ClangTidyOptions Opts = Context.getOptionsForFile(Filename); |
| 589 | + if (!Opts.Checks) |
| 590 | + return Args; |
| 591 | + |
| 592 | + CommandLineArguments AdjustedArgs = Args; |
| 593 | + CachedGlobList Filter(*Opts.Checks); |
| 594 | + |
| 595 | + for (StringRef Flag : clang::DiagnosticIDs::getDiagnosticFlags()) { |
| 596 | + if (Flag.starts_with("-Wno")) |
| 597 | + continue; |
| 598 | + |
| 599 | + std::string CheckName = "clang-additional-diagnostic-"; |
| 600 | + CheckName += Flag.drop_front(2); |
| 601 | + |
| 602 | + if (Filter.contains(CheckName)) |
| 603 | + AdjustedArgs.insert(AdjustedArgs.end(), Flag.str()); |
| 604 | + } |
| 605 | + |
| 606 | + return AdjustedArgs; |
| 607 | + }; |
| 608 | + |
584 | 609 | Tool.appendArgumentsAdjuster(PerFileExtraArgumentsInserter);
|
| 610 | + Tool.appendArgumentsAdjuster(ClangAdditionalDiagnosticArgumentsInserter); |
585 | 611 | Tool.appendArgumentsAdjuster(getStripPluginsAdjuster());
|
586 | 612 | Context.setEnableProfiling(EnableCheckProfile);
|
587 | 613 | Context.setProfileStoragePrefix(StoreCheckProfile);
|
|
0 commit comments