https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118881
--- Comment #1 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:a1f63ea36e9c9f2f66980dccc76d18cf781716a7 commit r15-7561-ga1f63ea36e9c9f2f66980dccc76d18cf781716a7 Author: David Malcolm <dmalc...@redhat.com> Date: Sat Feb 15 08:13:06 2025 -0500 sarif-replay: display annotations as labelled ranges (§3.28.6) [PR118881] In our .sarif output from e.g.: bad-binary-op.c: In function âtest_4â: bad-binary-op.c:19:23: error: invalid operands to binary + (have âSâ {aka âstruct sâ} and âTâ {aka âstruct tâ}) 19 | return callee_4a () + callee_4b (); | ~~~~~~~~~~~~ ^ ~~~~~~~~~~~~ | | | | | T {aka struct t} | S {aka struct s} the labelled ranges are captured in the 'annotations' property of the 'location' object (§3.28.6). However sarif-replay emits just: In function 'test_4': bad-binary-op.c:19:23: error: invalid operands to binary + (have âSâ {aka âstruct sâ} and âTâ {aka âstruct tâ}) [error] 19 | return callee_4a () + callee_4b (); | ^ missing the labelled ranges. This patch adds support to sarif-replay for the 'annotations' property; with this patch we emit: In function 'test_4': bad-binary-op.c:19:23: error: invalid operands to binary + (have âSâ {aka âstruct sâ} and âTâ {aka âstruct tâ}) [error] 19 | return callee_4a () + callee_4b (); | ~~~~~~~~~~~~ ^ ~~~~~~~~~~~~ | | | | | T {aka struct t} | S {aka struct s} thus showing the labelled ranges. Doing so requires adding a new entrypoint to libgdiagnostics: diagnostic_physical_location_get_file Given that we haven't yet released a stable version and that sarif-replay is built together with libgdiagnostics I didn't bother updating the ABI version. gcc/ChangeLog: PR sarif-replay/118881 * doc/libgdiagnostics/topics/physical-locations.rst: Add diagnostic_physical_location_get_file. * libgdiagnostics++.h (physical_location::get_file): New wrapper. (diagnostic::add_location): Likewise. * libgdiagnostics.cc (diagnostic_manager::get_file_by_name): New. (diagnostic_physical_location::get_file): New. (diagnostic_physical_location_get_file): New. * libgdiagnostics.h (diagnostic_physical_location_get_file): New. * libgdiagnostics.map (diagnostic_physical_location_get_file): New. * libsarifreplay.cc (class annotation): New. (add_any_annotations): New. (sarif_replayer::handle_result_obj): Collect vectors of annotations in the calls to handle_location_object and apply them to "err" and to "note" as appropriate. (sarif_replayer::handle_thread_flow_location_object): Pass nullptr for annotations. (sarif_replayer::handle_location_object): Handle §3.28.6 "annotations" property, using it to populate a new "out_annotations" param. gcc/testsuite/ChangeLog: PR sarif-replay/118881 * sarif-replay.dg/2.1.0-valid/3.28.6-annotations-1.sarif: New test. Signed-off-by: David Malcolm <dmalc...@redhat.com>