]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
sarif-replay: don't add trailing " [error]"
authorDavid Malcolm <dmalcolm@redhat.com>
Sat, 15 Feb 2025 13:17:09 +0000 (08:17 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Sat, 15 Feb 2025 13:17:09 +0000 (08:17 -0500)
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.

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 <dmalcolm@redhat.com>
gcc/libsarifreplay.cc
gcc/testsuite/sarif-replay.dg/2.1.0-valid/3.28.6-annotations-1.sarif
gcc/testsuite/sarif-replay.dg/2.1.0-valid/unlabelled-secondary-locations.sarif

index e2d09088a4a6fc5f0bcf728543f89433cdb49ec2..21d8e6ce7cf7aaedcbd7b40174544f88135c78ee 100644 (file)
@@ -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);
index 4ff6e07ab4d4279567fe125813326ce3a0c5c113..fd7e2be44811c4114ead6ba007de0b9a9566d2da 100644 (file)
 /* 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]
index 251e2fd2e78691a8b5c779113e52c5a77d607418..d462bf8045a959539d1c6c038f26762496fb25be 100644 (file)
 /* 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]