[libcxx-commits] [clang] [libcxx] [llvm] Triple::normalize: Set OS for 3-component triple with none as middle (PR #89638)

YunQiang Su via libcxx-commits libcxx-commits at lists.llvm.org
Fri Apr 26 20:06:20 PDT 2024


https://github.com/wzssyqa updated https://github.com/llvm/llvm-project/pull/89638

>From aafa018b3d7657483738fa91812e3e8bbdd8205a Mon Sep 17 00:00:00 2001
From: YunQiang Su <syq at gcc.gnu.org>
Date: Sat, 27 Apr 2024 10:55:38 +0800
Subject: [PATCH] Triple::normalize: Use none as OS for XX-none-ABI

When we parse 3-components triples, if the Arch and Env have been
parsed successfully, we have to make a choice between Vendor and
OS for the unrecoginzed component. Noramlly it is the middle one.

In the current code, Vendor is choosed, and then OS is fallbacked
to unknown. It is OK for most cases. But if the unrecoginzed
component is `none`, it is expected to be OS instead of Vendor.

Fixes: #89582.
---
 clang/docs/Multilib.rst          | 4 ++--
 libcxx/utils/ci/run-buildbot     | 2 +-
 llvm/lib/TargetParser/Triple.cpp | 7 +++++++
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/docs/Multilib.rst b/clang/docs/Multilib.rst
index ab737e43b97d23..063fe9a336f2fe 100644
--- a/clang/docs/Multilib.rst
+++ b/clang/docs/Multilib.rst
@@ -188,9 +188,9 @@ For a more comprehensive example see
   - Dir: thumb/v6-m
     # List of one or more normalized command line options, as generated by Clang
     # from the command line options or from Mappings below.
-    # Here, if the flags are a superset of {target=thumbv6m-none-unknown-eabi}
+    # Here, if the flags are a superset of {target=thumbv6m-unknown-none-eabi}
     # then this multilib variant will be considered a match.
-    Flags: [--target=thumbv6m-none-unknown-eabi]
+    Flags: [--target=thumbv6m-unknown-none-eabi]
 
   # Similarly, a multilib variant targeting Arm v7-M with an FPU (floating
   # point unit).
diff --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot
index 60307a7d4f350a..3523a29e4f4613 100755
--- a/libcxx/utils/ci/run-buildbot
+++ b/libcxx/utils/ci/run-buildbot
@@ -217,7 +217,7 @@ function test-armv7m-picolibc() {
         "${@}"
 
     ${NINJA} -vC "${BUILD_DIR}/compiler-rt" install
-    mv "${BUILD_DIR}/install/lib/armv7m-none-unknown-eabi"/* "${BUILD_DIR}/install/lib"
+    mv "${BUILD_DIR}/install/lib/armv7m-unknown-none-eabi"/* "${BUILD_DIR}/install/lib"
 
     check-runtimes
 }
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 2c5aee3dfb2f3e..9c04574fe1e4bc 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -1151,6 +1151,13 @@ std::string Triple::normalize(StringRef Str) {
     }
   }
 
+  // For 3-component triples, the middle component is used to set Vendor;
+  // while if it is "none", we'd prefer to set OS.
+  // This is for some baremetal cases, such as "arm-none-elf".
+  if (Found[0] && !Found[1] && !Found[2] && Found[3] &&
+      Components[1].equals("none") && Components[2].empty())
+    std::swap(Components[1], Components[2]);
+
   // Replace empty components with "unknown" value.
   for (StringRef &C : Components)
     if (C.empty())



More information about the libcxx-commits mailing list