[PATCH] D34529: [Driver] Check that the iOS deployment target is iOS 10 or earlier if the target is 32-bit

2017-06-30 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306922: [Driver] Check that the iOS deployment target is iOS 
10 or earlier if (authored by ahatanak).

Changed prior to commit:
  https://reviews.llvm.org/D34529?vs=104958=104972#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34529

Files:
  cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
  cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
  cfe/trunk/test/Driver/darwin-version.c

Index: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
@@ -1150,6 +1150,17 @@
   Args.getLastArg(options::OPT_mwatchos_version_min_EQ,
   options::OPT_mwatchos_simulator_version_min_EQ);
 
+  unsigned Major, Minor, Micro;
+  bool HadExtra;
+
+  // iOS 10 is the maximum deployment target for 32-bit targets.
+  if (iOSVersion && getTriple().isArch32Bit() &&
+  Driver::GetReleaseVersion(iOSVersion->getValue(), Major, Minor, Micro,
+HadExtra) &&
+  Major > 10)
+getDriver().Diag(diag::err_invalid_ios_deployment_target)
+<< iOSVersion->getAsString(Args);
+
   // Add a macro to differentiate between m(iphone|tv|watch)os-version-min=X.Y and
   // -m(iphone|tv|watch)simulator-version-min=X.Y.
   if (Args.hasArg(options::OPT_mios_simulator_version_min_EQ) ||
@@ -1191,6 +1202,14 @@
 if (char *env = ::getenv("WATCHOS_DEPLOYMENT_TARGET"))
   WatchOSTarget = env;
 
+// iOS 10 is the maximum deployment target for 32-bit targets.
+if (!iOSTarget.empty() && getTriple().isArch32Bit() &&
+Driver::GetReleaseVersion(iOSTarget.c_str(), Major, Minor, Micro,
+  HadExtra) &&
+Major > 10)
+  getDriver().Diag(diag::err_invalid_ios_deployment_target)
+  << std::string("IPHONEOS_DEPLOYMENT_TARGET=") + iOSTarget;
+
 // If there is no command-line argument to specify the Target version and
 // no environment variable defined, see if we can set the default based
 // on -isysroot.
@@ -1308,8 +1327,6 @@
 llvm_unreachable("Unable to infer Darwin variant");
 
   // Set the tool chain target information.
-  unsigned Major, Minor, Micro;
-  bool HadExtra;
   if (Platform == MacOS) {
 assert((!iOSVersion && !TvOSVersion && !WatchOSVersion) &&
"Unknown target platform!");
@@ -1325,6 +1342,13 @@
 HadExtra || Major >= 100 || Minor >= 100 || Micro >= 100)
   getDriver().Diag(diag::err_drv_invalid_version_number)
   << iOSVersion->getAsString(Args);
+  // iOS 10 is the maximum deployment target for 32-bit targets. If the
+  // inferred deployment target is iOS 11 or later, set it to 10.99.
+  if (getTriple().isArch32Bit() && Major >= 11) {
+Major = 10;
+Minor = 99;
+Micro = 99;
+  }
   } else if (Platform == TvOS) {
 if (!Driver::GetReleaseVersion(TvOSVersion->getValue(), Major, Minor,
Micro, HadExtra) || HadExtra ||
Index: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
@@ -138,6 +138,9 @@
 def err_drv_lto_without_lld : Error<"LTO requires -fuse-ld=lld">;
 def err_drv_preamble_format : Error<
 "incorrect format for -preamble-bytes=N,END">;
+def err_invalid_ios_deployment_target : Error<
+  "invalid iOS deployment version '%0', iOS 10 is the maximum deployment "
+  "target for 32-bit targets">;
 def err_drv_conflicting_deployment_targets : Error<
   "conflicting deployment targets, both '%0' and '%1' are present in environment">;
 def err_arc_unsupported_on_runtime : Error<
Index: cfe/trunk/test/Driver/darwin-version.c
===
--- cfe/trunk/test/Driver/darwin-version.c
+++ cfe/trunk/test/Driver/darwin-version.c
@@ -10,6 +10,41 @@
 // RUN: %clang -target armv6-apple-darwin9 -miphoneos-version-min=3.0 -c %s -### 2>&1 | \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-IOS3 %s
 // CHECK-VERSION-IOS3: "armv6k-apple-ios3.0.0"
+
+// RUN: env IPHONEOS_DEPLOYMENT_TARGET=11.0 \
+// RUN:   %clang -target armv7-apple-ios9.0 -c -### %s 2> %t.err
+// RUN:   FileCheck --input-file=%t.err --check-prefix=CHECK-VERSION-IOS4 %s
+// CHECK-VERSION-IOS4: invalid iOS deployment version 'IPHONEOS_DEPLOYMENT_TARGET=11.0'
+
+// RUN: %clang -target armv7-apple-ios9.0 -miphoneos-version-min=11.0 -c -### %s 2> %t.err
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-VERSION-IOS5 %s
+// CHECK-VERSION-IOS5: invalid iOS deployment version '-miphoneos-version-min=11.0'
+
+// RUN: %clang -target i386-apple-darwin -mios-simulator-version-min=11.0 -c -### %s 2> %t.err
+// RUN: FileCheck --input-file=%t.err 

[PATCH] D34529: [Driver] Check that the iOS deployment target is iOS 10 or earlier if the target is 32-bit

2017-06-30 Thread Bob Wilson via Phabricator via cfe-commits
bob.wilson accepted this revision.
bob.wilson added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D34529



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34529: [Driver] Check that the iOS deployment target is iOS 10 or earlier if the target is 32-bit

2017-06-30 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 104958.
ahatanak marked an inline comment as done.
ahatanak added a comment.

Set Micro to 99 too.


https://reviews.llvm.org/D34529

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/ToolChains/Darwin.cpp
  test/Driver/darwin-version.c

Index: test/Driver/darwin-version.c
===
--- test/Driver/darwin-version.c
+++ test/Driver/darwin-version.c
@@ -10,6 +10,41 @@
 // RUN: %clang -target armv6-apple-darwin9 -miphoneos-version-min=3.0 -c %s -### 2>&1 | \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-IOS3 %s
 // CHECK-VERSION-IOS3: "armv6k-apple-ios3.0.0"
+
+// RUN: env IPHONEOS_DEPLOYMENT_TARGET=11.0 \
+// RUN:   %clang -target armv7-apple-ios9.0 -c -### %s 2> %t.err
+// RUN:   FileCheck --input-file=%t.err --check-prefix=CHECK-VERSION-IOS4 %s
+// CHECK-VERSION-IOS4: invalid iOS deployment version 'IPHONEOS_DEPLOYMENT_TARGET=11.0'
+
+// RUN: %clang -target armv7-apple-ios9.0 -miphoneos-version-min=11.0 -c -### %s 2> %t.err
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-VERSION-IOS5 %s
+// CHECK-VERSION-IOS5: invalid iOS deployment version '-miphoneos-version-min=11.0'
+
+// RUN: %clang -target i386-apple-darwin -mios-simulator-version-min=11.0 -c -### %s 2> %t.err
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-VERSION-IOS6 %s
+// CHECK-VERSION-IOS6: invalid iOS deployment version '-mios-simulator-version-min=11.0'
+
+// RUN: %clang -target armv7-apple-ios11.1 -c -### %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS7 %s
+// CHECK-VERSION-IOS7: thumbv7-apple-ios10.99.99
+
+// RUN: env IPHONEOS_DEPLOYMENT_TARGET=11.0 \
+// RUN:   %clang -target arm64-apple-ios11.0 -c -### %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-IOS8 %s
+// CHECK-VERSION-IOS8: arm64-apple-ios11.0.0
+
+// RUN: %clang -target arm64-apple-ios11.0 -miphoneos-version-min=11.0 -c -### %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS9 %s
+// CHECK-VERSION-IOS9: arm64-apple-ios11.0.0
+
+// RUN: %clang -target x86_64-apple-darwin -mios-simulator-version-min=11.0 -c -### %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS10 %s
+// CHECK-VERSION-IOS10: x86_64-apple-ios11.0.0
+
+// RUN: %clang -target arm64-apple-ios11.1 -c -### %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS11 %s
+// CHECK-VERSION-IOS11: arm64-apple-ios11.1.0
+
 // RUN: %clang -target i686-apple-darwin8 -c %s -### 2>&1 | \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-OSX4 %s
 // RUN: %clang -target i686-apple-darwin9 -mmacosx-version-min=10.4 -c %s -### 2>&1 | \
Index: lib/Driver/ToolChains/Darwin.cpp
===
--- lib/Driver/ToolChains/Darwin.cpp
+++ lib/Driver/ToolChains/Darwin.cpp
@@ -1150,6 +1150,17 @@
   Args.getLastArg(options::OPT_mwatchos_version_min_EQ,
   options::OPT_mwatchos_simulator_version_min_EQ);
 
+  unsigned Major, Minor, Micro;
+  bool HadExtra;
+
+  // iOS 10 is the maximum deployment target for 32-bit targets.
+  if (iOSVersion && getTriple().isArch32Bit() &&
+  Driver::GetReleaseVersion(iOSVersion->getValue(), Major, Minor, Micro,
+HadExtra) &&
+  Major > 10)
+getDriver().Diag(diag::err_invalid_ios_deployment_target)
+<< iOSVersion->getAsString(Args);
+
   // Add a macro to differentiate between m(iphone|tv|watch)os-version-min=X.Y and
   // -m(iphone|tv|watch)simulator-version-min=X.Y.
   if (Args.hasArg(options::OPT_mios_simulator_version_min_EQ) ||
@@ -1191,6 +1202,14 @@
 if (char *env = ::getenv("WATCHOS_DEPLOYMENT_TARGET"))
   WatchOSTarget = env;
 
+// iOS 10 is the maximum deployment target for 32-bit targets.
+if (!iOSTarget.empty() && getTriple().isArch32Bit() &&
+Driver::GetReleaseVersion(iOSTarget.c_str(), Major, Minor, Micro,
+  HadExtra) &&
+Major > 10)
+  getDriver().Diag(diag::err_invalid_ios_deployment_target)
+  << std::string("IPHONEOS_DEPLOYMENT_TARGET=") + iOSTarget;
+
 // If there is no command-line argument to specify the Target version and
 // no environment variable defined, see if we can set the default based
 // on -isysroot.
@@ -1308,8 +1327,6 @@
 llvm_unreachable("Unable to infer Darwin variant");
 
   // Set the tool chain target information.
-  unsigned Major, Minor, Micro;
-  bool HadExtra;
   if (Platform == MacOS) {
 assert((!iOSVersion && !TvOSVersion && !WatchOSVersion) &&
"Unknown target platform!");
@@ -1325,6 +1342,13 @@
 HadExtra || Major >= 100 || Minor >= 100 || Micro >= 100)
   getDriver().Diag(diag::err_drv_invalid_version_number)
   << iOSVersion->getAsString(Args);
+  // iOS 10 is the maximum deployment target for 32-bit targets. If the
+  // inferred deployment target is iOS 11 or later, set it to 10.99.
+  if 

[PATCH] D34529: [Driver] Check that the iOS deployment target is iOS 10 or earlier if the target is 32-bit

2017-06-30 Thread Bob Wilson via Phabricator via cfe-commits
bob.wilson added inline comments.



Comment at: lib/Driver/ToolChains/Darwin.cpp:1350
+Minor = 99;
+  }
   } else if (Platform == TvOS) {

What about Micro = 99?


https://reviews.llvm.org/D34529



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34529: [Driver] Check that the iOS deployment target is iOS 10 or earlier if the target is 32-bit

2017-06-30 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 104906.
ahatanak added a comment.

Address review comments.

- Change the error message from "invalid iOS deployment version '%0', maximum 
allowable version is iOS 10" to "invalid iOS deployment version '%0', iOS 10 is 
the maximum deployment target for 32-bit targets"

- If the inferred version is iOS 11 or later, reset it to 10.99.


https://reviews.llvm.org/D34529

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/ToolChains/Darwin.cpp
  test/Driver/darwin-version.c

Index: test/Driver/darwin-version.c
===
--- test/Driver/darwin-version.c
+++ test/Driver/darwin-version.c
@@ -10,6 +10,41 @@
 // RUN: %clang -target armv6-apple-darwin9 -miphoneos-version-min=3.0 -c %s -### 2>&1 | \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-IOS3 %s
 // CHECK-VERSION-IOS3: "armv6k-apple-ios3.0.0"
+
+// RUN: env IPHONEOS_DEPLOYMENT_TARGET=11.0 \
+// RUN:   %clang -target armv7-apple-ios9.0 -c -### %s 2> %t.err
+// RUN:   FileCheck --input-file=%t.err --check-prefix=CHECK-VERSION-IOS4 %s
+// CHECK-VERSION-IOS4: invalid iOS deployment version 'IPHONEOS_DEPLOYMENT_TARGET=11.0'
+
+// RUN: %clang -target armv7-apple-ios9.0 -miphoneos-version-min=11.0 -c -### %s 2> %t.err
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-VERSION-IOS5 %s
+// CHECK-VERSION-IOS5: invalid iOS deployment version '-miphoneos-version-min=11.0'
+
+// RUN: %clang -target i386-apple-darwin -mios-simulator-version-min=11.0 -c -### %s 2> %t.err
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-VERSION-IOS6 %s
+// CHECK-VERSION-IOS6: invalid iOS deployment version '-mios-simulator-version-min=11.0'
+
+// RUN: %clang -target armv7-apple-ios11.1 -c -### %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS7 %s
+// CHECK-VERSION-IOS7: thumbv7-apple-ios10.99.0
+
+// RUN: env IPHONEOS_DEPLOYMENT_TARGET=11.0 \
+// RUN:   %clang -target arm64-apple-ios11.0 -c -### %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-IOS8 %s
+// CHECK-VERSION-IOS8: arm64-apple-ios11.0.0
+
+// RUN: %clang -target arm64-apple-ios11.0 -miphoneos-version-min=11.0 -c -### %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS9 %s
+// CHECK-VERSION-IOS9: arm64-apple-ios11.0.0
+
+// RUN: %clang -target x86_64-apple-darwin -mios-simulator-version-min=11.0 -c -### %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS10 %s
+// CHECK-VERSION-IOS10: x86_64-apple-ios11.0.0
+
+// RUN: %clang -target arm64-apple-ios11.1 -c -### %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS11 %s
+// CHECK-VERSION-IOS11: arm64-apple-ios11.1.0
+
 // RUN: %clang -target i686-apple-darwin8 -c %s -### 2>&1 | \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-OSX4 %s
 // RUN: %clang -target i686-apple-darwin9 -mmacosx-version-min=10.4 -c %s -### 2>&1 | \
Index: lib/Driver/ToolChains/Darwin.cpp
===
--- lib/Driver/ToolChains/Darwin.cpp
+++ lib/Driver/ToolChains/Darwin.cpp
@@ -1150,6 +1150,17 @@
   Args.getLastArg(options::OPT_mwatchos_version_min_EQ,
   options::OPT_mwatchos_simulator_version_min_EQ);
 
+  unsigned Major, Minor, Micro;
+  bool HadExtra;
+
+  // iOS 10 is the maximum deployment target for 32-bit targets.
+  if (iOSVersion && getTriple().isArch32Bit() &&
+  Driver::GetReleaseVersion(iOSVersion->getValue(), Major, Minor, Micro,
+HadExtra) &&
+  Major > 10)
+getDriver().Diag(diag::err_invalid_ios_deployment_target)
+<< iOSVersion->getAsString(Args);
+
   // Add a macro to differentiate between m(iphone|tv|watch)os-version-min=X.Y and
   // -m(iphone|tv|watch)simulator-version-min=X.Y.
   if (Args.hasArg(options::OPT_mios_simulator_version_min_EQ) ||
@@ -1191,6 +1202,14 @@
 if (char *env = ::getenv("WATCHOS_DEPLOYMENT_TARGET"))
   WatchOSTarget = env;
 
+// iOS 10 is the maximum deployment target for 32-bit targets.
+if (!iOSTarget.empty() && getTriple().isArch32Bit() &&
+Driver::GetReleaseVersion(iOSTarget.c_str(), Major, Minor, Micro,
+  HadExtra) &&
+Major > 10)
+  getDriver().Diag(diag::err_invalid_ios_deployment_target)
+  << std::string("IPHONEOS_DEPLOYMENT_TARGET=") + iOSTarget;
+
 // If there is no command-line argument to specify the Target version and
 // no environment variable defined, see if we can set the default based
 // on -isysroot.
@@ -1308,8 +1327,6 @@
 llvm_unreachable("Unable to infer Darwin variant");
 
   // Set the tool chain target information.
-  unsigned Major, Minor, Micro;
-  bool HadExtra;
   if (Platform == MacOS) {
 assert((!iOSVersion && !TvOSVersion && !WatchOSVersion) &&
"Unknown target platform!");
@@ -1325,6 +1342,12 @@
 HadExtra || Major >= 100 || Minor >= 100 || Micro >= 100)
   

[PATCH] D34529: [Driver] Check that the iOS deployment target is iOS 10 or earlier if the target is 32-bit

2017-06-29 Thread Bob Wilson via Phabricator via cfe-commits
bob.wilson added a comment.

The proposed error message does not provide any information about why the 
version is invalid. That could be confusing. Your comment in the code is more 
clear: "iOS 10 is the maximum deployment target for 32-bit targets". Can you 
say something like that in the error message?

In the case where the version is inferred from the SDK, you're resetting 
Major=10 but leaving Minor and Micro unchanged. That seems wrong. Those should 
be set to the most recent release of iOS 10. Perhaps you could set those to big 
numbers, e.g., 99, so that they are sure to include any future iOS 10 releases.


https://reviews.llvm.org/D34529



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34529: [Driver] Check that the iOS deployment target is iOS 10 or earlier if the target is 32-bit

2017-06-22 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak created this revision.

The following changes are made to the driver since 32-bit apps do not run on 
iOS 11 or later:

- If the deployment target is set explicitly, either with a command-line option 
or an environment variable, the driver should report an error if the version is 
greater than iOS 10.

- In the case where the deployment target is not set explicitly and the default 
is inferred from the target triple or SDK version, it should use a maximum 
default of iOS 10.

rdar://problem/32230613


https://reviews.llvm.org/D34529

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/ToolChains/Darwin.cpp
  test/Driver/darwin-version.c

Index: test/Driver/darwin-version.c
===
--- test/Driver/darwin-version.c
+++ test/Driver/darwin-version.c
@@ -10,6 +10,41 @@
 // RUN: %clang -target armv6-apple-darwin9 -miphoneos-version-min=3.0 -c %s -### 2>&1 | \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-IOS3 %s
 // CHECK-VERSION-IOS3: "armv6k-apple-ios3.0.0"
+
+// RUN: env IPHONEOS_DEPLOYMENT_TARGET=11.0 \
+// RUN:   %clang -target armv7-apple-ios9.0 -c -### %s 2> %t.err
+// RUN:   FileCheck --input-file=%t.err --check-prefix=CHECK-VERSION-IOS4 %s
+// CHECK-VERSION-IOS4: invalid iOS deployment version 'IPHONEOS_DEPLOYMENT_TARGET=11.0'
+
+// RUN: %clang -target armv7-apple-ios9.0 -miphoneos-version-min=11.0 -c -### %s 2> %t.err
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-VERSION-IOS5 %s
+// CHECK-VERSION-IOS5: invalid iOS deployment version '-miphoneos-version-min=11.0'
+
+// RUN: %clang -target i386-apple-darwin -mios-simulator-version-min=11.0 -c -### %s 2> %t.err
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-VERSION-IOS6 %s
+// CHECK-VERSION-IOS6: invalid iOS deployment version '-mios-simulator-version-min=11.0'
+
+// RUN: %clang -target armv7-apple-ios11.1 -c -### %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS7 %s
+// CHECK-VERSION-IOS7: thumbv7-apple-ios10.1.0
+
+// RUN: env IPHONEOS_DEPLOYMENT_TARGET=11.0 \
+// RUN:   %clang -target arm64-apple-ios11.0 -c -### %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-IOS8 %s
+// CHECK-VERSION-IOS8: arm64-apple-ios11.0.0
+
+// RUN: %clang -target arm64-apple-ios11.0 -miphoneos-version-min=11.0 -c -### %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS9 %s
+// CHECK-VERSION-IOS9: arm64-apple-ios11.0.0
+
+// RUN: %clang -target x86_64-apple-darwin -mios-simulator-version-min=11.0 -c -### %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS10 %s
+// CHECK-VERSION-IOS10: x86_64-apple-ios11.0.0
+
+// RUN: %clang -target arm64-apple-ios11.1 -c -### %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS11 %s
+// CHECK-VERSION-IOS11: arm64-apple-ios11.1.0
+
 // RUN: %clang -target i686-apple-darwin8 -c %s -### 2>&1 | \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-OSX4 %s
 // RUN: %clang -target i686-apple-darwin9 -mmacosx-version-min=10.4 -c %s -### 2>&1 | \
Index: lib/Driver/ToolChains/Darwin.cpp
===
--- lib/Driver/ToolChains/Darwin.cpp
+++ lib/Driver/ToolChains/Darwin.cpp
@@ -1150,6 +1150,17 @@
   Args.getLastArg(options::OPT_mwatchos_version_min_EQ,
   options::OPT_mwatchos_simulator_version_min_EQ);
 
+  unsigned Major, Minor, Micro;
+  bool HadExtra;
+
+  // iOS 10 is the maximum deployment target for 32-bit targets.
+  if (iOSVersion && getTriple().isArch32Bit() &&
+  Driver::GetReleaseVersion(iOSVersion->getValue(), Major, Minor, Micro,
+HadExtra) &&
+  Major > 10)
+getDriver().Diag(diag::err_invalid_ios_deployment_target)
+<< iOSVersion->getAsString(Args);
+
   // Add a macro to differentiate between m(iphone|tv|watch)os-version-min=X.Y and
   // -m(iphone|tv|watch)simulator-version-min=X.Y.
   if (Args.hasArg(options::OPT_mios_simulator_version_min_EQ) ||
@@ -1191,6 +1202,14 @@
 if (char *env = ::getenv("WATCHOS_DEPLOYMENT_TARGET"))
   WatchOSTarget = env;
 
+// iOS 10 is the maximum deployment target for 32-bit targets.
+if (!iOSTarget.empty() && getTriple().isArch32Bit() &&
+Driver::GetReleaseVersion(iOSTarget.c_str(), Major, Minor, Micro,
+  HadExtra) &&
+Major > 10)
+  getDriver().Diag(diag::err_invalid_ios_deployment_target)
+  << std::string("IPHONEOS_DEPLOYMENT_TARGET=") + iOSTarget;
+
 // If there is no command-line argument to specify the Target version and
 // no environment variable defined, see if we can set the default based
 // on -isysroot.
@@ -1308,8 +1327,6 @@
 llvm_unreachable("Unable to infer Darwin variant");
 
   // Set the tool chain target information.
-  unsigned Major, Minor, Micro;
-  bool HadExtra;
   if (Platform == MacOS) {
 assert((!iOSVersion && !TvOSVersion && !WatchOSVersion) &&
"Unknown target