Index: clang/lib/Driver/ToolChains/Darwin.cpp =================================================================== --- clang/lib/Driver/ToolChains/Darwin.cpp +++ clang/lib/Driver/ToolChains/Darwin.cpp @@ -1672,8 +1672,16 @@ 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; Index: clang/test/Driver/apple-arm64-arch.c =================================================================== --- /dev/null +++ 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.]+}}" Index: clang/test/Driver/apple-silicon-arch.c =================================================================== --- /dev/null +++ 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.]+}}" Index: clang/test/lit.cfg.py =================================================================== --- clang/test/lit.cfg.py +++ clang/test/lit.cfg.py @@ -155,6 +155,10 @@ 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']: Index: llvm/cmake/config.guess =================================================================== --- llvm/cmake/config.guess +++ llvm/cmake/config.guess @@ -1263,6 +1263,23 @@ UNAME_PROCESSOR="x86_64" fi fi ;; + arm) + eval $set_cc_for_build + if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then + if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + if (echo '#ifdef __PTRAUTH_INTRINSICS__'; echo HAS_AUTH; echo '#endif') | \ + (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep HAS_AUTH >/dev/null + then + UNAME_PROCESSOR="arm64e" + else + UNAME_PROCESSOR="arm64" + fi + fi + fi ;; unknown) UNAME_PROCESSOR=powerpc ;; esac echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}