[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
This commit is contained in:
Alex Lorenz 2022-11-29 13:12:22 -08:00
parent 624e9e1318
commit 2a6701444a
2 changed files with 24 additions and 5 deletions

View File

@ -2187,17 +2187,20 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
unsigned Major, Minor, Micro; unsigned Major, Minor, Micro;
bool HadExtra; bool HadExtra;
// The major version should not be over this number.
const unsigned MajorVersionLimit = 1000;
// Set the tool chain target information. // Set the tool chain target information.
if (Platform == MacOS) { if (Platform == MacOS) {
if (!Driver::GetReleaseVersion(OSTarget->getOSVersion(), Major, Minor, if (!Driver::GetReleaseVersion(OSTarget->getOSVersion(), Major, Minor,
Micro, HadExtra) || 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) getDriver().Diag(diag::err_drv_invalid_version_number)
<< OSTarget->getAsString(Args, Opts); << OSTarget->getAsString(Args, Opts);
} else if (Platform == IPhoneOS) { } else if (Platform == IPhoneOS) {
if (!Driver::GetReleaseVersion(OSTarget->getOSVersion(), Major, Minor, if (!Driver::GetReleaseVersion(OSTarget->getOSVersion(), Major, Minor,
Micro, HadExtra) || Micro, HadExtra) ||
HadExtra || Major >= 100 || Minor >= 100 || Micro >= 100) HadExtra || Major >= MajorVersionLimit || Minor >= 100 || Micro >= 100)
getDriver().Diag(diag::err_drv_invalid_version_number) getDriver().Diag(diag::err_drv_invalid_version_number)
<< OSTarget->getAsString(Args, Opts); << OSTarget->getAsString(Args, Opts);
; ;
@ -2229,19 +2232,20 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
} else if (Platform == TvOS) { } else if (Platform == TvOS) {
if (!Driver::GetReleaseVersion(OSTarget->getOSVersion(), Major, Minor, if (!Driver::GetReleaseVersion(OSTarget->getOSVersion(), Major, Minor,
Micro, HadExtra) || Micro, HadExtra) ||
HadExtra || Major >= 100 || Minor >= 100 || Micro >= 100) HadExtra || Major >= MajorVersionLimit || Minor >= 100 || Micro >= 100)
getDriver().Diag(diag::err_drv_invalid_version_number) getDriver().Diag(diag::err_drv_invalid_version_number)
<< OSTarget->getAsString(Args, Opts); << OSTarget->getAsString(Args, Opts);
} else if (Platform == WatchOS) { } else if (Platform == WatchOS) {
if (!Driver::GetReleaseVersion(OSTarget->getOSVersion(), Major, Minor, if (!Driver::GetReleaseVersion(OSTarget->getOSVersion(), Major, Minor,
Micro, HadExtra) || Micro, HadExtra) ||
HadExtra || Major >= 10 || Minor >= 100 || Micro >= 100) HadExtra || Major >= MajorVersionLimit || Minor >= 100 || Micro >= 100)
getDriver().Diag(diag::err_drv_invalid_version_number) getDriver().Diag(diag::err_drv_invalid_version_number)
<< OSTarget->getAsString(Args, Opts); << OSTarget->getAsString(Args, Opts);
} else if (Platform == DriverKit) { } else if (Platform == DriverKit) {
if (!Driver::GetReleaseVersion(OSTarget->getOSVersion(), Major, Minor, if (!Driver::GetReleaseVersion(OSTarget->getOSVersion(), Major, Minor,
Micro, HadExtra) || 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) getDriver().Diag(diag::err_drv_invalid_version_number)
<< OSTarget->getAsString(Args, Opts); << OSTarget->getAsString(Args, Opts);
} else } else

View File

@ -332,3 +332,18 @@
// RUN: FileCheck --check-prefix=CHECK-MACOS11 %s // RUN: FileCheck --check-prefix=CHECK-MACOS11 %s
// CHECK-MACOS11: "x86_64-apple-macosx11.0.0" // 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'