This is an archive of the discontinued LLVM Phabricator instance.

[flang] Support external procedure passed as actual argument with implicit character type
ClosedPublic

Authored by peixin on Apr 24 2022, 7:59 AM.

Details

Summary

As Fortran 2018 15.5.2.9 point 2, the actual argument and dummy argument
have the same type and type parameters and an external function with
assumed character length may be associated with a dummy argument with
explicit character length. As Fortran 2018 15.5.2.9 point 7, if an
external procedure is used as an actual argument, it can be explicitly
declared to have the EXTERNAL attribute. This supports the external
procedure passed as actual argument with implicit character type, either
explicit character length or assumed character length.

Diff Detail

Event Timeline

peixin created this revision.Apr 24 2022, 7:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 24 2022, 7:59 AM
peixin requested review of this revision.Apr 24 2022, 7:59 AM
jeanPerier added inline comments.May 2 2022, 5:57 AM
flang/lib/Optimizer/Builder/Character.cpp
721–724

Can you document in the in the header file that len may be a null Value in createCharacterProcedureTuple ?

flang/test/Lower/ext-proc-as-actual-argument-1.f90
20

I do not think this is a valid program since ext_func is implicitly typed in m, so it is not known to be an "external function with assumed character length" from a Fortran compiler. Ifort actually reject the program.

That being said, gfortran seems to support this, and if we do not want to allow this, we should at least block this in semantics. So something needs to be done, thanks for making this patch.

@peixin, are you adding support for this case because some existing Fortran code is doing this ?

@klausler, I think it is reasonable to support this case, do you agree ?

peixin added inline comments.May 2 2022, 6:43 AM
flang/test/Lower/ext-proc-as-actual-argument-1.f90
20

I do not think this is a valid program since ext_func is implicitly typed in m, so it is not known to be an "external function with assumed character length" from a Fortran compiler. Ifort actually reject the program.

Thanks for correcting me. I think you are right. I forgot to check ifort, which did give the following error:

test.f90(7): error #6633: The type of the actual argument differs from the type of the dummy argument.   [EXT_FUNC]
  call sub(ext_func)

This seems not to be correct. ext_func is implicitly typed to be the same type as dummy argument.

are you adding support for this case because some existing Fortran code is doing this ?

This test case is not from workloads. When I learn FIR lowering, I take in test cases in classic-flang, gfortran, or randomly searched online, or our internal test cases. And sometimes, I add or delete some components from those test cases. So, this is one mixed test case.

I concur, this case should work.

peixin updated this revision to Diff 426584.May 2 2022, 11:47 PM
peixin retitled this revision from [flang] Support external procedure passed as actual argument with character type to [flang] Support external procedure passed as actual argument with implicit character type.
peixin edited the summary of this revision. (Show Details)

Addressed the comments.

  1. Add changes to the header file.
  2. Change the descriptions in title, summary, and test cases.

character type -> implicit character type

jeanPerier accepted this revision.May 4 2022, 1:46 AM

Thanks

This revision is now accepted and ready to land.May 4 2022, 1:46 AM