Issue 185344
Summary [Flang][OpenMP] Compilation error when using use statement with only option for arrays with the same name but different subscripts
Labels flang:openmp
Assignees
Reporter ohno-fj
    ```
Version of flang : 23.0.0(d9ca61b6e7b9aa94d244b831a3cb6274d3839d1c)/AArch64
```

In the attached program (`sample.f90`), arrays with the same name (`ary`) are defined within different modules (`mod1` and `mod2`).
The ranks of the arrays are different.
These two modules are used with `use statement` specifying `only option`, and the array is used within `parallel do construct`.

In this case, the following compilation error occurs:
 `error: Reference to rank-3 object 'ary' has 5 subscripts`

Compilation completes successfully in the following cases:
- Do not specify `-fopenmp` option

I checked `Fortran Standard 2023: 14.2.2 The USE statement and use association`, and this program appears to be correct.


The following are the test program, Flang, Gfortran and ifx compilation/execution results.

sample.f90:
```fortran
module mod1
  implicit none
  save
 real(8),allocatable::ary(:,:,:)
end module mod1

module mod2
 real(8),allocatable,save::ary(:,:,:,:,:)
end module mod2

module mod3
 implicit none
contains
  subroutine sub(arg)
    use mod1,only:s_ary=>ary
    use mod2,only:ary
    implicit none
 integer(4),intent(in)::arg
    integer(4)::i,j,k
    integer(4):: xx,yy,zs,ze,mm

!$omp parallel do
    do j = 0, yy+1
       do i = 0, xx+1
          do k = zs, ze
             s_ary(k,i,j) = s_ary(k,i,j) + ary(k,-9999,i,j,mm)
             ary(k,-9999,i,j,mm) = 0._8
          end do
       end do
    end do
!$omp end parallel do

  end subroutine sub
end module mod3
```

```
$ flang -fopenmp -c sample.f90
error: Semantic errors in sample.f90
./sample.f90:26:44: error: Reference to rank-3 object 'ary' has 5 subscripts
               s_ary(k,i,j) = s_ary(k,i,j) + ary(k,-9999,i,j,mm)
 ^^^^^^^^^^^^^^^^^^^
./sample.f90:27:14: error: Reference to rank-3 object 'ary' has 5 subscripts
               ary(k,-9999,i,j,mm) = 0._8
 ^^^^^^^^^^^^^^^^^^^
$
```

```
$ flang -c sample.f90
$
```

```
$ gfortran -fopenmp -c sample.f90
$
```

```
$ ifx -qopenmp -c sample.f90
$
```

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to