From: Alexandros Lamprineas Date: Wed, 28 Oct 2015 10:10:03 +0000 (+0000) Subject: When running clang with an arm triple such as '--target=thumbv7m-none-eabi' X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c3808533a1d337988abf8051e3928bc1ad7fe279;p=clang When running clang with an arm triple such as '--target=thumbv7m-none-eabi' that has a thumb only CPU by default (cortex-m3), and when using the assembler, the default thumb state of the CPU does not get passed via the triple to LLVM: $ clang -target thumbv7m-none-eabi -c -v test.s clang -cc1as ... -triple armv7m-none--eabi ... test.s Differential Revision: http://reviews.llvm.org/D14121 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@251507 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp index 2002a9ae8b..ec62fba566 100644 --- a/lib/Driver/ToolChain.cpp +++ b/lib/Driver/ToolChain.cpp @@ -23,10 +23,12 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/TargetRegistry.h" +#include "llvm/Support/TargetParser.h" using namespace clang::driver; using namespace clang::driver::tools; using namespace clang; +using namespace llvm; using namespace llvm::opt; static llvm::opt::Arg *GetRTTIArgument(const ArgList &Args) { @@ -466,9 +468,9 @@ std::string ToolChain::ComputeLLVMTriple(const ArgList &Args, : tools::arm::getARMTargetCPU(MCPU, MArch, Triple); StringRef Suffix = tools::arm::getLLVMArchSuffixForARM(CPU, MArch, Triple); - bool ThumbDefault = Suffix.startswith("v6m") || Suffix.startswith("v7m") || - Suffix.startswith("v7em") || - (Suffix.startswith("v7") && getTriple().isOSBinFormatMachO()); + bool IsMProfile = ARM::parseArchProfile(Suffix) == ARM::PK_M; + bool ThumbDefault = IsMProfile || (ARM::parseArchVersion(Suffix) == 7 && + getTriple().isOSBinFormatMachO()); // FIXME: this is invalid for WindowsCE if (getTriple().isOSWindows()) ThumbDefault = true; @@ -478,9 +480,9 @@ std::string ToolChain::ComputeLLVMTriple(const ArgList &Args, else ArchName = "arm"; - // Assembly files should start in ARM mode. - if (InputType != types::TY_PP_Asm && - Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, ThumbDefault)) + // Assembly files should start in ARM mode, unless arch is M-profile. + if (IsMProfile || (InputType != types::TY_PP_Asm && + Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, ThumbDefault))) { if (IsBigEndian) ArchName = "thumbeb"; diff --git a/test/Driver/arm-ias-Wa.s b/test/Driver/arm-ias-Wa.s index 6eadd3b841..1483f902ff 100644 --- a/test/Driver/arm-ias-Wa.s +++ b/test/Driver/arm-ias-Wa.s @@ -62,3 +62,20 @@ // RUN: | FileCheck --check-prefix=CHECK-DUP-HDIV %s // CHECK-DUP-HDIV: "-target-feature" "-hwdiv-arm" // CHECK-DUP-HDIV: "-target-feature" "+hwdiv" + +// ========================================================== Triple +// RUN: %clang -target armv7a-none-eabi -c %s -### 2>&1 \ +// RUN: %clang -target x86_64-apple-darwin -arch armv7 -c %s -### 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-A-PROFILE %s +// CHECK-A-PROFILE: "-triple" "armv7-{{.*}}" + +// RUN: %clang -target armv7r-none-eabi -c %s -### 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-R-PROFILE %s +// CHECK-R-PROFILE: "-triple" "armv7r-none--eabi" + +// RUN: %clang -target armv7m-none-eabi -c %s -### 2>&1 \ +// RUN: %clang -target thumbv7m-none-eabi -c %s -### 2>&1 \ +// RUN: %clang -target x86_64-apple-darwin -arch armv7m -c %s -### 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-M-PROFILE %s +// CHECK-M-PROFILE: "-triple" "thumbv7m-{{.*}}" +