Skip to content

[Flang][OpenMP] Add semantic tests for threadprivate variables with host assoc #134680

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 2 commits into from
Apr 8, 2025

Conversation

mjklemm
Copy link
Contributor

@mjklemm mjklemm commented Apr 7, 2025

No description provided.

@mjklemm mjklemm self-assigned this Apr 7, 2025
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:openmp flang:semantics labels Apr 7, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 7, 2025

@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-flang-semantics

Author: Michael Klemm (mjklemm)

Changes

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

2 Files Affected:

  • (modified) flang/test/Semantics/OpenMP/default-none.f90 (+15)
  • (added) flang/test/Semantics/OpenMP/threadprivate09.f90 (+32)
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

Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

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

LGTM. Maybe it is worth adding a comment to the tests with no annotations just making it clear that the intention is that these will not generate any warnings or errors.

@mjklemm
Copy link
Contributor Author

mjklemm commented Apr 7, 2025

LGTM. Maybe it is worth adding a comment to the tests with no annotations just making it clear that the intention is that these will not generate any warnings or errors.

Good point! I will add such a comment.

Copy link
Contributor

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

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

LG

@mjklemm mjklemm merged commit 69c4e17 into llvm:main Apr 8, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:openmp flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants