https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116613

--- Comment #15 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
(In reply to Kamil Dudka from comment #14)
> I think that the above described interface looks reasonable.  A few
> questions:

Thanks for the feedback.

> 1. Will `file=` work with absolute paths?

Yes.  There might be some issues with expressing paths/filenames containing
whitespace, '=', or ',' due to the way the option-parsing works, but hopefully
that's acceptable.

> 2. If a file with the specified name exists, will it be overwritten?

Short answer: yes

Longer answer: My plan is to do:
  fopen (path, "w") 
on any specified outputs as cc1 starts up, and to fail with a hard error if any
of the fopen fail, telling you why.  Hence it could fail if a file with the
specified name exists, but e.g. you don't have write permissions on it.

Perhaps we need a specific exit code for the case of "can't open diagnostic
output stream"?

> 3. Will the file always be created, even if no diagnostics is produced by
> gcc?

Yes, with the caveat that if cc1 can't fopen a diagnostic output file it will
fail immediately (as above), and obviously the file won't be created in such a
case.

> 4. Will the SARIF data contain absolute paths to source code files?  If not
> will the working directory be recorded in each SARIF file?

GCC's current behavior is (as of GCC 13):

* for absolute paths, the GCC SARIF output for the "artifact" will have an
absolute value in its "uri".

  "artifacts": [{"location": {"uri": "/tmp/test.c"},

* for relative paths, the GCC SARIF output for the "artifact" will have a
relative uri, and a "uriBaseId" of "PWD":

  "artifacts": [{"location": {"uri":
"../../src/gcc/testsuite/gcc.dg/analyzer/malloc-1.c",
                              "uriBaseId": "PWD"},

and the "run" will have this giving the absolute path for "PWD":
   "originalUriBaseIds": {"PWD": {"uri":
"file:///home/david/coding-3/gcc-newgit-path-revamp/build/gcc/"}},

As of GCC 15 the "run"'s "invocation" also has the "workingDirectory" property:

  "workingDirectory": {"uri":
"/home/david/coding-3/gcc-newgit-path-revamp/build/gcc"},

Re my idea of:

>  -fdiagnostics-add-output=sarif:file={output-filename}.sarif
> 
> where e.g. {output-filename} would be substituted with the output filename 
> from the gcc invocation.

note that I don't have that working yet, or a precise set of "substitution"
names and their semantics (I plan to work on it today).  What "substitutions"
might you need for your use-cases?

Does the above support all your use-cases?

Reply via email to