diff options
author | David Malcolm <dmalcolm@redhat.com> | 2024-06-21 08:46:13 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2024-06-21 08:46:13 -0400 |
commit | 9f4fdc3acebcf6b045edea1361570658da4bc0ab (patch) | |
tree | 12e63288fd9b52218d302ccb660f95d3ba60aacc /libcpp | |
parent | 09ca26cd24778e0820525edfac1cce07262f7e6c (diff) | |
download | gcc-9f4fdc3acebcf6b045edea1361570658da4bc0ab.zip gcc-9f4fdc3acebcf6b045edea1361570658da4bc0ab.tar.gz gcc-9f4fdc3acebcf6b045edea1361570658da4bc0ab.tar.bz2 |
diagnostics: fixes to SARIF output [PR109360]
When adding validation of .sarif files against the schema
(PR testsuite/109360) I discovered various issues where we were
generating invalid .sarif files.
Specifically, in
c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c
the relatedLocations for the "note" diagnostics were missing column
numbers, leading to validation failure due to non-unique elements,
such as multiple:
"message": {"text": "invalid UTF-8 character <bf>"}},
on line 25 with no column information.
Root cause is that for some diagnostics in libcpp we have a location_t
representing the line as a whole, setting a column_override on the
rich_location (since the line hasn't been fully read yet). We were
handling this column override for plain text output, but not for .sarif
output.
Similarly, in diagnostic-format-sarif-file-pr111700.c there is a warning
emitted on "line 0" of the file, whereas SARIF requires line numbers to
be positive.
We also use column == 0 internally to mean "the line as a whole",
whereas SARIF required column numbers to be positive.
This patch fixes these various issues.
gcc/ChangeLog:
PR testsuite/109360
* diagnostic-format-sarif.cc
(sarif_builder::make_location_object): Pass any column override
from rich_loc to maybe_make_physical_location_object.
(sarif_builder::maybe_make_physical_location_object): Add
"column_override" param and pass it to maybe_make_region_object.
(sarif_builder::maybe_make_region_object): Add "column_override"
param and use it when the location has 0 for a column. Don't
add "startLine", "startColumn", "endLine", or "endColumn" if
the values aren't positive.
(sarif_builder::maybe_make_region_object_for_context): Don't
add "startLine" or "endLine" if the values aren't positive.
libcpp/ChangeLog:
PR testsuite/109360
* include/rich-location.h (rich_location::get_column_override):
New accessor.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/include/rich-location.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/libcpp/include/rich-location.h b/libcpp/include/rich-location.h index be424cb..cc4f888 100644 --- a/libcpp/include/rich-location.h +++ b/libcpp/include/rich-location.h @@ -514,6 +514,8 @@ class rich_location const line_maps *get_line_table () const { return m_line_table; } + int get_column_override () const { return m_column_override; } + private: bool reject_impossible_fixit (location_t where); void stop_supporting_fixits (); |