]> granicus.if.org Git - clang/commitdiff
[Driver][Darwin] Use Host Triple to infer target os version
authorSteven Wu <stevenwu@apple.com>
Tue, 3 Jul 2018 04:15:49 +0000 (04:15 +0000)
committerSteven Wu <stevenwu@apple.com>
Tue, 3 Jul 2018 04:15:49 +0000 (04:15 +0000)
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

lib/Driver/ToolChains/Darwin.cpp
test/Driver/clang-g-opts.c
test/Driver/target-triple-deployment.c

index d0c633b120737a916aec8a5f3a0172e779e9a4a8..11f77096ae9d5ec6222c7137550b9a2d277e67c0 100644 (file)
@@ -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;
index a26fb29652b47fa6ec209c644170a6d91207510b..bc714b6c9379178d3d66c13c2233676cfe44cb33 100644 (file)
@@ -3,7 +3,7 @@
 // RUN:             | FileCheck --check-prefix=CHECK-WITH-G %s
 
 // Assert that the toolchains which should default to a lower Dwarf version do so.
-// RUN: %clang -### -S %s -g -target x86_64-apple-darwin 2>&1 \
+// RUN: %clang -### -S %s -g -target x86_64-apple-darwin8 2>&1 \
 // RUN:             | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
 // RUN: %clang -### -S %s -g -target i686-pc-openbsd 2>&1 \
 // RUN:             | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
@@ -21,7 +21,7 @@
 //
 // RUN: %clang -### -S %s -g0 -g -target x86_64-linux-gnu 2>&1 \
 // RUN:             | FileCheck --check-prefix=CHECK-WITH-G %s
-// RUN: %clang -### -S %s -g0 -g -target x86_64-apple-darwin 2>&1 \
+// RUN: %clang -### -S %s -g0 -g -target x86_64-apple-darwin8 2>&1 \
 // RUN:             | FileCheck --check-prefix=CHECK-WITH-G-STANDALONE %s
 // RUN: %clang -### -S %s -g0 -g -target i686-pc-openbsd 2>&1 \
 // RUN:             | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
index 4f5de59e73d83113a12d4cad2c91f0c0d197ac7c..b59f81a0106f677eedbc98bdc9e9bb46924cd6e6 100644 (file)
@@ -1,5 +1,5 @@
 // RUN: touch %t.o
-// RUN: %clang -target x86_64-apple-macosx -### %t.o 2> %t.log
+// RUN: %clang -target x86_64-apple-macosx10.4 -### %t.o 2> %t.log
 // RUN: %clang -target x86_64-apple-darwin9 -### %t.o 2>> %t.log
 // RUN: %clang -target x86_64-apple-macosx10.7 -### %t.o 2>> %t.log
 //