Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit f7f62c5

Browse files
authored
Merge pull request #18 from bob-wilson/bigger-version-numbers
Allow iOS and tvOS version numbers with 2-digit major version numbers.
2 parents 20f1151 + f07c7bd commit f7f62c5

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

lib/Basic/Targets.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,25 @@ static void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts,
155155

156156
// Set the appropriate OS version define.
157157
if (Triple.isiOS()) {
158-
assert(Maj < 10 && Min < 100 && Rev < 100 && "Invalid version!");
159-
char Str[6];
160-
Str[0] = '0' + Maj;
161-
Str[1] = '0' + (Min / 10);
162-
Str[2] = '0' + (Min % 10);
163-
Str[3] = '0' + (Rev / 10);
164-
Str[4] = '0' + (Rev % 10);
165-
Str[5] = '\0';
158+
assert(Maj < 100 && Min < 100 && Rev < 100 && "Invalid version!");
159+
char Str[7];
160+
if (Maj < 10) {
161+
Str[0] = '0' + Maj;
162+
Str[1] = '0' + (Min / 10);
163+
Str[2] = '0' + (Min % 10);
164+
Str[3] = '0' + (Rev / 10);
165+
Str[4] = '0' + (Rev % 10);
166+
Str[5] = '\0';
167+
} else {
168+
// Handle versions >= 10.
169+
Str[0] = '0' + (Maj / 10);
170+
Str[1] = '0' + (Maj % 10);
171+
Str[2] = '0' + (Min / 10);
172+
Str[3] = '0' + (Min % 10);
173+
Str[4] = '0' + (Rev / 10);
174+
Str[5] = '0' + (Rev % 10);
175+
Str[6] = '\0';
176+
}
166177
if (Triple.isTvOS())
167178
Builder.defineMacro("__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__", Str);
168179
else

lib/Driver/ToolChains.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,13 +690,13 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
690690
assert(iOSVersion && "Unknown target platform!");
691691
if (!Driver::GetReleaseVersion(iOSVersion->getValue(), Major, Minor, Micro,
692692
HadExtra) ||
693-
HadExtra || Major >= 10 || Minor >= 100 || Micro >= 100)
693+
HadExtra || Major >= 100 || Minor >= 100 || Micro >= 100)
694694
getDriver().Diag(diag::err_drv_invalid_version_number)
695695
<< iOSVersion->getAsString(Args);
696696
} else if (Platform == TvOS) {
697697
if (!Driver::GetReleaseVersion(TvOSVersion->getValue(), Major, Minor,
698698
Micro, HadExtra) || HadExtra ||
699-
Major >= 10 || Minor >= 100 || Micro >= 100)
699+
Major >= 100 || Minor >= 100 || Micro >= 100)
700700
getDriver().Diag(diag::err_drv_invalid_version_number)
701701
<< TvOSVersion->getAsString(Args);
702702
} else if (Platform == WatchOS) {

test/Frontend/darwin-version.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
// RUN: %clang_cc1 -triple armv6-apple-ios2.3.1 -dM -E -o %t %s
1111
// RUN: grep '__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__' %t | grep '20301' | count 1
1212
// RUN: not grep '__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__' %t
13+
// RUN: %clang_cc1 -triple armv7-apple-ios10.1.2 -dM -E -o %t %s
14+
// RUN: grep '__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__' %t | grep '100102' | count 1
1315
// RUN: %clang_cc1 -triple i386-apple-macosx10.4.0 -dM -E -o %t %s
1416
// RUN: grep '__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__' %t | grep '1040' | count 1
1517
// RUN: not grep '__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__' %t
@@ -32,6 +34,8 @@
3234
// RUN: grep '__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__' %t | grep '80300' | count 1
3335
// RUN: not grep '__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__' %t
3436
// RUN: not grep '__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__' %t
37+
// RUN: %clang_cc1 -triple arm64-apple-tvos10.2.3 -dM -E -o %t %s
38+
// RUN: grep '__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__' %t | grep '100203' | count 1
3539

3640
// RUN: %clang_cc1 -triple x86_64-apple-tvos8.3 -dM -E -o %t %s
3741
// RUN: grep '__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__' %t | grep '80300' | count 1

0 commit comments

Comments
 (0)