diff options
| author | Nikolai Kosjar <nikolai.kosjar@qt.io> | 2019-06-06 13:13:27 +0000 |
|---|---|---|
| committer | Nikolai Kosjar <nikolai.kosjar@qt.io> | 2019-06-06 13:13:27 +0000 |
| commit | 60e1296a9a36186656989d8223b60b6d4cb67b34 (patch) | |
| tree | d789fa62cfa96907c7b4d1f195cac9f0849e094c /clang-tools-extra/clang-tidy/plugin | |
| parent | df95e6109e1cac8716bfc62ecf4500ed7420ecda (diff) | |
| download | bcm5719-llvm-60e1296a9a36186656989d8223b60b6d4cb67b34.tar.gz bcm5719-llvm-60e1296a9a36186656989d8223b60b6d4cb67b34.zip | |
[clang-tidy] Make the plugin honor NOLINT
Instantiate a ClangTidyDiagnosticConsumer also for the plugin case and
let it forward the diagnostics to the external diagnostic engine that is
already in place.
One minor difference to the clang-tidy executable case is that the
compiler checks/diagnostics are referred to with their original name.
For example, for -Wunused-variable the plugin will refer to the check as
"-Wunused-variable" while the clang-tidy executable will refer to that
as "clang-diagnostic- unused-variable". This is because the compiler
diagnostics never reach ClangTidyDiagnosticConsumer.
Differential Revision: https://reviews.llvm.org/D61487
llvm-svn: 362702
Diffstat (limited to 'clang-tools-extra/clang-tidy/plugin')
| -rw-r--r-- | clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp b/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp index 80208c78137..10165518161 100644 --- a/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp +++ b/clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "../ClangTidy.h" +#include "../ClangTidyDiagnosticConsumer.h" #include "../ClangTidyForceLinker.h" #include "../ClangTidyModule.h" #include "clang/Frontend/CompilerInstance.h" @@ -19,29 +20,39 @@ namespace tidy { /// The core clang tidy plugin action. This just provides the AST consumer and /// command line flag parsing for using clang-tidy as a clang plugin. class ClangTidyPluginAction : public PluginASTAction { - /// Wrapper to grant the context the same lifetime as the action. We use - /// MultiplexConsumer to avoid writing out all the forwarding methods. + /// Wrapper to grant the context and diagnostics engine the same lifetime as + /// the action. + /// We use MultiplexConsumer to avoid writing out all the forwarding methods. class WrapConsumer : public MultiplexConsumer { std::unique_ptr<ClangTidyContext> Context; + std::unique_ptr<DiagnosticsEngine> DiagEngine; public: WrapConsumer(std::unique_ptr<ClangTidyContext> Context, + std::unique_ptr<DiagnosticsEngine> DiagEngine, std::vector<std::unique_ptr<ASTConsumer>> Consumer) - : MultiplexConsumer(std::move(Consumer)), Context(std::move(Context)) {} + : MultiplexConsumer(std::move(Consumer)), Context(std::move(Context)), + DiagEngine(std::move(DiagEngine)) {} }; public: std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &Compiler, StringRef File) override { - // Insert the current diagnostics engine. - Context->setDiagnosticsEngine(&Compiler.getDiagnostics()); + // Create and set diagnostics engine + auto ExternalDiagEngine = &Compiler.getDiagnostics(); + auto DiagConsumer = + new ClangTidyDiagnosticConsumer(*Context, ExternalDiagEngine); + auto DiagEngine = llvm::make_unique<DiagnosticsEngine>( + new DiagnosticIDs, new DiagnosticOptions, DiagConsumer); + Context->setDiagnosticsEngine(DiagEngine.get()); // Create the AST consumer. ClangTidyASTConsumerFactory Factory(*Context); std::vector<std::unique_ptr<ASTConsumer>> Vec; Vec.push_back(Factory.CreateASTConsumer(Compiler, File)); - return llvm::make_unique<WrapConsumer>(std::move(Context), std::move(Vec)); + return llvm::make_unique<WrapConsumer>( + std::move(Context), std::move(DiagEngine), std::move(Vec)); } bool ParseArgs(const CompilerInstance &, |

