Our SARIF output supplies "error" for the rule ID for DK_ERROR, since a value is required, but it's not useful to print in sarif-replay.
Filter it out. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r15-7563-gd022a068e0c858. gcc/ChangeLog: * libsarifreplay.cc (should_add_rule_p): New. (sarif_replayer::handle_result_obj): Use it to filter out rules that don't make sense. gcc/testsuite/ChangeLog: * sarif-replay.dg/2.1.0-valid/3.28.6-annotations-1.sarif: Update expected output to remove trailing " [error]". * sarif-replay.dg/2.1.0-valid/unlabelled-secondary-locations.sarif: Likewise. Signed-off-by: David Malcolm <dmalc...@redhat.com> --- gcc/libsarifreplay.cc | 19 ++++++++++++++++++- .../2.1.0-valid/3.28.6-annotations-1.sarif | 3 +-- .../unlabelled-secondary-locations.sarif | 3 +-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/gcc/libsarifreplay.cc b/gcc/libsarifreplay.cc index e2d09088a4a..21d8e6ce7cf 100644 --- a/gcc/libsarifreplay.cc +++ b/gcc/libsarifreplay.cc @@ -992,6 +992,20 @@ add_any_annotations (libgdiagnostics::diagnostic &diag, diag.add_location (annotation.m_phys_loc); } +static bool +should_add_rule_p (const char *rule_id_str, const char *url) +{ + if (url) + return true; + + /* GCC's sarif output uses "error" for "ruleId", which is already + captured in the "level", so don't add a rule for that. */ + if (!strcmp (rule_id_str, "error")) + return false; + + return true; +} + /* Process a result object (SARIF v2.1.0 section 3.27). Known limitations: - doesn't yet handle "ruleIndex" property (§3.27.6) @@ -1119,7 +1133,10 @@ sarif_replayer::handle_result_obj (const json::object &result_obj, prop_help_uri)) url = url_val->get_string (); } - err.add_rule (rule_id->get_string (), url); + + const char *rule_id_str = rule_id->get_string (); + if (should_add_rule_p (rule_id_str, url)) + err.add_rule (rule_id_str, url); } err.set_location (physical_loc); err.set_logical_location (logical_loc); diff --git a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/3.28.6-annotations-1.sarif b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/3.28.6-annotations-1.sarif index 4ff6e07ab4d..fd7e2be4481 100644 --- a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/3.28.6-annotations-1.sarif +++ b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/3.28.6-annotations-1.sarif @@ -37,11 +37,10 @@ /* Verify that we underline and label the ranges for the "annotations" above. */ /* { dg-begin-multiline-output "" } -bad-binary-ops-highlight-colors.c:19:23: error: invalid operands to binary + (have ‘S’ {aka ‘struct s’} and ‘T’ {aka ‘struct t’}) [error] +bad-binary-ops-highlight-colors.c:19:23: error: invalid operands to binary + (have ‘S’ {aka ‘struct s’} and ‘T’ {aka ‘struct t’}) 19 | return callee_4a () + callee_4b (); | ~~~~~~~~~~~~ ^ ~~~~~~~~~~~~ | | | | | T {aka struct t} | S {aka struct s} { dg-end-multiline-output "" } */ -// TODO: trailing [error] diff --git a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/unlabelled-secondary-locations.sarif b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/unlabelled-secondary-locations.sarif index 251e2fd2e78..d462bf8045a 100644 --- a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/unlabelled-secondary-locations.sarif +++ b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/unlabelled-secondary-locations.sarif @@ -50,11 +50,10 @@ /* Verify that we underline the "42" here. */ /* { dg-begin-multiline-output "" } In function 'test_known_fn': -too-many-arguments.c:5:3: error: too many arguments to function 'fn_a'; expected 0, have 1 [error] +too-many-arguments.c:5:3: error: too many arguments to function 'fn_a'; expected 0, have 1 5 | fn_a (42); | ^~~~ ~~ too-many-arguments.c:1:13: note: declared here 1 | extern void fn_a (); | ^~~~ { dg-end-multiline-output "" } */ -// TODO: trailing [error] -- 2.26.3