This is an archive of the discontinued LLVM Phabricator instance.

[flang] Allow implicit procedure pointers to associate with explicit procedures
ClosedPublic

Authored by PeteSteinfeld on Nov 11 2021, 12:48 PM.

Details

Summary

Section 10.2.2.4, paragraph 3 states that, for procedure pointer assignment:

If the pointer object has an explicit interface, its characteristics shall be
the same as the pointer target ...

Thus, it's illegal for a procedure pointer with an explicit interface to be
associated with a procedure whose interface is implicit. However, there's no
prohibition that disallows a procedure pointer with an implicit interface from
being associated with a procedure whose interface is explicit.

We were incorrectly emitting an error message for this latter case.

We were also not covering the case of procedures with explicit
interfaces where calling them requires the use of a descriptor. Such
procedures cannot be associated with procedure pointers with implicit
interfaces.

Diff Detail

Event Timeline

PeteSteinfeld created this revision.Nov 11 2021, 12:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 11 2021, 12:48 PM
PeteSteinfeld requested review of this revision.Nov 11 2021, 12:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 11 2021, 12:48 PM

We should not allow a procedure pointer with an implicit interface to be associated with a procedure that must be called only via on explicit interface, though. Use characteristics::Procedure::CanBeCalledViaImplicitInterface() to be sure.

ekieri added a subscriber: ekieri.Nov 11 2021, 2:21 PM

I agree with your interpretation of paragraph 3 (and Peter's of paragraph 4). However, both gfortran and nvfortran allow pointers with explicit interface to target procedures with implicit interface, if my test case is correct. Perhaps it could be useful to test with other compilers? And _if_ most of them take the more liberal standpoint on this, do we keep to the standard, or is it more user-friendly to implement an established extension? Or could the standard be read differently? No strong opinion from my side (but my instinct is to stay with the standard), just wanted to bring this to your attention.

Standard conformance notwithstanding, a procedure pointer should not be allowed to be associated with any target procedure (or pointer) that is not callable via the pointer after the association.

We should not allow a procedure pointer with an implicit interface to be associated with a procedure that must be called only via on explicit interface, though. Use characteristics::Procedure::CanBeCalledViaImplicitInterface() to be sure.

So we already know that the right hand side has an explicit interface. I'm having trouble constructing a test case where a procedure has an explicit interface and also can't be called via an implicit interface. @klausler, do you have an example?

We should not allow a procedure pointer with an implicit interface to be associated with a procedure that must be called only via on explicit interface, though. Use characteristics::Procedure::CanBeCalledViaImplicitInterface() to be sure.

So we already know that the right hand side has an explicit interface. I'm having trouble constructing a test case where a procedure has an explicit interface and also can't be called via an implicit interface. @klausler, do you have an example?

See 15.4.2.2 items (3)-(5). A good simple test case is a procedure with an assumed-shape dummy argument, or any other kind of dummy argument that requires the use of a descriptor. Calls to implicit interfaces never pass descriptors.

Responding to Peter's input regarding procedures with explicit interfaces that
cannot be called via procedure pointers with implicit interfaces.

PeteSteinfeld edited the summary of this revision. (Show Details)Nov 12 2021, 7:36 AM

Thanks for your efforts! Looks good to me, but please wait for Peter. I left a few suggestions inline that you could consider.

flang/lib/Evaluate/tools.cpp
969

Nit: could be useful with a comment indicating that we have an "OK" path out of the function here, cf. ln 942.

It could also be useful if the error message mentioned which condition of 15.4.2.2 is violated. That would then apply to all checks through CanBeCalledViaImplicitInterface(), and I'd say it is better to land this patch first, and work on that as a follow-up (I could also help if you'd like). What do you think?

flang/test/Semantics/assign03.f90
174

Nit: As you mention in the summary, these are additional tests for 10.2.2.4(3).

Standard conformance notwithstanding, a procedure pointer should not be allowed to be associated with any target procedure (or pointer) that is not callable via the pointer after the association.

I find it hard not to agree, thanks for clarifying!

klausler accepted this revision.Nov 15 2021, 8:49 AM
klausler added inline comments.
flang/lib/Evaluate/tools.cpp
966

These lines can be joined.

This revision is now accepted and ready to land.Nov 15 2021, 8:49 AM
PeteSteinfeld marked 2 inline comments as done.Nov 15 2021, 9:53 AM
PeteSteinfeld added inline comments.
flang/lib/Evaluate/tools.cpp
969

Thanks, @ekieri.

I added an "OK". I also added a "TODO" to enhance our reporting for why procedures cannot be called via implicit interfaces.

flang/test/Semantics/assign03.f90
174

Thanks.

I added a comment saying this.