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

--- Comment #3 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:f25e178b8c2cc868168b0a29ab03260fbefa4ff7

commit r16-414-gf25e178b8c2cc868168b0a29ab03260fbefa4ff7
Author: David Malcolm <dmalc...@redhat.com>
Date:   Tue May 6 09:26:18 2025 -0400

    sarif output: capture nesting of logical locations [PR116176]

    Previously our SARIF output did not capture nesting of logical
    locations: any time a result or event referred to a logical location it
    would simply put a copy of the logical location into the pertinent
    location object without a "parentIndex" property.

    With this patch we instead populate such locations with minimal logical
    locations with an "index" that refers to theRuns.logicalLocations,
    populating theRuns.logicalLocations with the full logical locations,
    including "parentIndex", recursively adding entries for the ancestor
    locations as needed, so that the SARIF output captures the hierarchical
    structure of the logical locations.

    gcc/ChangeLog:
            PR other/116176
            * diagnostic-format-sarif.cc (class sarif_array_of_unique): New
            template.
            (class sarif_logical_location): Move here from
            diagnostic-format-sarif.h.
            (sarif_builder::m_cached_logical_locs): New.
            (sarif_builder::sarif_builder): Initialize it.
            (sarif_builder::set_any_logical_locs_arr): Call
            make_minimal_sarif_logical_location rather than
            make_sarif_logical_location_object.
            (sarif_property_bag::set_logical_location): Likewise.
            (make_sarif_logical_location_object): Replace with...
            (sarif_builder::ensure_sarif_logical_location_for): ...this.
            Capture "parentIndex" property.  Consolidate into
            theRuns.logicalLocations.
            (sarif_builder::make_minimal_sarif_logical_location): New.
            (sarif_builder::make_run_object): Add "index" properties to
            m_cached_logical_locs and move it to theRuns.logicalLocations.
            (selftest::test_sarif_array_of_unique_1): New.
            (selftest::test_sarif_array_of_unique_2): New.
            (selftest::diagnostic_format_sarif_cc_tests): Call the new
            selftests.
            * diagnostic-format-sarif.h (class sarif_logical_location): Move
            to diagnostic-format-sarif.cc.
            (make_sarif_logical_location_object): Drop decl.
            * json.cc (value::compare): New.
            (object::compare): New.
            (selftest::fail_comparison): New.
            (selftest::assert_json_equal): New.
            (ASSERT_JSON_EQ): New.
            (selftest::assert_json_non_equal): New.
            (ASSERT_JSON_NE): New.
            (selftest::test_comparisons): New.
            (selftest::json_cc_tests): Call the new selftest.
            * json.h (json::value::dyn_cast_object): New vfunc.
            (json::object::dyn_cast_object): New vfunc impl.
            (json::object::compare): New decl.
            * libgdiagnostics.cc
            (impl_logical_location_manager::get_parent): New.
            * logical-location.h (logical_location_manager::get_parent): New
            vfunc impl.
            * selftest-logical-location.h
            (test_logical_location_manager::get_parent): New vfunc impl.
            * tree-logical-location.cc (assert_valid_tree): New.
            (tree_logical_location_manager::get_short_name): Support types as
            well as decls.
            (tree_logical_location_manager::get_name_with_scope): Gracefully
            handle non-decl nodes.
            (tree_logical_location_manager::get_internal_name): Likewise.
            (tree_logical_location_manager::get_kind): Don't attempt to handle
            null nodes.  Handle NAMESPACE_DECL and RECORD_TYPE.
            (tree_logical_location_manager::get_name_for_path_output):
            Gracefully handle non-decl nodes.
            (tree_logical_location_manager::get_parent): New.
            * tree-logical-location.h
            (tree_logical_location_manager::get_parent): New vfunc impl.

    gcc/testsuite/ChangeLog:
            PR other/116176
            * g++.dg/sarif-output/logical-locations-1.C: New test.
            * g++.dg/sarif-output/logical-locations-1.py: New test script.
            * g++.dg/sarif-output/logical-locations-2.C: New test.
            * g++.dg/sarif-output/logical-locations-2.py: New test script.
            * g++.dg/sarif-output/logical-locations-3.C: New test.
            * g++.dg/sarif-output/logical-locations-3.py: New test script.
            * g++.dg/sarif-output/sarif-output.exp: New script, adapted
            from gcc.dg/sarif-output/sarif-output.exp.
            * libgdiagnostics.dg/test-logical-location-c.py: Update for using
            theRun.logicalLocations.
            * libgdiagnostics.dg/test-warning-with-path-c.py: Likewise.

    Signed-off-by: David Malcolm <dmalc...@redhat.com>
  • [Bug other/116176] SARIF output... cvs-commit at gcc dot gnu.org via Gcc-bugs

Reply via email to