Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -939,7 +939,8 @@ /// getAArch64TargetCPU - Get the (LLVM) name of the AArch64 cpu we are /// targeting. -static std::string getAArch64TargetCPU(const ArgList &Args) { +static std::string getAArch64TargetCPU(const ArgList &Args, + bool *IsNative) { Arg *A; std::string CPU; // If we have -mtune or -mcpu, use that. @@ -950,7 +951,11 @@ CPU = Mcpu.split("+").first.lower(); } - // Handle CPU name is 'native'. + // Set IsNative if it's not null. + if (IsNative) + *IsNative = CPU == "native"; + + // Handle CPU name is 'native'. if (CPU == "native") return llvm::sys::getHostCPUName(); else if (CPU.size()) @@ -964,6 +969,10 @@ return "generic"; } +static std::string getAArch64TargetCPU(const ArgList &Args) { + return getAArch64TargetCPU(Args, nullptr); +} + void Clang::AddAArch64TargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const { std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args); @@ -2055,17 +2064,20 @@ const llvm::Triple &Triple, const ArgList &Args, std::vector &Features) { - Arg *A; - bool success = true; + Arg *A = nullptr; + bool success = true, IsNative; + std::string CPU; + // Enable NEON by default. Features.push_back("+neon"); if ((A = Args.getLastArg(options::OPT_march_EQ))) success = getAArch64ArchFeaturesFromMarch(D, A->getValue(), Args, Features); else if ((A = Args.getLastArg(options::OPT_mcpu_EQ))) success = getAArch64ArchFeaturesFromMcpu(D, A->getValue(), Args, Features); - else if (Args.hasArg(options::OPT_arch)) - success = getAArch64ArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args), Args, - Features); + else if (Args.hasArg(options::OPT_arch)) { + CPU = getAArch64TargetCPU(Args, &IsNative); + success = getAArch64ArchFeaturesFromMcpu(D, CPU, Args, Features); + } if (success && (A = Args.getLastArg(options::OPT_mtune_EQ))) success = @@ -2073,12 +2085,14 @@ else if (success && (A = Args.getLastArg(options::OPT_mcpu_EQ))) success = getAArch64MicroArchFeaturesFromMcpu(D, A->getValue(), Args, Features); - else if (Args.hasArg(options::OPT_arch)) - success = getAArch64MicroArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args), - Args, Features); + else if (Args.hasArg(options::OPT_arch)) { + CPU = getAArch64TargetCPU(Args, &IsNative); + success = getAArch64MicroArchFeaturesFromMcpu(D, CPU, Args, Features); + } if (!success) - D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args); + D.Diag(diag::err_drv_clang_unsupported) + << (A ? A->getAsString(Args) : (IsNative ? "native" : CPU)); if (Args.getLastArg(options::OPT_mgeneral_regs_only)) { Features.push_back("-fp-armv8");