| Issue |
178398
|
| Summary |
[flang][OpenMP] Missing diagnostic for INTENT(IN) POINTER in LASTPRIVATE clause
|
| Labels |
flang
|
| Assignees |
|
| Reporter |
Saieiei
|
## What's happening?
Flang currently accepts code that uses an `INTENT(IN)` pointer in a `LASTPRIVATE` clause without any error. However, this should be rejected according to the OpenMP specification - and both gfortran and Cray compilers correctly flag this as an error.
## Reproducer
```fortran
subroutine test(p)
implicit none
integer, pointer, intent(in) :: p
integer :: i
!$omp parallel do lastprivate(p)
do i = 1, 10
end do
!$omp end parallel do
end subroutine
```
Compile with:
```bash
flang-new -fopenmp -fsyntax-only test.f90
```
## What I expected
An error like:
```
error: Pointer 'p' with the INTENT(IN) attribute may not appear in a LASTPRIVATE clause
```
## What actually happens
Flang compiles successfully with no errors (apart from the experimental OpenMP warning).
## Comparison with other compilers
**gfortran 15.2** (tested on https://godbolt.org with `-fopenmp`):
```
Error: INTENT(IN) POINTER 'p' in LASTPRIVATE clause at (1)
```
**Cray Fortran:**
```
ftn-1492 ftn: ERROR
Dummy argument "P" has the intent(in) attribute. It must not be declared
in the LASTPRIVATE clause because it is not definable.
```
## Why this matters
According to OpenMP 5.2, Section 5.4.5:
- A variable in a `lastprivate` clause must be **definable** (Fortran-specific restriction)
- For pointers, the update happens "as if by pointer assignment"
An `INTENT(IN)` pointer can't have its association changed, so it's not definable for pointer assignment purposes.
## Root cause (I think)
Looking at `flang/lib/Semantics/check-omp-structure.cpp`, the `LASTPRIVATE` clause handler doesn't check for `INTENT(IN)` pointers, but similar clauses like `PRIVATE`, `COPYPRIVATE`, and `REDUCTION` do have this check.
Happy to submit a PR if this analysis looks correct!
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs