Issue 130308
Summary Flang OpenMP default(private) clause fails to implicitly set the data-sharing of variables to private.
Labels flang
Assignees
Reporter scamp-nvidia
    We have found that the "default(private)" clause gets ignored by the compiler when it is used on a "parallel" construct that contains a "single" construct with a "copyprivate" clause. This clause should not be ignored. Here are the relevant rules from the OpenMP 6.0 specification:

> 210:23 7.1.1 Variables Referenced in a Construct
> 213:15 * In a parallel, teams, or task-generating construct, the data-sharing attributes of these
> 213:16 variables are determined by the default clause, if present (see Section 7.5.1).
> 
> 223:3  7.5.1 default Clause
> 223:12 The default clause determines the implicitly determined data-sharing attributes of certain
> 223:13 variables that are referenced in the construct, in accordance with the rules given in Section 7.1.1.
> 224:1  If data-sharing-attribute is not none, the data-sharing attributes of the selected variables will be
> 224:2 data-sharing-attribute.

We attach a simple reproducer that shows the error for scalar variables, but we have also seen it for pointers. 

test.F90:
```
Program main
  implicit none
  integer :: x
#if defined(USE_PRIVATE)
  !Explicitly set the data-sharing of x to be private
 !$omp parallel private(x) default(none)
#else
  !Implicitly obtain the data-sharing of x - see rule 213:15-16
  !$omp parallel default(private)
#endif
  !$omp single
  x = 1
  !$omp end single copyprivate(x)
  if (x == 1) then
     print *, "SUCCESS"
  else
 print *, "FAILURE"
  end if
  !$omp end parallel
End Program main
```

So compiling the code normally, without declaring "USE_PRIVATE", we get: 
```
scamp@dev-sky5:~$ flang --version
flang version 21.0.0git (https://github.com/llvm/llvm-project db5e4016c0332e7e5c0950414bb0b252975663ed)
Target: x86_64-unknown-linux-gnu
Thread model: posix
...
scamp@dev-sky5:~$ flang test.F90 -o test -fopenmp
flang-21: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
error: Semantic errors in test.F90
./test.F90:13:32: error: COPYPRIVATE variable 'x' is not PRIVATE or THREADPRIVATE in outer context
    !$omp end single copyprivate(x)
 ^
```
Whereas, if we compile with "-DUSE_PRIVATE", we get successful compilations. We believe this code should work without the "-DUSE_PRIVATE", however. We also identified this as a bug in gfortran 14.1.0. 
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to