[flang][hlfir] Ramp-up support of implicit interface mismatches
authorJean Perier <jperier@nvidia.com>
Fri, 10 Feb 2023 07:56:53 +0000 (08:56 +0100)
committerJean Perier <jperier@nvidia.com>
Fri, 10 Feb 2023 07:57:06 +0000 (08:57 +0100)
commit92e904b9ce2d3319bccf56f05179ee5b5a424f0a
tree5e663a09a3f1ef81b238f5d2bd48a2559f17b8f1
parentfc2c791e89cd10ab9225421f215c2267e832977f
[flang][hlfir] Ramp-up support of implicit interface mismatches

There is a lot of Fortran code that takes advantage of F77 implicit
interface to pass arguments with a different type than those from
the subprogram definition (which is well defined if the storage
and passing convention are the same or compatible).

When the definition and calls are in different files, there is nothing
special to do: the actual arguments are already used to compute the
call interface.

The trouble for lowering comes when the definition is in the same
compilation unit (Semantics raises warning). Then, lowering will
be provided with the interface from the definition to prepare the
argument, and this leads to many ad-hoc handling (see
builder.convertWithSemantics) in the current lowering to cope
with the dummy/actual mismatches on a case by case basis. The
current lowering to FIR is not even complete for all mismatch cases that
can be found in the wild (see https://github.com/llvm/llvm-project/issues/60550),
it is crashing or hitting asserts for many of the added tests.

For HLFIR, instead of coping on a case by case basis, the call
interface will be recomputed according to the actual arguments when
calling an external procedure that can be called with an explicit
interface.

One extra case still has to be handled manually because it may happen
in calls with explicit interfaces: passing a character procedure
designator to a non character procedure dummy (and vice-versa) is widely
accepted even with explicit interfaces (and flang semantic accepts it).
Yet, this "mismatch" cannot be dealt with a simple fir.convert because
character dummy procedure are passed with a different passing
convention: an extra argument is hoisted for the result length (in FIR,
there is no extra argument yet, but the MLIR func argument is a
tuple<fir.boxproc, len>).

Differential Revision: https://reviews.llvm.org/D143636
flang/include/flang/Optimizer/Dialect/FIROps.td
flang/lib/Lower/CallInterface.cpp
flang/lib/Lower/ConvertCall.cpp
flang/lib/Optimizer/Dialect/FIROps.cpp
flang/test/Lower/HLFIR/implicit-call-mismatch.f90 [new file with mode: 0644]