[PATCH] D93338: [mac/lld] simplify code using PackedVersion instead of VersionTuple

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 15 13:38:33 PST 2020


thakis created this revision.
thakis added a reviewer: lld-macho.
thakis requested review of this revision.

PackedVersion already does the correct range checks.

No behavior change.


https://reviews.llvm.org/D93338

Files:
  lld/MachO/Driver.cpp
  lld/test/MachO/dylib-version.s


Index: lld/test/MachO/dylib-version.s
===================================================================
--- lld/test/MachO/dylib-version.s
+++ lld/test/MachO/dylib-version.s
@@ -25,19 +25,19 @@
 # RUN:     -compatibility_version 80000.1 -current_version 1.2.3 2>&1 | \
 # RUN:     FileCheck --check-prefix=BADMAJOR %s
 
-# BADMAJOR: error: -compatibility_version 80000.1: component 80000 out of range
+# BADMAJOR: error: -compatibility_version 80000.1: malformed version
 
 # RUN: not %lld -dylib -o %t/executable %t.o -o /dev/null \
 # RUN:     -compatibility_version 8.300 -current_version 1.2.3 2>&1 | \
 # RUN:     FileCheck --check-prefix=BADMINOR %s
 
-# BADMINOR: error: -compatibility_version 8.300: component 300 out of range
+# BADMINOR: error: -compatibility_version 8.300: malformed version
 
 # RUN: not %lld -dylib -o %t/executable %t.o -o /dev/null \
 # RUN:     -compatibility_version 8.8.300 -current_version 1.2.3 2>&1 | \
 # RUN:     FileCheck --check-prefix=BADSUBMINOR %s
 
-# BADSUBMINOR: error: -compatibility_version 8.8.300: component 300 out of range
+# BADSUBMINOR: error: -compatibility_version 8.8.300: malformed version
 
 # RUN: %lld -dylib -o %t/executable %t.o -o %t.dylib \
 # RUN:     -compatibility_version 1.2.3 -current_version 2.5.6
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -40,6 +40,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TarWriter.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/TextAPI/MachO/PackedVersion.h"
 
 #include <algorithm>
 
@@ -673,34 +674,13 @@
     return 0;
   }
 
-  llvm::VersionTuple version;
-  if (version.tryParse(arg->getValue()) || version.getBuild().hasValue()) {
+  PackedVersion version;
+  if (!version.parse32(arg->getValue())) {
     error(arg->getAsString(args) + ": malformed version");
     return 0;
   }
 
-  unsigned major = version.getMajor();
-  if (major > UINT16_MAX) {
-    error(arg->getAsString(args) + ": component " + Twine(major) +
-          " out of range");
-    return 0;
-  }
-
-  unsigned minor = version.getMinor().getValueOr(0);
-  if (minor > UINT8_MAX) {
-    error(arg->getAsString(args) + ": component " + Twine(minor) +
-          " out of range");
-    return 0;
-  }
-
-  unsigned subminor = version.getSubminor().getValueOr(0);
-  if (subminor > UINT8_MAX) {
-    error(arg->getAsString(args) + ": component " + Twine(subminor) +
-          " out of range");
-    return 0;
-  }
-
-  return (major << 16) | (minor << 8) | subminor;
+  return version.rawValue();
 }
 
 bool macho::link(llvm::ArrayRef<const char *> argsArr, bool canExitEarly,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93338.312020.patch
Type: text/x-patch
Size: 2687 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201215/366e65e6/attachment.bin>


More information about the llvm-commits mailing list