llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-static-analyzer-1 Author: Jan Korous (jkorous-apple) <details> <summary>Changes</summary> For details please see individual commits. I feel the 4 commits might be easier to understand and review together (perhaps one by one). Alternatively, I can split this into 4 PRs - just let me know. --- Patch is 87.11 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/203660.diff 45 Files Affected: - (added) clang/docs/ScalableStaticAnalysisFramework/user-docs/SourceEditGeneration.rst (+77) - (modified) clang/include/clang/Basic/DiagnosticFrontendKinds.td (+46) - (modified) clang/include/clang/Basic/DiagnosticIDs.h (+1-1) - (modified) clang/include/clang/Frontend/FrontendOptions.h (+18) - (modified) clang/include/clang/Options/Options.td (+38) - (modified) clang/include/clang/ScalableStaticAnalysisFramework/BuiltinAnchorSources.def (+1) - (added) clang/include/clang/ScalableStaticAnalysisFramework/Frontend/SourceTransformationFrontendAction.h (+34) - (added) clang/include/clang/ScalableStaticAnalysisFramework/SourceTransformation/SARIFTransformationReportFormat.h (+50) - (added) clang/include/clang/ScalableStaticAnalysisFramework/SourceTransformation/SourceEditEmitter.h (+29) - (added) clang/include/clang/ScalableStaticAnalysisFramework/SourceTransformation/Transformation.h (+38) - (added) clang/include/clang/ScalableStaticAnalysisFramework/SourceTransformation/TransformationRegistry.h (+66) - (added) clang/include/clang/ScalableStaticAnalysisFramework/SourceTransformation/TransformationReportEmitter.h (+35) - (added) clang/include/clang/ScalableStaticAnalysisFramework/SourceTransformation/YAMLSourceEditFormat.h (+32) - (modified) clang/lib/Driver/CMakeLists.txt (+1) - (modified) clang/lib/Driver/ToolChains/Clang.cpp (+4) - (modified) clang/lib/FrontendTool/CMakeLists.txt (+1) - (modified) clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp (+7) - (modified) clang/lib/ScalableStaticAnalysisFramework/CMakeLists.txt (+1) - (modified) clang/lib/ScalableStaticAnalysisFramework/Frontend/CMakeLists.txt (+3) - (added) clang/lib/ScalableStaticAnalysisFramework/Frontend/SourceTransformationFrontendAction.cpp (+233) - (added) clang/lib/ScalableStaticAnalysisFramework/SourceTransformation/CMakeLists.txt (+15) - (added) clang/lib/ScalableStaticAnalysisFramework/SourceTransformation/SARIFTransformationReportFormat.cpp (+57) - (added) clang/lib/ScalableStaticAnalysisFramework/SourceTransformation/TransformationRegistry.cpp (+44) - (added) clang/lib/ScalableStaticAnalysisFramework/SourceTransformation/YAMLSourceEditFormat.cpp (+33) - (modified) clang/test/Analysis/Scalable/help.cpp (+8) - (added) clang/test/Analysis/Scalable/source-edit-generation/Inputs/empty-suite.json (+4) - (added) clang/test/Analysis/Scalable/source-edit-generation/Inputs/two-function-suite.json (+25) - (added) clang/test/Analysis/Scalable/source-edit-generation/Plugins/CMakeLists.txt (+3) - (added) clang/test/Analysis/Scalable/source-edit-generation/Plugins/TestTransformationPlugin/CMakeLists.txt (+16) - (added) clang/test/Analysis/Scalable/source-edit-generation/Plugins/TestTransformationPlugin/TestTransformation.cpp (+101) - (added) clang/test/Analysis/Scalable/source-edit-generation/Plugins/lit.local.cfg (+2) - (added) clang/test/Analysis/Scalable/source-edit-generation/cli-errors.cpp (+51) - (added) clang/test/Analysis/Scalable/source-edit-generation/coexistence.cpp (+33) - (added) clang/test/Analysis/Scalable/source-edit-generation/downgradable-errors.cpp (+35) - (added) clang/test/Analysis/Scalable/source-edit-generation/happy-path.cpp (+37) - (added) clang/test/Analysis/Scalable/source-edit-generation/write-failure.cpp (+41) - (modified) clang/test/CMakeLists.txt (+2) - (modified) clang/tools/clang-ssaf-analyzer/CMakeLists.txt (+1) - (modified) clang/tools/clang-ssaf-format/CMakeLists.txt (+1) - (modified) clang/tools/clang-ssaf-linker/CMakeLists.txt (+1) - (modified) clang/unittests/ScalableStaticAnalysisFramework/CMakeLists.txt (+6) - (added) clang/unittests/ScalableStaticAnalysisFramework/SourceTransformation/EmitterTest.cpp (+81) - (added) clang/unittests/ScalableStaticAnalysisFramework/SourceTransformation/RegistryTest.cpp (+78) - (added) clang/unittests/ScalableStaticAnalysisFramework/SourceTransformation/SARIFFormatTest.cpp (+185) - (added) clang/unittests/ScalableStaticAnalysisFramework/SourceTransformation/YAMLFormatTest.cpp (+97) ``````````diff diff --git a/clang/docs/ScalableStaticAnalysisFramework/user-docs/SourceEditGeneration.rst b/clang/docs/ScalableStaticAnalysisFramework/user-docs/SourceEditGeneration.rst new file mode 100644 index 0000000000000..c7027f8c9fc2c --- /dev/null +++ b/clang/docs/ScalableStaticAnalysisFramework/user-docs/SourceEditGeneration.rst @@ -0,0 +1,77 @@ +============================== +Source Edit Generation +============================== + +Source edit generation is the second stage of the SSAF pipeline. Given a +``WPASuite`` produced by an earlier whole-program analysis, a *source +transformation* runs alongside the normal compile and emits two +per-translation-unit artifacts: + +- a *source-edit file* (``--ssaf-src-edit-file=``) containing + ``clang::tooling::Replacement`` records ready for + ``clang-apply-replacements``, +- a *transformation-report file* (``--ssaf-transformation-report-file=``) + containing diagnostic-style findings. + +Driver flags +============ + +Four flags control the pipeline; they are all both ``--ssaf-…`` driver +flags and ``cc1`` flags. The compilation-unit identifier flag is shared +with the stage-1 pipeline. + +.. list-table:: + :header-rows: 1 + + * - Flag + - Purpose + * - ``--ssaf-source-transformation=<name>`` + - Name of the transformation to run. + * - ``--ssaf-global-scope-analysis-result=<path>.<format>`` + - WPASuite input. The extension selects the serialization format. + * - ``--ssaf-src-edit-file=<path>`` + - Source-edit output. Always written as a + ``clang-apply-replacements``-compatible YAML document; the + file extension is not interpreted. + * - ``--ssaf-transformation-report-file=<path>`` + - Transformation-report output. Always written as a SARIF 2.1.0 + JSON document; the file extension is not interpreted. + * - ``--ssaf-compilation-unit-id=<id>`` + - Stable identifier for this translation unit (also required by + the stage-1 pipeline). + +When ``--ssaf-source-transformation=`` is non-empty the framework wraps +the active ``FrontendAction`` in a ``SourceTransformationFrontendAction``; +otherwise the compile is byte-for-byte unchanged. + +Error policy +============ + +Every CLI-misuse and runtime-write diagnostic is registered as a +``Warning ... DefaultError`` under +``-Wscalable-static-analysis-framework``. This means errors stop the +compile by default but can be downgraded or silenced: + +- ``-Wno-error=scalable-static-analysis-framework`` — diagnostics + become warnings and the compile finishes normally. The edit/report + files may be absent (if the runner bailed out before writing) or + present (if a write call returned an error). +- ``-Wno-scalable-static-analysis-framework`` — diagnostics are + silenced entirely. The compile finishes normally. + +Examples +======== + +Apply the source edits with ``clang-apply-replacements``: + +.. code-block:: console + + $ 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 2.1.0 viewer. diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index 322ce2c3a75fd..a083a817a32a5 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -434,6 +434,52 @@ def warn_ssaf_tu_summary_requires_compilation_unit_id : "'--ssaf-compilation-unit-id=' to be set">, InGroup<ScalableStaticAnalysisFramework>, DefaultError; +def warn_ssaf_source_transformation_unknown_name : + Warning<"no source transformation registered with name: %0">, + InGroup<ScalableStaticAnalysisFramework>, DefaultError; + +def warn_ssaf_source_transformation_requires_wpa_file : + Warning<"option '--ssaf-source-transformation=' requires " + "'--ssaf-global-scope-analysis-result=' to be set">, + InGroup<ScalableStaticAnalysisFramework>, DefaultError; + +def warn_ssaf_source_transformation_requires_edit_file : + Warning<"option '--ssaf-source-transformation=' requires " + "'--ssaf-src-edit-file=' to be set">, + InGroup<ScalableStaticAnalysisFramework>, DefaultError; + +def warn_ssaf_source_transformation_requires_report_file : + Warning<"option '--ssaf-source-transformation=' requires " + "'--ssaf-transformation-report-file=' to be set">, + InGroup<ScalableStaticAnalysisFramework>, DefaultError; + +def warn_ssaf_source_transformation_requires_compilation_unit_id : + Warning<"option '--ssaf-source-transformation=' requires " + "'--ssaf-compilation-unit-id=' to be set">, + InGroup<ScalableStaticAnalysisFramework>, DefaultError; + +def warn_ssaf_read_wpa_suite_failed : + Warning<"failed to read whole-program analysis result from '%0': %1">, + InGroup<ScalableStaticAnalysisFramework>, DefaultError; + +def warn_ssaf_src_edit_file_requires_transformation : + Warning<"option '--ssaf-src-edit-file=' requires " + "'--ssaf-source-transformation=' to be set">, + InGroup<ScalableStaticAnalysisFramework>, DefaultError; + +def warn_ssaf_write_src_edit_failed : + Warning<"failed to write source edits to '%0': %1">, + InGroup<ScalableStaticAnalysisFramework>, DefaultError; + +def warn_ssaf_transformation_report_file_requires_transformation : + Warning<"option '--ssaf-transformation-report-file=' requires " + "'--ssaf-source-transformation=' to be set">, + InGroup<ScalableStaticAnalysisFramework>, DefaultError; + +def warn_ssaf_write_transformation_report_failed : + Warning<"failed to write transformation report to '%0': %1">, + InGroup<ScalableStaticAnalysisFramework>, DefaultError; + def err_extract_api_ignores_file_not_found : Error<"file '%0' specified by '--extract-api-ignores=' not found">, DefaultFatal; diff --git a/clang/include/clang/Basic/DiagnosticIDs.h b/clang/include/clang/Basic/DiagnosticIDs.h index 63b5e6a28aac0..2d7e32579b608 100644 --- a/clang/include/clang/Basic/DiagnosticIDs.h +++ b/clang/include/clang/Basic/DiagnosticIDs.h @@ -36,7 +36,7 @@ enum class Group; enum { DIAG_SIZE_COMMON = 300, DIAG_SIZE_DRIVER = 400, - DIAG_SIZE_FRONTEND = 200, + DIAG_SIZE_FRONTEND = 250, DIAG_SIZE_SERIALIZATION = 120, DIAG_SIZE_LEX = 500, DIAG_SIZE_PARSE = 800, diff --git a/clang/include/clang/Frontend/FrontendOptions.h b/clang/include/clang/Frontend/FrontendOptions.h index 7c242f6e94fe0..824e563a4c08a 100644 --- a/clang/include/clang/Frontend/FrontendOptions.h +++ b/clang/include/clang/Frontend/FrontendOptions.h @@ -556,6 +556,24 @@ class FrontendOptions { /// across stages of the SSAF pipeline. std::string SSAFCompilationUnitId; + /// Name of the SSAF source transformation to run. Exactly one transformation + /// per invocation; non-empty implies the source-transformation pipeline is + /// active. + std::string SSAFSourceTransformation; + + /// Path of the WPASuite input consumed by the source transformation. The + /// extension selects which serialization format reads it. + std::string SSAFGlobalScopeAnalysisResult; + + /// Path of the source-edit output file produced by the source + /// transformation. The extension selects which `SourceEditFormat` writes it. + std::string SSAFSrcEditFile; + + /// Path of the transformation-report output file produced by the source + /// transformation. The extension selects which `TransformationReportFormat` + /// writes it. + std::string SSAFTransformationReportFile; + /// Show available SSAF summary extractors. LLVM_PREFERRED_TYPE(bool) unsigned SSAFShowExtractors : 1; diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td index b4447fcc04120..e35ce85898038 100644 --- a/clang/include/clang/Options/Options.td +++ b/clang/include/clang/Options/Options.td @@ -979,6 +979,44 @@ def _ssaf_compilation_unit_id : "produced SSAF TU summary. Required when '--ssaf-tu-summary-file=' is " "set.">, MarshallingInfoString<FrontendOpts<"SSAFCompilationUnitId">>; +def _ssaf_source_transformation : + Joined<["--"], "ssaf-source-transformation=">, + MetaVarName<"<name>">, + Group<SSAF_Group>, + Visibility<[ClangOption, CC1Option]>, + HelpText< + "Name of the SSAF source transformation to run. Exactly one transformation " + "per invocation.">, + MarshallingInfoString<FrontendOpts<"SSAFSourceTransformation">>; +def _ssaf_global_scope_analysis_result : + Joined<["--"], "ssaf-global-scope-analysis-result=">, + MetaVarName<"<path>.<format>">, + Group<SSAF_Group>, + Visibility<[ClangOption, CC1Option]>, + HelpText< + "Path to the WPASuite file containing the whole-program analysis result " + "consumed by the source transformation. The extension selects which file " + "format to use.">, + MarshallingInfoString<FrontendOpts<"SSAFGlobalScopeAnalysisResult">>; +def _ssaf_src_edit_file : + Joined<["--"], "ssaf-src-edit-file=">, + MetaVarName<"<path>">, + Group<SSAF_Group>, + Visibility<[ClangOption, CC1Option]>, + HelpText< + "Output file for the source edits produced by the source transformation. " + "The output is a YAML document compatible with " + "'clang-apply-replacements'.">, + MarshallingInfoString<FrontendOpts<"SSAFSrcEditFile">>; +def _ssaf_transformation_report_file : + Joined<["--"], "ssaf-transformation-report-file=">, + MetaVarName<"<path>">, + Group<SSAF_Group>, + Visibility<[ClangOption, CC1Option]>, + HelpText< + "Output file for the transformation report produced by the source " + "transformation. The output is a SARIF 2.1.0 JSON document.">, + MarshallingInfoString<FrontendOpts<"SSAFTransformationReportFile">>; def Xarch__ : JoinedAndSeparate<["-"], "Xarch_">, Flags<[NoXarchOption]>, diff --git a/clang/include/clang/ScalableStaticAnalysisFramework/BuiltinAnchorSources.def b/clang/include/clang/ScalableStaticAnalysisFramework/BuiltinAnchorSources.def index 7dd866047f556..ba4944ea984cb 100644 --- a/clang/include/clang/ScalableStaticAnalysisFramework/BuiltinAnchorSources.def +++ b/clang/include/clang/ScalableStaticAnalysisFramework/BuiltinAnchorSources.def @@ -23,6 +23,7 @@ ANCHOR(JSONFormatAnchorSource) ANCHOR(PointerFlowAnalysisAnchorSource) ANCHOR(PointerFlowExtractorAnchorSource) ANCHOR(PointerFlowJSONFormatAnchorSource) +ANCHOR(SSAFSourceTransformationAnchorSource) ANCHOR(UnsafeBufferUsageAnalysisAnchorSource) ANCHOR(UnsafeBufferUsageExtractorAnchorSource) ANCHOR(UnsafeBufferUsageJSONFormatAnchorSource) diff --git a/clang/include/clang/ScalableStaticAnalysisFramework/Frontend/SourceTransformationFrontendAction.h b/clang/include/clang/ScalableStaticAnalysisFramework/Frontend/SourceTransformationFrontendAction.h new file mode 100644 index 0000000000000..bfde3646a7dcf --- /dev/null +++ b/clang/include/clang/ScalableStaticAnalysisFramework/Frontend/SourceTransformationFrontendAction.h @@ -0,0 +1,34 @@ +//===- SourceTransformationFrontendAction.h ---------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_FRONTEND_SOURCETRANSFORMATIONFRONTENDACTION_H +#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_FRONTEND_SOURCETRANSFORMATIONFRONTENDACTION_H + +#include "clang/Frontend/FrontendAction.h" +#include <memory> + +namespace clang::ssaf { + +/// Wraps the existing \c FrontendAction and runs the source-transformation +/// pipeline alongside it. The transformation consumes a \c WPASuite read +/// from \c FrontendOptions::SSAFGlobalScopeAnalysisResult and emits source +/// edits and a transformation report to the configured output files. +class SourceTransformationFrontendAction final : public WrapperFrontendAction { +public: + explicit SourceTransformationFrontendAction( + std::unique_ptr<FrontendAction> WrappedAction); + ~SourceTransformationFrontendAction(); + +protected: + std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; +}; + +} // namespace clang::ssaf + +#endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_FRONTEND_SOURCETRANSFORMATIONFRONTENDACTION_H diff --git a/clang/include/clang/ScalableStaticAnalysisFramework/SourceTransformation/SARIFTransformationReportFormat.h b/clang/include/clang/ScalableStaticAnalysisFramework/SourceTransformation/SARIFTransformationReportFormat.h new file mode 100644 index 0000000000000..cd49bd9fd267f --- /dev/null +++ b/clang/include/clang/ScalableStaticAnalysisFramework/SourceTransformation/SARIFTransformationReportFormat.h @@ -0,0 +1,50 @@ +//===- SARIFTransformationReportFormat.h ------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Built-in SARIF 2.1.0 transformation-report writer. Drives clang's existing +// `SarifDocumentWriter`; emits no `fix` keys (source edits live in the +// separate edit file). +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SOURCETRANSFORMATION_SARIFTRANSFORMATIONREPORTFORMAT_H +#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SOURCETRANSFORMATION_SARIFTRANSFORMATIONREPORTFORMAT_H + +#include "clang/Basic/Sarif.h" +#include "clang/Basic/SourceLocation.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/Error.h" +#include <string> +#include <vector> + +namespace clang { +class SourceManager; +} // namespace clang + +namespace clang::ssaf { + +struct ReportResult { + std::string RuleId; + clang::SarifResultLevel Level; + clang::CharSourceRange Range; + std::string Message; +}; + +struct ReportDocument { + std::string TransformationName; + const clang::SourceManager &SM; + std::vector<ReportResult> Results; +}; + +/// Writes \p Doc to \p Path as a SARIF 2.1.0 JSON document. +llvm::Error writeSARIFTransformationReport(const ReportDocument &Doc, + llvm::StringRef Path); + +} // namespace clang::ssaf + +#endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SOURCETRANSFORMATION_SARIFTRANSFORMATIONREPORTFORMAT_H diff --git a/clang/include/clang/ScalableStaticAnalysisFramework/SourceTransformation/SourceEditEmitter.h b/clang/include/clang/ScalableStaticAnalysisFramework/SourceTransformation/SourceEditEmitter.h new file mode 100644 index 0000000000000..e96c9846a35f2 --- /dev/null +++ b/clang/include/clang/ScalableStaticAnalysisFramework/SourceTransformation/SourceEditEmitter.h @@ -0,0 +1,29 @@ +//===- SourceEditEmitter.h --------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Abstract accumulator for source edits. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SOURCETRANSFORMATION_SOURCEEDITEMITTER_H +#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SOURCETRANSFORMATION_SOURCEEDITEMITTER_H + +#include "clang/Tooling/Core/Replacement.h" + +namespace clang::ssaf { + +class SourceEditEmitter { +public: + virtual ~SourceEditEmitter() = default; + + virtual void addReplacement(clang::tooling::Replacement R) = 0; +}; + +} // namespace clang::ssaf + +#endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SOURCETRANSFORMATION_SOURCEEDITEMITTER_H diff --git a/clang/include/clang/ScalableStaticAnalysisFramework/SourceTransformation/Transformation.h b/clang/include/clang/ScalableStaticAnalysisFramework/SourceTransformation/Transformation.h new file mode 100644 index 0000000000000..5553b7796b1ad --- /dev/null +++ b/clang/include/clang/ScalableStaticAnalysisFramework/SourceTransformation/Transformation.h @@ -0,0 +1,38 @@ +//===- Transformation.h -----------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Abstract base class for source transformations. A Transformation is an +// ASTConsumer that consumes a previously computed WPASuite. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SOURCETRANSFORMATION_TRANSFORMATION_H +#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SOURCETRANSFORMATION_TRANSFORMATION_H + +#include "clang/AST/ASTConsumer.h" +#include "clang/ScalableStaticAnalysisFramework/Core/WholeProgramAnalysis/WPASuite.h" +#include "clang/ScalableStaticAnalysisFramework/SourceTransformation/SourceEditEmitter.h" +#include "clang/ScalableStaticAnalysisFramework/SourceTransformation/TransformationReportEmitter.h" + +namespace clang::ssaf { + +class Transformation : public clang::ASTConsumer { +public: + Transformation(const WPASuite &Suite, SourceEditEmitter &Edits, + TransformationReportEmitter &Report) + : Suite(Suite), Edits(Edits), Report(Report) {} + +protected: + const WPASuite &Suite; + SourceEditEmitter &Edits; + TransformationReportEmitter &Report; +}; + +} // namespace clang::ssaf + +#endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SOURCETRANSFORMATION_TRANSFORMATION_H diff --git a/clang/include/clang/ScalableStaticAnalysisFramework/SourceTransformation/TransformationRegistry.h b/clang/include/clang/ScalableStaticAnalysisFramework/SourceTransformation/TransformationRegistry.h new file mode 100644 index 0000000000000..231a810f60f26 --- /dev/null +++ b/clang/include/clang/ScalableStaticAnalysisFramework/SourceTransformation/TransformationRegistry.h @@ -0,0 +1,66 @@ +//===- TransformationRegistry.h ---------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Registry for Transformations, and some helper functions. +// To register a transformation, insert this code: +// +// namespace clang::ssaf { +// // NOLINTNEXTLINE(misc-use-internal-linkage) +// volatile int MyTransformationAnchorSource = 0; +// } // namespace clang::ssaf +// static TransformationRegistry::Add<MyTransformation> +// X("MyTransformation", "My awesome transformation"); +// +// For a statically-linked transformation also extend the `AnchorSources` +// list in +// clang/include/clang/ScalableStaticAnalysisFramework/SSAFBuiltinForceLinker.h +// (plugin-loaded transformations do not need an anchor — the dynamic loader +// runs every global ctor on load). +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SOURCETRANSFORMATION_TRANSFORMATIONREGISTRY_H +#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SOURCETRANSFORMATION_TRANSFORMATIONREGISTRY_H + +#include "clang/ScalableStaticAnalysisFramework/Core/WholeProgramAnalysis/WPASuite.h" +#include "clang/ScalableStaticAnalysisFramework/SourceTransformation/SourceEditEmitter.h" +#include "clang/ScalableStaticAnalysisFramework/SourceTransformation/Transformation.h" +#include "clang/ScalableStaticAnalysisFramework/SourceTransformation/TransformationReportEmitter.h" +#include "clang/Support/Compiler.h" +#include "llvm/ADT/StringRef.h" +#include "llvm... [truncated] `````````` </details> https://github.com/llvm/llvm-project/pull/203660 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
