[clang] [libcxx] [llvm] Triple::normalize: Use none as OS for XX-none-ABI (PR #89638)
YunQiang Su via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 30 17:44:35 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 1/2] 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())
>From 56e8fd7fa124cedef134100174f8d7e6f1779a55 Mon Sep 17 00:00:00 2001
From: YunQiang Su <syq at gcc.gnu.org>
Date: Wed, 1 May 2024 08:44:09 +0800
Subject: [PATCH 2/2] fix test failures
---
clang/test/Driver/arm-ias-Wa.s | 2 +-
clang/test/Driver/arm-triple.c | 10 +++++-----
clang/test/Driver/baremetal-multilib-layered.yaml | 2 +-
clang/test/Driver/baremetal-multilib.yaml | 8 ++++----
clang/test/Driver/baremetal-sysroot.cpp | 2 +-
clang/test/Driver/baremetal.cpp | 2 +-
clang/test/Driver/print-multi-selection-flags.c | 2 +-
.../Interpreter/IncrementalCompilerBuilderTest.cpp | 2 +-
llvm/unittests/TargetParser/TripleTest.cpp | 2 +-
9 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/clang/test/Driver/arm-ias-Wa.s b/clang/test/Driver/arm-ias-Wa.s
index b82ce8dfb31ab3..5e9518ed2dc423 100644
--- a/clang/test/Driver/arm-ias-Wa.s
+++ b/clang/test/Driver/arm-ias-Wa.s
@@ -71,7 +71,7 @@
// RUN: %clang -target armv7r-none-eabi -c %s -### 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-R-PROFILE %s
-// CHECK-R-PROFILE: "-triple" "armv7r-none-unknown-eabi"
+// CHECK-R-PROFILE: "-triple" "armv7r-unknown-none-eabi"
// RUN: %clang -target armv7m-none-eabi -c %s -### 2>&1 \
// RUN: %clang -target thumbv7m-none-eabi -c %s -### 2>&1 \
diff --git a/clang/test/Driver/arm-triple.c b/clang/test/Driver/arm-triple.c
index fa9f7b189c8278..1fb2b5afe22a51 100644
--- a/clang/test/Driver/arm-triple.c
+++ b/clang/test/Driver/arm-triple.c
@@ -7,7 +7,7 @@
// RUN: %clang -print-effective-triple \
// RUN: --target=arm-none-eabihf -march=armv4t -mfloat-abi=softfp \
// RUN: | FileCheck %s --check-prefix=CHECK-DEFAULT
-// CHECK-DEFAULT: armv4t-none-unknown-eabi
+// CHECK-DEFAULT: armv4t-unknown-none-eabi
// RUN: %clang -print-effective-triple \
// RUN: --target=armeb-none-eabi \
@@ -15,7 +15,7 @@
// RUN: %clang -print-effective-triple \
// RUN: --target=arm-none-eabi -mbig-endian \
// RUN: | FileCheck %s --check-prefix=CHECK-EB
-// CHECK-EB: armebv4t-none-unknown-eabi
+// CHECK-EB: armebv4t-unknown-none-eabi
// RUN: %clang -print-effective-triple \
// RUN: --target=arm-none-eabihf -march=armv4t \
@@ -23,7 +23,7 @@
// RUN: %clang -print-effective-triple \
// RUN: --target=arm-none-eabi -mfloat-abi=hard \
// RUN: | FileCheck %s --check-prefix=CHECK-HF
-// CHECK-HF: armv4t-none-unknown-eabihf
+// CHECK-HF: armv4t-unknown-none-eabihf
// RUN: %clang -print-effective-triple \
// RUN: --target=armeb-none-eabihf -march=armv4t \
@@ -37,7 +37,7 @@
// RUN: %clang -print-effective-triple \
// RUN: --target=arm-none-eabi -mbig-endian -mfloat-abi=hard \
// RUN: | FileCheck %s --check-prefix=CHECK-EB-HF
-// CHECK-EB-HF: armebv4t-none-unknown-eabihf
+// CHECK-EB-HF: armebv4t-unknown-none-eabihf
// RUN: %clang -print-effective-triple \
// RUN: --target=arm-none-eabi -march=armv8m.main -mbig-endian -mfloat-abi=hard \
@@ -45,4 +45,4 @@
// RUN: %clang -print-effective-triple \
// RUN: --target=arm-none-eabi -mcpu=cortex-m33 -mbig-endian -mfloat-abi=hard \
// RUN: | FileCheck %s --check-prefix=CHECK-V8M-EB-HF
-// CHECK-V8M-EB-HF: thumbebv8m.main-none-unknown-eabihf
+// CHECK-V8M-EB-HF: thumbebv8m.main-unknown-none-eabihf
diff --git a/clang/test/Driver/baremetal-multilib-layered.yaml b/clang/test/Driver/baremetal-multilib-layered.yaml
index 2f86f8e3ea4f5f..a525436d8122f5 100644
--- a/clang/test/Driver/baremetal-multilib-layered.yaml
+++ b/clang/test/Driver/baremetal-multilib-layered.yaml
@@ -18,7 +18,7 @@
# RUN: %T/baremetal_multilib_layered/bin/clang -no-canonical-prefixes -x c++ %s -### -o %t.out 2>&1 \
# RUN: --target=thumbv7m-none-eabi -mfloat-abi=softfp --sysroot= \
# RUN: | FileCheck -DSYSROOT=%T/baremetal_multilib_layered %s
-# CHECK: "-cc1" "-triple" "thumbv7m-none-unknown-eabi"
+# CHECK: "-cc1" "-triple" "thumbv7m-unknown-none-eabi"
# CHECK-SAME: "-internal-isystem" "[[SYSROOT]]/bin/../lib/clang-runtimes/softfp/include/c++/v1"
# CHECK-SAME: "-internal-isystem" "[[SYSROOT]]/bin/../lib/clang-runtimes/soft/include/c++/v1"
# CHECK-SAME: "-internal-isystem" "[[SYSROOT]]/bin/../lib/clang-runtimes/softfp/include"
diff --git a/clang/test/Driver/baremetal-multilib.yaml b/clang/test/Driver/baremetal-multilib.yaml
index 3f026cbeb437b2..934178358dc3a0 100644
--- a/clang/test/Driver/baremetal-multilib.yaml
+++ b/clang/test/Driver/baremetal-multilib.yaml
@@ -9,7 +9,7 @@
# RUN: ln -s %s %T/baremetal_multilib/lib/clang-runtimes/multilib.yaml
# RUN: %T/baremetal_multilib/bin/clang -no-canonical-prefixes -x c++ %s -### -o %t.out 2>&1 \
-# RUN: --target=thumbv8m.main-none-eabihf --sysroot= \
+# RUN: --target=thumbv8m.main-none-unknown-eabihf --sysroot= \
# RUN: | FileCheck -DSYSROOT=%T/baremetal_multilib %s
# CHECK: "-cc1" "-triple" "thumbv8m.main-none-unknown-eabihf"
# CHECK-SAME: "-internal-isystem" "[[SYSROOT]]/bin/../lib/clang-runtimes/arm-none-eabi/thumb/v8-m.main/fp/include/c++/v1"
@@ -24,19 +24,19 @@
# RUN: --target=thumbv7em-none-eabi -mfpu=fpv4-sp-d16 --sysroot= \
# RUN: | FileCheck --check-prefix=CHECK-NO-MATCH %s
# CHECK-NO-MATCH: warning: no multilib found matching flags:
-# CHECK-NO-MATCH-SAME: --target=thumbv7em-none-unknown-eabi
+# CHECK-NO-MATCH-SAME: --target=thumbv7em-unknown-none-eabi
# CHECK-NO-MATCH: note: available multilibs are:
# CHECK-NO-MATCH: --target=thumbv6m-none-unknown-eabi -mfpu=none
# CHECK-NO-MATCH: --target=thumbv7m-none-unknown-eabi -mfpu=none
# CHECK-NO-MATCH: --target=thumbv7em-none-unknown-eabi -mfpu=none
# RUN: %T/baremetal_multilib/bin/clang -no-canonical-prefixes -print-multi-directory 2>&1 \
-# RUN: --target=thumbv8m.main-none-eabihf --sysroot= \
+# RUN: --target=thumbv8m.main-none-unknown-eabihf --sysroot= \
# RUN: | FileCheck --check-prefix=CHECK-PRINT-MULTI-DIRECTORY %s
# CHECK-PRINT-MULTI-DIRECTORY: arm-none-eabi/thumb/v8-m.main/fp
# RUN: %T/baremetal_multilib/bin/clang -no-canonical-prefixes -print-multi-lib 2>&1 \
-# RUN: --target=arm-none-eabi --sysroot= \
+# RUN: --target=arm-none-unknown-eabi --sysroot= \
# RUN: | FileCheck --check-prefix=CHECK-PRINT-MULTI-LIB %s
# CHECK-PRINT-MULTI-LIB: arm-none-eabi/thumb/v6-m/nofp;@-target=thumbv6m-none-unknown-eabi at mfpu=none
# CHECK-PRINT-MULTI-LIB: arm-none-eabi/thumb/v7-m/nofp;@-target=thumbv7m-none-unknown-eabi at mfpu=none
diff --git a/clang/test/Driver/baremetal-sysroot.cpp b/clang/test/Driver/baremetal-sysroot.cpp
index bbc608809d0e48..18654be33b87c9 100644
--- a/clang/test/Driver/baremetal-sysroot.cpp
+++ b/clang/test/Driver/baremetal-sysroot.cpp
@@ -12,7 +12,7 @@
// RUN: %T/baremetal_default_sysroot/bin/clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
// RUN: -target armv6m-none-eabi --sysroot= \
// RUN: | FileCheck --check-prefix=CHECK-V6M-C %s
-// CHECK-V6M-C: "{{.*}}clang{{.*}}" "-cc1" "-triple" "thumbv6m-none-unknown-eabi"
+// CHECK-V6M-C: "{{.*}}clang{{.*}}" "-cc1" "-triple" "thumbv6m-unknown-none-eabi"
// CHECK-V6M-C-SAME: "-internal-isystem" "{{.*}}/baremetal_default_sysroot{{[/\\]+}}bin{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+}}armv6m-none-eabi{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1"
// CHECk-V6M-C-SAME: "-internal-isystem" "{{.*}}/baremetal_default_sysroot{{[/\\]+}}bin{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+}}armv6m-none-eabi{{[/\\]+}}include"
// CHECK-V6M-C-SAME: "-x" "c++" "{{.*}}baremetal-sysroot.cpp"
diff --git a/clang/test/Driver/baremetal.cpp b/clang/test/Driver/baremetal.cpp
index 657611bb3f38de..cc14f045df3f9a 100644
--- a/clang/test/Driver/baremetal.cpp
+++ b/clang/test/Driver/baremetal.cpp
@@ -9,7 +9,7 @@
// RUN: -L some/directory/user/asked/for \
// RUN: --sysroot=%S/Inputs/baremetal_arm \
// RUN: | FileCheck --check-prefix=CHECK-V6M-C %s
-// CHECK-V6M-C: "-cc1" "-triple" "thumbv6m-none-unknown-eabi"
+// CHECK-V6M-C: "-cc1" "-triple" "thumbv6m-unknown-none-eabi"
// CHECK-V6M-C-SAME: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
// CHECK-V6M-C-SAME: "-isysroot" "[[SYSROOT:[^"]*]]"
// CHECK-V6M-C-SAME: "-internal-isystem" "[[SYSROOT]]{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1"
diff --git a/clang/test/Driver/print-multi-selection-flags.c b/clang/test/Driver/print-multi-selection-flags.c
index 06a12db9d97792..34171acdad3dc5 100644
--- a/clang/test/Driver/print-multi-selection-flags.c
+++ b/clang/test/Driver/print-multi-selection-flags.c
@@ -5,7 +5,7 @@
// 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
diff --git a/clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp b/clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp
index f729566f7efde6..c4a40071f55cf8 100644
--- a/clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp
+++ b/clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp
@@ -40,7 +40,7 @@ TEST(IncrementalCompilerBuilder, SetTargetTriple) {
auto CB = clang::IncrementalCompilerBuilder();
CB.SetTargetTriple("armv6-none-eabi");
auto CI = cantFail(CB.CreateCpp());
- EXPECT_EQ(CI->getTargetOpts().Triple, "armv6-none-unknown-eabi");
+ EXPECT_EQ(CI->getTargetOpts().Triple, "armv6-unknown-none-eabi");
cleanupRemappedFileBuffers(*CI);
}
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 llvm-commits
mailing list