[llvm][TextAPI] only compare deployment version for InterfaceFile.
authorCyndy Ishida <cyndy_ishida@apple.com>
Sat, 1 Apr 2023 15:28:48 +0000 (08:28 -0700)
committerCyndy Ishida <cyndy_ishida@apple.com>
Sat, 1 Apr 2023 15:38:30 +0000 (08:38 -0700)
llvm/include/llvm/TextAPI/Platform.h
llvm/include/llvm/TextAPI/Target.h
llvm/lib/TextAPI/InterfaceFile.cpp
llvm/lib/TextAPI/Target.cpp
llvm/tools/llvm-tapi-diff/DiffEngine.cpp

index 834f833..d828d9a 100644 (file)
@@ -20,6 +20,7 @@ namespace llvm {
 namespace MachO {
 
 using PlatformSet = SmallSet<PlatformType, 3>;
+using PlatformVersionSet = SmallSet<std::pair<PlatformType, VersionTuple>, 3>;
 
 PlatformType mapToPlatformType(PlatformType Platform, bool WantSim);
 PlatformType mapToPlatformType(const Triple &Target);
index 87895a9..c8a1c4f 100644 (file)
@@ -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<Target> Targets);
 PlatformSet mapToPlatformSet(ArrayRef<Target> Targets);
 ArchitectureSet mapToArchitectureSet(ArrayRef<Target> Targets);
 
index 5d3cf85..8c0b659 100644 (file)
@@ -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(),
index 3914d0f..e208424 100644 (file)
@@ -58,6 +58,13 @@ raw_ostream &operator<<(raw_ostream &OS, const Target &Target) {
   return OS;
 }
 
+PlatformVersionSet mapToPlatformVersionSet(ArrayRef<Target> Targets) {
+  PlatformVersionSet Result;
+  for (const auto &Target : Targets)
+    Result.insert({Target.Platform, Target.MinDeployment});
+  return Result;
+}
+
 PlatformSet mapToPlatformSet(ArrayRef<Target> Targets) {
   PlatformSet Result;
   for (const auto &Target : Targets)
index 02642f4..ab61d69 100644 (file)
@@ -16,6 +16,7 @@
 #include "llvm/TextAPI/InterfaceFile.h"
 #include "llvm/TextAPI/Symbol.h"
 #include "llvm/TextAPI/Target.h"
+#include <iterator>
 
 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; });
 }