https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117943
--- 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:778336e0e4f25745f76a127801dc3bab5e9c1334 commit r15-6284-g778336e0e4f25745f76a127801dc3bab5e9c1334 Author: David Malcolm <dmalc...@redhat.com> Date: Mon Dec 16 11:22:49 2024 -0500 sarif-replay: quote source from artifact contents [PR117943] The diagnostic source-quoting machinery uses class file_cache implemented in gcc/input.cc for (re)reading the source when issuing diagnostics. When sarif-replay issues a saved diagnostic it might be running in a different path to where the .sarif file was captured, or on an entirely different machine. Previously such invocations would lead to the source-quoting silently failing, even if the content of the file is recorded in the .sarif file in the artifact "contents" property (which gcc populates when emitting .sarif output). This patch: - adds the ability for slots in file_cache to be populated from memory rather than from the filesystem - exposes it in libgdiagnostics via a new entrypoint - uses this in sarif-replay for any artifacts with a "contents" property, so that source-quoting uses that rather than trying to read from the path on the filesystem gcc/ChangeLog: PR sarif-replay/117943 * doc/libgdiagnostics/topics/physical-locations.rst (diagnostic_manager_new_file): Drop "const" from return type. * doc/libgdiagnostics/tutorial/02-physical-locations.rst: Drop "const" from "main_file" decl. * input.cc (file_cache::add_buffered_content): New. (file_cache_slot::set_content): New. (file_cache_slot::dump): Use m_file_path being null rather than m_fp to determine empty slots. Dump m_fp. (find_end_of_line): Drop "const" from return type and param. Add forward decl. (file_cache_slot::get_next_line): Fix "const"-ness. (selftest::test_reading_source_buffer): New. (selftest::input_cc_tests): Call it. * input.h (file_cache::add_buffered_content): New decl. * libgdiagnostics++.h (class file): Drop const-ness from m_inner. (file::set_buffered_content): New. * libgdiagnostics.cc (class content_buffer): New. (diagnostic_file::diagnostic_file): Add "mgr" param. (diagnostic_file::get_content): New. (diagnostic_file::set_buffered_content): New. (diagnostic_file::m_mgr): New. (diagnostic_file::m_content): New. (diagnostic_manager::new_file): Drop const-ness. Pass *this to ctor. (diagnostic_file::set_buffered_content): New. (diagnostic_manager_new_file): Drop "const" from return type. (diagnostic_file_set_buffered_content): New entrypoint. (diagnostic_manager_debug_dump_file): Dump the content size, if any. * libgdiagnostics.h (diagnostic_manager_new_file): Drop "const" from return type. (diagnostic_file_set_buffered_content): New decl. * libgdiagnostics.map (diagnostic_file_set_buffered_content): New symbol. * libsarifreplay.cc (sarif_replayer::m_artifacts_arr): Convert from json::value to json::array. (sarif_replayer::handle_run_obj): Call handle_artifact_obj on all artifacts. (sarif_replayer::handle_artifact_obj): New. gcc/testsuite/ChangeLog: PR sarif-replay/117943 * sarif-replay.dg/2.1.0-valid/error-with-note.sarif: Update expected output to include quoted source code and underlines. * sarif-replay.dg/2.1.0-valid/signal-1.c.moved.sarif: New test. * sarif-replay.dg/2.1.0-valid/signal-1.c.sarif: Update expected output to include quoted source code and underlines. Signed-off-by: David Malcolm <dmalc...@redhat.com>