[Bug middle-end/114348] Corrupt SARIF output on stderr

2024-03-20 Thread specht.tobias at gmx dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114348

--- Comment #6 from Tobias Specht  ---
Thanks for fixing this!
Waiting for the gcc 13 backport.

Having formatted json output sounds like a nice feature for me too.

[Bug middle-end/114348] Corrupt SARIF output on stderr

2024-03-15 Thread specht.tobias at gmx dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114348

--- Comment #2 from Tobias Specht  ---
>From my understanding, the idea of the `-fdiagnostics-format=sarif-stderr`
option is, that the SARIF file will be printed to stderr and only the SARIF
file, so that one can take the stderr output and parse it as json for further
processing.
Due to the additional plain text output, the output on stderr is corrupted and
cannot be parsed as json.
A workaround could be, to only parse the first line as json, but this also
seems racy.

[Bug analyzer/114348] New: Corrupt SARIF output on stderr

2024-03-15 Thread specht.tobias at gmx dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114348

Bug ID: 114348
   Summary: Corrupt SARIF output on stderr
   Product: gcc
   Version: 13.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: analyzer
  Assignee: dmalcolm at gcc dot gnu.org
  Reporter: specht.tobias at gmx dot de
  Target Milestone: ---

I noticed a situation, where the SARIF output on stderr of the `-fanalyzer` is
corrupted by a compiler error message, also written to stderr:

```
$ cat test.c
#include "test.h"
$ gcc -fanalyzer -fdiagnostics-format=sarif-stderr -c test.c
{"$schema":
"https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json;,
"version": "2.1.0", "runs": [{"tool": {"driver": {"name": "GNU C17",
"fullName": "GNU C17 (GCC) version 13.2.1 20231205 (Red Hat 13.2.1-6)
(x86_64-redhat-linux)", "version": "13.2.1 20231205 (Red Hat 13.2.1-6)",
"informationUri": "https://gcc.gnu.org/gcc-13/;, "rules": []}}, "invocations":
[{"executionSuccessful": true, "toolExecutionNotifications": []}],
"originalUriBaseIds": {"PWD": {"uri": "file:///tmp"}}, "artifacts":
[{"location": {"uri": "test.c", "uriBaseId": "PWD"}, "contents": {"text":
"#include \"test.h\"\n"}, "sourceLanguage": "c"}], "results": [{"ruleId":
"fatal error", "message": {"text": "test.h: No such file or directory"},
"locations": [{"physicalLocation": {"artifactLocation": {"uri": "test.c",
"uriBaseId": "PWD"}, "region": {"startLine": 1, "startColumn": 10, "endColumn":
18}, "contextRegion": {"startLine": 1, "snippet": {"text": "#include
\"test.h\"\n"]}]}]}
compilation terminated.
```

The message `compilation terminated.` is written to stderr.

This happens when a header file is not found (also noted in the SARIF file).
Other compiler errors (e.g. missing symbol, syntax error) do not show this
problem and only generate SARIF output on stderr.
Maybe this bug is related to the preprocessor?