diff options
author | David Malcolm <dmalcolm@redhat.com> | 2024-03-19 13:57:35 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2024-03-19 13:57:35 -0400 |
commit | 0bf99b1b7eda2f4c34b9f56b895980ea1c261765 (patch) | |
tree | 7f01f8103b589fd373f5f482c24015e13abde390 /gcc/diagnostic-format-json.cc | |
parent | bc91e3870e9c984c180b478a3449a9a2e56cd107 (diff) | |
download | gcc-0bf99b1b7eda2f4c34b9f56b895980ea1c261765.zip gcc-0bf99b1b7eda2f4c34b9f56b895980ea1c261765.tar.gz gcc-0bf99b1b7eda2f4c34b9f56b895980ea1c261765.tar.bz2 |
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>
Diffstat (limited to 'gcc/diagnostic-format-json.cc')
-rw-r--r-- | gcc/diagnostic-format-json.cc | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc index 51e016b..0782ae8 100644 --- a/gcc/diagnostic-format-json.cc +++ b/gcc/diagnostic-format-json.cc @@ -314,6 +314,10 @@ public: { flush_to_file (stderr); } + bool machine_readable_stderr_p () const final override + { + return true; + } }; class json_file_output_format : public json_output_format @@ -345,6 +349,10 @@ public: fclose (outf); free (filename); } + bool machine_readable_stderr_p () const final override + { + return false; + } private: char *m_base_file_name; |