[llvm][TextAPI] compare deployment versions for equality check
authorCyndy Ishida <cyndy_ishida@apple.com>
Fri, 31 Mar 2023 23:20:40 +0000 (16:20 -0700)
committerCyndy Ishida <cyndy_ishida@apple.com>
Fri, 31 Mar 2023 23:50:08 +0000 (16:50 -0700)
llvm/include/llvm/TextAPI/Target.h
llvm/unittests/TextAPI/TextStubV5Tests.cpp

index 0ab2783..87895a9 100644 (file)
@@ -45,15 +45,21 @@ public:
 };
 
 inline bool operator==(const Target &LHS, const Target &RHS) {
-  return std::tie(LHS.Arch, LHS.Platform) == std::tie(RHS.Arch, RHS.Platform);
+  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;
 }
 
 inline bool operator!=(const Target &LHS, const Target &RHS) {
-  return std::tie(LHS.Arch, LHS.Platform) != std::tie(RHS.Arch, RHS.Platform);
+  return !(LHS == RHS);
 }
 
 inline bool operator<(const Target &LHS, const Target &RHS) {
-  return std::tie(LHS.Arch, LHS.Platform) < std::tie(RHS.Arch, RHS.Platform);
+  return std::tie(LHS.Arch, LHS.Platform, LHS.MinDeployment) <
+         std::tie(RHS.Arch, RHS.Platform, RHS.MinDeployment);
 }
 
 inline bool operator==(const Target &LHS, const Architecture &RHS) {
index b4e8f51..5f8d3de 100644 (file)
@@ -192,8 +192,8 @@ TEST(TBDv5, ReadFile) {
 
   TargetList AllTargets = {
       Target(AK_x86_64, PLATFORM_MACOS, VersionTuple(10, 14)),
-      Target(AK_arm64, PLATFORM_MACOS, VersionTuple(10, 14)),
-      Target(AK_arm64, PLATFORM_MACCATALYST, VersionTuple(12, 1)),
+      Target(AK_arm64, PLATFORM_MACOS, VersionTuple(11, 0, 0)),
+      Target(AK_arm64, PLATFORM_MACCATALYST, VersionTuple(14, 0)),
   };
   EXPECT_EQ(mapToPlatformSet(AllTargets), File->getPlatforms());
   EXPECT_EQ(mapToArchitectureSet(AllTargets), File->getArchitectures());
@@ -926,7 +926,7 @@ TEST(TBDv5, Target_Simulator) {
   EXPECT_EQ(FileType::TBD_V5, File->getFileType());
   TargetList ExpectedTargets = {
       Target(AK_x86_64, PLATFORM_IOSSIMULATOR, VersionTuple(11, 3)),
-      Target(AK_arm64, PLATFORM_IOSSIMULATOR, VersionTuple(11, 0)),
+      Target(AK_arm64, PLATFORM_IOSSIMULATOR, VersionTuple(14, 0)),
   };
   TargetList Targets{File->targets().begin(), File->targets().end()};
   llvm::sort(Targets);