]> gcc.gnu.org Git - gcc.git/commit
diagnostics: fix corrupt json/SARIF on stderr [PR114348]
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 19 Mar 2024 17:57:35 +0000 (13:57 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Tue, 19 Mar 2024 17:57:35 +0000 (13:57 -0400)
commit0bf99b1b7eda2f4c34b9f56b895980ea1c261765
tree7f01f8103b589fd373f5f482c24015e13abde390
parentbc91e3870e9c984c180b478a3449a9a2e56cd107
diagnostics: fix corrupt json/SARIF on stderr [PR114348]

Various values of -fdiagnostics-format= request machine-readable output
on stderr, using JSON, but in various places we use fnotice to write
free-form text to stderr, such as "compilation terminated", leading to
corrupt JSON.

Fix by having fnotice skip the output for such cases.

gcc/ChangeLog:
PR middle-end/114348
* diagnostic-format-json.cc
(json_stderr_output_format::machine_readable_stderr_p): New.
(json_file_output_format::machine_readable_stderr_p): New.
* diagnostic-format-sarif.cc
(sarif_stream_output_format::machine_readable_stderr_p): New.
(sarif_file_output_format::machine_readable_stderr_p): New.
* diagnostic.cc (diagnostic_context::action_after_output): Move
"fnotice" to before "finish" call, so that we still have the
diagnostic_context.
(fnotice): Bail out if the user requested one of the
machine-readable diagnostic output formats on stderr.
* diagnostic.h
(diagnostic_output_format::machine_readable_stderr_p): New pure
virtual function.
(diagnostic_text_output_format::machine_readable_stderr_p): New.
(diagnostic_context::get_output_format): New accessor.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/diagnostic-format-json.cc
gcc/diagnostic-format-sarif.cc
gcc/diagnostic.cc
gcc/diagnostic.h
This page took 0.059285 seconds and 6 git commands to generate.