diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp --- a/llvm/lib/TargetParser/Host.cpp +++ b/llvm/lib/TargetParser/Host.cpp @@ -1878,10 +1878,44 @@ bool sys::getHostCPUFeatures(StringMap &Features) { return false; } #endif +#if __APPLE__ +/// \returns the \p triple, but with the Host's arch spliced in. +static Triple withHostArch(Triple T) { +#if defined(__arm__) + T.setArch(Triple::arm); + T.setArchName("arm"); +#elif defined(__arm64e__) + T.setArch(Triple::aarch64, Triple::AArch64SubArch_arm64e); + T.setArchName("arm64e"); +#elif defined(__aarch64__) + T.setArch(Triple::aarch64); + T.setArchName("arm64"); +#elif defined(__x86_64h__) + T.setArch(Triple::x86_64); + T.setArchName("x86_64h"); +#elif defined(__x86_64__) + T.setArch(Triple::x86_64); + T.setArchName("x86_64"); +#elif defined(__powerpc__) + T.setArch(Triple::ppc); + T.setArchName("powerpc"); +#else +# error "Unimplemented host arch fixup" +#endif + return T; +} +#endif + std::string sys::getProcessTriple() { std::string TargetTripleString = updateTripleOSVersion(LLVM_HOST_TRIPLE); Triple PT(Triple::normalize(TargetTripleString)); +#if __APPLE__ + /// In Universal builds, LLVM_HOST_TRIPLE will have the wrong arch in one of + /// the slices. This fixes that up. + PT = withHostArch(PT); +#endif + if (sizeof(void *) == 8 && PT.isArch32Bit()) PT = PT.get64BitArchVariant(); if (sizeof(void *) == 4 && PT.isArch64Bit())