Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Semantic" markup in SARIF messages #662

Open
davidmalcolm opened this issue Oct 9, 2024 · 2 comments
Open

"Semantic" markup in SARIF messages #662

davidmalcolm opened this issue Oct 9, 2024 · 2 comments

Comments

@davidmalcolm
Copy link

There doesn't seem to be a way to add "semantic" markup to messages in SARIF logs.

For example, in GCC 15 I've added colorization to some diagnostics to highlight expected type vs actual type; see:
https://godbolt.org/z/zqWGe5jKh

image

where note how

  • the %i in the message line and quoted source and the int in the message line and the source annotation all appear in green (they're marked up internally as expected_type)
  • the const char * in the message line and in the source annotation and the msg in the quoted source all appear in dark blue (they're marked up internally as actual_type)

I'd like to capture this markup in the generated SARIF output, but we only support a subset of Markdown, and, in particular, HTML is forbidden.

@KalleOlaviNiemitalo
Copy link

KalleOlaviNiemitalo commented Oct 9, 2024

What does GCC output for that in SARIF now, without colorization?

My first thought is that I'd place the color annotations in the multiFormatMessageString object in the reportingDescriptor and associate them with the placeholder numbers, something like:

{
    "text": "format '{0}' expects argument of type '{1}', but argument {2} has type '{3}' [{4}]",
    "placeholders": {
        "0": { "role": "expected_type" },
        "1": { "role": "expected_type" },
        "3": { "role": "actual_type" },
        "4": { "role": "option" }
    }
}

or as an array:

{
    "text": "format '{0}' expects argument of type '{1}', but argument {2} has type '{3}' [{4}]",
    "placeholders": [
        { "role": "expected_type" },
        { "role": "expected_type" },
        {},
        { "role": "actual_type" },
        { "role": "option" }
    ]
}

This scheme would make the color information trivial to ignore for SARIF consumers that don't care about it. However, this does not seem easy to apply to msg in the quoted source code, and to the diagram below it.

@davidmalcolm
Copy link
Author

What does GCC output for that in SARIF now, without colorization?

From https://godbolt.org/z/9ja73xv19:

  "results": [{"ruleId": "-Wformat=",
                        "level": "warning",
                        "message": {"text": "format '%i' expects argument of type 'int', but argument 2 has type 'const char *'"},
                        "locations": [{"physicalLocation": {"artifactLocation": {"uri": "<source>"},
                                                            "region": {"startLine": 5,
                                                                       "startColumn": 17,
                                                                       "endColumn": 19},
                                                            "contextRegion": {"startLine": 5,
                                                                              "snippet": {"text": "  printf(\"hello %i\", msg);\n"}}},
                                       "logicalLocations": [{"name": "test_mismatching_types",
                                                             "fullyQualifiedName": "test_mismatching_types",
                                                             "decoratedName": "test_mismatching_types",
                                                             "kind": "function"}],
                                       "annotations": [{"startLine": 5,
                                                        "startColumn": 17,
                                                        "endColumn": 19,
                                                        "message": {"text": "int"}},
                                                       {"startLine": 5,
                                                        "startColumn": 22,
                                                        "endColumn": 25,
                                                        "message": {"text": "const char *"}}]}],
                        "fixes": [{"artifactChanges": [{"artifactLocation": {"uri": "<source>"},
                                                        "replacements": [{"deletedRegion": {"startLine": 5,
                                                                                            "startColumn": 17,
                                                                                            "endColumn": 19},
                                                                          "insertedContent": {"text": "%s"}}]}]}]}]}]}



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants