[flang-commits] [flang] [Flang][OpenMP] Add semantic tests for threadprivate variables with host assoc (PR #134680)
Michael Klemm via flang-commits
flang-commits at lists.llvm.org
Mon Apr 7 09:56:00 PDT 2025
https://github.com/mjklemm updated https://github.com/llvm/llvm-project/pull/134680
>From 629804683d2dcda5bda4fa9e06f13d1040b9595e Mon Sep 17 00:00:00 2001
From: Michael Klemm <michael.klemm at amd.com>
Date: Mon, 7 Apr 2025 11:12:55 -0500
Subject: [PATCH 1/2] [Flang][OpenMP] Add tests for threadprivate variables
with host association
---
flang/test/Semantics/OpenMP/default-none.f90 | 15 +++++++++
.../test/Semantics/OpenMP/threadprivate09.f90 | 32 +++++++++++++++++++
2 files changed, 47 insertions(+)
create mode 100644 flang/test/Semantics/OpenMP/threadprivate09.f90
diff --git a/flang/test/Semantics/OpenMP/default-none.f90 b/flang/test/Semantics/OpenMP/default-none.f90
index 761c2385466a0..a56657ccee467 100644
--- a/flang/test/Semantics/OpenMP/default-none.f90
+++ b/flang/test/Semantics/OpenMP/default-none.f90
@@ -58,3 +58,18 @@ subroutine sub( aaa)
ccc= aaa(ip)
end do
end subroutine sub
+
+! Test that threadprivate variables with host association
+! have a predetermined DSA
+subroutine host_assoc()
+ integer, save :: i
+ !$omp threadprivate(i)
+ real, save :: r
+ !$omp threadprivate(r)
+contains
+ subroutine internal()
+!$omp parallel default(none)
+ print *, i, r
+!$omp end parallel
+ end subroutine internal
+end subroutine host_assoc
diff --git a/flang/test/Semantics/OpenMP/threadprivate09.f90 b/flang/test/Semantics/OpenMP/threadprivate09.f90
new file mode 100644
index 0000000000000..462f476ae3e1e
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/threadprivate09.f90
@@ -0,0 +1,32 @@
+! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
+! OpenMP Version 5.1
+! Check OpenMP construct validity for the following directives:
+! 2.21.2 Threadprivate Directive
+
+subroutine host_assoc_fail()
+ integer :: i
+ ! ERROR: A variable that appears in a THREADPRIVATE directive must be declared in the scope of a module or have the SAVE attribute, either explicitly or implicitly
+ !$omp threadprivate(i)
+ real :: r
+ ! ERROR: A variable that appears in a THREADPRIVATE directive must be declared in the scope of a module or have the SAVE attribute, either explicitly or implicitly
+ !$omp threadprivate(r)
+contains
+ subroutine internal()
+!$omp parallel
+ print *, i, r
+!$omp end parallel
+ end subroutine internal
+end subroutine host_assoc_fail
+
+subroutine host_assoc()
+ integer, save :: i
+ !$omp threadprivate(i)
+ real, save :: r
+ !$omp threadprivate(r)
+contains
+ subroutine internal()
+!$omp parallel
+ print *, i, r
+!$omp end parallel
+ end subroutine internal
+end subroutine host_assoc
>From e21ee92f8753cf5198358e07fa8b1f2c39beb130 Mon Sep 17 00:00:00 2001
From: Michael Klemm <michael.klemm at amd.com>
Date: Mon, 7 Apr 2025 11:55:49 -0500
Subject: [PATCH 2/2] Add comment to test
---
flang/test/Semantics/OpenMP/threadprivate09.f90 | 1 +
1 file changed, 1 insertion(+)
diff --git a/flang/test/Semantics/OpenMP/threadprivate09.f90 b/flang/test/Semantics/OpenMP/threadprivate09.f90
index 462f476ae3e1e..64fe048fa3e60 100644
--- a/flang/test/Semantics/OpenMP/threadprivate09.f90
+++ b/flang/test/Semantics/OpenMP/threadprivate09.f90
@@ -18,6 +18,7 @@ subroutine internal()
end subroutine internal
end subroutine host_assoc_fail
+! This sub-test is not supposed to emit a compiler error.
subroutine host_assoc()
integer, save :: i
!$omp threadprivate(i)
More information about the flang-commits
mailing list