Skip to content

Commit f80b49b

Browse files
committed
Support: correct Windows normalisation
If the environment is unknown and no object file is provided, then assume an "MSVC" environment, otherwise, set the environment to the object file format. In the case that we have a known environment but a non-native file format for Windows (COFF) which is used for MCJIT, then append the custom file format to the triple as an additional component. This fixes the MCJIT tests on Windows. llvm-svn: 205130
1 parent ee4f402 commit f80b49b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

llvm/lib/Support/Triple.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ std::string Triple::normalize(StringRef Str) {
434434
if (Components.size() > 3)
435435
Environment = parseEnvironment(Components[3]);
436436
ObjectFormatType ObjectFormat = UnknownObjectFormat;
437+
if (Components.size() > 4)
438+
ObjectFormat = parseFormat(Components[4]);
437439

438440
// Note which components are already in their final position. These will not
439441
// be moved.
@@ -544,8 +546,16 @@ std::string Triple::normalize(StringRef Str) {
544546
if (OS == Triple::Win32) {
545547
Components.resize(4);
546548
Components[2] = "windows";
547-
if (Environment == UnknownEnvironment && ObjectFormat == UnknownObjectFormat)
548-
Components[3] = "msvc";
549+
if (Environment == UnknownEnvironment) {
550+
if (ObjectFormat == UnknownObjectFormat)
551+
Components[3] = "msvc";
552+
else
553+
Components[3] = getObjectFormatTypeName(ObjectFormat);
554+
} else if (ObjectFormat != UnknownObjectFormat &&
555+
ObjectFormat != Triple::COFF) {
556+
Components.resize(5);
557+
Components[4] = getObjectFormatTypeName(ObjectFormat);
558+
}
549559
} else if (OS == Triple::MinGW32) {
550560
Components.resize(4);
551561
Components[2] = "windows";

llvm/unittests/ADT/TripleTest.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,13 @@ TEST(TripleTest, FileFormat) {
513513

514514
EXPECT_EQ(Triple::COFF, Triple("i686--win32").getObjectFormat());
515515

516+
EXPECT_EQ(Triple::ELF, Triple("i686-pc-windows-msvc-elf").getObjectFormat());
517+
518+
{
519+
Triple Normalized(Triple::normalize("i686-pc-windows-msvc-elf"));
520+
EXPECT_EQ(Triple::ELF, Normalized.getObjectFormat());
521+
}
522+
516523
Triple T = Triple("");
517524
T.setObjectFormat(Triple::ELF);
518525
EXPECT_EQ(Triple::ELF, T.getObjectFormat());
@@ -546,5 +553,7 @@ TEST(TripleTest, NormalizeWindows) {
546553
EXPECT_EQ("x86_64--windows-macho", Triple::normalize("x86_64-win32-macho"));
547554

548555
EXPECT_EQ("i686-pc-windows-itanium", Triple::normalize("i686-pc-windows-itanium"));
556+
557+
EXPECT_EQ("i686-pc-windows-msvc", Triple::normalize("i686-pc-windows-msvc"));
549558
}
550559
}

0 commit comments

Comments
 (0)