[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
This commit is contained in:
Alex Lorenz 2020-06-23 21:05:11 -07:00
parent 050ed9720f
commit 565603cc94
4 changed files with 26 additions and 2 deletions

View File

@ -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;

View File

@ -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.]+}}"

View File

@ -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.]+}}"

View File

@ -155,6 +155,10 @@ if not re.match(r'^x86_64.*-(windows-msvc|windows-gnu)$', config.target_triple):
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']: