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

Fparser frontend: Array assignments may wrongfully be interpreted as StatementFunction #326

Closed reuterbal closed 1 month ago

reuterbal commented 1 month ago

Consider the following reproducer:

SUBROUTINE SOME_ROUTINE(YDFIELDS,YDMODEL)
USE FIELDS_MOD         , ONLY : FIELDS
USE TYPE_MODEL         , ONLY : MODEL
USE VAR_MOD            , ONLY : ARR
IMPLICIT NONE
TYPE(FIELDS)        ,INTENT(INOUT) :: YDFIELDS
TYPE(MODEL)         ,INTENT(INOUT) :: YDMODEL

ASSOCIATE(YDSURF=>YDFIELDS%YRSURF)
ASSOCIATE(SD_VN=>YDSURF%SD_VN,YSD_VN=>YDSURF%YSD_VN, &
 & LEGBRAD=>YDMODEL%YRML_PHY_EC%YREPHY%LEGBRAD)
IF(LEGBRAD)SD_VN(:,YSD_VN%YACCPR5%MP,:)=SD_VN(:,YSD_VN%YACCPR%MP,:)
IF(LEGBRAD)ARR(:,YSD_VN%YACCPR5%MP,:)=SD_VN(:,YSD_VN%YACCPR%MP,:)
END ASSOCIATE
END ASSOCIATE
END SUBROUTINE SOME_ROUTINE

The lhs symbols in the array assignments (SD_VN or ARR) are missing shape information, which we use as an indicator to assume that this could be a statement function declaration that has simply been misclassified by Fparser. We need to expand the check to make sure these are not missing the shape information simply because it's deferred, e.g., due to import or association.