diff options
author | Abraham Corea Diaz <abrahamcd@google.com> | 2022-08-26 18:31:38 +0000 |
---|---|---|
committer | Christopher Di Bella <cjdb@google.com> | 2022-08-26 18:49:29 +0000 |
commit | 82e893c47c77430ca59f92d7a814a336e3873a35 (patch) | |
tree | 7cbf70b06ba58685ddb67947eb0c5e7e990d69a1 /clang/lib/Frontend/FrontendAction.cpp | |
parent | 47166968db5c5c677bda996e0c5e40e94d8ef09f (diff) | |
download | llvm-82e893c47c77430ca59f92d7a814a336e3873a35.zip llvm-82e893c47c77430ca59f92d7a814a336e3873a35.tar.gz llvm-82e893c47c77430ca59f92d7a814a336e3873a35.tar.bz2 |
[clang] Enable output of SARIF diagnostics
Enables Clang to emit diagnostics in SARIF format when
`-fdiagnostics-format=sarif`. Adds a new DiagnosticConsumer named
SARIFDiagnosticPrinter and a new DiagnosticRenderer named SARIFDiagnostic
to constuct and emit a SARIF object containing the run's basic diagnostic info.
Reviewed By: cjdb, denik, aaron.ballman
Differential Revision: https://reviews.llvm.org/D131632
Diffstat (limited to 'clang/lib/Frontend/FrontendAction.cpp')
-rw-r--r-- | clang/lib/Frontend/FrontendAction.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index 53cb48d..4b639a7 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -11,13 +11,16 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/DeclGroup.h" #include "clang/Basic/Builtins.h" +#include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/LangStandard.h" +#include "clang/Basic/Sarif.h" #include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/FrontendPluginRegistry.h" #include "clang/Frontend/LayoutOverrideSource.h" #include "clang/Frontend/MultiplexConsumer.h" +#include "clang/Frontend/SARIFDiagnosticPrinter.h" #include "clang/Frontend/Utils.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/LiteralSupport.h" @@ -35,6 +38,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" +#include <memory> #include <system_error> using namespace clang; @@ -717,8 +721,14 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, return false; } } - if (!CI.hasSourceManager()) + if (!CI.hasSourceManager()) { CI.createSourceManager(CI.getFileManager()); + if (CI.getDiagnosticOpts().getFormat() == DiagnosticOptions::SARIF) { + static_cast<SARIFDiagnosticPrinter *>(&CI.getDiagnosticClient()) + ->setSarifWriter( + std::make_unique<SarifDocumentWriter>(CI.getSourceManager())); + } + } // Set up embedding for any specified files. Do this before we load any // source files, including the primary module map for the compilation. |