[PATCH] D48849: [Driver][Darwin] Use Host Triple to infer target os version
Steven Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 2 16:18:41 PDT 2018
steven_wu updated this revision to Diff 153822.
steven_wu added a comment.
handle *-apple-macosx target option
Repository:
rC Clang
https://reviews.llvm.org/D48849
Files:
lib/Driver/ToolChains/Darwin.cpp
test/Driver/clang-g-opts.c
test/Driver/target-triple-deployment.c
Index: test/Driver/target-triple-deployment.c
===================================================================
--- test/Driver/target-triple-deployment.c
+++ test/Driver/target-triple-deployment.c
@@ -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
//
Index: test/Driver/clang-g-opts.c
===================================================================
--- test/Driver/clang-g-opts.c
+++ test/Driver/clang-g-opts.c
@@ -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: lib/Driver/ToolChains/Darwin.cpp
===================================================================
--- lib/Driver/ToolChains/Darwin.cpp
+++ lib/Driver/ToolChains/Darwin.cpp
@@ -1512,9 +1512,18 @@
else if (MachOArchName == "armv7k")
OSTy = llvm::Triple::WatchOS;
else if (MachOArchName != "armv6m" && MachOArchName != "armv7m" &&
- MachOArchName != "armv7em")
+ MachOArchName != "armv7em") {
+ // Default to macOS for other architectures.
OSTy = llvm::Triple::MacOSX;
+ // If there is no version specified on triple, and both host and target are
+ // macos, use the host triple to infer OS version.
+ llvm::Triple SystemTriple(llvm::sys::getProcessTriple());
+ if (SystemTriple.isMacOSX() && !Triple.getOSMajorVersion())
+ return DarwinPlatform::createFromArch(
+ OSTy, getOSVersion(OSTy, SystemTriple, TheDriver));
+ }
+
if (OSTy == llvm::Triple::UnknownOS)
return None;
return DarwinPlatform::createFromArch(OSTy,
@@ -1529,7 +1538,17 @@
if (Triple.getOS() == llvm::Triple::Darwin ||
Triple.getOS() == llvm::Triple::UnknownOS)
return None;
- std::string OSVersion = getOSVersion(Triple.getOS(), Triple, TheDriver);
+
+ // If the host and target are both macos, and the OS version is not set in
+ // the target, infer the os version from host triple.
+ std::string OSVersion;
+ llvm::Triple SystemTriple(llvm::sys::getProcessTriple());
+ if (Triple.isMacOSX() && SystemTriple.isMacOSX() &&
+ !Triple.getOSMajorVersion())
+ OSVersion = getOSVersion(SystemTriple.getOS(), SystemTriple, TheDriver);
+ else
+ OSVersion = getOSVersion(Triple.getOS(), Triple, TheDriver);
+
return DarwinPlatform::createFromTarget(Triple, OSVersion,
Args.getLastArg(options::OPT_target));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48849.153822.patch
Type: text/x-patch
Size: 3508 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180702/9e14dbca/attachment-0001.bin>
More information about the cfe-commits
mailing list