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

This commit is contained in:
Michael Klemm
2025-04-08 13:22:05 +02:00
committed by GitHub
parent c2c1031e90
commit 69c4e172d9
2 changed files with 48 additions and 0 deletions

View File

@@ -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

View File

@@ -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