1. Source Edit Generation¶
Source edit generation relies on a WPASuite result produced by an
earlier whole-program analysis. It runs alongside the normal compile
and emits two per-translation-unit artifacts:
a source-edit file (
--ssaf-src-edit-file=) containingclang::tooling::Replacementrecords ready forclang-apply-replacements,a transformation-report file (
--ssaf-transformation-report-file=) containing diagnostic-style findings.
1.1. Driver options¶
Four options control the pipeline; they are all both --ssaf-… driver
options and cc1 options. The compilation-unit identifier is shared
with the summary extraction step. A given compilation unit needs to
receive the same identifier for both summary extraction and source
edit generation.
Option |
Purpose |
|---|---|
|
Name of the transformation to run. |
|
WPASuite input. The extension selects the serialization format. |
|
Source-edit output. Always written as a
|
|
Transformation-report output. Always written as a SARIF JSON document; the file extension is not interpreted. |
|
Stable identifier for this translation unit (also required by the summary extraction). |
When --ssaf-source-transformation= is non-empty the framework wraps
the active FrontendAction in a SourceTransformationFrontendAction;
otherwise the compile is byte-for-byte unchanged.
1.2. Examples¶
Apply the source edits with clang-apply-replacements:
$ clang -c foo.cpp \
--ssaf-source-transformation=my-transformation \
--ssaf-global-scope-analysis-result=wpa.json \
--ssaf-src-edit-file=foo.yaml \
--ssaf-transformation-report-file=foo.sarif \
--ssaf-compilation-unit-id=cu-foo
$ clang-apply-replacements --remove-change-desc-files <dir-with-yaml>
The transformation report can be consumed by any SARIF viewer.