https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110522
Bug ID: 110522 Summary: `-fdiagnostics-format=sarif-file`: file name conflicts / races Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: driver Assignee: unassigned at gcc dot gnu.org Reporter: lebedev.ri at gmail dot com Target Milestone: --- The sarif-file is stored into PWD of the compiler invocation. Worse yet, it uses only a basename of the target object file, but with a `.c.sarif` suffix. What happens when the same object file is created multiple times, in different directories? The results will be overwritten. And in some cases, you may even lose the whole log of the failed compilation, (especially because the moment you specify `-fdiagnostics-format=sarif-file`, there's *NOTHING* in stderr, and you can't even specify `-fdiagnostics-format=` twice) if it will later be overwritten by the successful compilation of some different TU that happened to produce object file with the same base name. I'm not sure how this was not pointed out during the initial implementation, this seems problematic. ``` $ cat Makefile bad: gcc-13 -fdiagnostics-format=sarif-file -c common/a.c -o common/file.o good: gcc-13 -fdiagnostics-format=sarif-file -c b.c -o file.o all: good bad clean: rm common/file.o file.o $ cat common/a.c bad $ cat b.c // good $ VERBOSE=1 make bad good gcc-13 -fdiagnostics-format=sarif-file -c common/a.c -o common/file.o make: *** [Makefile:2: bad] Error 1 $ ls Makefile b.c common file.c.sarif file.o $ cat file.c.sarif {"$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 (Debian 13.1.0-7) version 13.1.0 (x86_64-linux-gnu)", "version": "13.1.0", "informationUri": "https://gcc.gnu.org/gcc-13/", "rules": []}}, "invocations": [{"executionSuccessful": true, "toolExecutionNotifications": []}], "originalUriBaseIds": {"PWD": {"uri": "file:///tmp/test/"}}, "artifacts": [{"location": {"uri": "common/a.c", "uriBaseId": "PWD"}, "contents": {"text": "bad\n"}, "sourceLanguage": "c"}], "results": [{"ruleId": "error", "level": "error", "message": {"text": "expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ at end of input"}, "locations": [{"physicalLocation": {"artifactLocation": {"uri": "common/a.c", "uriBaseId": "PWD"}, "region": {"startLine": 1, "startColumn": 1, "endColumn": 4}, "contextRegion": {"startLine": 1, "snippet": {"text": "bad\n"}}}}]}]}]} $ VERBOSE=1 make -k bad good gcc-13 -fdiagnostics-format=sarif-file -c common/a.c -o common/file.o make: *** [Makefile:2: bad] Error 1 gcc-13 -fdiagnostics-format=sarif-file -c b.c -o file.o $ cat file.c.sarif {"$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 (Debian 13.1.0-7) version 13.1.0 (x86_64-linux-gnu)", "version": "13.1.0", "informationUri": "https://gcc.gnu.org/gcc-13/", "rules": []}}, "invocations": [{"executionSuccessful": true, "toolExecutionNotifications": []}], "artifacts": [], "results": []}]} ```