ecmwf-ifs / loki

Freely programmable source-to-source translation for Fortran
https://sites.ecmwf.int/docs/loki/
Apache License 2.0
22 stars 11 forks source link

Parsing Cray pointer in Loki #338

Open dhaumont opened 5 days ago

dhaumont commented 5 days ago

Parsing files containing Cray pointers output this error:

No specific handler for node type <class 'fparser.two.Fortran2003.Cray_Pointer_Stmt'>

No specific handler for node type <class 'fparser.two.Fortran2003.Cray_Pointer_Decl_List'>

The message indicates that the fparser frontend successfully parsed the statements as Cray Pointer statements but the translation into a Loki IR failed because there is no representation for them in Loki.

reuterbal commented 5 days ago

Thanks. Could you add a small Fortran reproducer for this?

dhaumont commented 5 days ago

@reuterbal Yes, I am working on the reproducer. Coming soon...

dhaumont commented 5 days ago

cray_pointer.tar.gz @reuterbal Here is the reproducer

reuterbal commented 4 days ago

Thanks. Slightly modified this to a pytest reproducing the issue:

@pytest.mark.parametrize('frontend', available_frontends())
def test_cray_pointers(frontend):
    fcode = """
SUBROUTINE SUBROUTINE_WITH_CRAY_POINTER (KLON,KLEV)
IMPLICIT NONE
INTEGER, INTENT(IN) :: KLON, KLEV
REAL, DIMENSION(KLON,KLEV) :: ZQ
POINTER (IP_ZQ, ZQ)
END SUBROUTINE
    """.strip()
    routine = Subroutine.from_source(fcode, frontend=frontend)

For this, the frontends produce the following:

As a quick fix, I will implement representing the pointer statement as an Intrinsic node for OFP and Fparser.

dhaumont commented 4 days ago

Thanks Balthasar, the reproducer looks much better like that. I will be happy with the workaround, please tell me when it will be available.

reuterbal commented 4 days ago

A fix has been implemented in aea722fd60fa67d0e34fd9bdc161a566ca615fce and filed as a PR. It may take a little while until this lands on the main branch but feel free to test this in the meantime.