Author: Ziqing Luo Date: 2026-07-13T13:51:48-07:00 New Revision: 612e7ca85c53e85a7444bfc23e763a756a50f69a
URL: https://github.com/llvm/llvm-project/commit/612e7ca85c53e85a7444bfc23e763a756a50f69a DIFF: https://github.com/llvm/llvm-project/commit/612e7ca85c53e85a7444bfc23e763a756a50f69a.diff LOG: [SSAF][NFC] Rename operator new/delete pointers analysis to TypeConstrainedPointers (#208577) There will be more such pointer entities that must retain their type during the clang-reforge transformation. Since they are extracted and processed similarly, combining them into a single analysis simplifies maintenance. Therefore, we are using TypeConstrainedPointers as the umbrella name. Added: clang/include/clang/ScalableStaticAnalysis/Analyses/TypeConstrainedPointers/TypeConstrainedPointers.h clang/lib/ScalableStaticAnalysis/Analyses/TypeConstrainedPointers/TypeConstrainedPointers.cpp clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/tu-summary-bad-id.json clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/tu-summary-no-key.json clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/tu-summary.json clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/wpa-result-bad-id.json clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/wpa-result-empty.json clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/wpa-result-no-key.json clang/test/Analysis/Scalable/TypeConstrainedPointers/tu-summary-serialization.test clang/test/Analysis/Scalable/TypeConstrainedPointers/type-constrained-pointers.cpp clang/test/Analysis/Scalable/TypeConstrainedPointers/wpa-result-serialization.test clang/unittests/ScalableStaticAnalysis/Analyses/TypeConstrainedPointers/TypeConstrainedPointersExtractorTest.cpp Modified: clang/include/clang/ScalableStaticAnalysis/BuiltinAnchorSources.def clang/lib/ScalableStaticAnalysis/Analyses/CMakeLists.txt clang/unittests/ScalableStaticAnalysis/CMakeLists.txt Removed: clang/include/clang/ScalableStaticAnalysis/Analyses/OperatorNewDelete/OperatorNewDeletePointers.h clang/lib/ScalableStaticAnalysis/Analyses/OperatorNewDelete/OperatorNewDeletePointers.cpp clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/tu-summary-bad-id.json clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/tu-summary-no-key.json clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/tu-summary.json clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/wpa-result-bad-id.json clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/wpa-result-empty.json clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/wpa-result-no-key.json clang/test/Analysis/Scalable/OperatorNewDelete/operator-new-delete.cpp clang/test/Analysis/Scalable/OperatorNewDelete/tu-summary-serialization.test clang/test/Analysis/Scalable/OperatorNewDelete/wpa-result-serialization.test clang/unittests/ScalableStaticAnalysis/Analyses/OperatorNewDelete/OperatorNewDeletePointersExtractorTest.cpp ################################################################################ diff --git a/clang/include/clang/ScalableStaticAnalysis/Analyses/OperatorNewDelete/OperatorNewDeletePointers.h b/clang/include/clang/ScalableStaticAnalysis/Analyses/OperatorNewDelete/OperatorNewDeletePointers.h deleted file mode 100644 index f3524aa329673..0000000000000 --- a/clang/include/clang/ScalableStaticAnalysis/Analyses/OperatorNewDelete/OperatorNewDeletePointers.h +++ /dev/null @@ -1,79 +0,0 @@ -//===- OperatorNewDeletePointers.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 -// -//===----------------------------------------------------------------------===// -// -// Declares data structures for analysis that identifies pointer entities in -// operator new/delete overloads that must have a 'void*' type -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_SCALABLESTATICANALYSIS_ANALYSES_OPERATORNEWDELETE_OPERATORNEWDELETEPOINTERS_H -#define LLVM_CLANG_SCALABLESTATICANALYSIS_ANALYSES_OPERATORNEWDELETE_OPERATORNEWDELETEPOINTERS_H - -#include "clang/ScalableStaticAnalysis/Core/Model/EntityId.h" -#include "clang/ScalableStaticAnalysis/Core/Model/SummaryName.h" -#include "clang/ScalableStaticAnalysis/Core/TUSummary/EntitySummary.h" -#include "clang/ScalableStaticAnalysis/Core/WholeProgramAnalysis/AnalysisName.h" -#include "clang/ScalableStaticAnalysis/Core/WholeProgramAnalysis/AnalysisResult.h" -#include "llvm/ADT/StringRef.h" -#include <set> - -namespace clang::ssaf { - -/// \brief Collects specific pointer entities related to operator new and delete -/// overloads within a contributor. -/// -/// OperatorNewDeletePointersEntitySummary collects the following entities: -/// -# The returned entities of `operator new` overloads. -/// -# The parameter (optionally the second) of `operator new` overloads -/// representing the pointer to a memory area at which to initialize the -/// object. -/// -# The first parameter of `operator delete` overloads representing the -/// pointer -/// to a memory block to deallocate (or a null pointer). -/// -# The parameter (optionally the second) of `operator delete` overloads -/// representing the pointer used as the placement parameter in the matching -/// placement `new`. -struct OperatorNewDeletePointersEntitySummary final : public EntitySummary { - static constexpr llvm::StringLiteral Name = "OperatorNewDeletePointers"; - - static SummaryName summaryName() { return SummaryName(Name.str()); } - - SummaryName getSummaryName() const override { return summaryName(); } - - bool friend operator==(const OperatorNewDeletePointersEntitySummary &This, - const OperatorNewDeletePointersEntitySummary &Other) { - return This.Entities == Other.Entities; - } - - bool operator==(const std::set<EntityId> &OtherEntities) const { - return Entities == OtherEntities; - } - - bool empty() const { return Entities.empty(); } - - std::set<EntityId> Entities; -}; - -/// \brief Whole-program result of the operator new/delete pointer -/// analysis. -struct OperatorNewDeletePointersAnalysisResult final : AnalysisResult { - static constexpr llvm::StringLiteral Name = - "OperatorNewDeletePointersAnalysisResult"; - - static AnalysisName analysisName() { return AnalysisName(Name.str()); } - - std::set<EntityId> Entities; - - bool contains(const EntityId &Id) const { - return Entities.find(Id) != Entities.end(); - } -}; - -} // namespace clang::ssaf - -#endif // LLVM_CLANG_SCALABLESTATICANALYSIS_ANALYSES_OPERATORNEWDELETE_OPERATORNEWDELETEPOINTERS_H diff --git a/clang/include/clang/ScalableStaticAnalysis/Analyses/TypeConstrainedPointers/TypeConstrainedPointers.h b/clang/include/clang/ScalableStaticAnalysis/Analyses/TypeConstrainedPointers/TypeConstrainedPointers.h new file mode 100644 index 0000000000000..e785782c001fa --- /dev/null +++ b/clang/include/clang/ScalableStaticAnalysis/Analyses/TypeConstrainedPointers/TypeConstrainedPointers.h @@ -0,0 +1,75 @@ +//===- TypeConstrainedPointers.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 +// +//===----------------------------------------------------------------------===// +// +// Declares data structures for the Type Constrained Pointers analysis, which +// identifies pointer entities that must retain their pointer type throughout +// the program. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_SCALABLESTATICANALYSIS_ANALYSES_TYPECONSTRAINEDPOINTERS_TYPECONSTRAINEDPOINTERS_H +#define LLVM_CLANG_SCALABLESTATICANALYSIS_ANALYSES_TYPECONSTRAINEDPOINTERS_TYPECONSTRAINEDPOINTERS_H + +#include "clang/ScalableStaticAnalysis/Core/Model/EntityId.h" +#include "clang/ScalableStaticAnalysis/Core/Model/SummaryName.h" +#include "clang/ScalableStaticAnalysis/Core/TUSummary/EntitySummary.h" +#include "clang/ScalableStaticAnalysis/Core/WholeProgramAnalysis/AnalysisName.h" +#include "clang/ScalableStaticAnalysis/Core/WholeProgramAnalysis/AnalysisResult.h" +#include "llvm/ADT/StringRef.h" +#include <set> + +namespace clang::ssaf { + +/// Per-contributor set of pointer entities that must retain their pointer type. +/// +/// From `operator new` / `operator delete` overloads: +/// -# The return entity of `operator new` overloads. +/// -# The second parameter of `operator new(size_t, void*)` representing the +/// pointer to the memory area at which to initialize the object. +/// -# The first parameter of `operator delete` overloads representing the +/// pointer to the memory block to deallocate (or a null pointer). +/// -# The second parameter of `operator delete(void*, void*)` representing +/// the placement pointer matching the corresponding placement `new`. +struct TypeConstrainedPointersEntitySummary final : public EntitySummary { + static constexpr llvm::StringLiteral Name = "TypeConstrainedPointers"; + + static SummaryName summaryName() { return SummaryName(Name.str()); } + + SummaryName getSummaryName() const override { return summaryName(); } + + bool friend operator==(const TypeConstrainedPointersEntitySummary &This, + const TypeConstrainedPointersEntitySummary &Other) { + return This.Entities == Other.Entities; + } + + bool operator==(const std::set<EntityId> &OtherEntities) const { + return Entities == OtherEntities; + } + + bool empty() const { return Entities.empty(); } + + std::set<EntityId> Entities; +}; + +/// Whole-program set of pointer entities that must retain their pointer type. +struct TypeConstrainedPointersAnalysisResult final : AnalysisResult { + static constexpr llvm::StringLiteral Name = + "TypeConstrainedPointersAnalysisResult"; + + static AnalysisName analysisName() { return AnalysisName(Name.str()); } + + std::set<EntityId> Entities; + + bool contains(const EntityId &Id) const { + return Entities.find(Id) != Entities.end(); + } +}; + +} // namespace clang::ssaf + +#endif // LLVM_CLANG_SCALABLESTATICANALYSIS_ANALYSES_TYPECONSTRAINEDPOINTERS_TYPECONSTRAINEDPOINTERS_H diff --git a/clang/include/clang/ScalableStaticAnalysis/BuiltinAnchorSources.def b/clang/include/clang/ScalableStaticAnalysis/BuiltinAnchorSources.def index 186710f3ea00a..1afecd10bea78 100644 --- a/clang/include/clang/ScalableStaticAnalysis/BuiltinAnchorSources.def +++ b/clang/include/clang/ScalableStaticAnalysis/BuiltinAnchorSources.def @@ -20,7 +20,7 @@ ANCHOR(AnalysisRegistryAnchorSource) ANCHOR(CallGraphExtractorAnchorSource) ANCHOR(CallGraphJSONFormatAnchorSource) ANCHOR(JSONFormatAnchorSource) -ANCHOR(OperatorNewDeletePointersAnchorSource) +ANCHOR(TypeConstrainedPointersAnchorSource) ANCHOR(PointerFlowAnalysisAnchorSource) ANCHOR(PointerFlowExtractorAnchorSource) ANCHOR(PointerFlowJSONFormatAnchorSource) diff --git a/clang/lib/ScalableStaticAnalysis/Analyses/CMakeLists.txt b/clang/lib/ScalableStaticAnalysis/Analyses/CMakeLists.txt index caa4286b9f271..56b88a53e6665 100644 --- a/clang/lib/ScalableStaticAnalysis/Analyses/CMakeLists.txt +++ b/clang/lib/ScalableStaticAnalysis/Analyses/CMakeLists.txt @@ -8,12 +8,12 @@ add_clang_library(clangScalableStaticAnalysisAnalyses CallGraph/CallGraphJSONFormat.cpp EntityPointerLevel/EntityPointerLevel.cpp EntityPointerLevel/EntityPointerLevelFormat.cpp - OperatorNewDelete/OperatorNewDeletePointers.cpp PointerFlow/PointerFlow.cpp PointerFlow/PointerFlowAnalysis.cpp PointerFlow/PointerFlowExtractor.cpp PointerFlow/PointerFlowFormat.cpp SSAFAnalysesCommon.cpp + TypeConstrainedPointers/TypeConstrainedPointers.cpp UnsafeBufferUsage/UnsafeBufferUsage.cpp UnsafeBufferUsage/UnsafeBufferUsageAnalysis.cpp UnsafeBufferUsage/UnsafeBufferUsageExtractor.cpp diff --git a/clang/lib/ScalableStaticAnalysis/Analyses/OperatorNewDelete/OperatorNewDeletePointers.cpp b/clang/lib/ScalableStaticAnalysis/Analyses/TypeConstrainedPointers/TypeConstrainedPointers.cpp similarity index 63% rename from clang/lib/ScalableStaticAnalysis/Analyses/OperatorNewDelete/OperatorNewDeletePointers.cpp rename to clang/lib/ScalableStaticAnalysis/Analyses/TypeConstrainedPointers/TypeConstrainedPointers.cpp index 044faf60cfcb2..21bd75055e034 100644 --- a/clang/lib/ScalableStaticAnalysis/Analyses/OperatorNewDelete/OperatorNewDeletePointers.cpp +++ b/clang/lib/ScalableStaticAnalysis/Analyses/TypeConstrainedPointers/TypeConstrainedPointers.cpp @@ -1,4 +1,4 @@ -//===- OperatorNewDeletePointers.cpp --------------------------------------===// +//===- TypeConstrainedPointers.cpp ----------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,27 +6,19 @@ // //===----------------------------------------------------------------------===// // -// Implementation of the OperatorNewDeletePointers analysis, including +// Implementation of the Type Constrained Pointers analysis, including // -// a) the Extractor implementation for extracting from user-provided operator -// new/delete overloadings: -// 1 return entities of operator new overloads; -// 2 the parameter (optionally the 2nd) of operator new overloads -// representing the pointer to a memory area to initialize the object at; -// 3 the first parameter of operator delete overloads representing the -// pointer to a memory block to deallocate or a null pointer; -// 4 the parameter (optionally the 2nd) of operator delete overloads -// representing the pointer used as the placement parameter in the matching -// placement new. +// a) the Extractor implementation collecting pointer entities that shall retain +// their types // // b) the WPA implementation that simply groups extracted summaries into a -// OperatorNewDeletePointersAnalysisResult that other analysis can use. +// TypeConstrainedPointersAnalysisResult that other analysis can use. // // c) serialization implementations // //===----------------------------------------------------------------------===// -#include "clang/ScalableStaticAnalysis/Analyses/OperatorNewDelete/OperatorNewDeletePointers.h" +#include "clang/ScalableStaticAnalysis/Analyses/TypeConstrainedPointers/TypeConstrainedPointers.h" #include "../SSAFAnalysesCommon.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" @@ -53,31 +45,40 @@ using namespace ssaf; namespace { -class OperatorNewDeletePointersExtractor final : public TUSummaryExtractor { +// Extracts pointer entities that must retain their pointer type. +// +// From `operator new` / `operator delete` overloads: +// 1 the return entity of `operator new` overloads; +// 2 the second parameter of `operator new(size_t, void*)` representing the +// pointer to the memory area at which to initialize the object; +// 3 the first parameter of `operator delete` overloads representing the +// pointer to the memory block to deallocate (or a null pointer); +// 4 the second parameter of `operator delete(void*, void*)` representing +// the placement pointer matching the corresponding placement `new`. +class TypeConstrainedPointersExtractor final : public TUSummaryExtractor { public: using TUSummaryExtractor::TUSummaryExtractor; private: void HandleTranslationUnit(ASTContext &Ctx) override; - std::unique_ptr<OperatorNewDeletePointersEntitySummary> + std::unique_ptr<TypeConstrainedPointersEntitySummary> extractEntitySummary(const std::vector<const NamedDecl *> &Decls); }; -void OperatorNewDeletePointersExtractor::HandleTranslationUnit( - ASTContext &Ctx) { +void TypeConstrainedPointersExtractor::HandleTranslationUnit(ASTContext &Ctx) { extractAndAddSummaries( *this, SummaryBuilder, Ctx, [&](const std::vector<const NamedDecl *> &Decls) { return extractEntitySummary(Decls); }, - OperatorNewDeletePointersEntitySummary::Name); + TypeConstrainedPointersEntitySummary::Name); } -std::unique_ptr<OperatorNewDeletePointersEntitySummary> -OperatorNewDeletePointersExtractor::extractEntitySummary( +std::unique_ptr<TypeConstrainedPointersEntitySummary> +TypeConstrainedPointersExtractor::extractEntitySummary( const std::vector<const NamedDecl *> &ContributorDecls) { - auto Summary = std::make_unique<OperatorNewDeletePointersEntitySummary>(); + auto Summary = std::make_unique<TypeConstrainedPointersEntitySummary>(); auto Matcher = [&Summary, this](const DynTypedNode &Node) { const auto *FD = Node.get<FunctionDecl>(); @@ -122,23 +123,22 @@ OperatorNewDeletePointersExtractor::extractEntitySummary( //===----------------------------------------------------------------------===// // WPA implementation //===----------------------------------------------------------------------===// -class OperatorNewDeletePointersAnalysis final - : public SummaryAnalysis<OperatorNewDeletePointersAnalysisResult, - OperatorNewDeletePointersEntitySummary> { +class TypeConstrainedPointersAnalysis final + : public SummaryAnalysis<TypeConstrainedPointersAnalysisResult, + TypeConstrainedPointersEntitySummary> { public: llvm::Error - add(EntityId, - const OperatorNewDeletePointersEntitySummary &Summary) override { + add(EntityId, const TypeConstrainedPointersEntitySummary &Summary) override { getResult().Entities.insert(Summary.Entities.begin(), Summary.Entities.end()); return llvm::Error::success(); } }; -AnalysisRegistry::Add<OperatorNewDeletePointersAnalysis> - RegisterOperatorNewDeletePointersAnalysis( - "Whole-program set of pointer entities in operator new/delete " - "overloads that must retain their 'void*' type"); +AnalysisRegistry::Add<TypeConstrainedPointersAnalysis> + RegisterTypeConstrainedPointersAnalysis( + "Whole-program set of pointer entities that " + "must retain their pointer type"); //===----------------------------------------------------------------------===// // serialization implementation @@ -152,7 +152,7 @@ llvm::json::Object serializeImpl(const std::set<EntityId> &Set, DataArray.reserve(Set.size()); for (const auto &Ent : Set) DataArray.push_back(Fn(Ent)); - Result[OperatorNewDeletePointersAnalysisResult::Name] = std::move(DataArray); + Result[TypeConstrainedPointersAnalysisResult::Name] = std::move(DataArray); return Result; } @@ -160,13 +160,13 @@ llvm::Expected<std::set<EntityId>> deserializeImpl(const llvm::json::Object &Data, JSONFormat::EntityIdFromJSONFn Fn) { const auto *DataArray = - Data.getArray(OperatorNewDeletePointersAnalysisResult::Name); + Data.getArray(TypeConstrainedPointersAnalysisResult::Name); std::set<EntityId> EntitySet; if (!DataArray) { return makeSawButExpectedError( Data, "An object with a key %s", - OperatorNewDeletePointersAnalysisResult::Name.data()); + TypeConstrainedPointersAnalysisResult::Name.data()); } for (const auto &Elt : *DataArray) { const auto *EltAsObj = Elt.getAsObject(); @@ -186,8 +186,7 @@ deserializeImpl(const llvm::json::Object &Data, llvm::json::Object serializeSummary(const EntitySummary &S, JSONFormat::EntityIdToJSONFn Fn) { - const auto &SS = - static_cast<const OperatorNewDeletePointersEntitySummary &>(S); + const auto &SS = static_cast<const TypeConstrainedPointersEntitySummary &>(S); return serializeImpl(SS.Entities, Fn); } @@ -199,28 +198,28 @@ deserializeSummary(const llvm::json::Object &Data, EntityIdTable &, if (!EntityIDSet) return EntityIDSet.takeError(); - std::unique_ptr<OperatorNewDeletePointersEntitySummary> Sum = - std::make_unique<OperatorNewDeletePointersEntitySummary>(); + std::unique_ptr<TypeConstrainedPointersEntitySummary> Sum = + std::make_unique<TypeConstrainedPointersEntitySummary>(); Sum->Entities = std::move(*EntityIDSet); return Sum; } -struct OperatorNewDeletePointersJSONFormatInfo final : JSONFormat::FormatInfo { - OperatorNewDeletePointersJSONFormatInfo() +struct TypeConstrainedPointersJSONFormatInfo final : JSONFormat::FormatInfo { + TypeConstrainedPointersJSONFormatInfo() : JSONFormat::FormatInfo( - OperatorNewDeletePointersEntitySummary::summaryName(), + TypeConstrainedPointersEntitySummary::summaryName(), serializeSummary, deserializeSummary) {} }; static llvm::Registry<JSONFormat::FormatInfo>::Add< - OperatorNewDeletePointersJSONFormatInfo> - RegisterOperatorNewDeletePointersJSONFormatInfo( - OperatorNewDeletePointersEntitySummary::Name, - "JSON Format info for OperatorNewDeletePointersEntitySummary"); + TypeConstrainedPointersJSONFormatInfo> + RegisterTypeConstrainedPointersJSONFormatInfo( + TypeConstrainedPointersEntitySummary::Name, + "JSON Format info for TypeConstrainedPointersEntitySummary"); llvm::json::Object -serializeAnalysisResult(const OperatorNewDeletePointersAnalysisResult &R, +serializeAnalysisResult(const TypeConstrainedPointersAnalysisResult &R, JSONFormat::EntityIdToJSONFn Fn) { return serializeImpl(R.Entities, Fn); } @@ -233,26 +232,25 @@ deserializeAnalysisResult(const llvm::json::Object &Data, if (!EntityIDSet) return EntityIDSet.takeError(); - std::unique_ptr<OperatorNewDeletePointersAnalysisResult> AR = - std::make_unique<OperatorNewDeletePointersAnalysisResult>(); + std::unique_ptr<TypeConstrainedPointersAnalysisResult> AR = + std::make_unique<TypeConstrainedPointersAnalysisResult>(); AR->Entities = std::move(*EntityIDSet); return AR; } -JSONFormat::AnalysisResultRegistry::Add<OperatorNewDeletePointersAnalysisResult> - RegisterNewDeletePointersAnalysisResultForJSON(serializeAnalysisResult, - deserializeAnalysisResult); +JSONFormat::AnalysisResultRegistry::Add<TypeConstrainedPointersAnalysisResult> + RegisterTypeConstrainedPointersAnalysisResultForJSON( + serializeAnalysisResult, deserializeAnalysisResult); } // namespace namespace clang::ssaf { // NOLINTNEXTLINE(misc-use-internal-linkage) -volatile int OperatorNewDeletePointersAnchorSource = 0; +volatile int TypeConstrainedPointersAnchorSource = 0; } // namespace clang::ssaf -static TUSummaryExtractorRegistry::Add<OperatorNewDeletePointersExtractor> - RegisterOperatorNewDeletePointersExtractor( - OperatorNewDeletePointersEntitySummary::Name, - "Extract pointer entities in operator new/delete overloads that must " - "have a 'void*' type"); +static TUSummaryExtractorRegistry::Add<TypeConstrainedPointersExtractor> + RegisterTypeConstrainedPointersExtractor( + TypeConstrainedPointersEntitySummary::Name, + "Extract pointer entities that must retain their pointer type"); diff --git a/clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/wpa-result-empty.json b/clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/wpa-result-empty.json deleted file mode 100644 index 2aee489c6b429..0000000000000 --- a/clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/wpa-result-empty.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "id_table": [], - "results": [ - { - "analysis_name": "OperatorNewDeletePointersAnalysisResult", - "result": { - "OperatorNewDeletePointersAnalysisResult": [] - } - } - ], - "type": "WPASuite" -} diff --git a/clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/tu-summary-bad-id.json b/clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/tu-summary-bad-id.json similarity index 84% rename from clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/tu-summary-bad-id.json rename to clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/tu-summary-bad-id.json index e51268fdd7652..286826682b050 100644 --- a/clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/tu-summary-bad-id.json +++ b/clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/tu-summary-bad-id.json @@ -5,13 +5,13 @@ { "entity_id": 0, "entity_summary": { - "OperatorNewDeletePointersAnalysisResult": [ + "TypeConstrainedPointersAnalysisResult": [ "not-an-object" ] } } ], - "summary_name": "OperatorNewDeletePointers" + "summary_name": "TypeConstrainedPointers" } ], "id_table": [ diff --git a/clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/tu-summary-no-key.json b/clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/tu-summary-no-key.json similarity index 91% rename from clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/tu-summary-no-key.json rename to clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/tu-summary-no-key.json index 0ebf0c5719ede..3608117904567 100644 --- a/clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/tu-summary-no-key.json +++ b/clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/tu-summary-no-key.json @@ -9,7 +9,7 @@ } } ], - "summary_name": "OperatorNewDeletePointers" + "summary_name": "TypeConstrainedPointers" } ], "id_table": [ diff --git a/clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/tu-summary.json b/clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/tu-summary.json similarity index 90% rename from clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/tu-summary.json rename to clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/tu-summary.json index 1af51091706e6..a6231439888c5 100644 --- a/clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/tu-summary.json +++ b/clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/tu-summary.json @@ -5,7 +5,7 @@ { "entity_id": 0, "entity_summary": { - "OperatorNewDeletePointersAnalysisResult": [ + "TypeConstrainedPointersAnalysisResult": [ { "@": 1 }, @@ -16,7 +16,7 @@ } } ], - "summary_name": "OperatorNewDeletePointers" + "summary_name": "TypeConstrainedPointers" } ], "id_table": [ diff --git a/clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/wpa-result-bad-id.json b/clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/wpa-result-bad-id.json similarity index 53% rename from clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/wpa-result-bad-id.json rename to clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/wpa-result-bad-id.json index db3209c18028e..519ab894cb20d 100644 --- a/clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/wpa-result-bad-id.json +++ b/clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/wpa-result-bad-id.json @@ -2,9 +2,9 @@ "id_table": [], "results": [ { - "analysis_name": "OperatorNewDeletePointersAnalysisResult", + "analysis_name": "TypeConstrainedPointersAnalysisResult", "result": { - "OperatorNewDeletePointersAnalysisResult": [ + "TypeConstrainedPointersAnalysisResult": [ "not-an-object" ] } diff --git a/clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/wpa-result-empty.json b/clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/wpa-result-empty.json new file mode 100644 index 0000000000000..6b396740438f9 --- /dev/null +++ b/clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/wpa-result-empty.json @@ -0,0 +1,12 @@ +{ + "id_table": [], + "results": [ + { + "analysis_name": "TypeConstrainedPointersAnalysisResult", + "result": { + "TypeConstrainedPointersAnalysisResult": [] + } + } + ], + "type": "WPASuite" +} diff --git a/clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/wpa-result-no-key.json b/clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/wpa-result-no-key.json similarity index 65% rename from clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/wpa-result-no-key.json rename to clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/wpa-result-no-key.json index 262bef0bc96ec..ece27ea2a3410 100644 --- a/clang/test/Analysis/Scalable/OperatorNewDelete/Inputs/wpa-result-no-key.json +++ b/clang/test/Analysis/Scalable/TypeConstrainedPointers/Inputs/wpa-result-no-key.json @@ -2,7 +2,7 @@ "id_table": [], "results": [ { - "analysis_name": "OperatorNewDeletePointersAnalysisResult", + "analysis_name": "TypeConstrainedPointersAnalysisResult", "result": { "WrongKey": [] } diff --git a/clang/test/Analysis/Scalable/OperatorNewDelete/tu-summary-serialization.test b/clang/test/Analysis/Scalable/TypeConstrainedPointers/tu-summary-serialization.test similarity index 81% rename from clang/test/Analysis/Scalable/OperatorNewDelete/tu-summary-serialization.test rename to clang/test/Analysis/Scalable/TypeConstrainedPointers/tu-summary-serialization.test index acb5c802cadb6..047fa993cd6cd 100644 --- a/clang/test/Analysis/Scalable/OperatorNewDelete/tu-summary-serialization.test +++ b/clang/test/Analysis/Scalable/TypeConstrainedPointers/tu-summary-serialization.test @@ -4,10 +4,10 @@ // Negative tests: -// Missing the OperatorNewDeletePointersAnalysisResult key in the entity summary. +// Missing the TypeConstrainedPointersAnalysisResult key in the entity summary. // RUN: not clang-ssaf-format -type=tu %S/Inputs/tu-summary-no-key.json 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECK-MISSING-KEY -// CHECK-MISSING-KEY: saw an object of 1 key(s) but expected An object with a key OperatorNewDeletePointersAnalysisResult +// CHECK-MISSING-KEY: saw an object of 1 key(s) but expected An object with a key TypeConstrainedPointersAnalysisResult // Array element is not an object. // RUN: not clang-ssaf-format -type=tu %S/Inputs/tu-summary-bad-id.json 2>&1 \ diff --git a/clang/test/Analysis/Scalable/OperatorNewDelete/operator-new-delete.cpp b/clang/test/Analysis/Scalable/TypeConstrainedPointers/type-constrained-pointers.cpp similarity index 90% rename from clang/test/Analysis/Scalable/OperatorNewDelete/operator-new-delete.cpp rename to clang/test/Analysis/Scalable/TypeConstrainedPointers/type-constrained-pointers.cpp index 30e3e9caef9c2..2d2e39824e016 100644 --- a/clang/test/Analysis/Scalable/OperatorNewDelete/operator-new-delete.cpp +++ b/clang/test/Analysis/Scalable/TypeConstrainedPointers/type-constrained-pointers.cpp @@ -1,16 +1,16 @@ -// End-to-end test of the operator new/delete pointer analysis. +// End-to-end test of the Type Constrained Pointers analysis. // RUN: rm -rf %t && mkdir -p %t // RUN: %clang_cc1 -fsyntax-only %s \ -// RUN: --ssaf-extract-summaries=OperatorNewDeletePointers \ +// RUN: --ssaf-extract-summaries=TypeConstrainedPointers \ // RUN: --ssaf-tu-summary-file=%t/tu.summary.json \ // RUN: --ssaf-compilation-unit-id="tu-1" // RUN: clang-ssaf-linker %t/tu.summary.json -o %t/lu.json // RUN: clang-ssaf-analyzer %t/lu.json -o %t/wpa.json \ -// RUN: -a OperatorNewDeletePointersAnalysisResult +// RUN: -a TypeConstrainedPointersAnalysisResult // RUN: FileCheck %s --input-file=%t/wpa.json @@ -46,7 +46,7 @@ void operator delete(void *ptr, void *placement) noexcept {} // CHECK-DAG: "id": [[DEL_PLACE_PTR_ID:[0-9]+]],{{([^]]|[[:space:]])+\],[[:space:]]+"suffix": "1",[[:space:]]+"usr": }}"c:@F@operator delete#*v#S0_#" // CHECK-DAG: "id": [[DEL_PLACE_PARAM_ID:[0-9]+]],{{([^]]|[[:space:]])+\],[[:space:]]+"suffix": "2",[[:space:]]+"usr": }}"c:@F@operator delete#*v#S0_#" -// CHECK: "analysis_name": "OperatorNewDeletePointersAnalysisResult" +// CHECK: "analysis_name": "TypeConstrainedPointersAnalysisResult" // CHECK-DAG: "@": [[NEW_RET_ID]] // CHECK-DAG: "@": [[NEW_PLACE_RET_ID]] diff --git a/clang/test/Analysis/Scalable/OperatorNewDelete/wpa-result-serialization.test b/clang/test/Analysis/Scalable/TypeConstrainedPointers/wpa-result-serialization.test similarity index 77% rename from clang/test/Analysis/Scalable/OperatorNewDelete/wpa-result-serialization.test rename to clang/test/Analysis/Scalable/TypeConstrainedPointers/wpa-result-serialization.test index 0aca3af29a5c8..ae2d09e021227 100644 --- a/clang/test/Analysis/Scalable/OperatorNewDelete/wpa-result-serialization.test +++ b/clang/test/Analysis/Scalable/TypeConstrainedPointers/wpa-result-serialization.test @@ -5,13 +5,13 @@ // Generate wpa.json from the C++ source file so the test stays in sync with // the extractor output rather than relying on a hand-crafted snapshot. -// RUN: %clang_cc1 -fsyntax-only %S/operator-new-delete.cpp \ -// RUN: --ssaf-extract-summaries=OperatorNewDeletePointers \ +// RUN: %clang_cc1 -fsyntax-only %S/type-constrained-pointers.cpp \ +// RUN: --ssaf-extract-summaries=TypeConstrainedPointers \ // RUN: --ssaf-tu-summary-file=%t/tu.summary.json \ // RUN: --ssaf-compilation-unit-id="tu-1" // RUN: clang-ssaf-linker %t/tu.summary.json -o %t/lu.json // RUN: clang-ssaf-analyzer %t/lu.json -o %t/wpa.json \ -// RUN: -a OperatorNewDeletePointersAnalysisResult +// RUN: -a TypeConstrainedPointersAnalysisResult // RUN: clang-ssaf-format --type wpa %t/wpa.json -o %t/wpa-round-trip.json // RUN: diff %t/wpa.json %t/wpa-round-trip.json @@ -20,12 +20,12 @@ // Negative tests: -// Missing the OperatorNewDeletePointersAnalysisResult key in the result object. +// Missing the TypeConstrainedPointersAnalysisResult key in the result object. // RUN: not clang-ssaf-format --type wpa %S/Inputs/wpa-result-no-key.json 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECK-MISSING-KEY -// CHECK-MISSING-KEY: saw an object of 1 key(s) but expected An object with a key OperatorNewDeletePointersAnalysisResult +// CHECK-MISSING-KEY: saw an object of 1 key(s) but expected An object with a key TypeConstrainedPointersAnalysisResult // Array element is not an object. // RUN: not clang-ssaf-format --type wpa %S/Inputs/wpa-result-bad-id.json 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECK-BAD-ID -// CHECK-BAD-ID: saw "not-an-object" but expected an object representing EntityId +// CHECK-BAD-ID: saw "not-an-object" but expected an object representing EntityId \ No newline at end of file diff --git a/clang/unittests/ScalableStaticAnalysis/Analyses/OperatorNewDelete/OperatorNewDeletePointersExtractorTest.cpp b/clang/unittests/ScalableStaticAnalysis/Analyses/TypeConstrainedPointers/TypeConstrainedPointersExtractorTest.cpp similarity index 85% rename from clang/unittests/ScalableStaticAnalysis/Analyses/OperatorNewDelete/OperatorNewDeletePointersExtractorTest.cpp rename to clang/unittests/ScalableStaticAnalysis/Analyses/TypeConstrainedPointers/TypeConstrainedPointersExtractorTest.cpp index 055e599e1af43..68ce35aa2a695 100644 --- a/clang/unittests/ScalableStaticAnalysis/Analyses/OperatorNewDelete/OperatorNewDeletePointersExtractorTest.cpp +++ b/clang/unittests/ScalableStaticAnalysis/Analyses/TypeConstrainedPointers/TypeConstrainedPointersExtractorTest.cpp @@ -1,4 +1,4 @@ -//===- OperatorNewDeletePointersExtractorTest.cpp -------------------------===// +//===- TypeConstrainedPointersExtractorTest.cpp ---------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -12,7 +12,7 @@ #include "clang/AST/Decl.h" #include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/SSAFOptions.h" -#include "clang/ScalableStaticAnalysis/Analyses/OperatorNewDelete/OperatorNewDeletePointers.h" +#include "clang/ScalableStaticAnalysis/Analyses/TypeConstrainedPointers/TypeConstrainedPointers.h" #include "clang/ScalableStaticAnalysis/Core/Model/EntityId.h" #include "clang/ScalableStaticAnalysis/Core/TUSummary/ExtractorRegistry.h" #include "clang/ScalableStaticAnalysis/Core/TUSummary/TUSummary.h" @@ -71,7 +71,7 @@ const SummaryT *getEntitySummary(llvm::StringRef ContributorName, return static_cast<const SummaryT *>(EntIt->second.get()); } -class OperatorNewDeletePointersExtractorTest : public ssaf::TestFixture { +class TypeConstrainedPointersExtractorTest : public ssaf::TestFixture { protected: SSAFOptions Opts; TUSummary TUSum; @@ -79,7 +79,7 @@ class OperatorNewDeletePointersExtractorTest : public ssaf::TestFixture { std::unique_ptr<TUSummaryExtractor> Extractor; std::unique_ptr<ASTUnit> AST; - OperatorNewDeletePointersExtractorTest() + TypeConstrainedPointersExtractorTest() : TUSum(llvm::Triple("arm64-apple-macosx"), BuildNamespace(BuildNamespaceKind::CompilationUnit, "Mock.cpp")), Builder(TUSum, Opts), Extractor(nullptr) {} @@ -91,22 +91,22 @@ class OperatorNewDeletePointersExtractorTest : public ssaf::TestFixture { return false; } for (auto &E : TUSummaryExtractorRegistry::entries()) { - if (E.getName() == OperatorNewDeletePointersEntitySummary::Name) { + if (E.getName() == TypeConstrainedPointersEntitySummary::Name) { Extractor = E.instantiate(Builder); break; } } if (!Extractor) { - ADD_FAILURE() << "failed to find OperatorNewDeletePointersExtractor"; + ADD_FAILURE() << "failed to find TypeConstrainedPointersExtractor"; return false; } Extractor->HandleTranslationUnit(AST->getASTContext()); return true; } - const OperatorNewDeletePointersEntitySummary * + const TypeConstrainedPointersEntitySummary * getEntitySummary(llvm::StringRef FnName) { - return ::getEntitySummary<OperatorNewDeletePointersEntitySummary>( + return ::getEntitySummary<TypeConstrainedPointersEntitySummary>( FnName, AST->getASTContext(), *Extractor, getData(TUSum)); } @@ -127,16 +127,16 @@ class OperatorNewDeletePointersExtractorTest : public ssaf::TestFixture { // Registration sanity //===----------------------------------------------------------------------===// -TEST(OperatorNewDeletePointersExtractorRegistration, ExtractorRegistered) { +TEST(TypeConstrainedPointersExtractorRegistration, ExtractorRegistered) { EXPECT_TRUE(isTUSummaryExtractorRegistered( - OperatorNewDeletePointersEntitySummary::Name)); + TypeConstrainedPointersEntitySummary::Name)); } //===----------------------------------------------------------------------===// // Extractor cases //===----------------------------------------------------------------------===// -TEST_F(OperatorNewDeletePointersExtractorTest, FreeOperatorDelete) { +TEST_F(TypeConstrainedPointersExtractorTest, FreeOperatorDelete) { ASSERT_TRUE(setUpTest(R"cpp( void operator delete(void *ptr) noexcept; void operator delete(void *ptr) noexcept { (void)ptr; } @@ -153,7 +153,7 @@ TEST_F(OperatorNewDeletePointersExtractorTest, FreeOperatorDelete) { EXPECT_EQ(*S, std::set<EntityId>{*PtrId}); } -TEST_F(OperatorNewDeletePointersExtractorTest, MemberOperatorDelete) { +TEST_F(TypeConstrainedPointersExtractorTest, MemberOperatorDelete) { ASSERT_TRUE(setUpTest(R"cpp( class T { public: @@ -171,7 +171,7 @@ TEST_F(OperatorNewDeletePointersExtractorTest, MemberOperatorDelete) { EXPECT_EQ(*S, std::set<EntityId>{*PId}); } -TEST_F(OperatorNewDeletePointersExtractorTest, OperatorDeleteArray) { +TEST_F(TypeConstrainedPointersExtractorTest, OperatorDeleteArray) { ASSERT_TRUE(setUpTest(R"cpp( void operator delete[](void *p) noexcept; void operator delete[](void *p) noexcept { (void)p; } @@ -187,7 +187,7 @@ TEST_F(OperatorNewDeletePointersExtractorTest, OperatorDeleteArray) { EXPECT_EQ(*S, std::set<EntityId>{*PId}); } -TEST_F(OperatorNewDeletePointersExtractorTest, OperatorNew) { +TEST_F(TypeConstrainedPointersExtractorTest, OperatorNew) { ASSERT_TRUE(setUpTest(R"cpp( typedef unsigned long size_t; void *operator new(size_t size); @@ -204,7 +204,7 @@ TEST_F(OperatorNewDeletePointersExtractorTest, OperatorNew) { EXPECT_EQ(*S, std::set<EntityId>{*RetId}); } -TEST_F(OperatorNewDeletePointersExtractorTest, PlacementNew) { +TEST_F(TypeConstrainedPointersExtractorTest, PlacementNew) { ASSERT_TRUE(setUpTest(R"cpp( typedef unsigned long size_t; void *operator new(size_t size, void *placement) noexcept; @@ -225,7 +225,7 @@ TEST_F(OperatorNewDeletePointersExtractorTest, PlacementNew) { EXPECT_EQ(*S, (std::set<EntityId>{*PlacementId, *RetId})); } -TEST_F(OperatorNewDeletePointersExtractorTest, PlacementDelete) { +TEST_F(TypeConstrainedPointersExtractorTest, PlacementDelete) { ASSERT_TRUE(setUpTest(R"cpp( void operator delete(void *ptr, void *placement) noexcept; void operator delete(void *ptr, void *placement) noexcept { @@ -245,14 +245,14 @@ TEST_F(OperatorNewDeletePointersExtractorTest, PlacementDelete) { EXPECT_EQ(*S, (std::set<EntityId>{*PtrId, *PlacementId})); } -TEST_F(OperatorNewDeletePointersExtractorTest, NoOperatorNewOrDeleteSummary) { +TEST_F(TypeConstrainedPointersExtractorTest, NoOperatorNewOrDeleteSummary) { ASSERT_TRUE(setUpTest(R"cpp( class T { int x; }; )cpp")); auto &TUData = getData(TUSum); auto TUSummariesIter = - TUData.find(OperatorNewDeletePointersEntitySummary::summaryName()); + TUData.find(TypeConstrainedPointersEntitySummary::summaryName()); ASSERT_EQ(TUSummariesIter, TUData.end()); } diff --git a/clang/unittests/ScalableStaticAnalysis/CMakeLists.txt b/clang/unittests/ScalableStaticAnalysis/CMakeLists.txt index 08f82876aabf1..061c8a4d9069e 100644 --- a/clang/unittests/ScalableStaticAnalysis/CMakeLists.txt +++ b/clang/unittests/ScalableStaticAnalysis/CMakeLists.txt @@ -2,7 +2,7 @@ add_distinct_clang_unittest(ClangScalableAnalysisTests Analyses/PointerFlow/PointerFlowTest.cpp Analyses/PointerFlow/PointerFlowWPATest.cpp Analyses/CallGraph/CallGraphExtractorTest.cpp - Analyses/OperatorNewDelete/OperatorNewDeletePointersExtractorTest.cpp + Analyses/TypeConstrainedPointers/TypeConstrainedPointersExtractorTest.cpp Analyses/UnsafeBufferUsage/UnsafeBufferUsageTest.cpp Analyses/UnsafeBufferUsage/UnsafeBufferUsageWPATest.cpp ASTEntityMappingTest.cpp _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
