https://github.com/steakhal updated https://github.com/llvm/llvm-project/pull/189409
From 69d7ab94ba6b0a9b13bfa92c268c3346ae81b8b0 Mon Sep 17 00:00:00 2001 From: Balazs Benics <[email protected]> Date: Fri, 27 Mar 2026 19:43:55 +0000 Subject: [PATCH] [clang][ssaf][NFC] Rework how the Force linker anchors are defined and used - Moves them to the `clang::ssaf` namespace. - Drops the custom force linker header used for testing, because all object files are directly linked into the unittest executable, so we don't need special handling there. This reduces complexity. - Updates the documentation to reflect the new use. --- .../developer-docs/ForceLinkerHeaders.rst | 45 +++++++++++----- .../developer-docs/HowToExtend.rst | 14 +++-- .../SerializationFormatRegistry.h | 10 ++-- .../Core/TUSummary/ExtractorRegistry.h | 10 ++-- .../WholeProgramAnalysis/AnalysisRegistry.h | 14 ++--- .../SSAFBuiltinForceLinker.h | 31 ++++++----- .../Analyses/CallGraph/CallGraphExtractor.cpp | 6 +-- .../JSONFormat/JSONFormatImpl.cpp | 12 +++-- .../WholeProgramAnalysis/AnalysisRegistry.cpp | 11 ++-- .../TUSummaryExtractorFrontendActionTest.cpp | 4 -- .../Registries/FancyAnalysisData.cpp | 2 - .../Registries/MockSerializationFormat.cpp | 2 - .../Registries/MockSummaryExtractor1.cpp | 2 - .../Registries/MockSummaryExtractor2.cpp | 2 - .../SSAFBuiltinTestForceLinker.h | 51 ------------------- .../SSAFTestForceLinker.h | 23 --------- .../TestFixture.cpp | 1 - .../AnalysisDriverTest.cpp | 4 -- 18 files changed, 91 insertions(+), 153 deletions(-) delete mode 100644 clang/unittests/ScalableStaticAnalysisFramework/SSAFBuiltinTestForceLinker.h delete mode 100644 clang/unittests/ScalableStaticAnalysisFramework/SSAFTestForceLinker.h diff --git a/clang/docs/ScalableStaticAnalysisFramework/developer-docs/ForceLinkerHeaders.rst b/clang/docs/ScalableStaticAnalysisFramework/developer-docs/ForceLinkerHeaders.rst index c04b2b786308f..0788dfafed359 100644 --- a/clang/docs/ScalableStaticAnalysisFramework/developer-docs/ForceLinkerHeaders.rst +++ b/clang/docs/ScalableStaticAnalysisFramework/developer-docs/ForceLinkerHeaders.rst @@ -33,26 +33,42 @@ constructors unconditionally. The solution: anchor symbols **************************** -Each registration translation unit defines a ``volatile int`` **anchor symbol**: +Each registration translation unit defines a ``const volatile int`` **anchor symbol**: .. code-block:: c++ - // In MyExtractor.cpp — next to the registry Add<> object + // In MyExtractor.cpp - next to the registry Add<> object in the `clang::ssaf` namespace // NOLINTNEXTLINE(misc-use-internal-linkage) - volatile int SSAFMyExtractorAnchorSource = 0; + const volatile int MyExtractorAnchorSource = 0; -A **force-linker header** declares the symbol as ``extern`` and reads it into a -``[[maybe_unused]] static int`` destination: +The **force-linker header** (``SSAFBuiltinForceLinker.h``) then needs two +updates - both inside the ``clang::ssaf`` namespace: + +1. Add an ``extern`` declaration for the new anchor symbol. +2. Add the symbol to the ``AnchorSources`` list inside the + ``BuiltinAnchorDestination`` lambda. .. code-block:: c++ // In SSAFBuiltinForceLinker.h - extern volatile int SSAFMyExtractorAnchorSource; - [[maybe_unused]] static int SSAFMyExtractorAnchorDestination = - SSAFMyExtractorAnchorSource; + namespace clang::ssaf { + + // 1. Add the extern declaration alongside the existing ones. + extern const volatile int MyExtractorAnchorSource; + + [[maybe_unused]] static const int BuiltinAnchorDestination = [] { + // 2. Add the symbol to this list. + int AnchorSources[]{ + // ... existing anchors ... + MyExtractorAnchorSource, + }; + // ... + }(); + + } // namespace clang::ssaf Any translation unit that ``#include``\s this header now has a reference to -``SSAFMyExtractorAnchorSource``, which forces the linker to pull in +``MyExtractorAnchorSource``, which forces the linker to pull in ``MyExtractor.o`` — and with it, the static ``Add<>`` registration object. The ``volatile`` qualifier is essential: without it the compiler could @@ -85,11 +101,14 @@ point of a binary that uses ``clangScalableStaticAnalysisFrameworkCore``: Naming convention ================= -Anchor symbols follow the pattern ``SSAF<Component>AnchorSource`` and -``SSAF<Component>AnchorDestination``. For example: +Anchor symbols follow the pattern ``<Component>AnchorSource`` in the ``clang::ssaf`` namespace. +For example: + +- ``JSONFormatAnchorSource`` +- ``MyExtractorAnchorSource`` -- ``SSAFJSONFormatAnchorSource`` / ``SSAFJSONFormatAnchorDestination`` -- ``SSAFMyExtractorAnchorSource`` / ``SSAFMyExtractorAnchorDestination`` +All anchor sources are aggregated into a single ``BuiltinAnchorDestination`` +lambda in the force-linker header (see ``SSAFBuiltinForceLinker.h``). Considered alternatives *********************** diff --git a/clang/docs/ScalableStaticAnalysisFramework/developer-docs/HowToExtend.rst b/clang/docs/ScalableStaticAnalysisFramework/developer-docs/HowToExtend.rst index 7d92d7e6f2de7..80a2be28cdac7 100644 --- a/clang/docs/ScalableStaticAnalysisFramework/developer-docs/HowToExtend.rst +++ b/clang/docs/ScalableStaticAnalysisFramework/developer-docs/HowToExtend.rst @@ -53,8 +53,10 @@ Step 2: Register the extractor using namespace clang::ssaf; + namespace clang::ssaf { // NOLINTNEXTLINE(misc-use-internal-linkage) - volatile int SSAFMyExtractorAnchorSource = 0; + const volatile int MyExtractorAnchorSource = 0; + } // namespace clang::ssaf static TUSummaryExtractorRegistry::Add<MyExtractor> RegisterExtractor("MyExtractor", "My awesome summary extractor"); @@ -69,9 +71,9 @@ Add the following to the appropriate force-linker header: .. code-block:: c++ - extern volatile int SSAFMyExtractorAnchorSource; - [[maybe_unused]] static int SSAFMyExtractorAnchorDestination = - SSAFMyExtractorAnchorSource; + extern const volatile int MyExtractorAnchorSource; + // Don't forget to also extend the `BuiltinAnchorDestination` + // referencing this new anchor source. For **in-tree** additions, add this to ``clang/include/clang/ScalableStaticAnalysisFramework/SSAFBuiltinForceLinker.h``. @@ -125,8 +127,10 @@ Step 2: Register the format using namespace clang::ssaf; + namespace clang::ssaf { // NOLINTNEXTLINE(misc-use-internal-linkage) - volatile int SSAFMyFormatAnchorSource = 0; + const volatile int MyFormatAnchorSource = 0; + } // namespace clang::ssaf static SerializationFormatRegistry::Add<MyFormat> RegisterFormat("myformat", "My awesome serialization format"); diff --git a/clang/include/clang/ScalableStaticAnalysisFramework/Core/Serialization/SerializationFormatRegistry.h b/clang/include/clang/ScalableStaticAnalysisFramework/Core/Serialization/SerializationFormatRegistry.h index a1955e64d5137..bc146a5340339 100644 --- a/clang/include/clang/ScalableStaticAnalysisFramework/Core/Serialization/SerializationFormatRegistry.h +++ b/clang/include/clang/ScalableStaticAnalysisFramework/Core/Serialization/SerializationFormatRegistry.h @@ -24,8 +24,10 @@ // // Insert this code to the cpp file: // +// namespace clang::ssaf { // // NOLINTNEXTLINE(misc-use-internal-linkage) -// volatile int SSAFMyFormatAnchorSource = 0; +// const volatile int MyFormatAnchorSource = 0; +// } // namespace clang::ssaf // static SerializationFormatRegistry::Add<MyFormat> // RegisterFormat("MyFormat", "My awesome serialization format"); // LLVM_INSTANTIATE_REGISTRY(llvm::Registry<MyFormat::FormatInfo>) @@ -50,15 +52,11 @@ // "The MyFormat format info implementation for MyAnalysis" // ); // -// Finally, insert a use of the new anchor symbol into the force-linker header: +// Finally, extend the `AnchorSources` list in 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 4f8301dcbfed4..64c4f2f89b115 100644 --- a/clang/include/clang/ScalableStaticAnalysisFramework/Core/TUSummary/ExtractorRegistry.h +++ b/clang/include/clang/ScalableStaticAnalysisFramework/Core/TUSummary/ExtractorRegistry.h @@ -9,18 +9,16 @@ // Registry for TUSummaryExtractors, and some helper functions. // To register some custom extractor, insert this code: // +// namespace clang::ssaf { // // NOLINTNEXTLINE(misc-use-internal-linkage) -// volatile int SSAFMyExtractorAnchorSource = 0; +// const volatile int MyExtractorAnchorSource = 0; +// } // namespace clang::ssaf // static TUSummaryExtractorRegistry::Add<MyExtractor> // X("MyExtractor", "My awesome extractor"); // -// Finally, insert a use of the new anchor symbol into the force-linker header: +// Finally, extend the `AnchorSources` list in 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/Core/WholeProgramAnalysis/AnalysisRegistry.h b/clang/include/clang/ScalableStaticAnalysisFramework/Core/WholeProgramAnalysis/AnalysisRegistry.h index 44eabce6c809c..f747775c2c498 100644 --- a/clang/include/clang/ScalableStaticAnalysisFramework/Core/WholeProgramAnalysis/AnalysisRegistry.h +++ b/clang/include/clang/ScalableStaticAnalysisFramework/Core/WholeProgramAnalysis/AnalysisRegistry.h @@ -9,19 +9,19 @@ // Unified registry for both SummaryAnalysis and DerivedAnalysis subclasses. // // To register an analysis, add a static Add<AnalysisT> and an anchor source -// in its translation unit, then add the matching anchor destination to the -// relevant force-linker header: +// in its translation unit, then add the anchor source to the `AnchorSources` +// list in the relevant force-linker header: // // // MyAnalysis.cpp // static AnalysisRegistry::Add<MyAnalysis> // Registered("One-line description of MyAnalysis"); // -// volatile int SSAFMyAnalysisAnchorSource = 0; +// namespace clang::ssaf { +// // NOLINTNEXTLINE(misc-use-internal-linkage) +// const volatile int MyAnalysisAnchorSource = 0; +// } // namespace clang::ssaf // -// // SSAFBuiltinForceLinker.h (or the relevant force-linker header) -// extern volatile int SSAFMyAnalysisAnchorSource; -// [[maybe_unused]] static int SSAFMyAnalysisAnchorDestination = -// SSAFMyAnalysisAnchorSource; +// // Extend SSAFBuiltinForceLinker.h (or the relevant force-linker header) // // The registry entry name is derived automatically from // MyAnalysis::analysisName(), so name-mismatch bugs are impossible. diff --git a/clang/include/clang/ScalableStaticAnalysisFramework/SSAFBuiltinForceLinker.h b/clang/include/clang/ScalableStaticAnalysisFramework/SSAFBuiltinForceLinker.h index 707573ce34e46..e727125a0e0ac 100644 --- a/clang/include/clang/ScalableStaticAnalysisFramework/SSAFBuiltinForceLinker.h +++ b/clang/include/clang/ScalableStaticAnalysisFramework/SSAFBuiltinForceLinker.h @@ -20,21 +20,26 @@ #ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SSAFBUILTINFORCELINKER_H #define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SSAFBUILTINFORCELINKER_H -// TODO: Move these to the `clang::ssaf` namespace. +namespace clang::ssaf { +// Don't forget to also update the second list as well. +extern const volatile int AnalysisRegistryAnchorSource; +extern const volatile int CallGraphExtractorAnchorSource; +extern const volatile int JSONFormatAnchorSource; -// This anchor is used to force the linker to link the JSONFormat registration. -extern volatile int SSAFJSONFormatAnchorSource; -[[maybe_unused]] static int SSAFJSONFormatAnchorDestination = - SSAFJSONFormatAnchorSource; +// Force the linker to link in the built-in SSAF registrations. +[[maybe_unused]] static const int BuiltinAnchorDestination = [] { + int AnchorSources[]{ + AnalysisRegistryAnchorSource, + CallGraphExtractorAnchorSource, + JSONFormatAnchorSource, + }; -// This anchor is used to force the linker to link the AnalysisRegistry. -extern volatile int SSAFAnalysisRegistryAnchorSource; -[[maybe_unused]] static int SSAFAnalysisRegistryAnchorDestination = - SSAFAnalysisRegistryAnchorSource; + int SomeUse = 0; + for (int V : AnchorSources) + SomeUse |= V; + return SomeUse; +}(); -// This anchor is used to force the linker to link the CallGraphExtractor. -extern volatile int CallGraphExtractorAnchorSource; -[[maybe_unused]] static int CallGraphExtractorAnchorDestination = - CallGraphExtractorAnchorSource; +} // namespace clang::ssaf #endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_SSAFBUILTINFORCELINKER_H diff --git a/clang/lib/ScalableStaticAnalysisFramework/Analyses/CallGraph/CallGraphExtractor.cpp b/clang/lib/ScalableStaticAnalysisFramework/Analyses/CallGraph/CallGraphExtractor.cpp index b2cd2e40f33b5..c5ada1dc80ed5 100644 --- a/clang/lib/ScalableStaticAnalysisFramework/Analyses/CallGraph/CallGraphExtractor.cpp +++ b/clang/lib/ScalableStaticAnalysisFramework/Analyses/CallGraph/CallGraphExtractor.cpp @@ -100,7 +100,7 @@ void CallGraphExtractor::handleCallGraphNode(const ASTContext &Ctx, static TUSummaryExtractorRegistry::Add<CallGraphExtractor> RegisterExtractor("CallGraph", "Extracts static call-graph information"); -// This anchor is used to force the linker to link in the generated object file -// and thus register the CallGraphExtractor. +namespace clang::ssaf { // NOLINTNEXTLINE(misc-use-internal-linkage) -volatile int CallGraphExtractorAnchorSource = 0; +const volatile int CallGraphExtractorAnchorSource = 0; +} // namespace clang::ssaf diff --git a/clang/lib/ScalableStaticAnalysisFramework/Core/Serialization/JSONFormat/JSONFormatImpl.cpp b/clang/lib/ScalableStaticAnalysisFramework/Core/Serialization/JSONFormat/JSONFormatImpl.cpp index 4072532d4972c..894a568ae4193 100644 --- a/clang/lib/ScalableStaticAnalysisFramework/Core/Serialization/JSONFormat/JSONFormatImpl.cpp +++ b/clang/lib/ScalableStaticAnalysisFramework/Core/Serialization/JSONFormat/JSONFormatImpl.cpp @@ -11,15 +11,19 @@ #include "clang/ScalableStaticAnalysisFramework/Core/Serialization/SerializationFormatRegistry.h" #include "llvm/Support/Registry.h" -// NOLINTNEXTLINE(misc-use-internal-linkage) -volatile int SSAFJSONFormatAnchorSource = 0; -LLVM_INSTANTIATE_REGISTRY(llvm::Registry<clang::ssaf::JSONFormat::FormatInfo>) +using namespace clang; +using namespace ssaf; + +LLVM_INSTANTIATE_REGISTRY(llvm::Registry<JSONFormat::FormatInfo>) -static clang::ssaf::SerializationFormatRegistry::Add<clang::ssaf::JSONFormat> +static SerializationFormatRegistry::Add<JSONFormat> RegisterJSONFormat("json", "JSON serialization format"); namespace clang::ssaf { +// NOLINTNEXTLINE(misc-use-internal-linkage) +const volatile int JSONFormatAnchorSource = 0; + //---------------------------------------------------------------------------- // JSON Reader and Writer //---------------------------------------------------------------------------- diff --git a/clang/lib/ScalableStaticAnalysisFramework/Core/WholeProgramAnalysis/AnalysisRegistry.cpp b/clang/lib/ScalableStaticAnalysisFramework/Core/WholeProgramAnalysis/AnalysisRegistry.cpp index 8e1ea954d9afd..94241afe08153 100644 --- a/clang/lib/ScalableStaticAnalysisFramework/Core/WholeProgramAnalysis/AnalysisRegistry.cpp +++ b/clang/lib/ScalableStaticAnalysisFramework/Core/WholeProgramAnalysis/AnalysisRegistry.cpp @@ -13,11 +13,12 @@ using namespace clang; using namespace ssaf; -using RegistryT = llvm::Registry<AnalysisBase>; - +namespace clang::ssaf { // NOLINTNEXTLINE(misc-use-internal-linkage) -volatile int SSAFAnalysisRegistryAnchorSource = 0; -LLVM_INSTANTIATE_REGISTRY(RegistryT) +const volatile int AnalysisRegistryAnchorSource = 0; +} // namespace clang::ssaf + +LLVM_INSTANTIATE_REGISTRY(llvm::Registry<AnalysisBase>) std::vector<AnalysisName> &AnalysisRegistry::getAnalysisNames() { static std::vector<AnalysisName> Names; @@ -34,7 +35,7 @@ const std::vector<AnalysisName> &AnalysisRegistry::names() { llvm::Expected<std::unique_ptr<AnalysisBase>> AnalysisRegistry::instantiate(const AnalysisName &Name) { - for (const auto &Entry : RegistryT::entries()) { + for (const auto &Entry : llvm::Registry<AnalysisBase>::entries()) { if (Entry.getName() == Name.str()) { return std::unique_ptr<AnalysisBase>(Entry.instantiate()); } diff --git a/clang/unittests/ScalableStaticAnalysisFramework/Frontend/TUSummaryExtractorFrontendActionTest.cpp b/clang/unittests/ScalableStaticAnalysisFramework/Frontend/TUSummaryExtractorFrontendActionTest.cpp index d684366ed53ce..bc074c228a92c 100644 --- a/clang/unittests/ScalableStaticAnalysisFramework/Frontend/TUSummaryExtractorFrontendActionTest.cpp +++ b/clang/unittests/ScalableStaticAnalysisFramework/Frontend/TUSummaryExtractorFrontendActionTest.cpp @@ -48,8 +48,6 @@ class NoOpExtractor : public TUSummaryExtractor { }; } // namespace -// NOLINTNEXTLINE(misc-use-internal-linkage) -volatile int SSAFNoOpExtractorAnchorSource = 0; static TUSummaryExtractorRegistry::Add<NoOpExtractor> RegisterNoOp("NoOpExtractor", "No-op extractor for frontend action tests"); @@ -105,8 +103,6 @@ class FailingSerializationFormat final : public SerializationFormat { }; } // namespace -// NOLINTNEXTLINE(misc-use-internal-linkage) -volatile int SSAFFailingSerializationFormatAnchorSource = 0; static SerializationFormatRegistry::Add<FailingSerializationFormat> RegisterFormat( "FailingSerializationFormat", diff --git a/clang/unittests/ScalableStaticAnalysisFramework/Registries/FancyAnalysisData.cpp b/clang/unittests/ScalableStaticAnalysisFramework/Registries/FancyAnalysisData.cpp index 313c53518dfe8..084835190f7bd 100644 --- a/clang/unittests/ScalableStaticAnalysisFramework/Registries/FancyAnalysisData.cpp +++ b/clang/unittests/ScalableStaticAnalysisFramework/Registries/FancyAnalysisData.cpp @@ -54,8 +54,6 @@ struct FancyAnalysisFormatInfo final : FormatInfo { }; } // namespace -// NOLINTNEXTLINE(misc-use-internal-linkage) -volatile int SSAFFancyAnalysisDataAnchorSource = 0; static llvm::Registry<FormatInfo>::Add<FancyAnalysisFormatInfo> RegisterFormatInfo("FancyAnalysisData", "Format info for FancyAnalysisData for the " diff --git a/clang/unittests/ScalableStaticAnalysisFramework/Registries/MockSerializationFormat.cpp b/clang/unittests/ScalableStaticAnalysisFramework/Registries/MockSerializationFormat.cpp index 535b5fced0da6..e7a3e90e0bb31 100644 --- a/clang/unittests/ScalableStaticAnalysisFramework/Registries/MockSerializationFormat.cpp +++ b/clang/unittests/ScalableStaticAnalysisFramework/Registries/MockSerializationFormat.cpp @@ -160,8 +160,6 @@ llvm::Error MockSerializationFormat::writeTUSummary(const TUSummary &Summary, return llvm::Error::success(); } -// NOLINTNEXTLINE(misc-use-internal-linkage) -volatile int SSAFMockSerializationFormatAnchorSource = 0; static SerializationFormatRegistry::Add<MockSerializationFormat> RegisterFormat("MockSerializationFormat", "A serialization format for testing"); diff --git a/clang/unittests/ScalableStaticAnalysisFramework/Registries/MockSummaryExtractor1.cpp b/clang/unittests/ScalableStaticAnalysisFramework/Registries/MockSummaryExtractor1.cpp index 1bce78c8b1030..1d5a33900d3c2 100644 --- a/clang/unittests/ScalableStaticAnalysisFramework/Registries/MockSummaryExtractor1.cpp +++ b/clang/unittests/ScalableStaticAnalysisFramework/Registries/MockSummaryExtractor1.cpp @@ -40,7 +40,5 @@ class MockSummaryExtractor1 : public TUSummaryExtractor { } // namespace -// NOLINTNEXTLINE(misc-use-internal-linkage) -volatile int SSAFMockSummaryExtractor1AnchorSource = 0; static TUSummaryExtractorRegistry::Add<MockSummaryExtractor1> RegisterExtractor("MockSummaryExtractor1", "Mock summary extractor 1"); diff --git a/clang/unittests/ScalableStaticAnalysisFramework/Registries/MockSummaryExtractor2.cpp b/clang/unittests/ScalableStaticAnalysisFramework/Registries/MockSummaryExtractor2.cpp index 242f427f5e346..ab78b5c135faa 100644 --- a/clang/unittests/ScalableStaticAnalysisFramework/Registries/MockSummaryExtractor2.cpp +++ b/clang/unittests/ScalableStaticAnalysisFramework/Registries/MockSummaryExtractor2.cpp @@ -40,7 +40,5 @@ class MockSummaryExtractor2 : public TUSummaryExtractor { } // namespace -// NOLINTNEXTLINE(misc-use-internal-linkage) -volatile int SSAFMockSummaryExtractor2AnchorSource = 0; static TUSummaryExtractorRegistry::Add<MockSummaryExtractor2> RegisterExtractor("MockSummaryExtractor2", "Mock summary extractor 2"); diff --git a/clang/unittests/ScalableStaticAnalysisFramework/SSAFBuiltinTestForceLinker.h b/clang/unittests/ScalableStaticAnalysisFramework/SSAFBuiltinTestForceLinker.h deleted file mode 100644 index 05d96af80cb27..0000000000000 --- a/clang/unittests/ScalableStaticAnalysisFramework/SSAFBuiltinTestForceLinker.h +++ /dev/null @@ -1,51 +0,0 @@ -//===- SSAFBuiltinTestForceLinker.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 test-only SSAF mock extractor and format -/// registrations by referencing their anchor symbols. -/// -/// Include this header (with IWYU pragma: keep) in a translation unit that -/// is compiled into the SSAF unittest binary. -/// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_UNITTESTS_SCALABLESTATICANALYSISFRAMEWORK_SSAFBUILTINTESTFORCELINKER_H -#define LLVM_CLANG_UNITTESTS_SCALABLESTATICANALYSISFRAMEWORK_SSAFBUILTINTESTFORCELINKER_H - -// Force the linker to link NoOpExtractor registration. -extern volatile int SSAFNoOpExtractorAnchorSource; -[[maybe_unused]] static int SSAFNoOpExtractorAnchorDestination = - SSAFNoOpExtractorAnchorSource; - -// Force the linker to link MockSummaryExtractor1 registration. -extern volatile int SSAFMockSummaryExtractor1AnchorSource; -[[maybe_unused]] static int SSAFMockSummaryExtractor1AnchorDestination = - SSAFMockSummaryExtractor1AnchorSource; - -// Force the linker to link MockSummaryExtractor2 registration. -extern volatile int SSAFMockSummaryExtractor2AnchorSource; -[[maybe_unused]] static int SSAFMockSummaryExtractor2AnchorDestination = - SSAFMockSummaryExtractor2AnchorSource; - -// Force the linker to link FailingSerializationFormat registration. -extern volatile int SSAFFailingSerializationFormatAnchorSource; -[[maybe_unused]] static int SSAFFailingSerializationFormatAnchorDestination = - SSAFFailingSerializationFormatAnchorSource; - -// Force the linker to link MockSerializationFormat registration. -extern volatile int SSAFMockSerializationFormatAnchorSource; -[[maybe_unused]] static int SSAFMockSerializationFormatAnchorDestination = - SSAFMockSerializationFormatAnchorSource; - -// Force the linker to link FancyAnalysisData format info registration. -extern volatile int SSAFFancyAnalysisDataAnchorSource; -[[maybe_unused]] static int SSAFFancyAnalysisDataAnchorDestination = - SSAFFancyAnalysisDataAnchorSource; - -#endif // LLVM_CLANG_UNITTESTS_SCALABLESTATICANALYSISFRAMEWORK_SSAFBUILTINTESTFORCELINKER_H diff --git a/clang/unittests/ScalableStaticAnalysisFramework/SSAFTestForceLinker.h b/clang/unittests/ScalableStaticAnalysisFramework/SSAFTestForceLinker.h deleted file mode 100644 index dd2077569a4eb..0000000000000 --- a/clang/unittests/ScalableStaticAnalysisFramework/SSAFTestForceLinker.h +++ /dev/null @@ -1,23 +0,0 @@ -//===- SSAFTestForceLinker.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 test-only SSAF mock extractor and format -/// registrations by referencing their anchor symbols. -/// -/// Include this header (with IWYU pragma: keep) in a translation unit that -/// is compiled into the SSAF unittest binary. -/// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_UNITTESTS_SCALABLESTATICANALYSISFRAMEWORK_SSAFTESTFORCELINKER_H -#define LLVM_CLANG_UNITTESTS_SCALABLESTATICANALYSISFRAMEWORK_SSAFTESTFORCELINKER_H - -#include "SSAFBuiltinTestForceLinker.h" // IWYU pragma: keep - -#endif // LLVM_CLANG_UNITTESTS_SCALABLESTATICANALYSISFRAMEWORK_SSAFTESTFORCELINKER_H diff --git a/clang/unittests/ScalableStaticAnalysisFramework/TestFixture.cpp b/clang/unittests/ScalableStaticAnalysisFramework/TestFixture.cpp index 772eaf069a350..c1c41997abcf2 100644 --- a/clang/unittests/ScalableStaticAnalysisFramework/TestFixture.cpp +++ b/clang/unittests/ScalableStaticAnalysisFramework/TestFixture.cpp @@ -7,7 +7,6 @@ //===----------------------------------------------------------------------===// #include "TestFixture.h" -#include "SSAFBuiltinTestForceLinker.h" // IWYU pragma: keep #include "clang/ScalableStaticAnalysisFramework/Core/Model/BuildNamespace.h" #include "clang/ScalableStaticAnalysisFramework/Core/Model/EntityId.h" #include "clang/ScalableStaticAnalysisFramework/Core/Model/EntityLinkage.h" diff --git a/clang/unittests/ScalableStaticAnalysisFramework/WholeProgramAnalysis/AnalysisDriverTest.cpp b/clang/unittests/ScalableStaticAnalysisFramework/WholeProgramAnalysis/AnalysisDriverTest.cpp index e206b33d80295..900680539352f 100644 --- a/clang/unittests/ScalableStaticAnalysisFramework/WholeProgramAnalysis/AnalysisDriverTest.cpp +++ b/clang/unittests/ScalableStaticAnalysisFramework/WholeProgramAnalysis/AnalysisDriverTest.cpp @@ -180,10 +180,6 @@ class Analysis1 final } }; -// These static registrations are safe without SSAFBuiltinTestForceLinker.h -// because this translation unit is compiled directly into the test binary - -// the linker cannot dead-strip it, so all static initializers are guaranteed -// to run. static AnalysisRegistry::Add<Analysis1> RegAnalysis1("Analysis for Analysis1"); class Analysis2 final _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
