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

--- Comment #2 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:385a232229a5b4ee3f4d2a2472bcda28cd8d17b2

commit r15-4081-g385a232229a5b4ee3f4d2a2472bcda28cd8d17b2
Author: David Malcolm <dmalc...@redhat.com>
Date:   Fri Oct 4 18:31:17 2024 -0400

    diagnostics: bulletproof opening of SARIF output [PR116978]

    Introduce a new RAII class diagnostic_output_file to track ownership
    of the FILE * for SARIF output.

    In particular, the .sarif file is now opened immediately, rather
    than at the end of the compile, and so will fail earlier if the
    file can't be opened.

    Doing so fixes a couple of ICEs in -fdiagnostics-format=sarif-file when
    invoking, say, cc1 directly, rather than from the driver.

    gcc/ChangeLog:
            PR other/116978
            * diagnostic-format-sarif.cc (sarif_builder::sarif_builder):
            Gracefully handle "main_input_filename_" being NULL.
            (sarif_output_format::sarif_output_format): Replace param
            "base_file_name" with "output_file" and assert that the file
            was opened successfully and has a non-NULL filename.
            (sarif_output_format::~sarif_file_output_format): Move
            responsibility for building the filename and opening the file from
            here to the creator of the instance.
            (sarif_output_format::m_base_file_name): Replace with...
            (sarif_output_format::m_output_file): ...this.
            (diagnostic_output_format_init_sarif_file): Make "line_maps" param
            non-const.  Gracefully handle "base_file_name" being NULL.
            Construct the filename and open the file here, rather than in
            ~sarif_file_output_format, and handle failures immediately here,
            rather than at the end of the compile.
            * diagnostic-format-sarif.h: Include "diagnostic-output-file.h".
            (diagnostic_output_format_init_sarif_file): Make "line_maps" param
            non-const.
            * diagnostic-output-file.h: New file.
            * diagnostic.cc (diagnostic_context::emit_diagnostic): New.
            (diagnostic_context::emit_diagnostic_va): New.
            * diagnostic.h (diagnostic_context::emit_diagnostic): New decl.
            (diagnostic_context::emit_diagnostic_va): New decl.

    Signed-off-by: David Malcolm <dmalc...@redhat.com>

Reply via email to