aboutsummaryrefslogtreecommitdiff
path: root/gcc/selftest-json.h
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2024-07-24 18:07:56 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2024-07-24 18:07:56 -0400
commitd7a688fc960f78c62aacdc5acb8432873fed300e (patch)
treee67ed958b9050e2969c915b84677156e210b0772 /gcc/selftest-json.h
parentb4693ce3a0565bb75d0d5698f2ce2ffc53d1ff84 (diff)
downloadgcc-d7a688fc960f78c62aacdc5acb8432873fed300e.zip
gcc-d7a688fc960f78c62aacdc5acb8432873fed300e.tar.gz
gcc-d7a688fc960f78c62aacdc5acb8432873fed300e.tar.bz2
diagnostics: SARIF output: add "annotations" property (§3.28.6)
This patch extends our SARIF output so that if a diagnostic has any labelled source ranges, the "location" object gains an "annotations" property capturing them (§3.28.6). For example, given this textual output: ../../src/gcc/testsuite/gcc.dg/bad-binary-ops.c: In function ‘test_2’: ../../src/gcc/testsuite/gcc.dg/bad-binary-ops.c:31:11: error: invalid operands to binary + (have ‘struct s’ and ‘struct t’) 30 | return (some_function () | ~~~~~~~~~~~~~~~~ | | | struct s 31 | + some_other_function ()); | ^ ~~~~~~~~~~~~~~~~~~~~~~ | | | struct t the SARIF output gains this within the result's location[0]: "annotations": [{"startLine": 30, "startColumn": 11, "endColumn": 27, "message": {"text": "struct s"}}, {"startLine": 31, "startColumn": 13, "endColumn": 35, "message": {"text": "struct t"}}]}]}, gcc/ChangeLog: * diagnostic-format-sarif.cc (sarif_builder::make_location_object): Add "annotations" property if there are any labelled ranges (§3.28.6). (selftest::test_make_location_object): Verify annotations are added to location_obj. * json.h (json::array::size): New. (json::array::operator[]): New. * selftest-json.cc (selftest::expect_json_object_with_array_property): New. * selftest-json.h (selftest::expect_json_object_with_array_property): New decl. (EXPECT_JSON_OBJECT_WITH_ARRAY_PROPERTY): New macro. gcc/testsuite/ChangeLog: * c-c++-common/diagnostic-format-sarif-file-Wbidi-chars.c: Verify that we have an "annotations" property for the labelled ranges (§3.28.6). Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/selftest-json.h')
-rw-r--r--gcc/selftest-json.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/gcc/selftest-json.h b/gcc/selftest-json.h
index 75a20d5..23b4d18 100644
--- a/gcc/selftest-json.h
+++ b/gcc/selftest-json.h
@@ -78,6 +78,20 @@ expect_json_object_with_object_property (const location &loc,
(PROPERTY_NAME))
/* Assert that VALUE is a non-null json::object that has property
+ PROPERTY_NAME, and that the property value is a non-null JSON array.
+ Return the value of the property as a json::array.
+ Use LOC for any failures. */
+
+const json::array *
+expect_json_object_with_array_property (const location &loc,
+ const json::value *value,
+ const char *property_name);
+#define EXPECT_JSON_OBJECT_WITH_ARRAY_PROPERTY(JSON_VALUE, PROPERTY_NAME) \
+ expect_json_object_with_array_property ((SELFTEST_LOCATION), \
+ (JSON_VALUE), \
+ (PROPERTY_NAME))
+
+/* Assert that VALUE is a non-null json::object that has property
PROPERTY_NAME, and that the value of that property is a non-null
JSON string equalling EXPECTED_VALUE.
Use LOC for any failures. */