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
102 stars 27 forks source link

[fparser2-FE] Crash for variable declared as `CLASS(*)` #1494

Closed arporter closed 2 years ago

arporter commented 2 years ago

NEMOVAR has the following function:

! Return a variable by character key
FUNCTION get_var( c_key )

  CHARACTER(LEN=jp_var_name_max_len), INTENT(IN) :: c_key
  TYPE(fvar_typ), POINTER :: get_var
  CLASS(*), POINTER :: this=>null()
  INTEGER :: ilen

  ilen = LEN(c_key)
  CALL gvars_list%get( c_key(1:MIN(ilen, jp_var_name_max_len)), this )
  SELECT TYPE(self => this)
  TYPE IS (fvar_typ)
     get_var => self
  CLASS DEFAULT
     CALL abort
  END SELECT

END FUNCTION get_var

and we get an index-out-of-range because we expect a TYPE or CLASS declaration to always have an associated Fortran2003.Type_Name. We need to fix this at line 1532 of psyir/frontend/fparser2.py.

arporter commented 2 years ago

This has been 'fixed' in #1520 - class declarations are now captured as UnknownFortranType. #1504 remains open for us to discuss whether we should/need to do better than this.