aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2025-02-15 08:17:09 -0500
committerDavid Malcolm <dmalcolm@redhat.com>2025-02-15 08:17:09 -0500
commitd022a068e0c8587b2570147b738cb2781242f162 (patch)
tree478610086e6c11029c1665a72c1e0c9ba7adebed
parent79c311d42f846f3e65e012d66e5d8fde4c3b1958 (diff)
downloadgcc-d022a068e0c8587b2570147b738cb2781242f162.zip
gcc-d022a068e0c8587b2570147b738cb2781242f162.tar.gz
gcc-d022a068e0c8587b2570147b738cb2781242f162.tar.bz2
sarif-replay: don't add trailing " [error]"
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>
-rw-r--r--gcc/libsarifreplay.cc19
-rw-r--r--gcc/testsuite/sarif-replay.dg/2.1.0-valid/3.28.6-annotations-1.sarif3
-rw-r--r--gcc/testsuite/sarif-replay.dg/2.1.0-valid/unlabelled-secondary-locations.sarif3
3 files changed, 20 insertions, 5 deletions
diff --git a/gcc/libsarifreplay.cc b/gcc/libsarifreplay.cc
index e2d0908..21d8e6c 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 4ff6e07..fd7e2be 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 251e2fd..d462bf8 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]