Skip to content

Handling existing code that overrides Fortran intrinsics #3195

@arporter

Description

@arporter

We know that both NEMO and NEMOVAR override (different) Fortran intrinsics. PSyclone simply does not handle this situation correctly at present.

When attempting to match an intrinsic function call, fparser does check that it hasn't already got a Symbol defined with the same name.
If it has, then it does not match:
https://github.com/stfc/fparser/blob/eee1f4fd40b0b339e6190b709b853227e5b2d857/src/fparser/two/Fortran2003.py#L12526-L12536

However, if an application is using wildcard imports then there will be no Symbol already defined and fparser will match an intrinsic function call unless we are lucky and the overridden version has an argument count inconsistent with the standard-defined version. If fparser does match an intrinsic function then PSyclone simply converts this into an IntrinsicCall node - fparser2._intrinsic_handler does not check for any existing Symbols of the same name:

intrinsic = IntrinsicCall.Intrinsic[node.items[0].string.upper()]

A relatively simple(?) first step would be to extend fparser2._intrinsic_handler to attempt to lookup a symbol with the same name as the intrinsic. If it finds one, then it would have to call the appropriate handler (e.g. Call or ArrayReference). This would work provided:

  1. The symbol is not a transitive import;
  2. We have the originating module listed in RESOLVE_IMPORTS in the transformation script.

Metadata

Metadata

Labels

NEMOIssue relates to the NEMO domainNEMOVARRelating to the NEMOVAR code.bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions