2020-09-11 01:34:37 +08:00
|
|
|
<!--===- docs/Calls.md
|
|
|
|
|
|
|
|
Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
|
|
|
|
-->
|
|
|
|
|
2020-09-11 21:17:19 +08:00
|
|
|
# Representation of Fortran function calls
|
|
|
|
|
|
|
|
```eval_rst
|
|
|
|
.. contents::
|
|
|
|
:local:
|
|
|
|
```
|
|
|
|
|
2019-08-24 04:42:13 +08:00
|
|
|
## Procedure reference implementation protocol
|
|
|
|
|
|
|
|
Fortran function and subroutine references are complicated.
|
|
|
|
This document attempts to collect the requirements imposed by the 2018
|
|
|
|
standard (and legacy extensions) on programs and implementations, work
|
|
|
|
through the implications of the various features, and propose both a
|
2019-08-27 06:44:38 +08:00
|
|
|
runtime model and a compiler design.
|
2019-08-24 04:42:13 +08:00
|
|
|
|
|
|
|
All section, requirement, and constraint numbers herein pertain to
|
|
|
|
the Fortran 2018 standard.
|
|
|
|
|
|
|
|
This note does not consider calls to intrinsic procedures, statement
|
|
|
|
functions, or calls to internal runtime support library routines.
|
|
|
|
|
2019-08-29 02:25:55 +08:00
|
|
|
## Quick review of terminology
|
|
|
|
|
|
|
|
* A *dummy argument* is a function or subroutine parameter.
|
|
|
|
It is *associated* with an *effective argument* at each call
|
|
|
|
to the procedure.
|
2019-09-05 01:44:49 +08:00
|
|
|
* The *shape* of an array is a vector containing its extent (size)
|
|
|
|
on each dimension; the *rank* of an array is the number of its
|
|
|
|
dimensions (i.e., the shape of its shape).
|
|
|
|
The absolute values of the lower and upper bounds of the dimensions
|
|
|
|
of an array are not part of its shape, just their difference (plus 1).
|
2019-08-29 02:25:55 +08:00
|
|
|
* An *explicit-shape* array has all of its bounds specified; lower
|
|
|
|
bounds default to 1. These can be passed by with a single address
|
|
|
|
and their contents are contiguous.
|
|
|
|
* An *assumed-size* array is an explicit-shape array with `*` as its
|
2019-08-30 01:58:36 +08:00
|
|
|
final dimension, which is the most-significant one in Fortran
|
|
|
|
and whose value does not affect indexed address calculations.
|
|
|
|
* A *deferred-shape* array (`DIMENSION::A(:)`) is a `POINTER` or `ALLOCATABLE`.
|
2019-08-29 02:25:55 +08:00
|
|
|
`POINTER` target data might not be contiguous.
|
2019-09-05 01:44:49 +08:00
|
|
|
* An *assumed-shape* (not size!) array (`DIMENSION::A(:)`) is a dummy argument
|
|
|
|
that is neither `POINTER` nor `ALLOCATABLE`; its lower bounds can be set
|
|
|
|
by the procedure that receives them (defaulting to 1), and its
|
|
|
|
upper bounds are functions of the lower bounds and the extents of
|
|
|
|
dimensions in the *shape* of the effective argument.
|
2019-08-29 02:54:19 +08:00
|
|
|
* An *assumed-length* `CHARACTER(*)` dummy argument
|
|
|
|
takes its length from the effective argument.
|
2019-09-05 01:44:49 +08:00
|
|
|
* An *assumed-length* `CHARACTER(*)` *result* of an external function (C721)
|
2019-08-29 04:59:48 +08:00
|
|
|
has its length determined by its eventual declaration in a calling scope.
|
2019-08-30 01:58:36 +08:00
|
|
|
* An *assumed-rank* `DIMENSION::A(..)` dummy argument array has an unknown
|
|
|
|
number of dimensions.
|
2019-09-05 01:44:49 +08:00
|
|
|
* A *polymorphic* `CLASS(t)` dummy argument, `ALLOCATABLE`, or `POINTER`
|
|
|
|
has a specific derived type or some extension of that type.
|
|
|
|
An *unlimited polymorphic* `CLASS(*)` object can have any
|
|
|
|
intrinsic or derived type.
|
2019-08-29 04:59:48 +08:00
|
|
|
* *Interoperable* `BIND(C)` procedures are written in C or callable from C.
|
2019-08-29 02:25:55 +08:00
|
|
|
|
2019-08-24 04:42:13 +08:00
|
|
|
## Interfaces
|
|
|
|
|
|
|
|
Referenced procedures may or may not have declared interfaces
|
|
|
|
available to their call sites.
|
|
|
|
|
2019-08-29 04:59:48 +08:00
|
|
|
Procedures with some post-Fortran '77 features *require* an
|
2019-08-30 01:58:36 +08:00
|
|
|
explicit interface to be called (15.4.2.2) or even passed (4.3.4(5)):
|
2019-08-27 06:44:38 +08:00
|
|
|
|
2019-08-29 04:59:48 +08:00
|
|
|
* use of argument keywords in a call
|
2019-08-24 04:42:13 +08:00
|
|
|
* procedures that are `ELEMENTAL` or `BIND(C)`
|
|
|
|
* procedures that are required to be `PURE` due to the context of the call
|
|
|
|
(specification expression, `DO CONCURRENT`, `FORALL`)
|
|
|
|
* dummy arguments with these attributes: `ALLOCATABLE`, `POINTER`,
|
2019-08-30 01:58:36 +08:00
|
|
|
`VALUE`, `TARGET`, `OPTIONAL`, `ASYNCHRONOUS`, `VOLATILE`,
|
|
|
|
and, as a consequence of limitations on its use, `CONTIGUOUS`;
|
|
|
|
`INTENT()`, however, does *not* require an explicit interface
|
2019-08-29 04:59:48 +08:00
|
|
|
* dummy arguments that are coarrays
|
|
|
|
* dummy arguments that are assumed-shape or assumed-rank arrays
|
|
|
|
* dummy arguments with parameterized derived types
|
|
|
|
* dummy arguments that are polymorphic
|
|
|
|
* function result that is an array
|
|
|
|
* function result that is `ALLOCATABLE` or `POINTER`
|
|
|
|
* `CHARACTER` function result whose length is neither constant
|
|
|
|
nor assumed
|
|
|
|
* derived type function result with `LEN` type parameter value that is
|
|
|
|
not constant
|
|
|
|
(note that result derived type parameters cannot be assumed (C795))
|
2019-08-24 04:42:13 +08:00
|
|
|
|
|
|
|
Module procedures, internal procedures, procedure pointers,
|
|
|
|
type-bound procedures, and recursive references by a procedure to itself
|
|
|
|
always have explicit interfaces.
|
2019-08-30 01:58:36 +08:00
|
|
|
(Consequently, they cannot be assumed-length `CHARACTER(*)` functions;
|
2019-08-29 04:59:48 +08:00
|
|
|
conveniently, assumed-length `CHARACTER(*)` functions are prohibited from
|
|
|
|
recursion (15.6.2.1(3))).
|
2019-08-24 04:42:13 +08:00
|
|
|
|
|
|
|
Other uses of procedures besides calls may also require explicit interfaces,
|
|
|
|
such as procedure pointer assignment, type-bound procedure bindings, &c.
|
|
|
|
|
2019-08-27 06:44:38 +08:00
|
|
|
Note that non-parameterized monomorphic derived type arguments do
|
2019-08-29 04:59:48 +08:00
|
|
|
*not* by themselves require the use of an explicit interface.
|
|
|
|
However, dummy arguments with any derived type parameters *do*
|
|
|
|
require an explicit interface, even if they are all `KIND` type
|
|
|
|
parameters.
|
|
|
|
|
|
|
|
15.5.2.9(2) explicitly allows an assumed-length `CHARACTER(*)` function
|
2019-08-30 01:58:36 +08:00
|
|
|
to be passed as an actual argument to an explicit-length dummy;
|
2019-08-29 04:59:48 +08:00
|
|
|
this has implications for calls to character-valued dummy functions
|
|
|
|
and function pointers.
|
2019-08-29 02:25:55 +08:00
|
|
|
(In the scopes that reference `CHARACTER` functions, they must have
|
|
|
|
visible definitions with explicit result lengths.)
|
2019-08-28 01:15:31 +08:00
|
|
|
|
2019-08-24 04:42:13 +08:00
|
|
|
### Implicit interfaces
|
|
|
|
|
2019-08-29 04:59:48 +08:00
|
|
|
In the absence of any characteristic or context that *requires* an
|
2019-08-27 05:23:35 +08:00
|
|
|
explicit interface (see above), an external function or subroutine (R503)
|
|
|
|
or `ENTRY` (R1541) can be called directly or indirectly via its implicit interface.
|
2019-08-24 04:42:13 +08:00
|
|
|
Each of the arguments can be passed as a simple address, including
|
|
|
|
dummy procedures.
|
|
|
|
Procedures that *can* be called via an implicit interface can
|
2019-08-29 04:59:48 +08:00
|
|
|
undergo more thorough checking
|
|
|
|
by semantics when an explicit interface for them exists, but they must be
|
2019-08-24 04:42:13 +08:00
|
|
|
compiled as if all calls to them were through the implicit interface.
|
2019-08-29 04:59:48 +08:00
|
|
|
This note will mention special handling for procedures that are exposed
|
|
|
|
to the possibility of being called with an implicit interface as *F77ish* procedures
|
|
|
|
below; this is of course not standard terminology.
|
2019-08-24 04:42:13 +08:00
|
|
|
|
2019-08-27 05:23:35 +08:00
|
|
|
Internal and module subprograms that are ever passed as arguments &/or
|
2019-08-29 04:59:48 +08:00
|
|
|
assigned as targets of procedure pointers may be F77ish.
|
2019-08-27 03:41:10 +08:00
|
|
|
|
2020-09-21 13:32:18 +08:00
|
|
|
Every F77ish procedure can and must be distinguished at compilation time.
|
2019-08-27 05:23:35 +08:00
|
|
|
Such procedures should respect the external naming conventions (when external)
|
|
|
|
and any legacy ABI used for Fortran '77 programs on the target architecture,
|
|
|
|
so that portable libraries can be compiled
|
2019-08-27 03:41:10 +08:00
|
|
|
and used by distinct implementations (and their versions)
|
2019-08-24 04:42:13 +08:00
|
|
|
of Fortran.
|
|
|
|
|
2019-08-29 04:59:48 +08:00
|
|
|
Note that F77ish functions still have known result types, possibly by means
|
|
|
|
of implicit typing of their names.
|
2019-08-24 04:42:13 +08:00
|
|
|
They can also be `CHARACTER(*)` assumed-length character functions.
|
|
|
|
|
2019-08-29 04:59:48 +08:00
|
|
|
In other words: these F77sh procedures that do not require the use of an explicit
|
|
|
|
interface and that can possibly be referenced, directly or indirectly,
|
|
|
|
with implicit interfaces are limited to argument lists that comprise
|
|
|
|
only the addresses of effective arguments and the length of a `CHARACTER` function result
|
|
|
|
(when there is one), and they can return only scalar values with constant
|
|
|
|
type parameter values.
|
2019-08-27 03:41:10 +08:00
|
|
|
None of their arguments or results need be (or can be) implemented
|
|
|
|
with descriptors,
|
|
|
|
and any internal procedures passed to them as arguments must be
|
2019-08-29 04:59:48 +08:00
|
|
|
simple addresses of non-internal subprograms or trampolines for
|
|
|
|
internal procedures.
|
2019-08-24 04:42:13 +08:00
|
|
|
|
2019-08-30 01:58:36 +08:00
|
|
|
Note that the `INTENT` attribute does not, by itself,
|
2019-08-29 04:59:48 +08:00
|
|
|
require the use of explicit interface; neither does the use of a dummy
|
|
|
|
procedure (implicit or explicit in their interfaces).
|
2020-09-21 13:32:18 +08:00
|
|
|
So the analysis of calls to F77ish procedures must allow for the
|
2019-08-30 01:58:36 +08:00
|
|
|
invisible use of `INTENT(OUT)`.
|
2019-08-24 06:22:53 +08:00
|
|
|
|
2019-08-24 04:42:13 +08:00
|
|
|
## Protocol overview
|
|
|
|
|
|
|
|
Here is a summary script of all of the actions that may need to be taken
|
|
|
|
by the calling procedure and its referenced procedure to effect
|
|
|
|
the call, entry, exit, and return steps of the procedure reference
|
|
|
|
protocol.
|
|
|
|
The order of these steps is not particularly strict, and we have
|
|
|
|
some design alternatives that are explored further below.
|
|
|
|
|
|
|
|
### Before the call:
|
2019-08-24 05:35:38 +08:00
|
|
|
|
2019-08-24 04:42:13 +08:00
|
|
|
1. Compute &/or copy into temporary storage the values of
|
2019-08-29 02:25:55 +08:00
|
|
|
some effective argument expressions and designators (see below).
|
2019-08-28 04:09:31 +08:00
|
|
|
1. Create and populate descriptors for arguments that use them
|
|
|
|
(see below).
|
2019-08-24 05:35:38 +08:00
|
|
|
1. Possibly allocate function result storage,
|
2019-08-24 06:22:53 +08:00
|
|
|
when its size can be known by all callers; function results that are
|
2019-08-24 04:42:13 +08:00
|
|
|
neither `POINTER` nor `ALLOCATABLE` must have explicit shapes (C816).
|
|
|
|
1. Create and populate a descriptor for the function result, if it
|
|
|
|
needs one (deferred-shape/-length `POINTER`, any `ALLOCATABLE`,
|
2019-08-29 04:59:48 +08:00
|
|
|
derived type with non-constant length parameters, &c.).
|
2019-08-24 04:42:13 +08:00
|
|
|
1. Capture the values of host-escaping local objects in memory;
|
|
|
|
package them into single address (for calls to internal procedures &
|
|
|
|
for calls that pass internal procedures as arguments).
|
|
|
|
1. Resolve the target procedure's polymorphic binding, if any.
|
2019-08-30 03:45:42 +08:00
|
|
|
1. Marshal effective argument addresses (or values for `%VAL()` and some
|
|
|
|
discretionary `VALUE` arguments) into registers.
|
2019-08-29 02:25:55 +08:00
|
|
|
1. Marshal `CHARACTER` argument lengths in additional value arguments for
|
|
|
|
`CHARACTER` effective arguments not passed via descriptors.
|
2020-03-31 07:37:30 +08:00
|
|
|
These lengths must be 64-bit integers.
|
2019-08-29 04:59:48 +08:00
|
|
|
1. Marshal an extra argument for the length of a `CHARACTER` function
|
|
|
|
result if the function is F77ish.
|
2019-08-29 02:25:55 +08:00
|
|
|
1. Marshal an extra argument for the function result's descriptor,
|
|
|
|
if it needs one.
|
2019-08-28 05:27:14 +08:00
|
|
|
1. Set the "host instance" (static link) register when calling an internal
|
|
|
|
procedure from its host or another internal procedure, a procedure pointer,
|
2019-08-27 03:41:10 +08:00
|
|
|
or dummy procedure (when it has a descriptor).
|
2019-08-24 04:42:13 +08:00
|
|
|
1. Jump.
|
|
|
|
|
|
|
|
### On entry:
|
2019-08-30 03:45:42 +08:00
|
|
|
1. For subprograms with alternate `ENTRY` points: shuffle `ENTRY` dummy arguments
|
|
|
|
set a compiler-generated variable to identify the alternate entry point,
|
|
|
|
and jump to the common entry point for common processing and a `switch()`
|
|
|
|
to the statement after the `ENTRY`.
|
2019-08-29 02:25:55 +08:00
|
|
|
1. Capture `CHARACTER` argument &/or assumed-length result length values.
|
2019-08-24 05:35:38 +08:00
|
|
|
1. Complete `VALUE` copying if this step will not always be done
|
|
|
|
by the caller (as I think it should be).
|
2019-08-24 06:35:18 +08:00
|
|
|
1. Finalize &/or re-initialize `INTENT(OUT)` non-pointer
|
2019-08-29 02:25:55 +08:00
|
|
|
effective arguments (see below).
|
2019-08-28 04:09:31 +08:00
|
|
|
1. For interoperable procedures called from C: compact discontiguous
|
|
|
|
dummy argument values when necessary (`CONTIGUOUS` &/or
|
2019-08-29 02:25:55 +08:00
|
|
|
explicit-shape/assumed-size arrays of assumed-length `CHARACTER(*)`).
|
2019-08-24 06:22:53 +08:00
|
|
|
1. Optionally compact assumed-shape arguments for contiguity on one
|
|
|
|
or more leading dimensions to improve SIMD vectorization, if not
|
|
|
|
`TARGET` and not already sufficiently contiguous.
|
|
|
|
(PGI does this in the caller, whether the callee needs it or not.)
|
2019-08-24 04:42:13 +08:00
|
|
|
1. Complete allocation of function result storage, if that has
|
|
|
|
not been done by the caller.
|
|
|
|
1. Initialize components of derived type local variables,
|
|
|
|
including the function result.
|
|
|
|
|
|
|
|
Execute the callee, populating the function result or selecting
|
|
|
|
the subroutine's alternate return.
|
|
|
|
|
|
|
|
### On exit:
|
|
|
|
1. Clean up local scope (finalization, deallocation)
|
|
|
|
1. Deallocate `VALUE` argument temporaries.
|
|
|
|
(But don't finalize them; see 7.5.6.3(3)).
|
|
|
|
1. Replace any assumed-shape argument data that were compacted on
|
2019-08-28 04:09:31 +08:00
|
|
|
entry for contiguity when the data were possibly
|
2019-08-24 06:22:53 +08:00
|
|
|
modified across the call (never when `INTENT(IN)` or `VALUE`).
|
2019-08-24 04:42:13 +08:00
|
|
|
1. Identify alternate `RETURN` to caller.
|
|
|
|
1. Marshal results.
|
|
|
|
1. Jump
|
|
|
|
|
|
|
|
### On return to the caller:
|
2019-08-24 06:22:53 +08:00
|
|
|
1. Save the result registers, if any.
|
2019-08-29 02:25:55 +08:00
|
|
|
1. Copy effective argument array designator data that was copied into
|
2019-08-24 04:42:13 +08:00
|
|
|
a temporary back into its original storage (see below).
|
2019-08-29 02:25:55 +08:00
|
|
|
1. Complete deallocation of effective argument temporaries (not `VALUE`).
|
2019-08-24 06:35:18 +08:00
|
|
|
1. Reload definable host-escaping local objects from memory, if they
|
|
|
|
were saved to memory by the host before the call.
|
2019-08-24 04:42:13 +08:00
|
|
|
1. `GO TO` alternate return, if any.
|
|
|
|
1. Use the function result in an expression.
|
|
|
|
1. Eventually, finalize &/or deallocate the function result.
|
|
|
|
|
2019-08-30 01:58:36 +08:00
|
|
|
(I've omitted some obvious steps, like preserving/restoring callee-saved
|
|
|
|
registers on entry/exit, dealing with caller-saved registers before/after
|
|
|
|
calls, and architecture-dependent ABI requirements.)
|
|
|
|
|
2019-08-24 04:42:13 +08:00
|
|
|
## The messy details
|
|
|
|
|
2019-08-29 02:25:55 +08:00
|
|
|
### Copying effective argument values into temporary storage
|
2019-08-24 04:42:13 +08:00
|
|
|
|
|
|
|
There are several conditions that require the compiler to generate
|
|
|
|
code that allocates and populates temporary storage for an actual
|
|
|
|
argument.
|
|
|
|
|
2019-08-29 02:25:55 +08:00
|
|
|
First, effective arguments that are expressions, not designators, obviously
|
2019-08-24 04:42:13 +08:00
|
|
|
need to be computed and captured into memory in order to be passed
|
|
|
|
by reference.
|
2019-08-29 00:14:46 +08:00
|
|
|
This includes parenthesized designators like `(X)`, which are
|
|
|
|
expressions in Fortran, as an important special case.
|
|
|
|
(This case also technically includes unparenthesized constants,
|
|
|
|
but those are better implemented by passing addresses in read-only
|
|
|
|
memory.)
|
2019-08-24 06:22:53 +08:00
|
|
|
The dummy argument cannot be known to have `INTENT(OUT)` or
|
|
|
|
`INTENT(IN OUT)`.
|
2019-08-24 04:42:13 +08:00
|
|
|
|
2019-08-29 00:14:46 +08:00
|
|
|
Small scalar or elemental `VALUE` arguments may be passed in registers,
|
|
|
|
as should arguments wrapped in the legacy VMS `%VAL()` notation.
|
2019-08-24 04:42:13 +08:00
|
|
|
Multiple elemental `VALUE` arguments might be packed into SIMD registers.
|
|
|
|
|
2019-08-29 02:25:55 +08:00
|
|
|
Effective arguments that are designators, not expressions, must also
|
2019-08-24 06:22:53 +08:00
|
|
|
be copied into temporaries in the following situations.
|
2019-08-24 04:42:13 +08:00
|
|
|
|
|
|
|
1. Coindexed objects need to be copied into the local image.
|
2019-08-24 06:22:53 +08:00
|
|
|
This can get very involved if they contain `ALLOCATABLE`
|
2019-08-24 04:42:13 +08:00
|
|
|
components, which also need to be copied, along with their
|
|
|
|
`ALLOCATABLE` components, and may be best implemented with a runtime
|
2019-08-24 06:22:53 +08:00
|
|
|
library routine working off a description of the type.
|
2019-08-29 02:25:55 +08:00
|
|
|
1. Effective arguments associated with dummies with the `VALUE`
|
2019-08-30 01:58:36 +08:00
|
|
|
attribute need to be copied; this can be done on either
|
2019-08-24 04:42:13 +08:00
|
|
|
side of the call, but there are optimization opportunities
|
2019-08-30 01:58:36 +08:00
|
|
|
available when the caller's side bears the responsibility.
|
2019-08-24 04:42:13 +08:00
|
|
|
1. In non-elemental calls, the values of array sections with
|
2019-08-28 06:59:46 +08:00
|
|
|
vector-valued subscripts need to be gathered into temporaries.
|
2019-08-29 02:25:55 +08:00
|
|
|
These effective arguments are not definable, and they are not allowed to
|
2019-08-24 04:42:13 +08:00
|
|
|
be associated with non-`VALUE` dummy arguments with the attributes
|
2019-08-30 01:58:36 +08:00
|
|
|
`INTENT(OUT)`, `INTENT(IN OUT)`, `ASYNCHRONOUS`, or `VOLATILE`
|
|
|
|
(15.5.2.4(21)); `INTENT()` can't always be checked.
|
2019-08-24 06:22:53 +08:00
|
|
|
1. Non-simply-contiguous (9.5.4) arrays being passed to non-`POINTER`
|
2019-08-30 01:58:36 +08:00
|
|
|
dummy arguments that must be contiguous (due to a `CONTIGUOUS`
|
|
|
|
attribute, or not being assumed-shape or assumed-rank; this
|
2019-08-29 04:59:48 +08:00
|
|
|
is always the case for F77ish procedures).
|
2019-08-29 02:25:55 +08:00
|
|
|
This should be a runtime decision, so that effective arguments
|
2019-08-24 04:42:13 +08:00
|
|
|
that turn out to be contiguous can be passed cheaply.
|
2019-08-29 02:25:55 +08:00
|
|
|
This rule does not apply to coarray dummies, whose effective arguments
|
2019-08-24 06:22:53 +08:00
|
|
|
are required to be simply contiguous when this rule would otherwise
|
|
|
|
force the use of a temporary (15.5.2.8); neither does it apply
|
2019-08-29 02:25:55 +08:00
|
|
|
to `ASYNCHRONOUS` and `VOLATILE` effective arguments, which are
|
2019-08-30 03:45:42 +08:00
|
|
|
disallowed when copies would be necessary (C1538 - C1540).
|
2019-08-24 06:22:53 +08:00
|
|
|
*Only temporaries created by this contiguity requirement are
|
2019-08-29 02:25:55 +08:00
|
|
|
candidates for being copied back to the original variable after
|
2019-08-24 06:22:53 +08:00
|
|
|
the call* (see below).
|
|
|
|
|
2019-08-30 01:58:36 +08:00
|
|
|
Fortran requires (18.3.6(5)) that calls to interoperable procedures
|
|
|
|
with dummy argument arrays with contiguity requirements
|
|
|
|
handle the compaction of discontiguous data *in the Fortran callee*,
|
|
|
|
at least when called from C.
|
2019-08-28 04:09:31 +08:00
|
|
|
And discontiguous data must be compacted on the *caller's* side
|
|
|
|
when passed from Fortran to C (18.3.6(6)).
|
|
|
|
|
|
|
|
We could perform all argument compaction (discretionary or
|
|
|
|
required) in the callee, but there are many cases where the
|
2019-08-29 02:25:55 +08:00
|
|
|
compiler knows that the effective argument data are contiguous
|
2019-08-28 04:09:31 +08:00
|
|
|
when compiling the caller (a temporary is needed for other reasons,
|
2019-08-29 02:25:55 +08:00
|
|
|
or the effective argument is simply contiguous) and a run-time test for
|
2019-08-28 04:09:31 +08:00
|
|
|
discontiguity in the callee can be avoided by using a caller-compaction
|
|
|
|
convention when we have the freedom to choose.
|
|
|
|
|
2019-08-24 06:22:53 +08:00
|
|
|
While we are unlikely to want to _needlessly_ use a temporary for
|
2019-08-29 02:25:55 +08:00
|
|
|
an effective argument that does not require one for any of these
|
2019-08-24 05:35:38 +08:00
|
|
|
reasons above, we are specifically disallowed from doing so
|
|
|
|
by the standard in cases where pointers to the original target
|
|
|
|
data are required to be valid across the call (15.5.2.4(9-10)).
|
2019-08-28 04:09:31 +08:00
|
|
|
In particular, compaction of assumed-shape arrays for discretionary
|
|
|
|
contiguity on the leading dimension to ease SIMD vectorization
|
2019-08-28 06:59:46 +08:00
|
|
|
cannot be done safely for `TARGET` dummies without `VALUE`.
|
2019-08-24 05:35:38 +08:00
|
|
|
|
2019-08-29 02:25:55 +08:00
|
|
|
Effective arguments associated with known `INTENT(OUT)` dummies that
|
2019-08-24 06:22:53 +08:00
|
|
|
require allocation of a temporary -- and this can only be for reasons of
|
2019-08-24 05:35:38 +08:00
|
|
|
contiguity -- don't have to populate it, but they do have to perform
|
|
|
|
minimal initialization of any `ALLOCATABLE` components so that
|
|
|
|
the runtime doesn't crash when the callee finalizes and deallocates
|
|
|
|
them.
|
2019-08-30 03:45:42 +08:00
|
|
|
`ALLOCATABLE` coarrays are prohibited from being affected by `INTENT(OUT)`
|
|
|
|
(see C846).
|
2019-08-24 05:35:38 +08:00
|
|
|
Note that calls to implicit interfaces must conservatively allow
|
|
|
|
for the use of `INTENT(OUT)` by the callee.
|
2019-08-24 04:42:13 +08:00
|
|
|
|
2019-08-24 06:22:53 +08:00
|
|
|
Except for `VALUE` and known `INTENT(IN)` dummy arguments, the original
|
2019-08-24 04:42:13 +08:00
|
|
|
contents of local designators that have been compacted into temporaries
|
|
|
|
could optionally have their `ALLOCATABLE` components invalidated
|
|
|
|
across the call as an aid to debugging.
|
|
|
|
|
2019-08-24 06:22:53 +08:00
|
|
|
Except for `VALUE` and known `INTENT(IN)` dummy arguments, the contents of
|
2019-08-29 02:25:55 +08:00
|
|
|
the temporary storage will be copied back into the effective argument
|
2019-08-24 04:42:13 +08:00
|
|
|
designator after control returns from the procedure, and it may be necessary
|
|
|
|
to preserve addresses (or the values of subscripts and cosubscripts
|
2019-08-29 02:25:55 +08:00
|
|
|
needed to recalculate them) of the effective argument designator, or its
|
2019-08-24 04:42:13 +08:00
|
|
|
elements, in additional temporary storage if they can't be safely or
|
|
|
|
quickly recomputed after the call.
|
|
|
|
|
|
|
|
### `INTENT(OUT)` preparation
|
2019-08-24 05:35:38 +08:00
|
|
|
|
2019-08-29 02:25:55 +08:00
|
|
|
Effective arguments that are associated with `INTENT(OUT)`
|
2019-08-24 04:42:13 +08:00
|
|
|
dummy arguments are required to be definable.
|
2019-08-24 05:35:38 +08:00
|
|
|
This cannot always be checked, as the use of `INTENT(OUT)`
|
|
|
|
does not by itself mandate the use of an explicit interface.
|
2019-08-24 04:42:13 +08:00
|
|
|
|
2019-08-24 05:35:38 +08:00
|
|
|
`INTENT(OUT)` arguments are finalized (as if) on entry to the called
|
2019-08-24 04:42:13 +08:00
|
|
|
procedure. In particular, in calls to elemental procedures,
|
|
|
|
the elements of an array are finalized by a scalar or elemental
|
|
|
|
`FINAL` procedure (7.5.6.3(7)).
|
|
|
|
|
2019-08-24 05:35:38 +08:00
|
|
|
Derived type components that are `ALLOCATABLE` are finalized
|
2019-08-30 03:45:42 +08:00
|
|
|
and deallocated; they are prohibited from being coarrays.
|
2019-08-24 05:35:38 +08:00
|
|
|
Components with initializers are (re)initialized.
|
2019-08-24 04:42:13 +08:00
|
|
|
|
2019-08-29 02:25:55 +08:00
|
|
|
The preparation of effective arguments for `INTENT(OUT)` could be
|
2019-08-24 04:42:13 +08:00
|
|
|
done on either side of the call. If the preparation is
|
|
|
|
done by the caller, there is an optimization opportunity
|
|
|
|
in situations where unmodified incoming `INTENT(OUT)` dummy
|
2019-08-30 01:58:36 +08:00
|
|
|
arguments whose types lack `FINAL` procedures are being passed
|
|
|
|
onward as outgoing `INTENT(OUT)` arguments.
|
2019-08-24 04:42:13 +08:00
|
|
|
|
2019-08-28 04:09:31 +08:00
|
|
|
### Arguments and function results requiring descriptors
|
|
|
|
|
2019-08-30 01:58:36 +08:00
|
|
|
Dummy arguments are represented with the addresses of new descriptors
|
2019-08-28 04:09:31 +08:00
|
|
|
when they have any of the following characteristics:
|
|
|
|
|
2019-08-30 01:58:36 +08:00
|
|
|
1. assumed-shape array (`DIMENSION::A(:)`)
|
|
|
|
1. assumed-rank array (`DIMENSION::A(..)`)
|
2019-08-28 04:09:31 +08:00
|
|
|
1. parameterized derived type with assumed `LEN` parameters
|
|
|
|
1. polymorphic (`CLASS(T)`, `CLASS(*)`)
|
|
|
|
1. assumed-type (`TYPE(*)`)
|
|
|
|
1. coarray dummy argument
|
|
|
|
1. `INTENT(IN) POINTER` argument (15.5.2.7, C.10.4)
|
2019-08-29 02:54:19 +08:00
|
|
|
|
2019-08-30 01:58:36 +08:00
|
|
|
`ALLOCATABLE` and other `POINTER` arguments can be passed by simple
|
|
|
|
address.
|
|
|
|
|
2019-08-29 04:59:48 +08:00
|
|
|
Non-F77ish procedures use descriptors to represent two further
|
|
|
|
kinds of dummy arguments:
|
2019-08-29 02:54:19 +08:00
|
|
|
|
|
|
|
1. assumed-length `CHARACTER(*)`
|
2019-08-29 04:59:48 +08:00
|
|
|
1. dummy procedures
|
2019-08-29 02:54:19 +08:00
|
|
|
|
2019-08-29 04:59:48 +08:00
|
|
|
F77ish procedures use other means to convey character length and host instance
|
2019-08-29 02:54:19 +08:00
|
|
|
links (respectively) for these arguments.
|
2019-08-28 04:09:31 +08:00
|
|
|
|
|
|
|
Function results are described by the caller & callee in
|
|
|
|
a caller-supplied descriptor when they have any of the following
|
|
|
|
characteristics, some which necessitate an explicit interface:
|
|
|
|
|
|
|
|
1. deferred-shape array (so `ALLOCATABLE` or `POINTER`)
|
|
|
|
1. derived type with any non-constant `LEN` parameter
|
2019-08-29 04:59:48 +08:00
|
|
|
(C795 prohibit assumed lengths)
|
2019-08-28 04:09:31 +08:00
|
|
|
1. procedure pointer result (when the interface must be explicit)
|
|
|
|
|
|
|
|
Storage for a function call's result is allocated by the caller when
|
|
|
|
possible: the result is neither `ALLOCATABLE` nor `POINTER`,
|
|
|
|
the shape is scalar or explicit, and the type has `LEN` parameters
|
|
|
|
that are constant expressions.
|
|
|
|
In other words, the result doesn't require the use of a descriptor
|
|
|
|
but can't be returned in registers.
|
|
|
|
This allows a function result to be written directly into a local
|
|
|
|
variable or temporary when it is safe to treat the variable as if
|
|
|
|
it were an additional `INTENT(OUT)` argument.
|
2019-08-28 05:27:14 +08:00
|
|
|
(Storage for `CHARACTER` results, assumed or explicit, is always
|
|
|
|
allocated by the caller, and the length is always passed so that
|
2019-08-29 02:25:55 +08:00
|
|
|
an assumed-length external function will work when eventually
|
|
|
|
called from a scope that declares the length that it will use
|
|
|
|
(15.5.2.9 (2)).)
|
2019-08-28 04:09:31 +08:00
|
|
|
|
2019-08-28 06:59:46 +08:00
|
|
|
Note that the lower bounds of the dimensions of non-`POINTER`
|
|
|
|
non-`ALLOCATABLE` dummy argument arrays are determined by the
|
|
|
|
callee, not the caller.
|
|
|
|
(A Fortran pitfall: declaring `A(0:9)`, passing it to a dummy
|
|
|
|
array `D(:)`, and assuming that `LBOUND(D,1)` will be zero
|
|
|
|
in the callee.)
|
|
|
|
If the declaration of an assumed-shape dummy argument array
|
|
|
|
contains an explicit lower bound expression (R819), its value
|
|
|
|
needs to be computed by the callee;
|
|
|
|
it may be captured and saved in the incoming descriptor
|
|
|
|
as long as we assume that argument descriptors can be modified
|
|
|
|
by callees.
|
|
|
|
Callers should fill in all of the fields of outgoing
|
|
|
|
non-`POINTER` non-`ALLOCATABLE` argument
|
|
|
|
descriptors with the assumption that the callee will use 1 for
|
|
|
|
lower bound values, and callees can rely on them being 1 if
|
|
|
|
not modified.
|
2019-08-28 04:09:31 +08:00
|
|
|
|
2019-08-29 02:25:55 +08:00
|
|
|
### Copying temporary storage back into argument designators
|
2019-08-24 04:42:13 +08:00
|
|
|
|
2019-08-24 06:22:53 +08:00
|
|
|
Except for `VALUE` and known `INTENT(IN)` dummy arguments and array sections
|
2019-08-24 04:42:13 +08:00
|
|
|
with vector-valued subscripts (15.5.2.4(21)), temporary storage into
|
2019-08-29 02:25:55 +08:00
|
|
|
which effective argument data were compacted for contiguity before the call
|
2019-08-24 04:42:13 +08:00
|
|
|
must be redistributed back to its original storage by the caller after
|
|
|
|
the return.
|
|
|
|
|
|
|
|
In conjunction with saved cosubscript values, a standard descriptor
|
2019-08-30 01:58:36 +08:00
|
|
|
would suffice to represent a pointer to the original storage into which the
|
|
|
|
temporary data should be redistributed;
|
|
|
|
the descriptor need not be fully populated with type information.
|
2019-08-24 04:42:13 +08:00
|
|
|
|
|
|
|
Note that coindexed objects with `ALLOCATABLE` ultimate components
|
|
|
|
are required to be associated only with dummy arguments with the
|
|
|
|
`VALUE` &/or `INTENT(IN)` attributes (15.6.2.4(6)), so there is no
|
|
|
|
requirement that the local image somehow reallocate remote storage
|
|
|
|
when copying the data back.
|
|
|
|
|
2019-08-27 05:23:35 +08:00
|
|
|
### Polymorphic bindings
|
|
|
|
|
2019-08-27 06:44:38 +08:00
|
|
|
Calls to the type-bound procedures of monomorphic types are
|
2019-08-27 05:23:35 +08:00
|
|
|
resolved at compilation time, as are calls to `NON_OVERRIDABLE`
|
|
|
|
type-bound procedures.
|
|
|
|
The resolution of calls to overridable type-bound procedures of
|
|
|
|
polymorphic types must be completed at execution (generic resolution
|
2019-08-29 02:25:55 +08:00
|
|
|
of type-bound procedure bindings from effective argument types, kinds,
|
2019-08-28 05:27:14 +08:00
|
|
|
and ranks is always a compilation-time task (15.5.6, C.10.6)).
|
2019-08-27 05:23:35 +08:00
|
|
|
|
|
|
|
Each derived type that declares or inherits any overridable
|
|
|
|
type-bound procedure bindings must correspond to a static constant
|
|
|
|
table of code addresses (or, more likely, a static constant type
|
|
|
|
description containing or pointing to such a table, along with
|
|
|
|
information used by the runtime support library for initialization,
|
|
|
|
copying, finalization, and I/O of type instances). Each overridable
|
|
|
|
type-bound procedure in the type corresponds to an index into this table.
|
|
|
|
|
2019-08-28 05:27:14 +08:00
|
|
|
### Host instance linkage
|
2019-08-24 04:42:13 +08:00
|
|
|
|
|
|
|
Calls to dummy procedures and procedure pointers that resolve to
|
2019-08-28 05:27:14 +08:00
|
|
|
internal procedures need to pass an additional "host instance" argument that
|
2020-09-21 13:32:18 +08:00
|
|
|
addresses a block of storage in the stack frame of their
|
2019-08-24 04:42:13 +08:00
|
|
|
host subprogram that was active at the time they were passed as an
|
2019-08-29 02:25:55 +08:00
|
|
|
effective argument or associated with a procedure pointer.
|
2019-08-24 04:42:13 +08:00
|
|
|
This is similar to a static link in implementations of programming
|
|
|
|
languages with nested subprograms, although Fortran only allows
|
|
|
|
one level of nesting.
|
2019-08-27 03:41:10 +08:00
|
|
|
The 64-bit x86 and little-endian OpenPower ABIs reserve registers
|
|
|
|
for this purpose (`%r10` & `R11`); 64-bit ARM has a reserved register
|
|
|
|
that can be used (`x18`).
|
2019-08-24 04:42:13 +08:00
|
|
|
|
|
|
|
The host subprogram objects that are visible to any of their internal
|
|
|
|
subprograms need to be resident in memory across any calls to them
|
|
|
|
(direct or not). Any host subprogram object that might be defined
|
|
|
|
during a call to an internal subprogram needs to be reloaded after
|
|
|
|
a call or reside permanently in memory.
|
|
|
|
A simple conservative analysis of the internal subprograms can
|
|
|
|
identify all of these escaping objects and their definable subset.
|
|
|
|
|
|
|
|
The address of the host subprogram storage used to hold the escaping
|
|
|
|
objects needs to be saved alongside the code address(es) that
|
|
|
|
represent a procedure pointer.
|
2019-08-27 03:41:10 +08:00
|
|
|
It also needs to be conveyed alongside the text address for a
|
2019-08-24 04:42:13 +08:00
|
|
|
dummy procedure.
|
|
|
|
|
2019-08-29 04:59:48 +08:00
|
|
|
For F77ish procedures, we cannot use a "procedure pointer descriptor"
|
|
|
|
to pass a procedure argument -- they expect to receive a single
|
|
|
|
address argument.
|
|
|
|
We will need to package the host instance link in a trampoline
|
2019-08-28 05:27:14 +08:00
|
|
|
that loads its address into the designated register.
|
2019-08-27 03:41:10 +08:00
|
|
|
|
|
|
|
GNU Fortran and Intel Fortran construct trampolines by writing
|
|
|
|
a sequence of machine instructions to a block of storage in the
|
|
|
|
host's stack frame, which requires the stack to be executable,
|
|
|
|
which seems inadvisable for security reasons;
|
|
|
|
XLF manages trampolines in its runtime support library, which adds some overhead
|
|
|
|
to their construction and a reclamation obligation;
|
|
|
|
NAG Fortran manages a static fixed-sized stack of trampolines
|
|
|
|
per call site, imposing a hidden limit on recursion and foregoing
|
|
|
|
reentrancy;
|
2019-08-28 05:27:14 +08:00
|
|
|
PGI passes host instance links in descriptors in additional arguments
|
2019-08-27 05:23:35 +08:00
|
|
|
that are not always successfully forwarded across implicit interfaces,
|
|
|
|
sometimes leading to crashes when they turn out to be needed.
|
2019-08-27 03:41:10 +08:00
|
|
|
|
2019-08-28 01:15:31 +08:00
|
|
|
F18 will manage a pool of trampolines in its runtime support library
|
2019-08-29 02:25:55 +08:00
|
|
|
that can be used to pass internal procedures as effective arguments
|
2019-08-29 04:59:48 +08:00
|
|
|
to F77ish procedures, so that
|
|
|
|
a bare code address can serve to represent the effective argument.
|
2019-08-28 01:15:31 +08:00
|
|
|
But targets that can only be called with an explicit interface
|
|
|
|
have the option of using a "fat pointer" (or additional argument)
|
2019-08-28 06:59:46 +08:00
|
|
|
to represent a dummy procedure closure so as
|
2019-08-28 01:15:31 +08:00
|
|
|
to avoid the overhead of constructing and reclaiming a trampoline.
|
2019-08-28 06:59:46 +08:00
|
|
|
Procedure descriptors can also support multiple code addresses.
|
2019-08-24 04:42:13 +08:00
|
|
|
|
2019-08-27 05:23:35 +08:00
|
|
|
### Naming
|
|
|
|
|
|
|
|
External subroutines and functions (R503) and `ENTRY` points (R1541)
|
|
|
|
with `BIND(C)` (R808) have linker-visible names that are either explicitly
|
|
|
|
specified in the program or determined by straightforward rules.
|
2019-08-29 04:59:48 +08:00
|
|
|
The names of other F77ish external procedures should respect the conventions
|
|
|
|
of the target architecture for legacy Fortran '77 programs; this is typically
|
|
|
|
something like `foo_`.
|
2019-08-27 05:23:35 +08:00
|
|
|
|
2019-08-28 01:15:31 +08:00
|
|
|
In other cases, however, we have fewer constraints on external naming,
|
|
|
|
as well as some additional requirements and goals.
|
2019-08-27 05:23:35 +08:00
|
|
|
|
|
|
|
Module procedures need to be distinguished by the name of their module
|
|
|
|
and (when they have one) the submodule where their interface was
|
|
|
|
defined.
|
|
|
|
Note that submodule names are distinct in their modules, not hierarchical,
|
|
|
|
so at most two levels of qualification are needed.
|
|
|
|
|
|
|
|
Pure `ELEMENTAL` functions (15.8) must use distinct names for any alternate
|
|
|
|
entry points used for packed SIMD arguments of various widths if we support
|
|
|
|
calls to these functions in SIMD parallel contexts.
|
|
|
|
There are already conventions for these names in `libpgmath`.
|
|
|
|
|
2019-08-29 04:59:48 +08:00
|
|
|
The names of non-F77ish external procedures
|
2019-08-29 02:25:55 +08:00
|
|
|
should be distinguished as such so that incorrect attempts to call or pass
|
|
|
|
them with an implicit interface will fail to resolve at link time.
|
|
|
|
Fortran 2018 explicitly enables us to do this with a correction to Fortran
|
2019-08-30 01:58:36 +08:00
|
|
|
2003 in 4.3.4(5).
|
2019-08-27 05:23:35 +08:00
|
|
|
|
|
|
|
Last, there must be reasonably permanent naming conventions used
|
|
|
|
by the F18 runtime library for those unrestricted specific intrinsic
|
|
|
|
functions (table 16.2 in 16.8) and extensions that can be passed as
|
|
|
|
arguments.
|
|
|
|
|
2019-08-27 06:44:38 +08:00
|
|
|
In these cases where external naming is at the discretion
|
|
|
|
of the implementation, we should use names that are not in the C language
|
2019-08-27 05:23:35 +08:00
|
|
|
user namespace, begin with something that identifies
|
|
|
|
the current incompatible version of F18, the module, the submodule, and
|
|
|
|
elemental SIMD width, and are followed by the external name.
|
|
|
|
The parts of the external name can be separated by some character that
|
|
|
|
is acceptable for use in LLVM IR and assembly language but not in user
|
2019-08-27 06:44:38 +08:00
|
|
|
Fortran or C code, or by switching case
|
2019-08-27 06:56:08 +08:00
|
|
|
(so long as there's a way to cope with extension names that don't begin
|
2019-08-27 06:44:38 +08:00
|
|
|
with letters).
|
|
|
|
|
|
|
|
In particular, the period (`.`) seems safe to use as a separator character,
|
2019-08-27 06:56:08 +08:00
|
|
|
so a `Fa.` prefix can serve to isolate these discretionary names from
|
|
|
|
other uses and to identify the earliest link-compatible version.
|
2019-08-29 02:25:55 +08:00
|
|
|
For examples: `Fa.mod.foo`, `Fa.mod.submod.foo`, and (for an external
|
|
|
|
subprogram that requires an explicit interface) `Fa.foo`.
|
2019-09-05 01:44:49 +08:00
|
|
|
When the ABI changes in the future in an incompatible way, the
|
|
|
|
initial prefix becomes `Fb.`, `Fc.`, &c.
|
2019-08-27 05:23:35 +08:00
|
|
|
|
2019-08-28 05:27:14 +08:00
|
|
|
## Summary of checks to be enforced in semantics analysis
|
|
|
|
|
2019-08-30 03:45:42 +08:00
|
|
|
8.5.10 `INTENT` attributes
|
|
|
|
* (C846) An `INTENT(OUT)` argument shall not be associated with an
|
|
|
|
object that is or has an allocatable coarray.
|
|
|
|
* (C847) An `INTENT(OUT)` argument shall not have `LOCK_TYPE` or `EVENT_TYPE`.
|
|
|
|
|
|
|
|
8.5.18 `VALUE` attribute
|
|
|
|
* (C863) The argument cannot be assumed-size, a coarray, or have a coarray
|
|
|
|
ultimate component.
|
|
|
|
* (C864) The argument cannot be `ALLOCATABLE`, `POINTER`, `INTENT(OUT)`,
|
|
|
|
`INTENT(IN OUT)`, or `VOLATILE`.
|
|
|
|
* (C865) If the procedure is `BIND(C)`, the argument cannot be `OPTIONAL`.
|
|
|
|
|
2019-08-28 05:27:14 +08:00
|
|
|
15.5.1 procedure references:
|
2019-08-29 00:14:46 +08:00
|
|
|
* (C1533) can't pass non-intrinsic `ELEMENTAL` as argument
|
|
|
|
* (C1536) alternate return labels must be in the inclusive scope
|
|
|
|
* (C1537) coindexed argument cannot have a `POINTER` ultimate component
|
2019-08-28 05:27:14 +08:00
|
|
|
|
|
|
|
15.5.2.4 requirements for non-`POINTER` non-`ALLOCATABLE` dummies:
|
|
|
|
* (2) dummy must be monomorphic for coindexed polymorphic actual
|
|
|
|
* (2) dummy must be polymorphic for assumed-size polymorphic actual
|
2019-08-29 02:25:55 +08:00
|
|
|
* (2) dummy cannot be `TYPE(*)` if effective is PDT or has TBPs or `FINAL`
|
|
|
|
* (4) character length of effective cannot be less than dummy
|
|
|
|
* (6) coindexed effective with `ALLOCATABLE` ultimate component requires
|
2019-08-28 05:27:14 +08:00
|
|
|
`INTENT(IN)` &/or `VALUE` dummy
|
2019-08-29 02:25:55 +08:00
|
|
|
* (13) a coindexed scalar effective requires a scalar dummy
|
2019-08-30 01:58:36 +08:00
|
|
|
* (14) a non-conindexed scalar effective usually requires a scalar dummy,
|
|
|
|
but there are some exceptions that allow elements of storage sequences
|
2019-08-30 03:45:42 +08:00
|
|
|
to be passed and treated like explicit-shape or assumed-size arrays
|
|
|
|
(see 15.5.2.11)
|
|
|
|
* (16) array rank agreement
|
2019-08-28 05:27:14 +08:00
|
|
|
* (20) `INTENT(OUT)` & `INTENT(IN OUT)` dummies require definable actuals
|
|
|
|
* (21) array sections with vector subscripts can't be passed to definable dummies
|
|
|
|
(`INTENT(OUT)`, `INTENT(IN OUT)`, `ASYNCHRONOUS`, `VOLATILE`)
|
|
|
|
* (22) `VOLATILE` attributes must match when dummy has a coarray ultimate component
|
2019-08-29 00:14:46 +08:00
|
|
|
* (C1538 - C1540) checks for `ASYNCHRONOUS` and `VOLATILE`
|
2019-08-28 05:27:14 +08:00
|
|
|
|
|
|
|
15.5.2.5 requirements for `ALLOCATABLE` & `POINTER` arguments when both
|
2019-08-29 02:25:55 +08:00
|
|
|
the dummy and effective arguments have the same attributes:
|
2019-08-28 05:27:14 +08:00
|
|
|
* (2) both or neither can be polymorphic
|
|
|
|
* (2) both are unlimited polymorphic or both have the same declared type
|
|
|
|
* (3) rank compatibility
|
2019-08-29 02:25:55 +08:00
|
|
|
* (4) effective argument must have deferred the same type parameters as the dummy
|
2019-08-28 05:27:14 +08:00
|
|
|
|
|
|
|
15.5.2.6 `ALLOCATABLE` dummy arguments:
|
2019-08-29 02:25:55 +08:00
|
|
|
* (2) effective must be `ALLOCATABLE`
|
2019-08-28 05:27:14 +08:00
|
|
|
* (3) corank must match
|
2019-08-29 02:25:55 +08:00
|
|
|
* (4) coindexed effective requires `INTENT(IN)` dummy
|
2019-08-28 05:27:14 +08:00
|
|
|
* (7) `INTENT(OUT)` & `INTENT(IN OUT)` dummies require definable actuals
|
|
|
|
|
|
|
|
15.5.2.7 `POINTER` dummy arguments:
|
2019-08-29 00:14:46 +08:00
|
|
|
* (C1541) `CONTIGUOUS` dummy requires simply contiguous actual
|
2019-08-29 02:25:55 +08:00
|
|
|
* (C1542) effective argument cannot be coindexed unless procedure is intrinsic
|
|
|
|
* (2) effective argument must be `POINTER` unless dummy is `INTENT(IN)` and
|
|
|
|
effective could be the right-hand side of a pointer assignment statement
|
2019-08-28 05:27:14 +08:00
|
|
|
|
|
|
|
15.5.2.8 corray dummy arguments:
|
2019-08-29 02:25:55 +08:00
|
|
|
* (1) effective argument must be coarray
|
2019-08-28 05:27:14 +08:00
|
|
|
* (1) `VOLATILE` attributes must match
|
2019-08-30 01:58:36 +08:00
|
|
|
* (2) explicitly or implicitly contiguous dummy array requires a simply contiguous actual
|
2019-08-28 05:27:14 +08:00
|
|
|
|
|
|
|
15.5.2.9 dummy procedures:
|
|
|
|
* (1) explicit dummy procedure interface must have same characteristics as actual
|
2019-08-29 02:25:55 +08:00
|
|
|
* (5) dummy procedure `POINTER` requirements on effective arguments
|
2019-08-28 05:27:14 +08:00
|
|
|
|
|
|
|
15.6.2.1 procedure definitions:
|
|
|
|
* `NON_RECURSIVE` procedures cannot recurse.
|
2019-08-29 04:59:48 +08:00
|
|
|
* Assumed-length `CHARACTER(*)` functions cannot be declared as `RECURSIVE`, array-valued,
|
|
|
|
`POINTER`, `ELEMENTAL`, or `PURE' (C723), and cannot be called recursively (15.6.2.1(3)).
|
2019-09-05 01:44:49 +08:00
|
|
|
* (C823) A function result cannot be a coarray or contain a coarray ultimate component.
|
2019-08-28 05:27:14 +08:00
|
|
|
|
|
|
|
`PURE` requirements (15.7): C1583 - C1599.
|
|
|
|
These also apply to `ELEMENTAL` procedures that are not `IMPURE`.
|
|
|
|
|
|
|
|
`ELEMENTAL` requirements (15.8.1): C15100-C15103,
|
2019-08-29 02:25:55 +08:00
|
|
|
and C1533 (can't pass as effective argument unless intrinsic)
|
2019-08-28 05:27:14 +08:00
|
|
|
|
|
|
|
For interoperable procedures and interfaces (18.3.6):
|
|
|
|
* C1552 - C1559
|
|
|
|
* function result is scalar and of interoperable type (C1553, 18.3.1-3)
|
|
|
|
* `VALUE` arguments are scalar and of interoperable type
|
|
|
|
* `POINTER` dummies cannot be `CONTIGUOUS` (18.3.6 paragraph 2(5))
|
|
|
|
* assumed-type dummies cannot be `ALLOCATABLE`, `POINTER`, assumed-shape, or assumed-rank (18.3.6 paragraph 2 (5))
|
|
|
|
* `CHARACTER` dummies that are `ALLOCATABLE` or `POINTER` must be deferred-length
|
|
|
|
|
2019-08-27 05:23:35 +08:00
|
|
|
## Further topics to document
|
2019-08-24 04:42:13 +08:00
|
|
|
|
|
|
|
* Alternate return specifiers
|
2019-08-29 00:14:46 +08:00
|
|
|
* `%VAL()`, `%REF()`, and `%DESCR()` legacy VMS interoperability extensions
|
2019-08-29 02:25:55 +08:00
|
|
|
* Unrestricted specific intrinsic functions as effective arguments
|
2019-08-24 04:42:13 +08:00
|
|
|
* SIMD variants of `ELEMENTAL` procedures (& unrestricted specific intrinsics)
|
2019-08-28 06:59:46 +08:00
|
|
|
* Elemental subroutine calls with array arguments
|