[PATCH] D92732: [Flang][OpenMP 4.5] Add semantic check for OpenMP Do Loop Constructs

Kiran Chandramohan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 5 13:54:23 PST 2021


kiranchandramohan added inline comments.


================
Comment at: flang/lib/Semantics/resolve-directives.cpp:1039
   }
+  ClearThreadPrivateSymbols();
   PopContext();
----------------
yhegde wrote:
> kiranchandramohan wrote:
> > Will this work if there are two omp do loops having threadprivate iteration variables?
> For the the following test case
> 
> program omp_do1
>   integer, save:: i, j, k, n
>   !$omp  threadprivate(i)
>   !$omp  do
>   !ERROR: Loop iteration variable i is not allowed in THREADPRIVATE.
>   do i = 1, 10
>     !!$omp  threadprivate(j)
>     !$omp  do
>     do j = 1, 10
>       print *, "Hello"
>     end do
>   end do
>   !$omp end do
> 
>   !$omp  do
>   !ERROR: Loop iteration variable i is not allowed in THREADPRIVATE.
>   do i = 1, 10
>     !!$omp  threadprivate(j)
>     !$omp  do
>     do j = 1, 10
>       print *, "Hello"
>     end do
>   end do
>   !$omp end do
> 
> end program omp_do1
> 
> the error is 
> 
> ./kcmtp3.f90:6:6: error: Loop iteration variable i is not allowed in THREADPRIVATE.
>     do i = 1, 10
>        ^
> ./kcmtp3.f90:8:12: error: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
>       !$omp  do
>              ^^
> ./kcmtp3.f90:17:6: error: Loop iteration variable i is not allowed in THREADPRIVATE.
>     do i = 1, 10
>        ^
> ./kcmtp3.f90:19:12: error: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
>       !$omp  do
>              ^^
> 
> and if I uncomment !$omp  threadprivate(j) , I get parse errors. 
> 
> and the gfortran error is
> 
> kcmtp3.f90:6:14:
> 
>     6 |   do i = 1, 10
>       |              1
> Error: !$OMP DO iteration variable must not be THREADPRIVATE at (1)
> kcmtp3.f90:17:14:
> 
>    17 |   do i = 1, 10
>       |              1
> Error: !$OMP DO iteration variable must not be THREADPRIVATE at (1)
> 
I got that slightly wrong. What i meant is that if we clear the symbols after visiting a block construct then we will miss the error on a following loop construct. For e.g.

```
integer, save:: i, j, k, n
!$omp  threadprivate(i)

!$omp parallel
print *, "parallel"
!$omp end parallel

!$omp  do
do i = 1, 10
  do j = 1, 10
    print *, "Hello"
  end do
end do
!$omp end do

end program
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92732/new/

https://reviews.llvm.org/D92732



More information about the llvm-commits mailing list