[llvm] r222129 - Fix ARM triple parsing
Renato Golin
renato.golin at linaro.org
Mon Nov 17 06:08:57 PST 2014
Author: rengolin
Date: Mon Nov 17 08:08:57 2014
New Revision: 222129
URL: http://llvm.org/viewvc/llvm-project?rev=222129&view=rev
Log:
Fix ARM triple parsing
The triple parser should only accept existing architecture names
when the triple starts with armv, armebv, thumbv or thumbebv.
Patch by Gabor Ballabas.
Added:
llvm/trunk/test/CodeGen/ARM/invalid-target.ll
Modified:
llvm/trunk/lib/Support/Triple.cpp
Modified: llvm/trunk/lib/Support/Triple.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Triple.cpp?rev=222129&r1=222128&r2=222129&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Triple.cpp (original)
+++ llvm/trunk/lib/Support/Triple.cpp Mon Nov 17 08:08:57 2014
@@ -222,6 +222,50 @@ Triple::ArchType Triple::getArchTypeForL
.Default(UnknownArch);
}
+static Triple::ArchType parseARMArch(StringRef ArchName) {
+ size_t offset = StringRef::npos;
+ Triple::ArchType arch = Triple::UnknownArch;
+ bool isThumb = ArchName.startswith("thumb");
+
+ if (ArchName.equals("arm"))
+ return Triple::arm;
+ if (ArchName.equals("armeb"))
+ return Triple::armeb;
+ if (ArchName.equals("thumb"))
+ return Triple::thumb;
+ if (ArchName.equals("thumbeb"))
+ return Triple::thumbeb;
+ if (ArchName.equals("arm64") || ArchName.equals("aarch64"))
+ return Triple::aarch64;
+ if (ArchName.equals("aarch64_be"))
+ return Triple::aarch64_be;
+
+ if (ArchName.startswith("armv")) {
+ offset = 3;
+ arch = Triple::arm;
+ } else if (ArchName.startswith("armebv")) {
+ offset = 5;
+ arch = Triple::armeb;
+ } else if (ArchName.startswith("thumbv")) {
+ offset = 5;
+ arch = Triple::thumb;
+ } else if (ArchName.startswith("thumbebv")) {
+ offset = 7;
+ arch = Triple::thumbeb;
+ }
+ return StringSwitch<Triple::ArchType>(ArchName.substr(offset))
+ .Cases("v2", "v2a", isThumb ? Triple::UnknownArch : arch)
+ .Cases("v3", "v3m", isThumb ? Triple::UnknownArch : arch)
+ .Cases("v4", "v4t", arch)
+ .Cases("v5", "v5e", "v5t", "v5te", "v5tej", arch)
+ .Cases("v6", "v6j", "v6k", "v6m", arch)
+ .Cases("v6t2", "v6z", "v6zk", arch)
+ .Cases("v7", "v7a", "v7em", "v7l", arch)
+ .Cases("v7m", "v7r", "v7s", arch)
+ .Cases("v8", "v8a", arch)
+ .Default(Triple::UnknownArch);
+}
+
static Triple::ArchType parseArch(StringRef ArchName) {
return StringSwitch<Triple::ArchType>(ArchName)
.Cases("i386", "i486", "i586", "i686", Triple::x86)
@@ -231,19 +275,10 @@ static Triple::ArchType parseArch(String
.Case("powerpc", Triple::ppc)
.Cases("powerpc64", "ppu", Triple::ppc64)
.Case("powerpc64le", Triple::ppc64le)
- .Case("aarch64", Triple::aarch64)
- .Case("aarch64_be", Triple::aarch64_be)
- .Case("arm64", Triple::aarch64)
- .Cases("arm", "xscale", Triple::arm)
- // FIXME: It would be good to replace these with explicit names for all the
- // various suffixes supported.
- .StartsWith("armv", Triple::arm)
- .Case("armeb", Triple::armeb)
- .StartsWith("armebv", Triple::armeb)
- .Case("thumb", Triple::thumb)
- .StartsWith("thumbv", Triple::thumb)
- .Case("thumbeb", Triple::thumbeb)
- .StartsWith("thumbebv", Triple::thumbeb)
+ .Case("xscale", Triple::arm)
+ .StartsWith("arm", parseARMArch(ArchName))
+ .StartsWith("thumb", parseARMArch(ArchName))
+ .StartsWith("aarch64", parseARMArch(ArchName))
.Case("msp430", Triple::msp430)
.Cases("mips", "mipseb", "mipsallegrex", Triple::mips)
.Cases("mipsel", "mipsallegrexel", Triple::mipsel)
Added: llvm/trunk/test/CodeGen/ARM/invalid-target.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/invalid-target.ll?rev=222129&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/invalid-target.ll (added)
+++ llvm/trunk/test/CodeGen/ARM/invalid-target.ll Mon Nov 17 08:08:57 2014
@@ -0,0 +1,32 @@
+; RUN: not llc -mtriple armvinvalid-linux-gnueabi %s -o - 2>&1 | \
+; RUN: FileCheck %s --check-prefix=ARMVINVALID
+
+; RUN: not llc -mtriple armebvinvalid-linux-gnueabi %s -o - 2>&1 | \
+; RUN: FileCheck %s --check-prefix=ARMEBVINVALID
+
+; RUN: not llc -mtriple thumbvinvalid-linux-gnueabi %s -o - 2>&1 | \
+; RUN: FileCheck %s --check-prefix=THUMBVINVALID
+
+; RUN: not llc -mtriple thumbebvinvalid-linux-gnueabi %s -o - 2>&1 | \
+; RUN: FileCheck %s --check-prefix=THUMBEBVINVALID
+
+; RUN: not llc -mtriple thumbv2-linux-gnueabi %s -o - 2>&1 | \
+; RUN: FileCheck %s --check-prefix=THUMBV2
+
+; RUN: not llc -mtriple thumbv3-linux-gnueabi %s -o - 2>&1 | \
+; RUN: FileCheck %s --check-prefix=THUMBV3
+
+; RUN: not llc -mtriple arm64invalid-linux-gnu %s -o - 2>&1 | \
+; RUN: FileCheck %s --check-prefix=ARM64INVALID
+
+; RUN: not llc -mtriple aarch64invalid-linux-gnu %s -o - 2>&1 | \
+; RUN: FileCheck %s --check-prefix=AARCH64INVALID
+
+; ARMVINVALID: error: unable to get target for 'armvinvalid--linux-gnueabi'
+; ARMEBVINVALID: error: unable to get target for 'armebvinvalid--linux-gnueabi'
+; THUMBVINVALID: error: unable to get target for 'thumbvinvalid--linux-gnueabi'
+; THUMBEBVINVALID: error: unable to get target for 'thumbebvinvalid--linux-gnueabi'
+; THUMBV2: error: unable to get target for 'thumbv2--linux-gnueabi'
+; THUMBV3: error: unable to get target for 'thumbv3--linux-gnueabi'
+; ARM64INVALID: error: unable to get target for 'arm64invalid--linux-gnu'
+; AARCH64INVALID: error: unable to get target for 'aarch64invalid--linux-gnu'
More information about the llvm-commits
mailing list