https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114348

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by David Malcolm <dmalc...@gcc.gnu.org>:

https://gcc.gnu.org/g:0bf99b1b7eda2f4c34b9f56b895980ea1c261765

commit r14-9554-g0bf99b1b7eda2f4c34b9f56b895980ea1c261765
Author: David Malcolm <dmalc...@redhat.com>
Date:   Tue Mar 19 13:57:35 2024 -0400

    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 <dmalc...@redhat.com>

Reply via email to