aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/analyzer
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2024-06-03 16:51:54 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2024-06-03 16:51:54 -0400
commita67595d5c5d4bd4937de39158b268aed61f3d8d0 (patch)
tree7e26e5ca42a29a42aa42da8fad0c50ee703add37 /gcc/testsuite/c-c++-common/analyzer
parent2a83084ce5536353ceb8554e906f87273a59c4fd (diff)
downloadgcc-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/testsuite/c-c++-common/analyzer')
-rw-r--r--gcc/testsuite/c-c++-common/analyzer/sarif-path-role.c21
-rw-r--r--gcc/testsuite/c-c++-common/analyzer/sarif-path-role.h2
2 files changed, 23 insertions, 0 deletions
diff --git a/gcc/testsuite/c-c++-common/analyzer/sarif-path-role.c b/gcc/testsuite/c-c++-common/analyzer/sarif-path-role.c
new file mode 100644
index 0000000..d0f6cef
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/analyzer/sarif-path-role.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-additional-options " -fno-diagnostics-json-formatting -fdiagnostics-format=sarif-file" } */
+
+#include <stdlib.h>
+
+void test_1 (void)
+{
+ void *ptr = malloc (1024);
+#include "sarif-path-role.h"
+ free (ptr);
+}
+
+/* Verify SARIF output.
+
+ { dg-final { verify-sarif-file } }
+
+ Verify that the artifact for the header has this role, given
+ that it's only referenced by an execution path event.
+
+ { dg-final { scan-sarif-file "\"roles\": \\\[\"tracedFile\"\\\]" } }
+*/
diff --git a/gcc/testsuite/c-c++-common/analyzer/sarif-path-role.h b/gcc/testsuite/c-c++-common/analyzer/sarif-path-role.h
new file mode 100644
index 0000000..fe620f9b
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/analyzer/sarif-path-role.h
@@ -0,0 +1,2 @@
+/* Generate an execution path event within a header. */
+free (ptr);