[llvm] r339294 - [ADT] Normalize empty triple components
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 8 15:23:57 PDT 2018
Author: phosek
Date: Wed Aug 8 15:23:57 2018
New Revision: 339294
URL: http://llvm.org/viewvc/llvm-project?rev=339294&view=rev
Log:
[ADT] Normalize empty triple components
LLVM triple normalization is handling "unknown" and empty components
differently; for example given "x86_64-unknown-linux-gnu" and
"x86_64-linux-gnu" which should be equivalent, triple normalization
returns "x86_64-unknown-linux-gnu" and "x86_64--linux-gnu". autoconf's
config.sub returns "x86_64-unknown-linux-gnu" for both
"x86_64-linux-gnu" and "x86_64-unknown-linux-gnu". This changes the
triple normalization to behave the same way, replacing empty triple
components with "unknown".
This addresses PR37129.
Differential Revision: https://reviews.llvm.org/D50219
Modified:
llvm/trunk/lib/Support/Triple.cpp
llvm/trunk/test/CodeGen/ARM/invalid-target.ll
llvm/trunk/tools/llvm-mc/llvm-mc.cpp
llvm/trunk/tools/llvm-mca/llvm-mca.cpp
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
llvm/trunk/unittests/ADT/TripleTest.cpp
Modified: llvm/trunk/lib/Support/Triple.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Triple.cpp?rev=339294&r1=339293&r2=339294&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Triple.cpp (original)
+++ llvm/trunk/lib/Support/Triple.cpp Wed Aug 8 15:23:57 2018
@@ -887,6 +887,12 @@ std::string Triple::normalize(StringRef
}
}
+ // Replace empty components with "unknown" value.
+ for (unsigned i = 0, e = Components.size(); i < e; ++i) {
+ if (Components[i].empty())
+ Components[i] = "unknown";
+ }
+
// Special case logic goes here. At this point Arch, Vendor and OS have the
// correct values for the computed components.
std::string NormalizedEnvironment;
Modified: llvm/trunk/test/CodeGen/ARM/invalid-target.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/invalid-target.ll?rev=339294&r1=339293&r2=339294&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/invalid-target.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/invalid-target.ll Wed Aug 8 15:23:57 2018
@@ -22,11 +22,11 @@
; 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'
+; ARMVINVALID: error: unable to get target for 'armvinvalid-unknown-linux-gnueabi'
+; ARMEBVINVALID: error: unable to get target for 'armebvinvalid-unknown-linux-gnueabi'
+; THUMBVINVALID: error: unable to get target for 'thumbvinvalid-unknown-linux-gnueabi'
+; THUMBEBVINVALID: error: unable to get target for 'thumbebvinvalid-unknown-linux-gnueabi'
+; THUMBV2: error: unable to get target for 'thumbv2-unknown-linux-gnueabi'
+; THUMBV3: error: unable to get target for 'thumbv3-unknown-linux-gnueabi'
+; ARM64INVALID: error: unable to get target for 'arm64invalid-unknown-linux-gnu'
+; AARCH64INVALID: error: unable to get target for 'aarch64invalid-unknown-linux-gnu'
Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=339294&r1=339293&r2=339294&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Wed Aug 8 15:23:57 2018
@@ -313,7 +313,6 @@ int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv, "llvm machine code playground\n");
MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags();
- TripleName = Triple::normalize(TripleName);
setDwarfDebugFlags(argc, argv);
setDwarfDebugProducer();
Modified: llvm/trunk/tools/llvm-mca/llvm-mca.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/llvm-mca.cpp?rev=339294&r1=339293&r2=339294&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/llvm-mca.cpp (original)
+++ llvm/trunk/tools/llvm-mca/llvm-mca.cpp Wed Aug 8 15:23:57 2018
@@ -180,7 +180,6 @@ static cl::opt<bool>
namespace {
const Target *getTarget(const char *ProgName) {
- TripleName = Triple::normalize(TripleName);
if (TripleName.empty())
TripleName = Triple::normalize(sys::getDefaultTargetTriple());
Triple TheTriple(TripleName);
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=339294&r1=339293&r2=339294&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Wed Aug 8 15:23:57 2018
@@ -2382,7 +2382,6 @@ int main(int argc, char **argv) {
cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
cl::ParseCommandLineOptions(argc, argv, "llvm object file dumper\n");
- TripleName = Triple::normalize(TripleName);
ToolName = argv[0];
Modified: llvm/trunk/unittests/ADT/TripleTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/TripleTest.cpp?rev=339294&r1=339293&r2=339294&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/TripleTest.cpp (original)
+++ llvm/trunk/unittests/ADT/TripleTest.cpp Wed Aug 8 15:23:57 2018
@@ -378,22 +378,33 @@ TEST(TripleTest, ParsedIDs) {
}
static std::string Join(StringRef A, StringRef B, StringRef C) {
- std::string Str = A; Str += '-'; Str += B; Str += '-'; Str += C;
+ std::string Str = A;
+ Str += '-';
+ Str += B;
+ Str += '-';
+ Str += C;
return Str;
}
static std::string Join(StringRef A, StringRef B, StringRef C, StringRef D) {
- std::string Str = A; Str += '-'; Str += B; Str += '-'; Str += C; Str += '-';
- Str += D; return Str;
+ std::string Str = A;
+ Str += '-';
+ Str += B;
+ Str += '-';
+ Str += C;
+ Str += '-';
+ Str += D;
+ return Str;
}
TEST(TripleTest, Normalization) {
- EXPECT_EQ("", Triple::normalize(""));
- EXPECT_EQ("-", Triple::normalize("-"));
- EXPECT_EQ("--", Triple::normalize("--"));
- EXPECT_EQ("---", Triple::normalize("---"));
- EXPECT_EQ("----", Triple::normalize("----"));
+ EXPECT_EQ("unknown", Triple::normalize(""));
+ EXPECT_EQ("unknown-unknown", Triple::normalize("-"));
+ EXPECT_EQ("unknown-unknown-unknown", Triple::normalize("--"));
+ EXPECT_EQ("unknown-unknown-unknown-unknown", Triple::normalize("---"));
+ EXPECT_EQ("unknown-unknown-unknown-unknown-unknown",
+ Triple::normalize("----"));
EXPECT_EQ("a", Triple::normalize("a"));
EXPECT_EQ("a-b", Triple::normalize("a-b"));
@@ -406,24 +417,24 @@ TEST(TripleTest, Normalization) {
EXPECT_EQ("i386-a-b-c", Triple::normalize("a-b-c-i386"));
EXPECT_EQ("a-pc-c", Triple::normalize("a-pc-c"));
- EXPECT_EQ("-pc-b-c", Triple::normalize("pc-b-c"));
+ EXPECT_EQ("unknown-pc-b-c", Triple::normalize("pc-b-c"));
EXPECT_EQ("a-pc-b", Triple::normalize("a-b-pc"));
EXPECT_EQ("a-pc-b-c", Triple::normalize("a-b-c-pc"));
EXPECT_EQ("a-b-linux", Triple::normalize("a-b-linux"));
- EXPECT_EQ("--linux-b-c", Triple::normalize("linux-b-c"));
- EXPECT_EQ("a--linux-c", Triple::normalize("a-linux-c"));
+ EXPECT_EQ("unknown-unknown-linux-b-c", Triple::normalize("linux-b-c"));
+ EXPECT_EQ("a-unknown-linux-c", Triple::normalize("a-linux-c"));
EXPECT_EQ("i386-pc-a", Triple::normalize("a-pc-i386"));
- EXPECT_EQ("i386-pc-", Triple::normalize("-pc-i386"));
- EXPECT_EQ("-pc-linux-c", Triple::normalize("linux-pc-c"));
- EXPECT_EQ("-pc-linux", Triple::normalize("linux-pc-"));
+ EXPECT_EQ("i386-pc-unknown", Triple::normalize("-pc-i386"));
+ EXPECT_EQ("unknown-pc-linux-c", Triple::normalize("linux-pc-c"));
+ EXPECT_EQ("unknown-pc-linux", Triple::normalize("linux-pc-"));
EXPECT_EQ("i386", Triple::normalize("i386"));
- EXPECT_EQ("-pc", Triple::normalize("pc"));
- EXPECT_EQ("--linux", Triple::normalize("linux"));
+ EXPECT_EQ("unknown-pc", Triple::normalize("pc"));
+ EXPECT_EQ("unknown-unknown-linux", Triple::normalize("linux"));
- EXPECT_EQ("x86_64--linux-gnu", Triple::normalize("x86_64-gnu-linux"));
+ EXPECT_EQ("x86_64-unknown-linux-gnu", Triple::normalize("x86_64-gnu-linux"));
// Check that normalizing a permutated set of valid components returns a
// triple with the unpermuted components.
@@ -499,12 +510,18 @@ TEST(TripleTest, Normalization) {
// Various real-world funky triples. The value returned by GCC's config.sub
// is given in the comment.
- EXPECT_EQ("i386--windows-gnu", Triple::normalize("i386-mingw32")); // i386-pc-mingw32
- EXPECT_EQ("x86_64--linux-gnu", Triple::normalize("x86_64-linux-gnu")); // x86_64-pc-linux-gnu
- EXPECT_EQ("i486--linux-gnu", Triple::normalize("i486-linux-gnu")); // i486-pc-linux-gnu
- EXPECT_EQ("i386-redhat-linux", Triple::normalize("i386-redhat-linux")); // i386-redhat-linux-gnu
- EXPECT_EQ("i686--linux", Triple::normalize("i686-linux")); // i686-pc-linux-gnu
- EXPECT_EQ("arm-none--eabi", Triple::normalize("arm-none-eabi")); // arm-none-eabi
+ EXPECT_EQ("i386-unknown-windows-gnu",
+ Triple::normalize("i386-mingw32")); // i386-pc-mingw32
+ EXPECT_EQ("x86_64-unknown-linux-gnu",
+ Triple::normalize("x86_64-linux-gnu")); // x86_64-pc-linux-gnu
+ EXPECT_EQ("i486-unknown-linux-gnu",
+ Triple::normalize("i486-linux-gnu")); // i486-pc-linux-gnu
+ EXPECT_EQ("i386-redhat-linux",
+ Triple::normalize("i386-redhat-linux")); // i386-redhat-linux-gnu
+ EXPECT_EQ("i686-unknown-linux",
+ Triple::normalize("i686-linux")); // i686-pc-linux-gnu
+ EXPECT_EQ("arm-none-unknown-eabi",
+ Triple::normalize("arm-none-eabi")); // arm-none-eabi
}
TEST(TripleTest, MutateName) {
@@ -1077,38 +1094,46 @@ TEST(TripleTest, FileFormat) {
TEST(TripleTest, NormalizeWindows) {
EXPECT_EQ("i686-pc-windows-msvc", Triple::normalize("i686-pc-win32"));
- EXPECT_EQ("i686--windows-msvc", Triple::normalize("i686-win32"));
+ EXPECT_EQ("i686-unknown-windows-msvc", Triple::normalize("i686-win32"));
EXPECT_EQ("i686-pc-windows-gnu", Triple::normalize("i686-pc-mingw32"));
- EXPECT_EQ("i686--windows-gnu", Triple::normalize("i686-mingw32"));
+ EXPECT_EQ("i686-unknown-windows-gnu", Triple::normalize("i686-mingw32"));
EXPECT_EQ("i686-pc-windows-gnu", Triple::normalize("i686-pc-mingw32-w64"));
- EXPECT_EQ("i686--windows-gnu", Triple::normalize("i686-mingw32-w64"));
+ EXPECT_EQ("i686-unknown-windows-gnu", Triple::normalize("i686-mingw32-w64"));
EXPECT_EQ("i686-pc-windows-cygnus", Triple::normalize("i686-pc-cygwin"));
- EXPECT_EQ("i686--windows-cygnus", Triple::normalize("i686-cygwin"));
+ EXPECT_EQ("i686-unknown-windows-cygnus", Triple::normalize("i686-cygwin"));
EXPECT_EQ("x86_64-pc-windows-msvc", Triple::normalize("x86_64-pc-win32"));
- EXPECT_EQ("x86_64--windows-msvc", Triple::normalize("x86_64-win32"));
+ EXPECT_EQ("x86_64-unknown-windows-msvc", Triple::normalize("x86_64-win32"));
EXPECT_EQ("x86_64-pc-windows-gnu", Triple::normalize("x86_64-pc-mingw32"));
- EXPECT_EQ("x86_64--windows-gnu", Triple::normalize("x86_64-mingw32"));
- EXPECT_EQ("x86_64-pc-windows-gnu", Triple::normalize("x86_64-pc-mingw32-w64"));
- EXPECT_EQ("x86_64--windows-gnu", Triple::normalize("x86_64-mingw32-w64"));
+ EXPECT_EQ("x86_64-unknown-windows-gnu", Triple::normalize("x86_64-mingw32"));
+ EXPECT_EQ("x86_64-pc-windows-gnu",
+ Triple::normalize("x86_64-pc-mingw32-w64"));
+ EXPECT_EQ("x86_64-unknown-windows-gnu",
+ Triple::normalize("x86_64-mingw32-w64"));
EXPECT_EQ("i686-pc-windows-elf", Triple::normalize("i686-pc-win32-elf"));
- EXPECT_EQ("i686--windows-elf", Triple::normalize("i686-win32-elf"));
+ EXPECT_EQ("i686-unknown-windows-elf", Triple::normalize("i686-win32-elf"));
EXPECT_EQ("i686-pc-windows-macho", Triple::normalize("i686-pc-win32-macho"));
- EXPECT_EQ("i686--windows-macho", Triple::normalize("i686-win32-macho"));
+ EXPECT_EQ("i686-unknown-windows-macho",
+ Triple::normalize("i686-win32-macho"));
EXPECT_EQ("x86_64-pc-windows-elf", Triple::normalize("x86_64-pc-win32-elf"));
- EXPECT_EQ("x86_64--windows-elf", Triple::normalize("x86_64-win32-elf"));
- EXPECT_EQ("x86_64-pc-windows-macho", Triple::normalize("x86_64-pc-win32-macho"));
- EXPECT_EQ("x86_64--windows-macho", Triple::normalize("x86_64-win32-macho"));
+ EXPECT_EQ("x86_64-unknown-windows-elf",
+ Triple::normalize("x86_64-win32-elf"));
+ EXPECT_EQ("x86_64-pc-windows-macho",
+ Triple::normalize("x86_64-pc-win32-macho"));
+ EXPECT_EQ("x86_64-unknown-windows-macho",
+ Triple::normalize("x86_64-win32-macho"));
EXPECT_EQ("i686-pc-windows-cygnus",
Triple::normalize("i686-pc-windows-cygnus"));
EXPECT_EQ("i686-pc-windows-gnu", Triple::normalize("i686-pc-windows-gnu"));
- EXPECT_EQ("i686-pc-windows-itanium", Triple::normalize("i686-pc-windows-itanium"));
+ EXPECT_EQ("i686-pc-windows-itanium",
+ Triple::normalize("i686-pc-windows-itanium"));
EXPECT_EQ("i686-pc-windows-msvc", Triple::normalize("i686-pc-windows-msvc"));
- EXPECT_EQ("i686-pc-windows-elf", Triple::normalize("i686-pc-windows-elf-elf"));
+ EXPECT_EQ("i686-pc-windows-elf",
+ Triple::normalize("i686-pc-windows-elf-elf"));
}
TEST(TripleTest, getARMCPUForArch) {
@@ -1175,14 +1200,22 @@ TEST(TripleTest, getARMCPUForArch) {
}
TEST(TripleTest, NormalizeARM) {
- EXPECT_EQ("armv6--netbsd-eabi", Triple::normalize("armv6-netbsd-eabi"));
- EXPECT_EQ("armv7--netbsd-eabi", Triple::normalize("armv7-netbsd-eabi"));
- EXPECT_EQ("armv6eb--netbsd-eabi", Triple::normalize("armv6eb-netbsd-eabi"));
- EXPECT_EQ("armv7eb--netbsd-eabi", Triple::normalize("armv7eb-netbsd-eabi"));
- EXPECT_EQ("armv6--netbsd-eabihf", Triple::normalize("armv6-netbsd-eabihf"));
- EXPECT_EQ("armv7--netbsd-eabihf", Triple::normalize("armv7-netbsd-eabihf"));
- EXPECT_EQ("armv6eb--netbsd-eabihf", Triple::normalize("armv6eb-netbsd-eabihf"));
- EXPECT_EQ("armv7eb--netbsd-eabihf", Triple::normalize("armv7eb-netbsd-eabihf"));
+ EXPECT_EQ("armv6-unknown-netbsd-eabi",
+ Triple::normalize("armv6-netbsd-eabi"));
+ EXPECT_EQ("armv7-unknown-netbsd-eabi",
+ Triple::normalize("armv7-netbsd-eabi"));
+ EXPECT_EQ("armv6eb-unknown-netbsd-eabi",
+ Triple::normalize("armv6eb-netbsd-eabi"));
+ EXPECT_EQ("armv7eb-unknown-netbsd-eabi",
+ Triple::normalize("armv7eb-netbsd-eabi"));
+ EXPECT_EQ("armv6-unknown-netbsd-eabihf",
+ Triple::normalize("armv6-netbsd-eabihf"));
+ EXPECT_EQ("armv7-unknown-netbsd-eabihf",
+ Triple::normalize("armv7-netbsd-eabihf"));
+ EXPECT_EQ("armv6eb-unknown-netbsd-eabihf",
+ Triple::normalize("armv6eb-netbsd-eabihf"));
+ EXPECT_EQ("armv7eb-unknown-netbsd-eabihf",
+ Triple::normalize("armv7eb-netbsd-eabihf"));
EXPECT_EQ("armv7-suse-linux-gnueabihf",
Triple::normalize("armv7-suse-linux-gnueabi"));
More information about the llvm-commits
mailing list