Adding options for Clang to write diagnostics to file

Clang has had support for SARIF for a bit, but there are two problems:

  1. Piping stderr to a requires manual editing before feeding to a SARIF consumer.
  2. There isn’t support for batching builds (e.g. using a build system).

I propose adding two flags to resolve this problem:

  • -fdiagnostics-output=(stderr|file-overwrite|file-append), which tells Clang how the user expects diagnostics to be written
    • stderr is the default option, and will tell the compiler to write to standard error, as it does today
    • file-overwrite will write to a specified file, and overwrite the file if it exists
    • file-append will write to a specified file, and append the file if it exists
  • -fdiagnostics-output-path=, which tells Clang where to output diagnostics if the above option is not stderr. It’s intended to be an error to set -fdiagnostics-output-path in the event of -fdiagnostics-output=stderr.

It will then be up to build systems to provide support for using these flags with append mode. I suspect that handwritten Makefiles would need to have a clobber step for each invocation. Build system generators (CMake) and more intelligent build systems can probably do something a bit better.

I just want to point you at this diff: ⚙ D78903 [Driver] Add option -fproc-stat-report
This diff is a child dependency :⚙ D79066 [Support] Class to facilitate file locking

He faced the same challenge with concurrent appends to a file.

1 Like