tstellar created this revision.
tstellar added reviewers: aaronpuchert, hvdijk, MaskRay.
Herald added a subscriber: pengfei.
tstellar requested review of this revision.
Herald added a project: clang.

There are some gcc triples, like x86_64-redhat-linux, that provide the
same behavior as a clang triple with a similar name (e.g.
x86_64-redhat-linux-gnu).  When searching for a gcc install, also search
for a gcc equivalent triple if one exists.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111207

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp


Index: clang/lib/Driver/ToolChains/Gnu.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1884,6 +1884,18 @@
   return GCC_INSTALL_PREFIX;
 }
 
+/// This function takes a 'clang' triple and converts it to an equivalent gcc
+/// triple.
+static const char *ConvertToGccTriple(StringRef CandidateTriple) {
+  return llvm::StringSwitch<const char *>(CandidateTriple)
+      .Case("aarch64-redhat-linux-gnu", "aarch64-redhat-linux")
+      .Case("i686-redhat-linux-gnu", "i686-redhat-linux")
+      .Case("ppc64le-redhat-linux-gnu", "ppc64le-redhat-linux")
+      .Case("s390x-redhat-linux-gnu", "s390x-redhat-linux")
+      .Case("x86_64-redhat-linux-gnu", "x86_64-redhat-linux")
+      .Default(NULL);
+}
+
 /// Initialize a GCCInstallationDetector from the driver.
 ///
 /// This performs all of the autodetection and sets up the various paths.
@@ -1904,6 +1916,16 @@
   // The compatible GCC triples for this particular architecture.
   SmallVector<StringRef, 16> CandidateTripleAliases;
   SmallVector<StringRef, 16> CandidateBiarchTripleAliases;
+
+  // In some cases gcc uses a slightly different triple than clang for the
+  // same target.  Convert the clang triple to the gcc equivalent and use that
+  // to search for the gcc install.
+  const char *ConvertedTriple = ConvertToGccTriple(TargetTriple.str());
+  if (ConvertedTriple) {
+    CandidateTripleAliases.push_back(ConvertedTriple);
+    CandidateBiarchTripleAliases.push_back(ConvertedTriple);
+  }
+
   CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs,
                            CandidateTripleAliases, CandidateBiarchLibDirs,
                            CandidateBiarchTripleAliases);


Index: clang/lib/Driver/ToolChains/Gnu.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1884,6 +1884,18 @@
   return GCC_INSTALL_PREFIX;
 }
 
+/// This function takes a 'clang' triple and converts it to an equivalent gcc
+/// triple.
+static const char *ConvertToGccTriple(StringRef CandidateTriple) {
+  return llvm::StringSwitch<const char *>(CandidateTriple)
+      .Case("aarch64-redhat-linux-gnu", "aarch64-redhat-linux")
+      .Case("i686-redhat-linux-gnu", "i686-redhat-linux")
+      .Case("ppc64le-redhat-linux-gnu", "ppc64le-redhat-linux")
+      .Case("s390x-redhat-linux-gnu", "s390x-redhat-linux")
+      .Case("x86_64-redhat-linux-gnu", "x86_64-redhat-linux")
+      .Default(NULL);
+}
+
 /// Initialize a GCCInstallationDetector from the driver.
 ///
 /// This performs all of the autodetection and sets up the various paths.
@@ -1904,6 +1916,16 @@
   // The compatible GCC triples for this particular architecture.
   SmallVector<StringRef, 16> CandidateTripleAliases;
   SmallVector<StringRef, 16> CandidateBiarchTripleAliases;
+
+  // In some cases gcc uses a slightly different triple than clang for the
+  // same target.  Convert the clang triple to the gcc equivalent and use that
+  // to search for the gcc install.
+  const char *ConvertedTriple = ConvertToGccTriple(TargetTriple.str());
+  if (ConvertedTriple) {
+    CandidateTripleAliases.push_back(ConvertedTriple);
+    CandidateBiarchTripleAliases.push_back(ConvertedTriple);
+  }
+
   CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs,
                            CandidateTripleAliases, CandidateBiarchLibDirs,
                            CandidateBiarchTripleAliases);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D111207: Driver: Add ... Tom Stellard via Phabricator via cfe-commits

Reply via email to