From 7de8cd617b6980e0881a84e3dbfda94c3227e98a Mon Sep 17 00:00:00 2001 From: Cyndy Ishida Date: Sat, 1 Apr 2023 08:28:48 -0700 Subject: [PATCH] [llvm][TextAPI] only compare deployment version for InterfaceFile. --- llvm/include/llvm/TextAPI/Platform.h | 1 + llvm/include/llvm/TextAPI/Target.h | 9 +++------ llvm/lib/TextAPI/InterfaceFile.cpp | 2 ++ llvm/lib/TextAPI/Target.cpp | 7 +++++++ llvm/tools/llvm-tapi-diff/DiffEngine.cpp | 4 ++++ 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/llvm/include/llvm/TextAPI/Platform.h b/llvm/include/llvm/TextAPI/Platform.h index 834f833..d828d9a 100644 --- a/llvm/include/llvm/TextAPI/Platform.h +++ b/llvm/include/llvm/TextAPI/Platform.h @@ -20,6 +20,7 @@ namespace llvm { namespace MachO { using PlatformSet = SmallSet; +using PlatformVersionSet = SmallSet, 3>; PlatformType mapToPlatformType(PlatformType Platform, bool WantSim); PlatformType mapToPlatformType(const Triple &Target); diff --git a/llvm/include/llvm/TextAPI/Target.h b/llvm/include/llvm/TextAPI/Target.h index 87895a9..c8a1c4f 100644 --- a/llvm/include/llvm/TextAPI/Target.h +++ b/llvm/include/llvm/TextAPI/Target.h @@ -45,12 +45,8 @@ public: }; inline bool operator==(const Target &LHS, const Target &RHS) { - bool CrossLinkMatch = - std::tie(LHS.Arch, LHS.Platform) == std::tie(RHS.Arch, RHS.Platform); - // Ignore potential mismatches due to missing deployment versions. - if (LHS.MinDeployment.empty() || RHS.MinDeployment.empty()) - return CrossLinkMatch; - return CrossLinkMatch && LHS.MinDeployment == RHS.MinDeployment; + // In most cases the deployment version is not useful to compare. + return std::tie(LHS.Arch, LHS.Platform) == std::tie(RHS.Arch, RHS.Platform); } inline bool operator!=(const Target &LHS, const Target &RHS) { @@ -70,6 +66,7 @@ inline bool operator!=(const Target &LHS, const Architecture &RHS) { return LHS.Arch != RHS; } +PlatformVersionSet mapToPlatformVersionSet(ArrayRef Targets); PlatformSet mapToPlatformSet(ArrayRef Targets); ArchitectureSet mapToArchitectureSet(ArrayRef Targets); diff --git a/llvm/lib/TextAPI/InterfaceFile.cpp b/llvm/lib/TextAPI/InterfaceFile.cpp index 5d3cf85..8c0b659 100644 --- a/llvm/lib/TextAPI/InterfaceFile.cpp +++ b/llvm/lib/TextAPI/InterfaceFile.cpp @@ -174,6 +174,8 @@ bool InterfaceFile::operator==(const InterfaceFile &O) const { if (!(isYAMLTextStub(FileKind)) && !(isYAMLTextStub(O.FileKind))) { if (RPaths != O.RPaths) return false; + if (mapToPlatformVersionSet(Targets) != mapToPlatformVersionSet(O.Targets)) + return false; } if (!std::equal(Documents.begin(), Documents.end(), O.Documents.begin(), diff --git a/llvm/lib/TextAPI/Target.cpp b/llvm/lib/TextAPI/Target.cpp index 3914d0f..e208424 100644 --- a/llvm/lib/TextAPI/Target.cpp +++ b/llvm/lib/TextAPI/Target.cpp @@ -58,6 +58,13 @@ raw_ostream &operator<<(raw_ostream &OS, const Target &Target) { return OS; } +PlatformVersionSet mapToPlatformVersionSet(ArrayRef Targets) { + PlatformVersionSet Result; + for (const auto &Target : Targets) + Result.insert({Target.Platform, Target.MinDeployment}); + return Result; +} + PlatformSet mapToPlatformSet(ArrayRef Targets) { PlatformSet Result; for (const auto &Target : Targets) diff --git a/llvm/tools/llvm-tapi-diff/DiffEngine.cpp b/llvm/tools/llvm-tapi-diff/DiffEngine.cpp index 02642f4..ab61d69 100644 --- a/llvm/tools/llvm-tapi-diff/DiffEngine.cpp +++ b/llvm/tools/llvm-tapi-diff/DiffEngine.cpp @@ -16,6 +16,7 @@ #include "llvm/TextAPI/InterfaceFile.h" #include "llvm/TextAPI/Symbol.h" #include "llvm/TextAPI/Target.h" +#include using namespace llvm; using namespace MachO; @@ -114,6 +115,9 @@ void SymScalar::print(raw_ostream &OS, std::string Indent, MachO::Target Targ) { bool checkSymbolEquality(llvm::MachO::InterfaceFile::const_symbol_range LHS, llvm::MachO::InterfaceFile::const_symbol_range RHS) { + if (std::distance(LHS.begin(), LHS.end()) != + std::distance(RHS.begin(), RHS.end())) + return false; return std::equal(LHS.begin(), LHS.end(), RHS.begin(), [&](auto LHS, auto RHS) { return *LHS == *RHS; }); } -- 2.7.4