Skip to content

Commit

Permalink
Triple::normalize: Set OS for 3-component triple with none as middle
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wzssyqa committed Apr 23, 2024
1 parent ec062f5 commit a40bf92
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
14 changes: 7 additions & 7 deletions clang/test/Driver/print-multi-selection-flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{{.*}}
2 changes: 1 addition & 1 deletion libcxx/utils/ci/run-buildbot
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/TargetParser/Triple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/TargetParser/TripleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a40bf92

Please sign in to comment.