diff options
author | David Malcolm <dmalcolm@redhat.com> | 2024-06-03 16:51:54 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2024-06-03 16:51:54 -0400 |
commit | a67595d5c5d4bd4937de39158b268aed61f3d8d0 (patch) | |
tree | 7e26e5ca42a29a42aa42da8fad0c50ee703add37 /gcc/gcc.cc | |
parent | 2a83084ce5536353ceb8554e906f87273a59c4fd (diff) | |
download | gcc-a67595d5c5d4bd4937de39158b268aed61f3d8d0.zip gcc-a67595d5c5d4bd4937de39158b268aed61f3d8d0.tar.gz gcc-a67595d5c5d4bd4937de39158b268aed61f3d8d0.tar.bz2 |
diagnostics: add SARIF property artifact.roles (3.24.6)
Add the property "roles" (SARIF v2.1 3.24.6) to artifacts.
Populate it with:
* "analysisTarget" for the top-level input file
* "resultFile" for any other file a diagnostic is reported in
* "tracedFile" for any file a diagnostic event is reported in
gcc/ChangeLog:
* diagnostic-format-sarif.cc: Include "ordered-hash-map.h" and
"sbitmap.h".
(enum class diagnostic_artifact_role): New.
(class sarif_artifact): New.
(sarif_builder::maybe_make_artifact_content_object): Make public.
(sarif_builder::m_filenames): Replace with...
(sarif_builder::m_filename_to_artifact_map): ...this.
(sarif_artifact::add_role): New.
(sarif_artifact::populate_contents): New.
(get_artifact_role_string): New.
(sarif_artifact::populate_roles): New.
(sarif_result::on_nested_diagnostic): Pass role to
make_location_object.
(sarif_ice_notification::sarif_ice_notification): Likewise.
(sarif_builder::sarif_builder): Add "main_input_filename_" param.
Mark it as the artifact that the tool was instructed to scan.
(sarif_builder::make_result_object): Pass role to
make_locations_arr.
(sarif_builder::make_locations_arr): Add "role" param and pass it
to make_location_object.
(sarif_builder::make_location_object): Add "role" param and pass
it to maybe_make_physical_location_object.
(sarif_builder::maybe_make_physical_location_object): Add "role"
param and pass it to call to get_or_create_artifact, rather than
adding to now-removed "m_filenames". Flag the artifact for its
contents to be embedded.
(sarif_builder::make_thread_flow_location_object): Pass role to
make_location_object.
(sarif_builder::make_run_object): Update for change from
m_filename to m_filename_to_artifact_map. Call populate_contents
and populate_roles on each artifact_obj.
(sarif_builder::make_artifact_object): Convert to...
(sarif_builder::get_or_create_artifact): ...this, moving addition
of contents to make_run_object, and conditionalizing setting of
sourceLanguage on "role".
(sarif_output_format::sarif_output_format): Add
"main_input_filename_" param and pass to m_builder's ctor.
(sarif_stream_output_format::sarif_stream_output_format):
Likewise.
(sarif_file_output_format::sarif_file_output_format): Likewise.
(diagnostic_output_format_init_sarif_stderr): Add
"main_input_filename_" param and pass to ctor.
(diagnostic_output_format_init_sarif_file): Likewise.
(diagnostic_output_format_init_sarif_stream): Likewise.
* diagnostic.cc (diagnostic_output_format_init): Add
"main_input_filename_" param and pass to the
diagnostic_output_format_init_sarif_* calls.
* diagnostic.h (diagnostic_output_format_init): Add
main_input_filename_" param to decl.
(diagnostic_output_format_init_sarif_stderr): Likewise.
(diagnostic_output_format_init_sarif_file): Likewise.
(diagnostic_output_format_init_sarif_stream): Likewise.
* gcc.cc (driver_handle_option): Pass main input filename to
diagnostic_output_format_init.
* opts.cc (common_handle_option): Likewise.
gcc/testsuite/ChangeLog:
* c-c++-common/analyzer/sarif-path-role.c: New test.
* c-c++-common/analyzer/sarif-path-role.h: New header for above
test.
* c-c++-common/diagnostic-format-sarif-file-1.c: Verify the
artifact's "role" property.
* c-c++-common/diagnostic-format-sarif-file-header-role.c: New
test.
* c-c++-common/diagnostic-format-sarif-file-header-role.h: New
header for above test.
* c-c++-common/diagnostic-format-sarif-file-no-results.c: New
test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/gcc.cc')
-rw-r--r-- | gcc/gcc.cc | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -4354,7 +4354,8 @@ driver_handle_option (struct gcc_options *opts, { const char *basename = (opts->x_dump_base_name ? opts->x_dump_base_name : opts->x_main_input_basename); - diagnostic_output_format_init (dc, basename, + diagnostic_output_format_init (dc, + opts->x_main_input_filename, basename, (enum diagnostics_output_format)value, opts->x_flag_diagnostics_json_formatting); break; |