Skip to content

[Arm] Add more -mtp=cp15 tests #134098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2025

Conversation

VladiKrapp-Arm
Copy link
Contributor

This patch systematically covers all -mtp=cp15 behaviour options for better code coverage.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Apr 2, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 2, 2025

@llvm/pr-subscribers-clang

Author: Vladi Krapp (VladiKrapp-Arm)

Changes

This patch systematically covers all -mtp=cp15 behaviour options for better code coverage.


Full diff: https://github.com/llvm/llvm-project/pull/134098.diff

1 Files Affected:

  • (modified) clang/test/Driver/arm-thread-pointer.c (+94-93)
diff --git a/clang/test/Driver/arm-thread-pointer.c b/clang/test/Driver/arm-thread-pointer.c
index 37d1a3e4d7e89..0a783ab888649 100644
--- a/clang/test/Driver/arm-thread-pointer.c
+++ b/clang/test/Driver/arm-thread-pointer.c
@@ -1,93 +1,94 @@
-// Test of the AArch32 values of -mtp=, checking that each one maps to
-// the right target features.
-
-// RUN: %clang --target=armv7-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER-HARD %s
-// ARMv7_THREAD_POINTER-HARD: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv7-linux -mtp=tpidruro -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER-HARD %s
-// RUN: %clang --target=armv7-linux -mtp=tpidrurw -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER-TPIDRURW %s
-// ARMv7_THREAD_POINTER-TPIDRURW: "-target-feature" "+read-tp-tpidrurw"
-// RUN: %clang --target=armv7-linux -mtp=tpidrprw -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER-TPIDRPRW %s
-// ARMv7_THREAD_POINTER-TPIDRPRW: "-target-feature" "+read-tp-tpidrprw"
-
-// RUN: %clang --target=armv6k-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER-HARD %s
-// ARM_THREAD_POINTER-HARD: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv6k-linux -mtp=auto -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER_AUTO %s
-// ARM_THREAD_POINTER_AUTO-NOT: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=thumbv6k-apple-darwin -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=THUMBv6_THREAD_POINTER_NO_AUTO %s
-// THUMBv6_THREAD_POINTER_NO_AUTO-NOT: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: not %clang --target=thumbv6k-apple-darwin -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=THUMBv6_THREAD_POINTER_NO_HARD %s
-// THUMBv6_THREAD_POINTER_NO_HARD: unsupported option '-mtp=' for target 'thumbv6k-apple-darwin'
-
-// RUN: not %clang --target=thumbv6t2-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER_NO_HARD %s
-// ARM_THREAD_POINTER_NO_HARD: hardware TLS register is not supported for the armv6t2 sub-architecture
-
-// RUN: %clang --target=armv5t-linux -mtp=cp15 -x assembler -### %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv5_THREAD_POINTER_ASSEMBLER %s
-// ARMv5_THREAD_POINTER_ASSEMBLER-NOT: hardware TLS register is not supported for the armv5 sub-architecture
-
-// RUN: not %clang --target=armv6-linux -mthumb -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=THUMBv6_THREAD_POINTER_UNSUPP %s
-// RUN: not %clang --target=thumbv6-linux -mthumb -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=THUMBv6_THREAD_POINTER_UNSUPP %s
-// THUMBv6_THREAD_POINTER_UNSUPP: hardware TLS register is not supported for the thumbv6 sub-architecture
-
-// RUN: %clang --target=armv7-linux -mtp=soft -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_SOFT %s
-// ARMv7_THREAD_POINTER_SOFT-NOT: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv7-linux -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_NON %s
-// ARMv7_THREAD_POINTER_NON: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv7-linux -mtp=auto -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_Auto %s
-// ARMv7_THREAD_POINTER_Auto: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv7-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_HARD %s
-// ARMv7_THREAD_POINTER_HARD: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv7m-linux -mtp=auto -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7m_THREAD_POINTER_Auto %s
-// ARMv7m_THREAD_POINTER_Auto-NOT: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: not %clang --target=armv7m-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7m_THREAD_POINTER_HARD %s
-// ARMv7m_THREAD_POINTER_HARD: hardware TLS register is not supported for the thumbv7m sub-architecture
-
-// RUN: %clang --target=armv5t-linux -mtp=auto -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv5t_THREAD_POINTER_Auto %s
-// ARMv5t_THREAD_POINTER_Auto-NOT: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv6k-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv6k_THREAD_POINTER_Auto %s
-// ARMv6k_THREAD_POINTER_Auto: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: not %clang --target=armv6t2-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv6t2_THREAD_POINTER_HARD %s
-// ARMv6t2_THREAD_POINTER_HARD: hardware TLS register is not supported for the armv6t2 sub-architecture
-
-// RUN: %clang --target=armv6t2-linux -mtp=auto -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMV6t2_THREAD_POINTER_AUTO %s
-// ARMV6t2_THREAD_POINTER_AUTO-NOT: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv6kz-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv6kz_THREAD_POINTER_HARD %s
-// ARMv6kz_THREAD_POINTER_HARD: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv6kz-linux -mtp=auto -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMV6KZ_THREAD_POINTER_AUTO %s
-// ARMV6KZ_THREAD_POINTER_AUTO-NOT: "-target-feature" "+read-tp-tpidruro"
\ No newline at end of file
+// This file tests the -mtp=<mode> functionality in Clang’s ARM driver.
+// It verifies:
+//
+//   1. ARMv7 targets: explicit hardware modes, explicit soft mode, and auto mode.
+//   2. M Profile variants: explicit hardware mode should fail and auto mode defaults to soft.
+//   3. ARMv6 variants: explicit hardware modes on ARMv6K/KZ work, but auto mode falls back to soft when Thumb2 is missing.
+//   4. ARMv5 variants: explicit hardware mode is rejected and auto mode defaults to soft.
+//   5. Miscellaneous error cases (e.g. empty -mtp value).
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+// 1. ARMv7 Targets
+//===----------------------------------------------------------------------===//
+
+// Test explicit hardware mode using "tpidrprw" on an ARMv7 target.
+// RUN: %clang --target=armv7-linux -mtp=tpidrprw -### -S %s 2>&1 | FileCheck -check-prefix=ARMv7_TPIDRPRW %s
+// ARMv7_TPIDRPRW: "-target-feature" "+read-tp-tpidrprw"
+
+// Test explicit hardware mode using "tpidrurw" on an ARMv7 target.
+// RUN: %clang --target=armv7-linux -mtp=tpidrurw -### -S %s 2>&1 | FileCheck -check-prefix=ARMv7_TPIDRURW %s
+// ARMv7_TPIDRURW: "-target-feature" "+read-tp-tpidrurw"
+
+// Test explicit hardware mode using "tpidruro" on an ARMv7 target.
+// RUN: %clang --target=armv7-linux -mtp=tpidruro -### -S %s 2>&1 | FileCheck -check-prefix=ARMv7_TPIDRURO %s
+// ARMv7_TPIDRURO: "-target-feature" "+read-tp-tpidruro"
+
+// Test explicit "soft" mode on an ARMv7 target (forces software mode).
+// RUN: %clang --target=armv7-linux -mtp=soft -### -S %s 2>&1 | FileCheck -check-prefix=ARM_Soft %s
+// ARM_Soft-NOT: "-target-feature" "+read-tp-"
+
+// Test auto mode on an ARMv7 target (hardware support and Thumb2 yield HW mode).
+// RUN: %clang --target=armv7-linux -mtp=auto -### -S %s 2>&1 | FileCheck -check-prefix=ARMv7_Auto %s
+// ARMv7_Auto: "-target-feature" "+read-tp-tpidruro"
+
+//===----------------------------------------------------------------------===//
+// 2. M Profile Variants (e.g. thumbv6t2)
+//===----------------------------------------------------------------------===//
+
+// Test explicit hardware mode on a M Profile target: thumbv6t2 does not support CP15.
+// RUN: not %clang --target=thumbv6t2-linux -mtp=cp15 -### -S %s 2>&1 | FileCheck -check-prefix=Thumbv6t2_Error %s
+// Thumbv6t2_Error: error: hardware TLS register is not supported for the armv6t2 sub-architecture
+
+// Test auto mode on a M Profile target: should default to soft mode.
+// RUN: %clang --target=thumbv6t2-linux -mtp=auto -### -S %s 2>&1 | FileCheck -check-prefix=Thumbv6t2_Auto %s
+// Thumbv6t2_Auto-NOT: "-target-feature" "+read-tp-"
+
+// Test explicit hardware mode in assembler mode on a M Profile target (bypass check).
+// RUN: %clang --target=thumbv6t2-linux -mtp=cp15 -x assembler -### %s 2>&1 | FileCheck -check-prefix=Thumbv6t2_Asm %s
+// Thumbv6t2_Asm-NOT: "-target-feature" "+read-tp-"
+
+//===----------------------------------------------------------------------===//
+// 3. ARMv6 Variants
+//===----------------------------------------------------------------------===//
+
+// Test explicit hardware mode using "cp15" on an ARMv6K target.
+// RUN: %clang --target=armv6k-linux -mtp=cp15 -### -S %s 2>&1 | FileCheck -check-prefix=ARMv6k_Cp15 %s
+// ARMv6k_Cp15: "-target-feature" "+read-tp-tpidruro"
+
+// Test explicit hardware mode using "cp15" on an ARMv6KZ target.
+// RUN: %clang --target=armv6kz-linux -mtp=cp15 -### -S %s 2>&1 | FileCheck -check-prefix=ARMv6kz_Cp15 %s
+// ARMv6kz_Cp15: "-target-feature" "+read-tp-tpidruro"
+
+// Test auto mode on an ARMv6K target: lack of Thumb2 forces soft mode.
+// RUN: %clang --target=armv6k-linux -mtp=auto -### -S %s 2>&1 | FileCheck -check-prefix=ARMv6k_Auto %s
+// ARMv6k_Auto-NOT: "-target-feature" "+read-tp-"
+
+// Test auto mode on an ARMv6KZ target: defaults to soft mode due to missing Thumb2.
+// RUN: %clang --target=armv6kz-linux -mtp=auto -### -S %s 2>&1 | FileCheck -check-prefix=ARMv6kz_Auto %s
+// ARMv6kz_Auto-NOT: "-target-feature" "+read-tp-"
+
+//===----------------------------------------------------------------------===//
+// 4. ARMv5 Variants
+//===----------------------------------------------------------------------===//
+
+// Test explicit hardware mode on an ARMv5T target: hardware TP is not supported.
+// RUN: not %clang --target=armv5t-linux -mtp=cp15 -### -S %s 2>&1 | FileCheck -check-prefix=ARMv5t_Error %s
+// ARMv5t_Error: error: hardware TLS register is not supported for the armv5 sub-architecture
+
+// Test auto mode on an ARMv5T target: should default to soft mode.
+// RUN: %clang --target=armv5t-linux -mtp=auto -### -S %s 2>&1 | FileCheck -check-prefix=ARMv5t_Auto %s
+// ARMv5t_Auto-NOT: "-target-feature" "+read-tp-"
+
+//===----------------------------------------------------------------------===//
+// 5. Miscellaneous Tests
+//===----------------------------------------------------------------------===//
+
+// Test empty -mtp value on an ARMv7 target: should produce a missing argument error.
+// RUN: not %clang --target=armv7-linux -mtp= -### -S %s 2>&1 | FileCheck -check-prefix=Empty_MTP %s
+// Empty_MTP: error: {{.*}}missing
+
+// A dummy main is provided to form a valid translation unit.
+int main(void) { return 0; }
+

@llvmbot
Copy link
Member

llvmbot commented Apr 2, 2025

@llvm/pr-subscribers-clang-driver

Author: Vladi Krapp (VladiKrapp-Arm)

Changes

This patch systematically covers all -mtp=cp15 behaviour options for better code coverage.


Full diff: https://github.com/llvm/llvm-project/pull/134098.diff

1 Files Affected:

  • (modified) clang/test/Driver/arm-thread-pointer.c (+94-93)
diff --git a/clang/test/Driver/arm-thread-pointer.c b/clang/test/Driver/arm-thread-pointer.c
index 37d1a3e4d7e89..0a783ab888649 100644
--- a/clang/test/Driver/arm-thread-pointer.c
+++ b/clang/test/Driver/arm-thread-pointer.c
@@ -1,93 +1,94 @@
-// Test of the AArch32 values of -mtp=, checking that each one maps to
-// the right target features.
-
-// RUN: %clang --target=armv7-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER-HARD %s
-// ARMv7_THREAD_POINTER-HARD: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv7-linux -mtp=tpidruro -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER-HARD %s
-// RUN: %clang --target=armv7-linux -mtp=tpidrurw -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER-TPIDRURW %s
-// ARMv7_THREAD_POINTER-TPIDRURW: "-target-feature" "+read-tp-tpidrurw"
-// RUN: %clang --target=armv7-linux -mtp=tpidrprw -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER-TPIDRPRW %s
-// ARMv7_THREAD_POINTER-TPIDRPRW: "-target-feature" "+read-tp-tpidrprw"
-
-// RUN: %clang --target=armv6k-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER-HARD %s
-// ARM_THREAD_POINTER-HARD: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv6k-linux -mtp=auto -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER_AUTO %s
-// ARM_THREAD_POINTER_AUTO-NOT: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=thumbv6k-apple-darwin -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=THUMBv6_THREAD_POINTER_NO_AUTO %s
-// THUMBv6_THREAD_POINTER_NO_AUTO-NOT: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: not %clang --target=thumbv6k-apple-darwin -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=THUMBv6_THREAD_POINTER_NO_HARD %s
-// THUMBv6_THREAD_POINTER_NO_HARD: unsupported option '-mtp=' for target 'thumbv6k-apple-darwin'
-
-// RUN: not %clang --target=thumbv6t2-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER_NO_HARD %s
-// ARM_THREAD_POINTER_NO_HARD: hardware TLS register is not supported for the armv6t2 sub-architecture
-
-// RUN: %clang --target=armv5t-linux -mtp=cp15 -x assembler -### %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv5_THREAD_POINTER_ASSEMBLER %s
-// ARMv5_THREAD_POINTER_ASSEMBLER-NOT: hardware TLS register is not supported for the armv5 sub-architecture
-
-// RUN: not %clang --target=armv6-linux -mthumb -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=THUMBv6_THREAD_POINTER_UNSUPP %s
-// RUN: not %clang --target=thumbv6-linux -mthumb -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=THUMBv6_THREAD_POINTER_UNSUPP %s
-// THUMBv6_THREAD_POINTER_UNSUPP: hardware TLS register is not supported for the thumbv6 sub-architecture
-
-// RUN: %clang --target=armv7-linux -mtp=soft -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_SOFT %s
-// ARMv7_THREAD_POINTER_SOFT-NOT: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv7-linux -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_NON %s
-// ARMv7_THREAD_POINTER_NON: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv7-linux -mtp=auto -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_Auto %s
-// ARMv7_THREAD_POINTER_Auto: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv7-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_HARD %s
-// ARMv7_THREAD_POINTER_HARD: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv7m-linux -mtp=auto -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7m_THREAD_POINTER_Auto %s
-// ARMv7m_THREAD_POINTER_Auto-NOT: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: not %clang --target=armv7m-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7m_THREAD_POINTER_HARD %s
-// ARMv7m_THREAD_POINTER_HARD: hardware TLS register is not supported for the thumbv7m sub-architecture
-
-// RUN: %clang --target=armv5t-linux -mtp=auto -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv5t_THREAD_POINTER_Auto %s
-// ARMv5t_THREAD_POINTER_Auto-NOT: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv6k-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv6k_THREAD_POINTER_Auto %s
-// ARMv6k_THREAD_POINTER_Auto: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: not %clang --target=armv6t2-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv6t2_THREAD_POINTER_HARD %s
-// ARMv6t2_THREAD_POINTER_HARD: hardware TLS register is not supported for the armv6t2 sub-architecture
-
-// RUN: %clang --target=armv6t2-linux -mtp=auto -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMV6t2_THREAD_POINTER_AUTO %s
-// ARMV6t2_THREAD_POINTER_AUTO-NOT: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv6kz-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv6kz_THREAD_POINTER_HARD %s
-// ARMv6kz_THREAD_POINTER_HARD: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv6kz-linux -mtp=auto -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMV6KZ_THREAD_POINTER_AUTO %s
-// ARMV6KZ_THREAD_POINTER_AUTO-NOT: "-target-feature" "+read-tp-tpidruro"
\ No newline at end of file
+// This file tests the -mtp=<mode> functionality in Clang’s ARM driver.
+// It verifies:
+//
+//   1. ARMv7 targets: explicit hardware modes, explicit soft mode, and auto mode.
+//   2. M Profile variants: explicit hardware mode should fail and auto mode defaults to soft.
+//   3. ARMv6 variants: explicit hardware modes on ARMv6K/KZ work, but auto mode falls back to soft when Thumb2 is missing.
+//   4. ARMv5 variants: explicit hardware mode is rejected and auto mode defaults to soft.
+//   5. Miscellaneous error cases (e.g. empty -mtp value).
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+// 1. ARMv7 Targets
+//===----------------------------------------------------------------------===//
+
+// Test explicit hardware mode using "tpidrprw" on an ARMv7 target.
+// RUN: %clang --target=armv7-linux -mtp=tpidrprw -### -S %s 2>&1 | FileCheck -check-prefix=ARMv7_TPIDRPRW %s
+// ARMv7_TPIDRPRW: "-target-feature" "+read-tp-tpidrprw"
+
+// Test explicit hardware mode using "tpidrurw" on an ARMv7 target.
+// RUN: %clang --target=armv7-linux -mtp=tpidrurw -### -S %s 2>&1 | FileCheck -check-prefix=ARMv7_TPIDRURW %s
+// ARMv7_TPIDRURW: "-target-feature" "+read-tp-tpidrurw"
+
+// Test explicit hardware mode using "tpidruro" on an ARMv7 target.
+// RUN: %clang --target=armv7-linux -mtp=tpidruro -### -S %s 2>&1 | FileCheck -check-prefix=ARMv7_TPIDRURO %s
+// ARMv7_TPIDRURO: "-target-feature" "+read-tp-tpidruro"
+
+// Test explicit "soft" mode on an ARMv7 target (forces software mode).
+// RUN: %clang --target=armv7-linux -mtp=soft -### -S %s 2>&1 | FileCheck -check-prefix=ARM_Soft %s
+// ARM_Soft-NOT: "-target-feature" "+read-tp-"
+
+// Test auto mode on an ARMv7 target (hardware support and Thumb2 yield HW mode).
+// RUN: %clang --target=armv7-linux -mtp=auto -### -S %s 2>&1 | FileCheck -check-prefix=ARMv7_Auto %s
+// ARMv7_Auto: "-target-feature" "+read-tp-tpidruro"
+
+//===----------------------------------------------------------------------===//
+// 2. M Profile Variants (e.g. thumbv6t2)
+//===----------------------------------------------------------------------===//
+
+// Test explicit hardware mode on a M Profile target: thumbv6t2 does not support CP15.
+// RUN: not %clang --target=thumbv6t2-linux -mtp=cp15 -### -S %s 2>&1 | FileCheck -check-prefix=Thumbv6t2_Error %s
+// Thumbv6t2_Error: error: hardware TLS register is not supported for the armv6t2 sub-architecture
+
+// Test auto mode on a M Profile target: should default to soft mode.
+// RUN: %clang --target=thumbv6t2-linux -mtp=auto -### -S %s 2>&1 | FileCheck -check-prefix=Thumbv6t2_Auto %s
+// Thumbv6t2_Auto-NOT: "-target-feature" "+read-tp-"
+
+// Test explicit hardware mode in assembler mode on a M Profile target (bypass check).
+// RUN: %clang --target=thumbv6t2-linux -mtp=cp15 -x assembler -### %s 2>&1 | FileCheck -check-prefix=Thumbv6t2_Asm %s
+// Thumbv6t2_Asm-NOT: "-target-feature" "+read-tp-"
+
+//===----------------------------------------------------------------------===//
+// 3. ARMv6 Variants
+//===----------------------------------------------------------------------===//
+
+// Test explicit hardware mode using "cp15" on an ARMv6K target.
+// RUN: %clang --target=armv6k-linux -mtp=cp15 -### -S %s 2>&1 | FileCheck -check-prefix=ARMv6k_Cp15 %s
+// ARMv6k_Cp15: "-target-feature" "+read-tp-tpidruro"
+
+// Test explicit hardware mode using "cp15" on an ARMv6KZ target.
+// RUN: %clang --target=armv6kz-linux -mtp=cp15 -### -S %s 2>&1 | FileCheck -check-prefix=ARMv6kz_Cp15 %s
+// ARMv6kz_Cp15: "-target-feature" "+read-tp-tpidruro"
+
+// Test auto mode on an ARMv6K target: lack of Thumb2 forces soft mode.
+// RUN: %clang --target=armv6k-linux -mtp=auto -### -S %s 2>&1 | FileCheck -check-prefix=ARMv6k_Auto %s
+// ARMv6k_Auto-NOT: "-target-feature" "+read-tp-"
+
+// Test auto mode on an ARMv6KZ target: defaults to soft mode due to missing Thumb2.
+// RUN: %clang --target=armv6kz-linux -mtp=auto -### -S %s 2>&1 | FileCheck -check-prefix=ARMv6kz_Auto %s
+// ARMv6kz_Auto-NOT: "-target-feature" "+read-tp-"
+
+//===----------------------------------------------------------------------===//
+// 4. ARMv5 Variants
+//===----------------------------------------------------------------------===//
+
+// Test explicit hardware mode on an ARMv5T target: hardware TP is not supported.
+// RUN: not %clang --target=armv5t-linux -mtp=cp15 -### -S %s 2>&1 | FileCheck -check-prefix=ARMv5t_Error %s
+// ARMv5t_Error: error: hardware TLS register is not supported for the armv5 sub-architecture
+
+// Test auto mode on an ARMv5T target: should default to soft mode.
+// RUN: %clang --target=armv5t-linux -mtp=auto -### -S %s 2>&1 | FileCheck -check-prefix=ARMv5t_Auto %s
+// ARMv5t_Auto-NOT: "-target-feature" "+read-tp-"
+
+//===----------------------------------------------------------------------===//
+// 5. Miscellaneous Tests
+//===----------------------------------------------------------------------===//
+
+// Test empty -mtp value on an ARMv7 target: should produce a missing argument error.
+// RUN: not %clang --target=armv7-linux -mtp= -### -S %s 2>&1 | FileCheck -check-prefix=Empty_MTP %s
+// Empty_MTP: error: {{.*}}missing
+
+// A dummy main is provided to form a valid translation unit.
+int main(void) { return 0; }
+

Copy link
Collaborator

@statham-arm statham-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This certainly looks more organised than the previous version, but I have a few nitpicks in comments.

This patch systematically covers all -mtp=cp15 behaviour options for
better code coverage.

Follow up for llvm#130027
Copy link
Collaborator

@statham-arm statham-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the tweaks.

As usual, probably best to give other reviewers a chance to comment too.

@VladiKrapp-Arm VladiKrapp-Arm merged commit f528a80 into llvm:main Apr 4, 2025
11 checks passed
// Thumbv6t2_Asm-NOT: "-target-feature" "+read-tp-"

// A dummy main is provided to form a valid translation unit.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly so that code analysis tools don't complain when openning the file to view.
Not strictly necessary.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. We would not add it to any other test case - it is probably best to remove it as it is not testing anything useful.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In particular, all these tests use -###, which should mean clang doesn't even try to compile the translation unit – it just runs the driver logic, decides what subcommands (including cc1) it would run, and prints them out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants