Triple: Make setEnvironment not override the object format
authorReid Kleckner <reid@kleckner.net>
Fri, 13 Feb 2015 22:05:50 +0000 (22:05 +0000)
committerReid Kleckner <reid@kleckner.net>
Fri, 13 Feb 2015 22:05:50 +0000 (22:05 +0000)
Discovered by Halide users who had C++ code like this:
  Triple.setArch(Triple::x86);
  Triple.setOS(Triple::Windows);
  Triple.setObjectFormat(Triple::ELF);
  Triple.setEnvironment(Triple::MSVC);

This would produce the stringified triple of x86-windows-msvc, instead
of the x86-windows-msvc-elf string needed to run MCJIT.

With this change, they retain the -elf suffix.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229160 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/Triple.cpp

index 9627f8f2f9aaa600bef09655c34872e92af71bc9..e74b23ca0cacf7a697b4bcd7759f1f98d7b4efe6 100644 (file)
@@ -816,7 +816,11 @@ void Triple::setOS(OSType Kind) {
 }
 
 void Triple::setEnvironment(EnvironmentType Kind) {
-  setEnvironmentName(getEnvironmentTypeName(Kind));
+  if (ObjectFormat == getDefaultFormat(*this))
+    return setEnvironmentName(getEnvironmentTypeName(Kind));
+
+  setEnvironmentName((getEnvironmentTypeName(Kind) + Twine("-") +
+                      getObjectFormatTypeName(ObjectFormat)).str());
 }
 
 void Triple::setObjectFormat(ObjectFormatType Kind) {