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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions flang/test/Semantics/OpenMP/default-none.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 33 additions & 0 deletions flang/test/Semantics/OpenMP/threadprivate09.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
! 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

! This sub-test is not supposed to emit a compiler error.
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