stfc / PSyclone

Domain-specific compiler and code transformation system for Finite Difference/Volume/Element Earth-system models in Fortran
BSD 3-Clause "New" or "Revised" License
104 stars 27 forks source link

Complex expression in array declaration #2720

Open hbrunie opened 1 week ago

hbrunie commented 1 week ago

This unit test shows the bug:

def test_psyclone_boundary_expr_wrong():
    code = """subroutine foo(a,b,c,n)
  integer :: n
  real*8, dimension(1:) :: a
  real*8, dimension(1:n) :: b
  real*8, dimension(n:) :: c
  real*8, dimension(:) :: d

end subroutine foo\n"""
    reader = FortranReader()
    psyir_tree = reader.psyir_from_source(code)
    writer = FortranWriter()
    output = writer(psyir_tree)
    assert code == output

With this one gfortran -c test.f90 returns no error.

But with the one generated by psyclone, there is an error.

    subroutine foo(a, b, c, n)
      integer :: n
  -   real*8, dimension() :: a
  +   real*8, dimension(1:) :: a
  ?                     ++
  -   real*8, dimension(n) :: b
  +   real*8, dimension(1:n) :: b
  ?                     ++
      real*8, dimension(n:) :: c
      real*8, dimension(:) :: d

    end subroutine foo

Here the error

 >> gfortran test.f90 -c
test.f90:3:21:

    3 |   real*8, dimension() :: a
      |                     1
Error: Expected expression in array specification at (1)