diff options
author | David Malcolm <dmalcolm@redhat.com> | 2024-07-31 20:38:41 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2024-07-31 20:38:41 -0400 |
commit | a874b8301d9aa0421522d5aa11736f1510edb13a (patch) | |
tree | bb01436ab0d7506080fe01f12c4bd4a2073fed7e /gcc/dwarf2codeview.cc | |
parent | c990667996ff79cc5be6c898621811eeed4ad0a4 (diff) | |
download | gcc-a874b8301d9aa0421522d5aa11736f1510edb13a.zip gcc-a874b8301d9aa0421522d5aa11736f1510edb13a.tar.gz gcc-a874b8301d9aa0421522d5aa11736f1510edb13a.tar.bz2 |
diagnostics: SARIF output: capture unlabelled secondary locations
This patch extends
* the work done in r15-2291-gd7a688fc960f78 to capture labels
on location ranges in rich_locations in SARIF form as
"annotations" (§3.28.6)
* the work done in r15-2354-g4d1f71d49e396c to support
related locations (§3.27.22 and §3.34)
so that all location ranges in a rich_location now get captured in
the SARIF output:
- those with a label are handled as before as "annotations" (§3.28.6),
per r15-2291-gd7a688fc960f78
- those without a label now get captured, in the result's
"relatedLocations" (§3.27.22)
For example, given:
int missing_semicolon (void)
{
return 42
}
for which the textual output looks like this:
PATH/missing-semicolon.c: In function 'missing_semicolon':
PATH/missing-semicolon.c:9:12: error: expected ';' before '}' token
9 | return 42
| ^
| ;
10 | }
| ~
with this patch the SARIF output now has this for the result's location:
"relationships": [{"target": 0,
"kinds": ["relevant"]}]}],
where the result gains a related location :
"relatedLocations": [{"physicalLocation": {"artifactLocation": { [...snip...] },
"region": {"startLine": 10,
"startColumn": 1,
"endColumn": 2},
"contextRegion": {"startLine": 10,
"snippet": {"text": "}\n"}}},
"id": 0}]}]}]}
i.e. that the error also has the secondary location at the trailing
close brace which has the relationship "relevant" to the primary
location (at the suggested insertion point).
The patch also adds test coverage for the SARIF encoding of the fix-it hint.
gcc/ChangeLog:
* diagnostic-format-sarif.cc
(sarif_location_manager::worklist_item::unlabelled_secondary_location):
New enum value.
(sarif_location_manager::m_unlabelled_secondary_locations): New
field.
(sarif_location_manager::process_worklist_item): Handle unlabelled
secondary locations.
(sarif_builder::make_location_object): Generalize code to handle
ranges within a rich_location so as well as using annotations for
those with labels, we now add related locations for those without
labels.
gcc/testsuite/ChangeLog:
* gcc.dg/sarif-output/missing-semicolon.c: New test.
* gcc.dg/sarif-output/sarif.py (get_location_physical_region): New.
(get_location_snippet_text): New.
* gcc.dg/sarif-output/test-missing-semicolon.py: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/dwarf2codeview.cc')
0 files changed, 0 insertions, 0 deletions