[clang] 2a67014 - [clang][driver][darwin] Enforce consistent major version limit for any Darwin OS
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 29 13:19:05 PST 2022
Author: Alex Lorenz
Date: 2022-11-29T13:18:56-08:00
New Revision: 2a6701444af816f9048c788513abf4d2e9fa785d
URL: https://github.com/llvm/llvm-project/commit/2a6701444af816f9048c788513abf4d2e9fa785d
DIFF: https://github.com/llvm/llvm-project/commit/2a6701444af816f9048c788513abf4d2e9fa785d.diff
LOG: [clang][driver][darwin] Enforce consistent major version limit for any Darwin OS
Limit can also be bumped up to 999 to allow OS versions over 100
Added:
Modified:
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/darwin-version.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index c3a7627460ae..050b90a344a4 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -2187,17 +2187,20 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
unsigned Major, Minor, Micro;
bool HadExtra;
+ // The major version should not be over this number.
+ const unsigned MajorVersionLimit = 1000;
// Set the tool chain target information.
if (Platform == MacOS) {
if (!Driver::GetReleaseVersion(OSTarget->getOSVersion(), Major, Minor,
Micro, HadExtra) ||
- HadExtra || Major < 10 || Major >= 100 || Minor >= 100 || Micro >= 100)
+ HadExtra || Major < 10 || Major >= MajorVersionLimit || Minor >= 100 ||
+ Micro >= 100)
getDriver().Diag(diag::err_drv_invalid_version_number)
<< OSTarget->getAsString(Args, Opts);
} else if (Platform == IPhoneOS) {
if (!Driver::GetReleaseVersion(OSTarget->getOSVersion(), Major, Minor,
Micro, HadExtra) ||
- HadExtra || Major >= 100 || Minor >= 100 || Micro >= 100)
+ HadExtra || Major >= MajorVersionLimit || Minor >= 100 || Micro >= 100)
getDriver().Diag(diag::err_drv_invalid_version_number)
<< OSTarget->getAsString(Args, Opts);
;
@@ -2229,19 +2232,20 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
} else if (Platform == TvOS) {
if (!Driver::GetReleaseVersion(OSTarget->getOSVersion(), Major, Minor,
Micro, HadExtra) ||
- HadExtra || Major >= 100 || Minor >= 100 || Micro >= 100)
+ HadExtra || Major >= MajorVersionLimit || Minor >= 100 || Micro >= 100)
getDriver().Diag(diag::err_drv_invalid_version_number)
<< OSTarget->getAsString(Args, Opts);
} else if (Platform == WatchOS) {
if (!Driver::GetReleaseVersion(OSTarget->getOSVersion(), Major, Minor,
Micro, HadExtra) ||
- HadExtra || Major >= 10 || Minor >= 100 || Micro >= 100)
+ HadExtra || Major >= MajorVersionLimit || Minor >= 100 || Micro >= 100)
getDriver().Diag(diag::err_drv_invalid_version_number)
<< OSTarget->getAsString(Args, Opts);
} else if (Platform == DriverKit) {
if (!Driver::GetReleaseVersion(OSTarget->getOSVersion(), Major, Minor,
Micro, HadExtra) ||
- HadExtra || Major < 19 || Major >= 100 || Minor >= 100 || Micro >= 100)
+ HadExtra || Major < 19 || Major >= MajorVersionLimit || Minor >= 100 ||
+ Micro >= 100)
getDriver().Diag(diag::err_drv_invalid_version_number)
<< OSTarget->getAsString(Args, Opts);
} else
diff --git a/clang/test/Driver/darwin-version.c b/clang/test/Driver/darwin-version.c
index db6a81cd6542..71f3f2c4cc17 100644
--- a/clang/test/Driver/darwin-version.c
+++ b/clang/test/Driver/darwin-version.c
@@ -332,3 +332,18 @@
// RUN: FileCheck --check-prefix=CHECK-MACOS11 %s
// CHECK-MACOS11: "x86_64-apple-macosx11.0.0"
+
+// RUN: %clang -target arm64-apple-macos999 -c %s -### 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-MACOS999 %s
+
+// CHECK-MACOS999: "arm64-apple-macosx999.0.0"
+
+// RUN: %clang -target arm64-apple-watchos99 -c %s -### 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-WATCHOS99 %s
+
+// CHECK-WATCHOS99: "arm64-apple-watchos99.0.0"
+
+// RUN: not %clang -target arm64-apple-ios999999 -c %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-IOS999999 %s
+
+// CHECK-IOS999999: error: invalid version number in '-target arm64-apple-ios999999'
More information about the cfe-commits
mailing list