[clang] [llvm] Reapply "[clang][ssaf] Add --ssaf-extract-summaries= and --ssaf-tu-summary-file= options" (PR #186463)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 13 10:30:53 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-ssaf
Author: Balázs Benics (steakhal)
<details>
<summary>Changes</summary>
This reverts commit 3548ec95178c00a2895a65b435945ce318396c8e and adapts the code to the new ScalableStaticAnalysisFramework/ directory layout.
Re-adds:
- TUSummaryExtractorFrontendAction and its integration into ExecuteCompilerInvocation
- --ssaf-extract-summaries= and --ssaf-tu-summary-file= CLI options
- SSAFForceLinker / SSAFBuiltinForceLinker headers and anchor symbols
- Diagnostics under -Wscalable-static-analysis-framework
- Lit tests for the CLI and unit tests for the frontend action
- Changes the Formats to be lowercase - and match their spellings in the file paths.
---
Patch is 59.48 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/186463.diff
36 Files Affected:
- (modified) clang/include/clang/Basic/DiagnosticFrontendKinds.td (+23)
- (modified) clang/include/clang/Basic/DiagnosticGroups.td (+3)
- (modified) clang/include/clang/Frontend/FrontendOptions.h (+7)
- (modified) clang/include/clang/Options/Options.td (+20)
- (modified) clang/include/clang/ScalableStaticAnalysisFramework/Core/Serialization/JSONFormat.h (-4)
- (modified) clang/include/clang/ScalableStaticAnalysisFramework/Core/Serialization/SerializationFormatRegistry.h (+12-2)
- (modified) clang/include/clang/ScalableStaticAnalysisFramework/Core/TUSummary/ExtractorRegistry.h (+9)
- (added) clang/include/clang/ScalableStaticAnalysisFramework/Frontend/TUSummaryExtractorFrontendAction.h (+33)
- (added) clang/include/clang/ScalableStaticAnalysisFramework/SSAFBuiltinForceLinker.h (+28)
- (added) clang/include/clang/ScalableStaticAnalysisFramework/SSAFForceLinker.h (+25)
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+3)
- (modified) clang/lib/FrontendTool/CMakeLists.txt (+2)
- (modified) clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp (+6)
- (modified) clang/lib/ScalableStaticAnalysisFramework/CMakeLists.txt (+1)
- (modified) clang/lib/ScalableStaticAnalysisFramework/Core/Serialization/JSONFormat/JSONFormatImpl.cpp (+3-4)
- (added) clang/lib/ScalableStaticAnalysisFramework/Frontend/CMakeLists.txt (+14)
- (added) clang/lib/ScalableStaticAnalysisFramework/Frontend/TUSummaryExtractorFrontendAction.cpp (+181)
- (added) clang/test/Analysis/SSAF/command-line-interface.cpp (+22)
- (added) clang/test/Analysis/SSAF/downgradable-errors.cpp (+15)
- (added) clang/test/Analysis/SSAF/help.cpp (+7)
- (modified) clang/test/Analysis/Scalable/ssaf-format/list.test (+1-1)
- (modified) clang/tools/ssaf-format/SSAFFormat.cpp (+3-7)
- (modified) clang/tools/ssaf-linker/SSAFLinker.cpp (+3-8)
- (modified) clang/unittests/ScalableStaticAnalysisFramework/CMakeLists.txt (+3)
- (added) clang/unittests/ScalableStaticAnalysisFramework/Frontend/TUSummaryExtractorFrontendActionTest.cpp (+366)
- (modified) clang/unittests/ScalableStaticAnalysisFramework/Registries/FancyAnalysisData.cpp (+2)
- (modified) clang/unittests/ScalableStaticAnalysisFramework/Registries/MockSerializationFormat.cpp (+2)
- (modified) clang/unittests/ScalableStaticAnalysisFramework/Registries/MockSummaryExtractor1.cpp (+4-2)
- (modified) clang/unittests/ScalableStaticAnalysisFramework/Registries/MockSummaryExtractor2.cpp (+4-2)
- (modified) clang/unittests/ScalableStaticAnalysisFramework/Registries/SummaryExtractorRegistryTest.cpp (+1)
- (added) clang/unittests/ScalableStaticAnalysisFramework/SSAFBuiltinTestForceLinker.h (+51)
- (added) clang/unittests/ScalableStaticAnalysisFramework/SSAFTestForceLinker.h (+23)
- (modified) clang/unittests/ScalableStaticAnalysisFramework/TestFixture.cpp (+1)
- (modified) llvm/utils/gn/secondary/clang/lib/FrontendTool/BUILD.gn (+2)
- (added) llvm/utils/gn/secondary/clang/lib/ScalableStaticAnalysisFramework/Frontend/BUILD.gn (+15)
- (modified) llvm/utils/gn/secondary/clang/unittests/ScalableStaticAnalysisFramework/BUILD.gn (+3)
``````````diff
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 5c62bb70ebd0f..00db1e7ee5afa 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -379,6 +379,29 @@ def warn_profile_data_misexpect : Warning<
BackendInfo, InGroup<MisExpect>;
} // end of instrumentation issue category
+def warn_ssaf_extract_tu_summary_file_unknown_output_format :
+ Warning<"unknown output summary file format '%0' "
+ "specified by '--ssaf-tu-summary-file=%1'">,
+ InGroup<ScalableStaticAnalysisFramework>, DefaultError;
+
+def warn_ssaf_extract_tu_summary_file_unknown_format :
+ Warning<"failed to parse the value of '--ssaf-tu-summary-file=%0' "
+ "the value must follow the '<path>.<format>' pattern">,
+ InGroup<ScalableStaticAnalysisFramework>, DefaultError;
+
+def warn_ssaf_must_enable_summary_extractors :
+ Warning<"must enable some summary extractors using the "
+ "'--ssaf-extract-summaries=' option">,
+ InGroup<ScalableStaticAnalysisFramework>, DefaultError;
+
+def warn_ssaf_extract_summary_unknown_extractor_name :
+ Warning<"no summary extractor%s0 %plural{1:was|:were}0 registered with name: %1">,
+ InGroup<ScalableStaticAnalysisFramework>, DefaultError;
+
+def warn_ssaf_write_tu_summary_failed :
+ Warning<"failed to write TU summary 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/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 5d39f12d5c00f..e440c9d2fb982 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1907,6 +1907,9 @@ def BitIntExtension : DiagGroup<"bit-int-extension">;
// Warnings about misuse of ExtractAPI options.
def ExtractAPIMisuse : DiagGroup<"extractapi-misuse">;
+// Warnings related to the "Scalable Static Analysis Framework" - SSAF.
+def ScalableStaticAnalysisFramework : DiagGroup<"scalable-static-analysis-framework">;
+
// Warnings about using the non-standard extension having an explicit specialization
// with a storage class specifier.
def ExplicitSpecializationStorageClass : DiagGroup<"explicit-specialization-storage-class">;
diff --git a/clang/include/clang/Frontend/FrontendOptions.h b/clang/include/clang/Frontend/FrontendOptions.h
index 9e05181ac916c..0d8eb6a1b7379 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -543,6 +543,13 @@ class FrontendOptions {
/// minimization hints.
std::string DumpMinimizationHintsPath;
+ /// List of SSAF extractors to enable.
+ std::vector<std::string> SSAFExtractSummaries;
+
+ /// The TU summary output file with the file extension representing the file
+ /// format.
+ std::string SSAFTUSummaryFile;
+
public:
FrontendOptions()
: DisableFree(false), RelocatablePCH(false), ShowHelp(false),
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 8e17cd5ae15b5..692df65abb367 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -274,6 +274,10 @@ def StaticAnalyzer_Group : OptionGroup<"<Static analyzer group>">,
DocName<"Static analyzer options">, DocBrief<[{
Flags controlling the behavior of the Clang Static Analyzer.}]>;
+def SSAF_Group : OptionGroup<"<ssaf options>">,
+ DocName<"SSAF options">, DocBrief<[{
+Flags controlling the behavior of the Scalable Static Analysis Framework (SSAF).}]>;
+
// gfortran options that we recognize in the driver and pass along when
// invoking GCC to compile Fortran code.
def gfortran_Group : OptionGroup<"<gfortran group>">,
@@ -941,6 +945,22 @@ def W_Joined : Joined<["-"], "W">, Group<W_Group>,
def Xanalyzer : Separate<["-"], "Xanalyzer">,
HelpText<"Pass <arg> to the static analyzer">, MetaVarName<"<arg>">,
Group<StaticAnalyzer_Group>;
+def _ssaf_extract_summaries :
+ CommaJoined<["--"], "ssaf-extract-summaries=">,
+ MetaVarName<"<summary-names>">,
+ Group<SSAF_Group>,
+ Visibility<[ClangOption, CC1Option]>,
+ HelpText<"Comma-separated list of summary names to extract">,
+ MarshallingInfoStringVector<FrontendOpts<"SSAFExtractSummaries">>;
+def _ssaf_tu_summary_file :
+ Joined<["--"], "ssaf-tu-summary-file=">,
+ MetaVarName<"<path>.<format>">,
+ Group<SSAF_Group>,
+ Visibility<[ClangOption, CC1Option]>,
+ HelpText<
+ "The output file for the extracted summaries. "
+ "The extension selects which file format to use.">,
+ MarshallingInfoString<FrontendOpts<"SSAFTUSummaryFile">>;
def Xarch__
: JoinedAndSeparate<["-"], "Xarch_">,
Flags<[NoXarchOption]>,
diff --git a/clang/include/clang/ScalableStaticAnalysisFramework/Core/Serialization/JSONFormat.h b/clang/include/clang/ScalableStaticAnalysisFramework/Core/Serialization/JSONFormat.h
index 6c5303c928661..47b46cbe42698 100644
--- a/clang/include/clang/ScalableStaticAnalysisFramework/Core/Serialization/JSONFormat.h
+++ b/clang/include/clang/ScalableStaticAnalysisFramework/Core/Serialization/JSONFormat.h
@@ -28,10 +28,6 @@ class EntityIdTable;
class EntitySummary;
class SummaryName;
-/// Call this from main() to prevent the linker from dead-stripping the
-/// JSONFormat library and its static registration objects.
-void initializeJSONFormat();
-
class JSONFormat final : public SerializationFormat {
using Array = llvm::json::Array;
using Object = llvm::json::Object;
diff --git a/clang/include/clang/ScalableStaticAnalysisFramework/Core/Serialization/SerializationFormatRegistry.h b/clang/include/clang/ScalableStaticAnalysisFramework/Core/Serialization/SerializationFormatRegistry.h
index 9f83955b884e8..ea916dd397b79 100644
--- a/clang/include/clang/ScalableStaticAnalysisFramework/Core/Serialization/SerializationFormatRegistry.h
+++ b/clang/include/clang/ScalableStaticAnalysisFramework/Core/Serialization/SerializationFormatRegistry.h
@@ -24,10 +24,11 @@
//
// Insert this code to the cpp file:
//
-// LLVM_INSTANTIATE_REGISTRY(llvm::Registry<MyFormat::FormatInfo>)
-//
+// // NOLINTNEXTLINE(misc-use-internal-linkage)
+// volatile int SSAFMyFormatAnchorSource = 0;
// static SerializationFormatRegistry::Add<MyFormat>
// RegisterFormat("MyFormat", "My awesome serialization format");
+// LLVM_INSTANTIATE_REGISTRY(llvm::Registry<MyFormat::FormatInfo>)
//
// Then implement the formatter for the specific analysis and register the
// format info for it:
@@ -49,6 +50,15 @@
// "The MyFormat format info implementation for MyAnalysis"
// );
//
+// Finally, insert a use of the new anchor symbol into the force-linker header:
+// clang/include/clang/ScalableStaticAnalysisFramework/SSAFBuiltinForceLinker.h:
+//
+// This anchor is used to force the linker to link the MyFormat registration.
+//
+// extern volatile int SSAFMyFormatAnchorSource;
+// [[maybe_unused]] static int SSAFMyFormatAnchorDestination =
+// SSAFMyFormatAnchorSource;
+//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_SERIALIZATION_SERIALIZATIONFORMATREGISTRY_H
diff --git a/clang/include/clang/ScalableStaticAnalysisFramework/Core/TUSummary/ExtractorRegistry.h b/clang/include/clang/ScalableStaticAnalysisFramework/Core/TUSummary/ExtractorRegistry.h
index a49d0e5faeeb1..9c3f7088c62e5 100644
--- a/clang/include/clang/ScalableStaticAnalysisFramework/Core/TUSummary/ExtractorRegistry.h
+++ b/clang/include/clang/ScalableStaticAnalysisFramework/Core/TUSummary/ExtractorRegistry.h
@@ -9,9 +9,18 @@
// Registry for TUSummaryExtractors, and some helper functions.
// To register some custom extractor, insert this code:
//
+// // NOLINTNEXTLINE(misc-use-internal-linkage)
+// volatile int SSAFMyExtractorAnchorSource = 0;
// static TUSummaryExtractorRegistry::Add<MyExtractor>
// X("MyExtractor", "My awesome extractor");
//
+// Finally, insert a use of the new anchor symbol into the force-linker header:
+// clang/include/clang/ScalableStaticAnalysisFramework/SSAFBuiltinForceLinker.h:
+//
+// extern volatile int SSAFMyExtractorAnchorSource;
+// [[maybe_unused]] static int SSAFMyExtractorAnchorDestination =
+// SSAFMyExtractorAnchorSource;
+//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_TUSUMMARY_EXTRACTORREGISTRY_H
diff --git a/clang/include/clang/ScalableStaticAnalysisFramework/Frontend/TUSummaryExtractorFrontendAction.h b/clang/include/clang/ScalableStaticAnalysisFramework/Frontend/TUSummaryExtractorFrontendAction.h
new file mode 100644
index 0000000000000..fe5d75149914e
--- /dev/null
+++ b/clang/include/clang/ScalableStaticAnalysisFramework/Frontend/TUSummaryExtractorFrontendAction.h
@@ -0,0 +1,33 @@
+//===- TUSummaryExtractorFrontendAction.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_TUSUMMARYEXTRACTORFRONTENDACTION_H
+#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_FRONTEND_TUSUMMARYEXTRACTORFRONTENDACTION_H
+
+#include "clang/Frontend/FrontendAction.h"
+#include <memory>
+
+namespace clang::ssaf {
+
+/// Wraps the existing \c FrontendAction and injects the extractor
+/// \c ASTConsumers into the pipeline after the ASTConsumers of the wrapped
+/// action.
+class TUSummaryExtractorFrontendAction final : public WrapperFrontendAction {
+public:
+ explicit TUSummaryExtractorFrontendAction(
+ std::unique_ptr<FrontendAction> WrappedAction);
+ ~TUSummaryExtractorFrontendAction();
+
+protected:
+ std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
+ StringRef InFile) override;
+};
+
+} // namespace clang::ssaf
+
+#endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_FRONTEND_TUSUMMARYEXTRACTORFRONTENDACTION_H
diff --git a/clang/include/clang/ScalableStaticAnalysisFramework/SSAFBuiltinForceLinker.h b/clang/include/clang/ScalableStaticAnalysisFramework/SSAFBuiltinForceLinker.h
new file mode 100644
index 0000000000000..5f201487ca1fe
--- /dev/null
+++ b/clang/include/clang/ScalableStaticAnalysisFramework/SSAFBuiltinForceLinker.h
@@ -0,0 +1,28 @@
+//===- SSAFBuiltinForceLinker.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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file pulls in all built-in SSAF extractor and format registrations
+/// by referencing their anchor symbols, preventing the static linker from
+/// discarding the containing object files.
+///
+/// Include this header (with IWYU pragma: keep) in any translation unit that
+/// must guarantee these registrations are active — typically the entry point
+/// of a binary that uses clangScalableStaticAnalysisFrameworkCore.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SSAFBUILTINFORCELINKER_H
+#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SSAFBUILTINFORCELINKER_H
+
+// This anchor is used to force the linker to link the JSONFormat registration.
+extern volatile int SSAFJSONFormatAnchorSource;
+[[maybe_unused]] static int SSAFJSONFormatAnchorDestination =
+ SSAFJSONFormatAnchorSource;
+
+#endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SSAFBUILTINFORCELINKER_H
diff --git a/clang/include/clang/ScalableStaticAnalysisFramework/SSAFForceLinker.h b/clang/include/clang/ScalableStaticAnalysisFramework/SSAFForceLinker.h
new file mode 100644
index 0000000000000..204a504c36435
--- /dev/null
+++ b/clang/include/clang/ScalableStaticAnalysisFramework/SSAFForceLinker.h
@@ -0,0 +1,25 @@
+//===- SSAFForceLinker.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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file pulls in all built-in SSAF extractor and format registrations
+/// by referencing their anchor symbols, preventing the static linker from
+/// discarding the containing object files.
+///
+/// Include this header (with IWYU pragma: keep) in any translation unit that
+/// must guarantee these registrations are active — typically the entry point
+/// of a binary that uses clangScalableStaticAnalysisFrameworkCore.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SSAFFORCELINKER_H
+#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SSAFFORCELINKER_H
+
+#include "SSAFBuiltinForceLinker.h" // IWYU pragma: keep
+
+#endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SSAFFORCELINKER_H
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index c5b75bdb2511f..3b852528d92c4 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7707,6 +7707,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
Args.AddLastArg(CmdArgs, options::OPT_fmax_tokens_EQ);
+ Args.AddLastArg(CmdArgs, options::OPT__ssaf_extract_summaries);
+ Args.AddLastArg(CmdArgs, options::OPT__ssaf_tu_summary_file);
+
// Handle serialized diagnostics.
if (Arg *A = Args.getLastArg(options::OPT__serialize_diags)) {
CmdArgs.push_back("-serialize-diagnostic-file");
diff --git a/clang/lib/FrontendTool/CMakeLists.txt b/clang/lib/FrontendTool/CMakeLists.txt
index 66213f76eb968..a451eb967e904 100644
--- a/clang/lib/FrontendTool/CMakeLists.txt
+++ b/clang/lib/FrontendTool/CMakeLists.txt
@@ -4,6 +4,8 @@ set(LLVM_LINK_COMPONENTS
)
set(link_libs
+ clangScalableStaticAnalysisFrameworkCore
+ clangScalableStaticAnalysisFrameworkFrontend
clangBasic
clangCodeGen
clangDriver
diff --git a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index c8ad63bc989a4..e4622496758ac 100644
--- a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -23,6 +23,8 @@
#include "clang/FrontendTool/Utils.h"
#include "clang/Options/Options.h"
#include "clang/Rewrite/Frontend/FrontendActions.h"
+#include "clang/ScalableStaticAnalysisFramework/Frontend/TUSummaryExtractorFrontendAction.h"
+#include "clang/ScalableStaticAnalysisFramework/SSAFForceLinker.h" // IWYU pragma: keep
#include "clang/StaticAnalyzer/Frontend/AnalyzerHelpFlags.h"
#include "clang/StaticAnalyzer/Frontend/FrontendActions.h"
#include "llvm/Option/OptTable.h"
@@ -207,6 +209,10 @@ CreateFrontendAction(CompilerInstance &CI) {
Act = std::make_unique<ASTMergeAction>(std::move(Act),
FEOpts.ASTMergeFiles);
+ if (!FEOpts.SSAFTUSummaryFile.empty()) {
+ Act = std::make_unique<ssaf::TUSummaryExtractorFrontendAction>(
+ std::move(Act));
+ }
return Act;
}
diff --git a/clang/lib/ScalableStaticAnalysisFramework/CMakeLists.txt b/clang/lib/ScalableStaticAnalysisFramework/CMakeLists.txt
index 194a13a1af845..d3d75430233fe 100644
--- a/clang/lib/ScalableStaticAnalysisFramework/CMakeLists.txt
+++ b/clang/lib/ScalableStaticAnalysisFramework/CMakeLists.txt
@@ -1 +1,2 @@
add_subdirectory(Core)
+add_subdirectory(Frontend)
diff --git a/clang/lib/ScalableStaticAnalysisFramework/Core/Serialization/JSONFormat/JSONFormatImpl.cpp b/clang/lib/ScalableStaticAnalysisFramework/Core/Serialization/JSONFormat/JSONFormatImpl.cpp
index 0f1b9ccf6258e..4072532d4972c 100644
--- a/clang/lib/ScalableStaticAnalysisFramework/Core/Serialization/JSONFormat/JSONFormatImpl.cpp
+++ b/clang/lib/ScalableStaticAnalysisFramework/Core/Serialization/JSONFormat/JSONFormatImpl.cpp
@@ -9,18 +9,17 @@
#include "JSONFormatImpl.h"
#include "clang/ScalableStaticAnalysisFramework/Core/Serialization/SerializationFormatRegistry.h"
-#include "clang/ScalableStaticAnalysisFramework/Core/TUSummary/TUSummary.h"
#include "llvm/Support/Registry.h"
+// NOLINTNEXTLINE(misc-use-internal-linkage)
+volatile int SSAFJSONFormatAnchorSource = 0;
LLVM_INSTANTIATE_REGISTRY(llvm::Registry<clang::ssaf::JSONFormat::FormatInfo>)
static clang::ssaf::SerializationFormatRegistry::Add<clang::ssaf::JSONFormat>
- RegisterJSONFormat("JSON", "JSON serialization format");
+ RegisterJSONFormat("json", "JSON serialization format");
namespace clang::ssaf {
-void initializeJSONFormat() {}
-
//----------------------------------------------------------------------------
// JSON Reader and Writer
//----------------------------------------------------------------------------
diff --git a/clang/lib/ScalableStaticAnalysisFramework/Frontend/CMakeLists.txt b/clang/lib/ScalableStaticAnalysisFramework/Frontend/CMakeLists.txt
new file mode 100644
index 0000000000000..b90d9c0ded1a9
--- /dev/null
+++ b/clang/lib/ScalableStaticAnalysisFramework/Frontend/CMakeLists.txt
@@ -0,0 +1,14 @@
+set(LLVM_LINK_COMPONENTS
+ Support
+ )
+
+add_clang_library(clangScalableStaticAnalysisFrameworkFrontend
+ TUSummaryExtractorFrontendAction.cpp
+
+ LINK_LIBS
+ clangAST
+ clangBasic
+ clangFrontend
+ clangScalableStaticAnalysisFrameworkCore
+ clangSema
+ )
diff --git a/clang/lib/ScalableStaticAnalysisFramework/Frontend/TUSummaryExtractorFrontendAction.cpp b/clang/lib/ScalableStaticAnalysisFramework/Frontend/TUSummaryExtractorFrontendAction.cpp
new file mode 100644
index 0000000000000..9a75b20fa548b
--- /dev/null
+++ b/clang/lib/ScalableStaticAnalysisFramework/Frontend/TUSummaryExtractorFrontendAction.cpp
@@ -0,0 +1,181 @@
+//===- TUSummaryExtractorFrontendAction.cpp -------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/ScalableStaticAnalysisFramework/Frontend/TUSummaryExtractorFrontendAction.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/Basic/DiagnosticFrontend.h"
+#include "clang/Frontend/MultiplexConsumer.h"
+#include "clang/ScalableStaticAnalysisFramework/Core/Serialization/SerializationFormatRegistry.h"
+#include "clang/ScalableStaticAnalysisFramework/Core/TUSummary/ExtractorRegistry.h"
+#include "clang/ScalableStaticAnalysisFramework/Core/TUSummary/TUSummary.h"
+#include "clang/ScalableStaticAnalysisFramework/Core/TUSummary/TUSummaryBuilder.h"
+#include "clang/ScalableStaticAnalysisFramework/Core/TUSummary/TUSummaryExtractor.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include <memory>
+#include <string>
+#include <vector>
+
+using namespace clang;
+using namespace ssaf;
+
+static std::optional<std::pair<llvm::StringRef, llvm::StringRef>>
+parseOutputFileFormatAndPathOrReportError(DiagnosticsEngine &Diags,
+ StringRef SSAFTUSummaryFile) {
+
+ StringRef Ext = llvm::sys::path::extension(SSAFTUSummaryFile);
+ StringRef FilePath = SSAFTUSummaryFile.drop_back(Ext.size());
+
+ if (!Ext.consume_front(".") || FilePath.empty()) {
+ Diags.Report(diag::warn_ssaf_extract_tu_summary_file_unknown_format)
+ << SSAFTUSummaryFile;
+ return std::nullopt;
+ }
+
+ if (!isFormatRegistered(Ext)) {
+ Diags.Report(diag::warn_ssaf_extract_tu_summary_file_unknown_output_format)
+ << Ext << SSAFTUSummaryFile;
+ return std::nullopt;
+ }
+
+ return std::pair{...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/186463
More information about the cfe-commits
mailing list