[PATCH] i686-unknown-gnu0.3 really means i686-unknown-gnu0.3-gnu.

Thomas Schwinge thomas at codesourcery.com
Mon Mar 25 09:03:00 PDT 2013


Do as the GNU tools do, a special case for GNU/Hurd: instead of using
*-*-gnu*-gnu, i686-unknown-gnu0.3 (and similar) implicitly means that the
environment is GNU.
---
 lib/Support/Triple.cpp       |    9 +++++++++
 unittests/ADT/TripleTest.cpp |   24 ++++++++++++++++++++++--
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git lib/Support/Triple.cpp lib/Support/Triple.cpp
index 7033067..2fe2f02 100644
--- lib/Support/Triple.cpp
+++ lib/Support/Triple.cpp
@@ -472,6 +472,15 @@ std::string Triple::normalize(StringRef Str) {
   // Special case logic goes here.  At this point Arch, Vendor and OS have the
   // correct values for the computed components.
 
+  // Special case for GNU/Hurd: i686-unknown-gnu0.3 (and similar) implicitly
+  // means that the environment is GNU; used instead of *-*-gnu*-gnu.
+  if (Components.size() == 3 && OS == Triple::Hurd) {
+    assert(!Found[3] && Environment == UnknownEnvironment);
+    Environment = Triple::GNU;
+    Components.push_back(getEnvironmentTypeName(Environment));
+    Found[3] = true;
+  }
+
   // Stick the corrected components back together to form the normalized string.
   std::string Normalized;
   for (unsigned i = 0, e = Components.size(); i != e; ++i) {
diff --git unittests/ADT/TripleTest.cpp unittests/ADT/TripleTest.cpp
index cff2d63..0e914ad 100644
--- unittests/ADT/TripleTest.cpp
+++ unittests/ADT/TripleTest.cpp
@@ -179,6 +179,20 @@ TEST(TripleTest, Normalization) {
   EXPECT_EQ("-pc", Triple::normalize("pc"));
   EXPECT_EQ("--linux", Triple::normalize("linux"));
 
+  // Special case for GNU/Hurd: i686-unknown-gnu0.3 (and similar) implicitly
+  // means that the environment is GNU; used instead of *-*-gnu*-gnu.
+  EXPECT_EQ("a-b-gnu-gnu", Triple::normalize("a-b-gnu"));
+  EXPECT_EQ("a-b-gnu0.3-gnu", Triple::normalize("a-b-gnu0.3"));
+  EXPECT_EQ("--gnu-b-c", Triple::normalize("gnu-b-c"));
+  EXPECT_EQ("--gnu0.3-b-c", Triple::normalize("gnu0.3-b-c"));
+  EXPECT_EQ("a--gnu-c", Triple::normalize("a-gnu-c"));
+  EXPECT_EQ("a--gnu0.3-c", Triple::normalize("a-gnu0.3-c"));
+  EXPECT_EQ("-pc-gnu-c", Triple::normalize("gnu-pc-c"));
+  EXPECT_EQ("-pc-gnu0.3-c", Triple::normalize("gnu0.3-pc-c"));
+  EXPECT_EQ("-pc-gnu-gnu", Triple::normalize("gnu-pc-"));
+  EXPECT_EQ("-pc-gnu0.3-gnu", Triple::normalize("gnu0.3-pc-"));
+  EXPECT_EQ("--gnu-gnu", Triple::normalize("gnu"));
+  EXPECT_EQ("--gnu0.3-gnu", Triple::normalize("gnu0.3"));
 
   // Check that normalizing a permutated set of valid components returns a
   // triple with the unpermuted components.
@@ -189,6 +203,12 @@ TEST(TripleTest, Normalization) {
          ++Vendor) {
       C[1] = Triple::getVendorTypeName(Triple::VendorType(Vendor));
       for (int OS = 1+Triple::UnknownOS; OS <= Triple::Minix; ++OS) {
+        // As a "gnu" OS will be extended to "gnu" OS with "gnu" Environment,
+        // there will be a lot of "failures" detected in the following, so
+        // avoid testing these combinations.
+        if (OS == Triple::Hurd)
+          continue;
+
         C[2] = Triple::getOSTypeName(Triple::OSType(OS));
 
         std::string E = Join(C[0], C[1], C[2]);
@@ -251,8 +271,8 @@ TEST(TripleTest, Normalization) {
   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--gnu", Triple::normalize("i386-gnu")); // i386-pc-gnu
-  EXPECT_EQ("i386--gnu0.3", Triple::normalize("i386-gnu0.3")); // i386-pc-gnu0.3
+  EXPECT_EQ("i386--gnu-gnu", Triple::normalize("i386-gnu")); // i386-pc-gnu
+  EXPECT_EQ("i386--gnu0.3-gnu", Triple::normalize("i386-gnu0.3")); // i386-pc-gnu0.3
 }
 
 TEST(TripleTest, MutateName) {
-- 
1.7.9.5




More information about the llvm-commits mailing list