SARIF support in GCC
The Static Analysis Results Interchange Format (SARIF) is "an industry standard format for the output of static analysis tools" i.e. a machine-readable file format that can represent compiler diagnostics. (see also old SARIF website here, as the sarif.info link seems to have changed)
GCC's statement of use in the SARIF specification's issue tracker can be seen here
GCC as a SARIF producer
GCC 13 onwards can output its diagnostics in SARIF format.
GCC 15 onwards can output its diagnostics in multiple formats at once (such as text *and* SARIF).
User-facing documentation:
-fdiagnostics-add-output=sarif (GCC 15 onwards)
-fdiagnostics-set-output=sarif (GCC 15 onwards)
Implementation: gcc/diagnostic-format-sarif.cc
History of GCC as a SARIF producer
GCC 17 (in development)
2026-10-28: Added analyzer-graphs=yes option to SARIF output for capturing detailed information about -fanalyzer's internal state to a SARIF sink
2026-10-23: Updated version=2.2-prerelease from a snapshot from 2024 to CSD01
GCC 16
2026-02-02: Fixed a bug in choosing the output path for .sarif files, so that it now respects the "dumpdir" option, and is thus affected by the path of the .o file.
2026-01-09: Add "cfgs=yes" option for diagnostics output that adds a machine-readable serialization of (some of GCC's) intermediate representation to the SARIF output, for each function after each optimization pass.
2025-11-11: Add EXPERIMENTAL_SARIF_SOCKET for JSON-RPC notifications for IDEs
2025-11-03: Added new kinds of event for exception-handling and longjmp
2025-09-23: Added descriptions to fix-it hints in GCC's SARIF output (§3.55.2)
2025-07-11: Added support for graphs to GCC's SARIF output, using this for analyzer state information
2025-06-23: Added support for SARIF output to sarif-replay, dg-lint, and potentially other libgdiagnostics users
2025-06-23: Added state information to SARIF property bags
2025-05-05: SARIF output now captures nesting of logical locations (PR116176)
2025-04-30: Added "serialization" param to -fdiagnostics-add-output='s "sarif" scheme (must be "json" for now).
GCC 15
2024-11-29: "libdiagnostics" renamed to "libgdiagnostics"
2024-11-18: libdiagnostics implementation pushed to trunk
2024-11-13: Posted v4 patch kit of libdiagnostics, a new shared library which has an API for client code to write out .sarif files.
2024-10-29: Added support for emitting diagnostics to multiple output sinks simultaneously, such as multiple SARIF files, potentially of different formats.
2024-10-23: Added buffering support to diagnostic subsystem, fixing bug in SARIF output from Fortran frontend
2024-10-16: SARIF output now captures backtraces in the "internal compiler error" handler
2024-10-04: Moved opening of .sarif output file to the start of the compile, rather than the end
2024-10-02: Added initial support for SARIF 2.2 output (draft spec as of 2024-08-08)
2024-09-09: Fixed SARIF schema URL (§3.13.3)
2024-08-29: Added embedded URLs in SARIF text messages (§3.11.6)
2024-08-15: Posted v3 patch kit of libdiagnostics, a new shared library which has an API for client code to write out .sarif files.
2024-08-06: Fix invocation property "executionSuccessful" (§3.20.14)
2024-08-01: Capture secondary locations without labels as relatedLocations (§3.27.22)
2024-07-26: Added #include information (§3.34) to locations
- 2024-07-24:
Added escaped renderings of source for diagnostics relating to encodings (§3.3.4)
Added "arguments" (§3.20.2), "startTimeUtc" (§3.20.7), "endTimeUtc" (§3.20.8), and "workingDirectory" (§3.20.19) properties to invocation objects.
Use the location "annotations" property (§3.28.6) to encode labelled source ranges from diagnostics into the SARIF output.
Tweak the SARIF output for diagnostics involving UNKNOWN_LOCATION
- Internal cleanups to implementation of SARIF output:
Use sarif_object subclasses throughout to help enforce schema compliance
Use std::unique_ptr throughout to avoid manual memory management
2024-06-25: Use check-jsonschema rather than the deprecated jsonschema when validating .sarif files in DejaGnu
- 2024-06-21:
2024-06-03: Added the property "artifact.roles" to GCC's SARIF output (SARIF v2.1 §3.24.6)
GCC 14
2023-12-06: Formatting of JSON/SARIF output
2023-12-01: Added per-diagnostic property bags to SARIF for debugging analyzer
2023-09-22: Talk at GNU Tools Cauldron 2023: Updates to Diagnostics in GCC 14
2023-09-14: Added support for multithreaded diagnostics in GCC (although nothing yet takes advantage of this)
2023-07-31: Added timing/profile information to SARIF output
GCC 13
2023-05-31: Blog post: Improvements to static analysis in the GCC 13 compiler
2023-03-15: Added SARIF support for internal compiler errors to capture crashes as SARIF notifications
2022-06-02: Implemented SARIF output for GCC diagnostics (including analyzer warnings)
GCC as a SARIF consumer
As of GCC 15, GCC optionally provides a sarif-replay tool that accepts SARIF as input. This uses libgdiagnostics to "replay" any diagnostics within the .sarif files as if they were GCC diagnostics.
History of GCC as a SARIF consumer
GCC 17 (under development)
2026-04-28: sarif-replay: round-trip event IDs in execution paths
GCC 16
2026-01-27: sarif-replay: improve output when source is unavailable
2025-07-11: Added support for graphs to sarif-replay
2025-06-23: Added support for HTML (and SARIF) output to sarif-replay
2025-05-05: sarif-replay now shows logical locations of errors within SARIF input using JSON pointer (PR117988)
GCC 15
- 2025-02-15: Improvements to sarif-replay:
2025-02-01: sarif-replay now handles "cached" logical locations §3.33.3
2024-12-16: Improvements to libgdiagnostics/sarif-replay handling of logical locations
2024-12-16: Initial handling of embedded URLS in sarif-replay
2024-12-16: sarif-replay can now use the "contents" attribute of an artifact when quoting source, rather than accessing the path in the filesystem, which should help when copying .sarif files around between machines.
2024-11-29: "libdiagnostics" renamed to "libgdiagnostics"
2024-11-18: libdiagnostics implementation pushed to trunk
2024-11-13: Posted v4 patch kit for libdiagnostics, which adds a sarif-replay command-line tool
2024-08-15: Posted v3 patch kit for libdiagnostics, which adds a sarif-replay command-line tool
2022-06-22: Posted experimental patches for replay of serialized diagnostics (including analyzer warnings)
Bugs relating to GCC SARIF support
There is a "SARIF" keyword in GCC's bug tracker for bugs relating to GCC's SARIF support.
By keyword:
By text:
Bugs relating to sarif-replay: