[flang] Do not pass derived type by descriptor when not needed
authorJean Perier <jperier@nvidia.com>
Wed, 20 Apr 2022 07:57:41 +0000 (09:57 +0200)
committerJean Perier <jperier@nvidia.com>
Wed, 20 Apr 2022 08:00:34 +0000 (10:00 +0200)
commit3d63d2111c3e8ee2c897caa6d71429e3bf183e2d
treeaab8cf462f4deff4c6bb304f73b7ca05a6412ed5
parentd46fa023caa2db5a9f1e21dd038bcb626261d958
[flang] Do not pass derived type by descriptor when not needed

A missing "!" in the call interface lowering caused all derived type
arguments without length parameters that require and explicit interface
to be passed via fir.box (runtime descriptor).

This was not the intent: there is no point passing a simple derived type
scalars or explicit shapes by descriptor just because they have an attribute
like TARGET. This would actually be problematic with existing code that is
not always 100% compliant: some code implicitly calls procedures with
TARGET dummy attributes (this is not something a compiler can enforce
if the call and procedure definition are not in the same file).

Add a Scope::IsDerivedTypeWithLengthParameter to avoid passing derived
types with only kind parameters by descriptor. There is no point, the
callee knows about the kind parameter values.

Differential Revision: https://reviews.llvm.org/D123990
flang/include/flang/Semantics/scope.h
flang/lib/Lower/CallInterface.cpp
flang/lib/Semantics/scope.cpp
flang/test/Lower/default-initialization.f90
flang/test/Lower/dummy-argument-derived.f90 [new file with mode: 0644]