Skip to content

Commit a40bf92

Browse files
committed
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.
1 parent ec062f5 commit a40bf92

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

clang/test/Driver/print-multi-selection-flags.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@
55
// CHECK-FUCHSIA: --target=aarch64-unknown-fuchsia
66

77
// RUN: %clang -print-multi-flags-experimental --target=arm-none-eabi -mfloat-abi=soft -fno-exceptions -fno-rtti | FileCheck --check-prefix=CHECK-ARMV4T %s
8-
// CHECK-ARMV4T: --target=armv4t-none-unknown-eabi
8+
// CHECK-ARMV4T: --target=armv4t-unknown-none-eabi
99
// CHECK-ARMV4T: -mfloat-abi=soft
1010
// CHECK-ARMV4T: -mfpu=none
1111

1212
// RUN: %clang -print-multi-flags-experimental --target=armv7em-none-eabi -mfloat-abi=softfp | FileCheck --check-prefix=CHECK-SOFTFP %s
13-
// CHECK-SOFTFP: --target=thumbv7em-none-unknown-eabi
13+
// CHECK-SOFTFP: --target=thumbv7em-unknown-none-eabi
1414
// CHECK-SOFTFP: -mfloat-abi=softfp
1515
// CHECK-SOFTFP: -mfpu=fpv4-sp-d16
1616

1717
// RUN: %clang -print-multi-flags-experimental --target=arm-none-eabihf -march=armv7em -mfpu=fpv5-d16 | FileCheck --check-prefix=CHECK-HARD %s
18-
// CHECK-HARD: --target=thumbv7em-none-unknown-eabihf
18+
// CHECK-HARD: --target=thumbv7em-unknown-none-eabihf
1919
// CHECK-HARD: -mfloat-abi=hard
2020
// CHECK-HARD: -mfpu=fpv5-d16
2121

2222
// 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
23-
// CHECK-V8MMAIN-NOFP: --target=thumbv8m.main-none-unknown-eabi
23+
// CHECK-V8MMAIN-NOFP: --target=thumbv8m.main-unknown-none-eabi
2424
// CHECK-V8MMAIN-NOFP: -mfloat-abi=soft
2525
// CHECK-V8MMAIN-NOFP: -mfpu=none
2626

2727
// 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
28-
// CHECK-MVE: --target=thumbv8.1m.main-none-unknown-eabihf
28+
// CHECK-MVE: --target=thumbv8.1m.main-unknown-none-eabihf
2929
// CHECK-MVE: -march=thumbv8.1m.main{{.*}}+mve{{.*}}+mve.fp{{.*}}
3030
// CHECK-MVE: -mfloat-abi=hard
3131
// CHECK-MVE: -mfpu=fp-armv8-fullfp16-sp-d16
@@ -51,10 +51,10 @@
5151
// CHECK-M85_NO_FP_DP: -mfpu=fp-armv8-fullfp16-sp-d16
5252

5353
// RUN: %clang -print-multi-flags-experimental --target=aarch64-none-elf -march=armv8-a+lse | FileCheck --check-prefix=CHECK-LSE %s
54-
// CHECK-LSE: --target=aarch64-none-unknown-elf
54+
// CHECK-LSE: --target=aarch64-unknown-none-elf
5555
// CHECK-LSE: -march=armv8-a{{.*}}+lse{{.*}}
5656

5757
// RUN: %clang -print-multi-flags-experimental --target=aarch64-none-elf -march=armv8.5-a+sve+sve2 | FileCheck --check-prefix=CHECK-SVE2 %s
5858
// RUN: %clang -print-multi-flags-experimental --target=aarch64-none-elf -march=armv9-a | FileCheck --check-prefix=CHECK-SVE2 %s
59-
// CHECK-SVE2: --target=aarch64-none-unknown-elf
59+
// CHECK-SVE2: --target=aarch64-unknown-none-elf
6060
// CHECK-SVE2: -march=armv{{.*}}-a{{.*}}+simd{{.*}}+sve{{.*}}+sve2{{.*}}

libcxx/utils/ci/run-buildbot

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function test-armv7m-picolibc() {
217217
"${@}"
218218

219219
${NINJA} -vC "${BUILD_DIR}/compiler-rt" install
220-
mv "${BUILD_DIR}/install/lib/armv7m-none-unknown-eabi"/* "${BUILD_DIR}/install/lib"
220+
mv "${BUILD_DIR}/install/lib/armv7m-unknown-none-eabi"/* "${BUILD_DIR}/install/lib"
221221

222222
check-runtimes
223223
}

llvm/lib/TargetParser/Triple.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,13 @@ std::string Triple::normalize(StringRef Str) {
11491149
}
11501150
}
11511151

1152+
// For 3-component triples, the middle component is used to set Vendor;
1153+
// while if it is "none", we'd prefer to set OS.
1154+
// This is for some baremetal cases, such as "arm-none-elf".
1155+
if (Found[0] && !Found[1] && !Found[2] && Found[3] &&
1156+
Components[1].equals("none") && Components[2].empty())
1157+
std::swap(Components[1], Components[2]);
1158+
11521159
// Replace empty components with "unknown" value.
11531160
for (StringRef &C : Components)
11541161
if (C.empty())

llvm/unittests/TargetParser/TripleTest.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ TEST(TripleTest, Normalization) {
12371237
Triple::normalize("i386-redhat-linux")); // i386-redhat-linux-gnu
12381238
EXPECT_EQ("i686-unknown-linux",
12391239
Triple::normalize("i686-linux")); // i686-pc-linux-gnu
1240-
EXPECT_EQ("arm-none-unknown-eabi",
1240+
EXPECT_EQ("arm-unknown-none-eabi",
12411241
Triple::normalize("arm-none-eabi")); // arm-none-eabi
12421242
EXPECT_EQ("ve-unknown-linux",
12431243
Triple::normalize("ve-linux")); // ve-linux

0 commit comments

Comments
 (0)