summaryrefslogtreecommitdiffstats
path: root/lib/Driver/ToolChains/Darwin.cpp
diff options
context:
space:
mode:
authorSteven Wu <stevenwu@apple.com>2018-07-03 04:15:49 +0000
committerSteven Wu <stevenwu@apple.com>2018-07-03 04:15:49 +0000
commitaa3be4e3c06473db5996695a3ab9755aee5f9f9d (patch)
tree0f757686c6139267d05b6bb00245fa6453a555e4 /lib/Driver/ToolChains/Darwin.cpp
parent2a670227465c2be203f30650676da8b51715c44f (diff)
[Driver][Darwin] Use Host Triple to infer target os version
Summary: When clang required to infer target os version from --target option and the os version is not specified in targets, check the host triple. If the host and target are both macOS, use host triple to infer target os version. rdar://problem/41651999 Reviewers: arphaman, dexonsmith Reviewed By: arphaman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48849 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336168 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/ToolChains/Darwin.cpp')
-rw-r--r--lib/Driver/ToolChains/Darwin.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/Driver/ToolChains/Darwin.cpp b/lib/Driver/ToolChains/Darwin.cpp
index d0c633b120..11f77096ae 100644
--- a/lib/Driver/ToolChains/Darwin.cpp
+++ b/lib/Driver/ToolChains/Darwin.cpp
@@ -1472,10 +1472,16 @@ Optional<DarwinPlatform> inferDeploymentTargetFromSDK(DerivedArgList &Args) {
std::string getOSVersion(llvm::Triple::OSType OS, const llvm::Triple &Triple,
const Driver &TheDriver) {
unsigned Major, Minor, Micro;
+ llvm::Triple SystemTriple(llvm::sys::getProcessTriple());
switch (OS) {
case llvm::Triple::Darwin:
case llvm::Triple::MacOSX:
- if (!Triple.getMacOSXVersion(Major, Minor, Micro))
+ // If there is no version specified on triple, and both host and target are
+ // macos, use the host triple to infer OS version.
+ if (Triple.isMacOSX() && SystemTriple.isMacOSX() &&
+ !Triple.getOSMajorVersion())
+ SystemTriple.getMacOSXVersion(Major, Minor, Micro);
+ else if (!Triple.getMacOSXVersion(Major, Minor, Micro))
TheDriver.Diag(diag::err_drv_invalid_darwin_version)
<< Triple.getOSName();
break;