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?