[clang] 565603c - [clang][driver] set macOS as the target OS for -arch arm64 when clang
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 23 21:09:02 PDT 2020
Author: Alex Lorenz
Date: 2020-06-23T21:08:11-07:00
New Revision: 565603cc94d79a8d0de6df840fd53714899fb890
URL: https://github.com/llvm/llvm-project/commit/565603cc94d79a8d0de6df840fd53714899fb890
DIFF: https://github.com/llvm/llvm-project/commit/565603cc94d79a8d0de6df840fd53714899fb890.diff
LOG: [clang][driver] set macOS as the target OS for -arch arm64 when clang
is running on an Apple Silicon mac
This change allows users to use `-arch arm64` to build for mac when
running it on Apple Silicon mac without explicit `-target` option.
Differential Revision: https://reviews.llvm.org/D82428
Added:
clang/test/Driver/apple-arm64-arch.c
clang/test/Driver/apple-silicon-arch.c
Modified:
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/lit.cfg.py
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index bb7c7f768b35..1b3a3e934995 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1672,8 +1672,16 @@ inferDeploymentTargetFromArch(DerivedArgList &Args, const Darwin &Toolchain,
llvm::Triple::OSType OSTy = llvm::Triple::UnknownOS;
StringRef MachOArchName = Toolchain.getMachOArchName(Args);
- if (MachOArchName == "armv7" || MachOArchName == "armv7s" ||
- MachOArchName == "arm64")
+ if (MachOArchName == "arm64") {
+#if __arm64__
+ // A clang running on an Apple Silicon mac defaults
+ // to building for mac when building for arm64 rather than
+ // defaulting to iOS.
+ OSTy = llvm::Triple::MacOSX;
+#else
+ OSTy = llvm::Triple::IOS;
+#endif
+ } else if (MachOArchName == "armv7" || MachOArchName == "armv7s")
OSTy = llvm::Triple::IOS;
else if (MachOArchName == "armv7k" || MachOArchName == "arm64_32")
OSTy = llvm::Triple::WatchOS;
diff --git a/clang/test/Driver/apple-arm64-arch.c b/clang/test/Driver/apple-arm64-arch.c
new file mode 100644
index 000000000000..fd9f9a2ccedb
--- /dev/null
+++ b/clang/test/Driver/apple-arm64-arch.c
@@ -0,0 +1,6 @@
+// RUN: env SDKROOT="/" %clang -arch arm64 -c -### %s 2>&1 | \
+// RUN: FileCheck %s
+//
+// XFAIL: apple-silicon-mac
+//
+// CHECK: "-triple" "arm64-apple-ios{{[0-9.]+}}"
diff --git a/clang/test/Driver/apple-silicon-arch.c b/clang/test/Driver/apple-silicon-arch.c
new file mode 100644
index 000000000000..b1201fa2d7dd
--- /dev/null
+++ b/clang/test/Driver/apple-silicon-arch.c
@@ -0,0 +1,6 @@
+// RUN: env SDKROOT="/" %clang -arch arm64 -c -### %s 2>&1 | \
+// RUN: FileCheck %s
+//
+// REQUIRES: apple-silicon-mac
+//
+// CHECK: "-triple" "arm64-apple-macosx{{[0-9.]+}}"
diff --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py
index 413f81175420..ade32988b9a8 100644
--- a/clang/test/lit.cfg.py
+++ b/clang/test/lit.cfg.py
@@ -155,6 +155,10 @@ def is_filesystem_case_insensitive():
if not re.match(r'.*-(cygwin)$', config.target_triple):
config.available_features.add('clang-driver')
+# Tests that are specific to the Apple Silicon macOS.
+if re.match(r'^arm64(e)?-apple-(macos|darwin)', config.target_triple):
+ config.available_features.add('apple-silicon-mac')
+
# [PR18856] Depends to remove opened file. On win32, a file could be removed
# only if all handles were closed.
if platform.system() not in ['Windows']:
More information about the cfe-commits
mailing list