diff options
author | Abraham Corea Diaz <abrahamcd@google.com> | 2022-07-21 16:50:43 +0000 |
---|---|---|
committer | Christopher Di Bella <cjdb@google.com> | 2022-07-21 16:51:15 +0000 |
commit | 119d22310bd622d4b39e9760667b6fa58d15a8c5 (patch) | |
tree | 59e34c7ce1c40639717916a22a815a6367d40734 /clang | |
parent | [libc++][NFC] Fix weird unicode character in release notes (diff) | |
download | llvm-project-119d22310bd622d4b39e9760667b6fa58d15a8c5.tar.gz llvm-project-119d22310bd622d4b39e9760667b6fa58d15a8c5.tar.bz2 llvm-project-119d22310bd622d4b39e9760667b6fa58d15a8c5.zip |
[clang] Add -fdiagnostics-format=sarif option for future SARIF output
Adds `sarif` option to the existing `-fdiagnostics-format` flag
for intended future work with SARIF diagnostics. Currently issues a warning
against the use of diagnostics in SARIF mode, then defaults to clang style for
diagnostics.
Reviewed By: cjdb, denik, aaron.ballman
Differential Revision: https://reviews.llvm.org/D129886
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang/Basic/DiagnosticDriverKinds.td | 4 | ||||
-rw-r--r-- | clang/include/clang/Basic/DiagnosticOptions.h | 2 | ||||
-rw-r--r-- | clang/include/clang/Driver/Options.td | 4 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/Clang.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Frontend/TextDiagnostic.cpp | 2 | ||||
-rw-r--r-- | clang/test/Driver/fdiagnostics-format-sarif.cpp | 5 |
6 files changed, 17 insertions, 3 deletions
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 68685baf7633..3c5f7e087de8 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -678,4 +678,8 @@ def err_drv_invalid_format_dxil_validator_version : Error< def err_drv_invalid_empty_dxil_validator_version : Error< "invalid validator version : %0\n" "If validator major version is 0, minor version must also be 0.">; + +def warn_drv_sarif_format_unstable : Warning< + "diagnostic formatting in SARIF mode is currently unstable">, + InGroup<DiagGroup<"sarif-format-unstable">>; } diff --git a/clang/include/clang/Basic/DiagnosticOptions.h b/clang/include/clang/Basic/DiagnosticOptions.h index 17533b38ff5f..c4134835b5de 100644 --- a/clang/include/clang/Basic/DiagnosticOptions.h +++ b/clang/include/clang/Basic/DiagnosticOptions.h @@ -74,7 +74,7 @@ class DiagnosticOptions : public RefCountedBase<DiagnosticOptions>{ friend class CompilerInvocation; public: - enum TextDiagnosticFormat { Clang, MSVC, Vi }; + enum TextDiagnosticFormat { Clang, MSVC, Vi, SARIF }; // Default values. enum { diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 3bd3550c9c60..b9c2e4d528e4 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5588,8 +5588,8 @@ def diagnostic_serialized_file : Separate<["-"], "serialize-diagnostic-file">, def fdiagnostics_format : Separate<["-"], "fdiagnostics-format">, HelpText<"Change diagnostic formatting to match IDE and command line tools">, - Values<"clang,msvc,vi">, - NormalizedValuesScope<"DiagnosticOptions">, NormalizedValues<["Clang", "MSVC", "Vi"]>, + Values<"clang,msvc,vi,sarif,SARIF">, + NormalizedValuesScope<"DiagnosticOptions">, NormalizedValues<["Clang", "MSVC", "Vi", "SARIF", "SARIF"]>, MarshallingInfoEnum<DiagnosticOpts<"Format">, "Clang">; def fdiagnostics_show_category : Separate<["-"], "fdiagnostics-show-category">, HelpText<"Print diagnostic category">, diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 6337a996a9ac..3ad08ad7e11d 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -4007,6 +4007,9 @@ static void RenderDiagnosticsOptions(const Driver &D, const ArgList &Args, if (const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_format_EQ)) { CmdArgs.push_back("-fdiagnostics-format"); CmdArgs.push_back(A->getValue()); + if (StringRef(A->getValue()) == "sarif" || + StringRef(A->getValue()) == "SARIF") + D.Diag(diag::warn_drv_sarif_format_unstable); } if (const Arg *A = Args.getLastArg( diff --git a/clang/lib/Frontend/TextDiagnostic.cpp b/clang/lib/Frontend/TextDiagnostic.cpp index 6c0ea0cde358..ab0dbcef6534 100644 --- a/clang/lib/Frontend/TextDiagnostic.cpp +++ b/clang/lib/Frontend/TextDiagnostic.cpp @@ -815,6 +815,7 @@ void TextDiagnostic::emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc, emitFilename(PLoc.getFilename(), Loc.getManager()); switch (DiagOpts->getFormat()) { + case DiagnosticOptions::SARIF: case DiagnosticOptions::Clang: if (DiagOpts->ShowLine) OS << ':' << LineNo; @@ -837,6 +838,7 @@ void TextDiagnostic::emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc, OS << ColNo; } switch (DiagOpts->getFormat()) { + case DiagnosticOptions::SARIF: case DiagnosticOptions::Clang: case DiagnosticOptions::Vi: OS << ':'; break; case DiagnosticOptions::MSVC: diff --git a/clang/test/Driver/fdiagnostics-format-sarif.cpp b/clang/test/Driver/fdiagnostics-format-sarif.cpp new file mode 100644 index 000000000000..f7e2274e532b --- /dev/null +++ b/clang/test/Driver/fdiagnostics-format-sarif.cpp @@ -0,0 +1,5 @@ +// RUN: %clang -fsyntax-only -fdiagnostics-format=sarif %s -### 2>&1 | FileCheck %s --check-prefix=WARN +// WARN: warning: diagnostic formatting in SARIF mode is currently unstable [-Wsarif-format-unstable] + +// RUN: %clang -fsyntax-only -fdiagnostics-format=SARIF %s -### 2>&1 | FileCheck %s --check-prefix=WARN2 +// WARN2: warning: diagnostic formatting in SARIF mode is currently unstable [-Wsarif-format-unstable] |