[llvm] [TargetParser] Recognize legacy GNU/Hurd triples (PR #214765)

Bhupesh Cholake via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 7 07:54:42 PDT 2026


https://github.com/RealBhupesh created https://github.com/llvm/llvm-project/pull/214765

Fixes #214440

### Summary

LLVM's bundled config.guess emits GNU/Hurd hosts using the legacy `*-unknown-gnu` and `*-pc-gnu` spellings. Triple normalization currently treats those as an unknown OS with a GNU environment, which makes `llvm-config --host-target` report a freestanding target.

Recognize only those legacy vendor forms as GNU/Hurd, preserve version suffixes such as `gnu0.9`, and leave ordinary triples such as `x86_64-unknown-linux-gnu` unchanged.

### Validation

- `TargetParserTests --gtest_filter=TripleTest.Normalization`
- Full `TargetParserTests`: 689 passed, 4 host-specific tests skipped on macOS
- Built `llvm-config` with `LLVM_HOST_TRIPLE=x86_64-unknown-gnu`; `--host-target` reports `x86_64-unknown-hurd-gnu`
- `git diff --check`

This patch was prepared with OpenAI Codex assistance. The implementation, regression tests, and validation were reviewed before submission; the commit includes the project's `Assisted-by: OpenAI Codex` trailer.

>From ed31ff8649ecc63c43dd9b4d5c61de5202bdf346 Mon Sep 17 00:00:00 2001
From: RealBhupesh <realbhupesh at gmail.com>
Date: Fri, 7 Aug 2026 20:17:32 +0530
Subject: [PATCH] [TargetParser] Recognize legacy GNU/Hurd triples

Treat the legacy *-unknown-gnu and *-pc-gnu forms emitted by config.guess as GNU/Hurd triples while preserving ordinary Linux triples. Add coverage for both vendor spellings and versioned GNU/Hurd output.

Assisted-by: OpenAI Codex
---
 llvm/lib/TargetParser/Triple.cpp           | 19 +++++++++++++++++++
 llvm/unittests/TargetParser/TripleTest.cpp |  8 ++++++++
 2 files changed, 27 insertions(+)

diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 1e421c428d8b4..ad4c709dd7514 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -1190,6 +1190,19 @@ std::string Triple::normalize(StringRef Str, CanonicalForm Form) {
   SmallVector<StringRef, 4> Components;
   Str.split(Components, '-');
 
+  // GNU/Hurd's config.guess output predates LLVM's canonical Hurd triple and
+  // uses the three-component forms *-unknown-gnu and *-pc-gnu.  Keep this
+  // special case narrow so triples such as x86_64-unknown-linux-gnu retain
+  // their normal interpretation.
+  bool IsGNUHurd = false;
+  if (Components.size() == 3 &&
+      (Components[1] == "unknown" || Components[1] == "pc") &&
+      Components[2].starts_with("gnu")) {
+    StringRef Version = Components[2].drop_front(strlen("gnu"));
+    IsGNUHurd = Version.empty() ||
+                Version.find_first_not_of("0123456789.") == StringRef::npos;
+  }
+
   // If the first component corresponds to a known architecture, preferentially
   // use it for the architecture.  If the second component corresponds to a
   // known vendor, preferentially use it for the vendor, etc.  This avoids silly
@@ -1327,6 +1340,12 @@ std::string Triple::normalize(StringRef Str, CanonicalForm Form) {
       Components[1] == "none" && Components[2].empty())
     std::swap(Components[1], Components[2]);
 
+  if (IsGNUHurd) {
+    Components.resize(4);
+    Components[2] = "hurd";
+    OS = Triple::Hurd;
+  }
+
   // Replace empty components with "unknown" value.
   for (StringRef &C : Components)
     if (C.empty())
diff --git a/llvm/unittests/TargetParser/TripleTest.cpp b/llvm/unittests/TargetParser/TripleTest.cpp
index 219e3ce9c0baf..f70097833eaff 100644
--- a/llvm/unittests/TargetParser/TripleTest.cpp
+++ b/llvm/unittests/TargetParser/TripleTest.cpp
@@ -2091,6 +2091,14 @@ TEST(TripleTest, Normalization) {
             Triple::normalize("i386-mingw32")); // i386-pc-mingw32
   EXPECT_EQ("x86_64-unknown-linux-gnu",
             Triple::normalize("x86_64-linux-gnu")); // x86_64-pc-linux-gnu
+  EXPECT_EQ("x86_64-unknown-hurd-gnu",
+            Triple::normalize("x86_64-unknown-gnu"));
+  EXPECT_EQ("i686-unknown-hurd-gnu",
+            Triple::normalize("i686-unknown-gnu"));
+  EXPECT_EQ("i686-pc-hurd-gnu",
+            Triple::normalize("i686-pc-gnu"));
+  EXPECT_EQ("x86_64-unknown-hurd-gnu0.9",
+            Triple::normalize("x86_64-unknown-gnu0.9"));
   EXPECT_EQ("i486-unknown-linux-gnu",
             Triple::normalize("i486-linux-gnu")); // i486-pc-linux-gnu
   EXPECT_EQ("i386-redhat-linux",



More information about the llvm-commits mailing list