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

YunQiang Su via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 22 23:03:56 PDT 2024


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

>From a40bf92dcdaa64c2ca73d9276972c8cd47750210 Mon Sep 17 00:00:00 2001
From: YunQiang Su <syq at gcc.gnu.org>
Date: Tue, 23 Apr 2024 01:36:17 +0800
Subject: [PATCH] Triple::normalize: Set OS for 3-component triple with none as
 middle

If the middle component of a 3-component triple fails to parse as known
Arch/Vendor/OS/Env, it will fallback as Vendor. While for some cases,
we may wish to recognize it as OS, such as `arm64-none-elf`.

In this patch, we will set OS as `none`, if:
	1) Arch is found;
	2) Env is found;
	3) OS is not found and thus is set as empty;
	4) Vendor is not found while is set as "none",
we will swap Component[2] and Component[3].

Use this new triple for these tests:
  - libcxx/utils/ci/run-buildbot
  - clang/test/Driver/print-multi-selection-flags.c
  - llvm/unittests/TargetParser/TripleTest.cpp

Fixes: #89582.
---
 clang/test/Driver/print-multi-selection-flags.c | 14 +++++++-------
 libcxx/utils/ci/run-buildbot                    |  2 +-
 llvm/lib/TargetParser/Triple.cpp                |  7 +++++++
 llvm/unittests/TargetParser/TripleTest.cpp      |  2 +-
 4 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/clang/test/Driver/print-multi-selection-flags.c b/clang/test/Driver/print-multi-selection-flags.c
index 06a12db9d97792..9f58d1b557fd74 100644
--- a/clang/test/Driver/print-multi-selection-flags.c
+++ b/clang/test/Driver/print-multi-selection-flags.c
@@ -5,27 +5,27 @@
 // CHECK-FUCHSIA: --target=aarch64-unknown-fuchsia
 
 // RUN: %clang -print-multi-flags-experimental --target=arm-none-eabi -mfloat-abi=soft -fno-exceptions -fno-rtti | FileCheck --check-prefix=CHECK-ARMV4T %s
-// CHECK-ARMV4T: --target=armv4t-none-unknown-eabi
+// CHECK-ARMV4T: --target=armv4t-unknown-none-eabi
 // CHECK-ARMV4T: -mfloat-abi=soft
 // CHECK-ARMV4T: -mfpu=none
 
 // RUN: %clang -print-multi-flags-experimental --target=armv7em-none-eabi -mfloat-abi=softfp | FileCheck --check-prefix=CHECK-SOFTFP %s
-// CHECK-SOFTFP: --target=thumbv7em-none-unknown-eabi
+// CHECK-SOFTFP: --target=thumbv7em-unknown-none-eabi
 // CHECK-SOFTFP: -mfloat-abi=softfp
 // CHECK-SOFTFP: -mfpu=fpv4-sp-d16
 
 // RUN: %clang -print-multi-flags-experimental --target=arm-none-eabihf -march=armv7em -mfpu=fpv5-d16 | FileCheck --check-prefix=CHECK-HARD %s
-// CHECK-HARD: --target=thumbv7em-none-unknown-eabihf
+// CHECK-HARD: --target=thumbv7em-unknown-none-eabihf
 // CHECK-HARD: -mfloat-abi=hard
 // CHECK-HARD: -mfpu=fpv5-d16
 
 // RUN: %clang -print-multi-flags-experimental --target=arm-none-eabi -mfloat-abi=soft -march=armv8-m.main+nofp | FileCheck --check-prefix=CHECK-V8MMAIN-NOFP %s
-// CHECK-V8MMAIN-NOFP: --target=thumbv8m.main-none-unknown-eabi
+// CHECK-V8MMAIN-NOFP: --target=thumbv8m.main-unknown-none-eabi
 // CHECK-V8MMAIN-NOFP: -mfloat-abi=soft
 // CHECK-V8MMAIN-NOFP: -mfpu=none
 
 // RUN: %clang -print-multi-flags-experimental --target=arm-none-eabi -mfloat-abi=hard -march=armv8.1m.main+mve.fp | FileCheck --check-prefix=CHECK-MVE %s
-// CHECK-MVE: --target=thumbv8.1m.main-none-unknown-eabihf
+// CHECK-MVE: --target=thumbv8.1m.main-unknown-none-eabihf
 // CHECK-MVE: -march=thumbv8.1m.main{{.*}}+mve{{.*}}+mve.fp{{.*}}
 // CHECK-MVE: -mfloat-abi=hard
 // CHECK-MVE: -mfpu=fp-armv8-fullfp16-sp-d16
@@ -51,10 +51,10 @@
 // CHECK-M85_NO_FP_DP: -mfpu=fp-armv8-fullfp16-sp-d16
 
 // RUN: %clang -print-multi-flags-experimental --target=aarch64-none-elf -march=armv8-a+lse | FileCheck --check-prefix=CHECK-LSE %s
-// CHECK-LSE: --target=aarch64-none-unknown-elf
+// CHECK-LSE: --target=aarch64-unknown-none-elf
 // CHECK-LSE: -march=armv8-a{{.*}}+lse{{.*}}
 
 // RUN: %clang -print-multi-flags-experimental --target=aarch64-none-elf -march=armv8.5-a+sve+sve2 | FileCheck --check-prefix=CHECK-SVE2 %s
 // RUN: %clang -print-multi-flags-experimental --target=aarch64-none-elf -march=armv9-a            | FileCheck --check-prefix=CHECK-SVE2 %s
-// CHECK-SVE2: --target=aarch64-none-unknown-elf
+// CHECK-SVE2: --target=aarch64-unknown-none-elf
 // CHECK-SVE2: -march=armv{{.*}}-a{{.*}}+simd{{.*}}+sve{{.*}}+sve2{{.*}}
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 77fdf31d4865c0..07f3df4145dad4 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -1149,6 +1149,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())
diff --git a/llvm/unittests/TargetParser/TripleTest.cpp b/llvm/unittests/TargetParser/TripleTest.cpp
index 0fa7e769038905..b8f5fbd87407d3 100644
--- a/llvm/unittests/TargetParser/TripleTest.cpp
+++ b/llvm/unittests/TargetParser/TripleTest.cpp
@@ -1237,7 +1237,7 @@ TEST(TripleTest, Normalization) {
             Triple::normalize("i386-redhat-linux")); // i386-redhat-linux-gnu
   EXPECT_EQ("i686-unknown-linux",
             Triple::normalize("i686-linux")); // i686-pc-linux-gnu
-  EXPECT_EQ("arm-none-unknown-eabi",
+  EXPECT_EQ("arm-unknown-none-eabi",
             Triple::normalize("arm-none-eabi")); // arm-none-eabi
   EXPECT_EQ("ve-unknown-linux",
             Triple::normalize("ve-linux")); // ve-linux



More information about the cfe-commits mailing list