[llvm] bdb0355 - [llvm-rc] Don't rewrite the arch in the default triple unless necessary

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 25 12:59:22 PDT 2021


Author: Martin Storsjö
Date: 2021-06-25T22:59:09+03:00
New Revision: bdb03557c05942d951e1c9b5d7033613323c3104

URL: https://github.com/llvm/llvm-project/commit/bdb03557c05942d951e1c9b5d7033613323c3104
DIFF: https://github.com/llvm/llvm-project/commit/bdb03557c05942d951e1c9b5d7033613323c3104.diff

LOG: [llvm-rc] Don't rewrite the arch in the default triple unless necessary

When the default target arch isn't one that is supported as a
windows target, we want to set a suitable architecture (so that
Clang tests that run plain 'llvm-rc' succeed checks for e.g.
"#ifdef _WIN32" even for llvm builds that default to e.g. ppc64).

But if the default target architecture is usable, don't rewrite it.
(Rewriting it, by e.g. "T.setArch(T.getArch())", normalizes the
spelling of the architecture, e.g. changing i686 to i386. Such a
change can make clang unable to find the right sysroot.)

This can't, unfortunately, practically be tested very well because
it is entirely dependent on the default triple of the llvm build.

Differential Revision: https://reviews.llvm.org/D104589

Added: 
    

Modified: 
    llvm/tools/llvm-rc/llvm-rc.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-rc/llvm-rc.cpp b/llvm/tools/llvm-rc/llvm-rc.cpp
index dc01fd0c2e9f0..0f70e30b2b38f 100644
--- a/llvm/tools/llvm-rc/llvm-rc.cpp
+++ b/llvm/tools/llvm-rc/llvm-rc.cpp
@@ -145,7 +145,7 @@ ErrorOr<std::string> findClang(const char *Argv0) {
   return Path;
 }
 
-Triple::ArchType getDefaultArch(Triple::ArchType Arch) {
+bool isUsableArch(Triple::ArchType Arch) {
   switch (Arch) {
   case Triple::x86:
   case Triple::x86_64:
@@ -154,17 +154,23 @@ Triple::ArchType getDefaultArch(Triple::ArchType Arch) {
   case Triple::aarch64:
     // These work properly with the clang driver, setting the expected
     // defines such as _WIN32 etc.
-    return Arch;
+    return true;
   default:
     // Other archs aren't set up for use with windows as target OS, (clang
-    // doesn't define e.g. _WIN32 etc), so set a reasonable default arch.
-    return Triple::x86_64;
+    // doesn't define e.g. _WIN32 etc), so with them we need to set a
+    // 
diff erent default arch.
+    return false;
   }
 }
 
+Triple::ArchType getDefaultFallbackArch() {
+  return Triple::x86_64;
+}
+
 std::string getClangClTriple() {
   Triple T(sys::getDefaultTargetTriple());
-  T.setArch(getDefaultArch(T.getArch()));
+  if (!isUsableArch(T.getArch()))
+    T.setArch(getDefaultFallbackArch());
   T.setOS(Triple::Win32);
   T.setVendor(Triple::PC);
   T.setEnvironment(Triple::MSVC);
@@ -174,7 +180,8 @@ std::string getClangClTriple() {
 
 std::string getMingwTriple() {
   Triple T(sys::getDefaultTargetTriple());
-  T.setArch(getDefaultArch(T.getArch()));
+  if (!isUsableArch(T.getArch()))
+    T.setArch(getDefaultFallbackArch());
   if (T.isWindowsGNUEnvironment())
     return T.str();
   // Write out the literal form of the vendor/env here, instead of


        


More information about the llvm-commits mailing list