Update tls-disable-literal-pool.c to use -mpure-code instead of
-mslow-flash-data, since TLS is now allowed with -mslow-flash-data.

Add thumb2-slow-flash-data-tls.c to verify that TLS access works
correctly with -mslow-flash-data and generates appropriate literal
pool entries.

Signed-off-by: Jérôme Pouiller <[email protected]>
Co-authored-by: Cursor <[email protected]>
---
 .../arm/thumb2-slow-flash-data-tls.c          | 35 +++++++++++++++++++
 .../gcc.target/arm/tls-disable-literal-pool.c |  5 ++-
 2 files changed, 37 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/arm/thumb2-slow-flash-data-tls.c

diff --git a/gcc/testsuite/gcc.target/arm/thumb2-slow-flash-data-tls.c 
b/gcc/testsuite/gcc.target/arm/thumb2-slow-flash-data-tls.c
new file mode 100644
index 00000000000..19ae57b6363
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/thumb2-slow-flash-data-tls.c
@@ -0,0 +1,35 @@
+/* Test that TLS access is allowed with -mslow-flash-data.
+   While -mslow-flash-data disables literal pools for performance,
+   TLS access requires literal pools and is therefore allowed as
+   an exception.  */
+
+/* { dg-do compile } */
+/* { dg-require-effective-target tls_native } */
+/* { dg-require-effective-target arm_cortex_m } */
+/* { dg-require-effective-target arm_thumb2_ok } */
+/* { dg-skip-if "-mslow-flash-data and -mword-relocations incompatible" { 
*-*-* } { "-mword-relocations" } } */
+/* { dg-options "-O2 -mthumb -mslow-flash-data" } */
+
+__thread int tls_var = 0;
+
+int
+test_tls_read (void)
+{
+  return tls_var;
+}
+
+void
+test_tls_write (int val)
+{
+  tls_var = val;
+}
+
+int
+test_tls_modify (int val)
+{
+  tls_var += val;
+  return tls_var;
+}
+
+/* TLS access should use literal pool with TLS relocation (tpoff).  */
+/* { dg-final { scan-assembler "\\(tpoff\\)" } } */
diff --git a/gcc/testsuite/gcc.target/arm/tls-disable-literal-pool.c 
b/gcc/testsuite/gcc.target/arm/tls-disable-literal-pool.c
index 834eaf6db92..d191838aa85 100644
--- a/gcc/testsuite/gcc.target/arm/tls-disable-literal-pool.c
+++ b/gcc/testsuite/gcc.target/arm/tls-disable-literal-pool.c
@@ -2,14 +2,13 @@
 /* { dg-require-effective-target tls_native } */
 /* { dg-require-effective-target arm_cortex_m } */
 /* { dg-require-effective-target arm_thumb2_ok } */
-/* { dg-skip-if "-mslow-flash-data and -mword-relocations incompatible" { 
*-*-* } { "-mword-relocations" } } */
-/* { dg-options "-mslow-flash-data" } */
+/* { dg-options "-mpure-code" } */
 
 __thread int x = 0;
 
 int
 bar ()
 {
-  return x; /* { dg-message "sorry, unimplemented: accessing thread-local 
storage is not currently supported with -mpure-code or -mslow-flash-data" } */
+  return x; /* { dg-message "sorry, unimplemented: accessing thread-local 
storage is not currently supported with -mpure-code" } */
 }
 
-- 
2.47.3

Reply via email to