2020-09-11 01:34:37 +08:00
|
|
|
<!--===- docs/Extensions.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
|
|
|
# Fortran Extensions supported by Flang
|
|
|
|
|
|
|
|
```eval_rst
|
|
|
|
.. contents::
|
|
|
|
:local:
|
|
|
|
```
|
|
|
|
|
2018-07-18 07:58:21 +08:00
|
|
|
As a general principle, this compiler will accept by default and
|
|
|
|
without complaint many legacy features, extensions to the standard
|
|
|
|
language, and features that have been deleted from the standard,
|
|
|
|
so long as the recognition of those features would not cause a
|
|
|
|
standard-conforming program to be rejected or misinterpreted.
|
2018-03-21 01:59:07 +08:00
|
|
|
|
2018-07-18 07:58:21 +08:00
|
|
|
Other non-standard features, which do conflict with the current
|
|
|
|
standard specification of the Fortran programming language, are
|
|
|
|
accepted if enabled by command-line options.
|
|
|
|
|
2020-09-11 21:17:19 +08:00
|
|
|
## Intentional violations of the standard
|
|
|
|
|
2019-12-20 11:13:16 +08:00
|
|
|
* Scalar `INTEGER` actual argument expressions (not variables!)
|
|
|
|
are converted to the kinds of scalar `INTEGER` dummy arguments
|
|
|
|
when the interface is explicit and the kinds differ.
|
|
|
|
This conversion allows the results of the intrinsics like
|
2020-01-04 08:32:23 +08:00
|
|
|
`SIZE` that (as mentioned below) may return non-default
|
2019-12-20 11:13:16 +08:00
|
|
|
`INTEGER` results by default to be passed. A warning is
|
|
|
|
emitted when truncation is possible.
|
2020-01-14 06:30:31 +08:00
|
|
|
* We are not strict on the contents of `BLOCK DATA` subprograms
|
|
|
|
so long as they contain no executable code, no internal subprograms,
|
|
|
|
and allocate no storage outside a named `COMMON` block. (C1415)
|
2019-07-09 01:44:14 +08:00
|
|
|
|
2020-09-11 21:17:19 +08:00
|
|
|
## Extensions, deletions, and legacy features supported by default
|
|
|
|
|
2018-03-21 01:59:07 +08:00
|
|
|
* Tabs in source
|
|
|
|
* `<>` as synonym for `.NE.` and `/=`
|
|
|
|
* `$` and `@` as legal characters in names
|
|
|
|
* Initialization in type declaration statements using `/values/`
|
|
|
|
* Kind specification with `*`, e.g. `REAL*4`
|
|
|
|
* `DOUBLE COMPLEX`
|
|
|
|
* Signed complex literal constants
|
2018-07-18 07:58:21 +08:00
|
|
|
* DEC `STRUCTURE`, `RECORD`, `UNION`, and `MAP`
|
2018-03-21 01:59:07 +08:00
|
|
|
* Structure field access with `.field`
|
|
|
|
* `BYTE` as synonym for `INTEGER(KIND=1)`
|
|
|
|
* Quad precision REAL literals with `Q`
|
|
|
|
* `X` prefix/suffix as synonym for `Z` on hexadecimal literals
|
|
|
|
* `B`, `O`, `Z`, and `X` accepted as suffixes as well as prefixes
|
|
|
|
* Triplets allowed in array constructors
|
|
|
|
* `%LOC`, `%VAL`, and `%REF`
|
|
|
|
* Leading comma allowed before I/O item list
|
|
|
|
* Empty parentheses allowed in `PROGRAM P()`
|
|
|
|
* Missing parentheses allowed in `FUNCTION F`
|
2019-07-02 04:22:22 +08:00
|
|
|
* Cray based `POINTER(p,x)` and `LOC()` intrinsic (with `%LOC()` as
|
|
|
|
an alias)
|
2018-07-18 07:58:21 +08:00
|
|
|
* Arithmetic `IF`. (Which branch should NaN take? Fall through?)
|
2018-03-21 01:59:07 +08:00
|
|
|
* `ASSIGN` statement, assigned `GO TO`, and assigned format
|
|
|
|
* `PAUSE` statement
|
|
|
|
* Hollerith literals and edit descriptors
|
|
|
|
* `NAMELIST` allowed in the execution part
|
|
|
|
* Omitted colons on type declaration statements with attributes
|
|
|
|
* COMPLEX constructor expression, e.g. `(x+y,z)`
|
|
|
|
* `+` and `-` before all primary expressions, e.g. `x*-y`
|
|
|
|
* `.NOT. .NOT.` accepted
|
|
|
|
* `NAME=` as synonym for `FILE=`
|
|
|
|
* Data edit descriptors without width or other details
|
|
|
|
* `D` lines in fixed form as comments or debug code
|
2020-09-03 01:37:48 +08:00
|
|
|
* `CARRIAGECONTROL=` on the OPEN and INQUIRE statements
|
2019-03-23 06:08:16 +08:00
|
|
|
* `CONVERT=` on the OPEN and INQUIRE statements
|
|
|
|
* `DISPOSE=` on the OPEN and INQUIRE statements
|
2018-07-13 06:32:31 +08:00
|
|
|
* Leading semicolons are ignored before any statement that
|
|
|
|
could have a label
|
2018-07-18 07:58:21 +08:00
|
|
|
* The character `&` in column 1 in fixed form source is a variant form
|
|
|
|
of continuation line.
|
2019-02-16 04:20:30 +08:00
|
|
|
* Character literals as elements of an array constructor without an explicit
|
|
|
|
type specifier need not have the same length; the longest literal determines
|
|
|
|
the length parameter of the implicit type, not the first.
|
2019-03-15 05:51:40 +08:00
|
|
|
* Outside a character literal, a comment after a continuation marker (&)
|
|
|
|
need not begin with a comment marker (!).
|
2019-03-16 06:19:27 +08:00
|
|
|
* Classic C-style /*comments*/ are skipped, so multi-language header
|
|
|
|
files are easier to write and use.
|
2019-03-23 05:27:18 +08:00
|
|
|
* $ and \ edit descriptors are supported in FORMAT to suppress newline
|
|
|
|
output on user prompts.
|
2019-06-05 06:14:34 +08:00
|
|
|
* REAL and DOUBLE PRECISION variable and bounds in DO loops
|
2019-05-31 04:31:11 +08:00
|
|
|
* Integer literals without explicit kind specifiers that are out of range
|
|
|
|
for the default kind of INTEGER are assumed to have the least larger kind
|
|
|
|
that can hold them, if one exists.
|
2019-06-04 01:51:51 +08:00
|
|
|
* BOZ literals can be used as INTEGER values in contexts where the type is
|
2019-07-10 02:53:11 +08:00
|
|
|
unambiguous: the right hand sides of assigments and initializations
|
|
|
|
of INTEGER entities, and as actual arguments to a few intrinsic functions
|
2019-07-18 03:51:52 +08:00
|
|
|
(ACHAR, BTEST, CHAR). But they cannot be used if the type would not
|
|
|
|
be known (e.g., `IAND(X'1',X'2')`).
|
2019-07-18 05:29:11 +08:00
|
|
|
* BOZ literals can also be used as REAL values in some contexts where the
|
|
|
|
type is unambiguous, such as initializations of REAL parameters.
|
2019-06-20 07:34:22 +08:00
|
|
|
* EQUIVALENCE of numeric and character sequences (a ubiquitous extension)
|
2019-06-22 05:07:39 +08:00
|
|
|
* Values for whole anonymous parent components in structure constructors
|
|
|
|
(e.g., `EXTENDEDTYPE(PARENTTYPE(1,2,3))` rather than `EXTENDEDTYPE(1,2,3)`
|
|
|
|
or `EXTENDEDTYPE(PARENTTYPE=PARENTTYPE(1,2,3))`).
|
2019-07-18 03:51:52 +08:00
|
|
|
* Some intrinsic functions are specified in the standard as requiring the
|
|
|
|
same type and kind for their arguments (viz., ATAN with two arguments,
|
|
|
|
ATAN2, DIM, HYPOT, MAX, MIN, MOD, and MODULO);
|
|
|
|
we allow distinct types to be used, promoting
|
|
|
|
the arguments as if they were operands to an intrinsic `+` operator,
|
|
|
|
and defining the result type accordingly.
|
2019-09-17 16:54:51 +08:00
|
|
|
* DOUBLE COMPLEX intrinsics DREAL, DCMPLX, DCONJG, and DIMAG.
|
2019-08-27 05:58:10 +08:00
|
|
|
* INT_PTR_KIND intrinsic returns the kind of c_intptr_t.
|
2019-09-17 00:34:10 +08:00
|
|
|
* Restricted specific conversion intrinsics FLOAT, SNGL, IDINT, IFIX, DREAL,
|
|
|
|
and DCMPLX accept arguments of any kind instead of only the default kind or
|
|
|
|
double precision kind. Their result kinds remain as specified.
|
|
|
|
* Specific intrinsics AMAX0, AMAX1, AMIN0, AMIN1, DMAX1, DMIN1, MAX0, MAX1,
|
2019-09-17 16:54:51 +08:00
|
|
|
MIN0, and MIN1 accept more argument types than specified. They are replaced by
|
2019-09-17 00:34:10 +08:00
|
|
|
the related generics followed by conversions to the specified result types.
|
2019-10-17 06:36:54 +08:00
|
|
|
* When a scalar CHARACTER actual argument of the same kind is known to
|
|
|
|
have a length shorter than the associated dummy argument, it is extended
|
|
|
|
on the right with blanks, similar to assignment.
|
2019-10-30 03:46:25 +08:00
|
|
|
* When a dummy argument is `POINTER` or `ALLOCATABLE` and is `INTENT(IN)`, we
|
|
|
|
relax enforcement of some requirements on actual arguments that must otherwise
|
|
|
|
hold true for definable arguments.
|
2019-12-07 01:37:07 +08:00
|
|
|
* Assignment of `LOGICAL` to `INTEGER` and vice versa (but not other types) is
|
|
|
|
allowed. The values are normalized.
|
|
|
|
* An effectively empty source file (no program unit) is accepted and
|
|
|
|
produces an empty relocatable output file.
|
2020-01-14 07:13:09 +08:00
|
|
|
* A `RETURN` statement may appear in a main program.
|
2020-06-20 00:16:21 +08:00
|
|
|
* DATA statement initialization is allowed for procedure pointers outside
|
|
|
|
structure constructors.
|
2020-12-16 03:06:44 +08:00
|
|
|
* Nonstandard intrinsic functions: ISNAN, SIZEOF
|
2021-02-19 03:55:31 +08:00
|
|
|
* A forward reference to a default INTEGER scalar dummy argument is
|
|
|
|
permitted to appear in a specification expression, such as an array
|
|
|
|
bound, in a scope with IMPLICIT NONE(TYPE) if the name
|
|
|
|
of the dummy argument would have caused it to be implicitly typed
|
|
|
|
as default INTEGER if IMPLICIT NONE(TYPE) were absent.
|
2021-05-13 03:03:21 +08:00
|
|
|
* OPEN(ACCESS='APPEND') is interpreted as OPEN(POSITION='APPEND')
|
|
|
|
to ease porting from Sun Fortran.
|
2018-07-18 07:58:21 +08:00
|
|
|
|
2020-09-11 21:17:19 +08:00
|
|
|
### Extensions supported when enabled by options
|
|
|
|
|
2018-07-18 07:58:21 +08:00
|
|
|
* C-style backslash escape sequences in quoted CHARACTER literals
|
|
|
|
(but not Hollerith) [-fbackslash]
|
|
|
|
* Logical abbreviations `.T.`, `.F.`, `.N.`, `.A.`, `.O.`, and `.X.`
|
|
|
|
[-flogical-abbreviations]
|
|
|
|
* `.XOR.` as a synonym for `.NEQV.` [-fxor-operator]
|
2020-01-10 01:39:09 +08:00
|
|
|
* The default `INTEGER` type is required by the standard to occupy
|
|
|
|
the same amount of storage as the default `REAL` type. Default
|
|
|
|
`REAL` is of course 32-bit IEEE-754 floating-point today. This legacy
|
|
|
|
rule imposes an artificially small constraint in some cases
|
|
|
|
where Fortran mandates that something have the default `INTEGER`
|
|
|
|
type: specifically, the results of references to the intrinsic functions
|
2020-12-16 03:06:44 +08:00
|
|
|
`SIZE`, `STORAGE_SIZE`,`LBOUND`, `UBOUND`, `SHAPE`, and the location reductions
|
2020-01-10 01:39:09 +08:00
|
|
|
`FINDLOC`, `MAXLOC`, and `MINLOC` in the absence of an explicit
|
|
|
|
`KIND=` actual argument. We return `INTEGER(KIND=8)` by default in
|
|
|
|
these cases when the `-flarge-sizes` option is enabled.
|
2020-12-16 03:06:44 +08:00
|
|
|
`SIZEOF` and `C_SIZEOF` always return `INTEGER(KIND=8)`.
|
2020-08-06 21:47:59 +08:00
|
|
|
* Treat each specification-part like is has `IMPLICIT NONE`
|
|
|
|
[-fimplicit-none-type-always]
|
|
|
|
* Ignore occurrences of `IMPLICIT NONE` and `IMPLICIT NONE(TYPE)`
|
|
|
|
[-fimplicit-none-type-never]
|
2021-01-30 05:34:22 +08:00
|
|
|
* Old-style `PARAMETER pi=3.14` statement without parentheses
|
|
|
|
[-falternative-parameter-statement]
|
2018-03-21 01:59:07 +08:00
|
|
|
|
2020-09-11 21:17:19 +08:00
|
|
|
### Extensions and legacy features deliberately not supported
|
|
|
|
|
2018-03-21 01:59:07 +08:00
|
|
|
* `.LG.` as synonym for `.NE.`
|
|
|
|
* `REDIMENSION`
|
|
|
|
* Allocatable `COMMON`
|
|
|
|
* Expressions in formats
|
|
|
|
* `ACCEPT` as synonym for `READ *`
|
2018-03-24 06:14:52 +08:00
|
|
|
* `TYPE` as synonym for `PRINT`
|
2018-03-21 01:59:07 +08:00
|
|
|
* `ARRAY` as synonym for `DIMENSION`
|
|
|
|
* `VIRTUAL` as synonym for `DIMENSION`
|
|
|
|
* `ENCODE` and `DECODE` as synonyms for internal I/O
|
|
|
|
* `IMPLICIT AUTOMATIC`, `IMPLICIT STATIC`
|
|
|
|
* Default exponent of zero, e.g. `3.14159E`
|
|
|
|
* Characters in defined operators that are neither letters nor digits
|
|
|
|
* `B` suffix on unquoted octal constants
|
2018-10-17 05:42:22 +08:00
|
|
|
* `Z` prefix on unquoted hexadecimal constants (dangerous)
|
2019-06-04 01:51:51 +08:00
|
|
|
* `T` and `F` as abbreviations for `.TRUE.` and `.FALSE.` in DATA (PGI/XLF)
|
2019-02-09 02:39:10 +08:00
|
|
|
* Use of host FORMAT labels in internal subprograms (PGI-only feature)
|
2019-05-31 03:08:06 +08:00
|
|
|
* ALLOCATE(TYPE(derived)::...) as variant of correct ALLOCATE(derived::...) (PGI only)
|
2019-06-25 01:25:37 +08:00
|
|
|
* Defining an explicit interface for a subprogram within itself (PGI only)
|
2019-06-05 05:51:56 +08:00
|
|
|
* USE association of a procedure interface within that same procedure's definition
|
2019-06-06 06:40:59 +08:00
|
|
|
* NULL() as a structure constructor expression for an ALLOCATABLE component (PGI).
|
2019-12-06 08:18:39 +08:00
|
|
|
* Conversion of LOGICAL to INTEGER in expressions.
|
2019-06-06 06:40:59 +08:00
|
|
|
* IF (integer expression) THEN ... END IF (PGI/Intel)
|
|
|
|
* Comparsion of LOGICAL with ==/.EQ. rather than .EQV. (also .NEQV.) (PGI/Intel)
|
|
|
|
* Procedure pointers in COMMON blocks (PGI/Intel)
|
2019-06-26 04:07:32 +08:00
|
|
|
* Underindexing multi-dimensional arrays (e.g., A(1) rather than A(1,1)) (PGI only)
|
2019-06-29 02:16:37 +08:00
|
|
|
* Legacy PGI `NCHARACTER` type and `NC` Kanji character literals
|
2019-07-10 02:53:11 +08:00
|
|
|
* Using non-integer expressions for array bounds (e.g., REAL A(3.14159)) (PGI/Intel)
|
|
|
|
* Mixing INTEGER types as operands to bit intrinsics (e.g., IAND); only two
|
|
|
|
compilers support it, and they disagree on sign extension.
|
2019-07-19 04:57:21 +08:00
|
|
|
* Module & program names that conflict with an object inside the unit (PGI only).
|
2019-07-19 06:26:17 +08:00
|
|
|
* When the same name is brought into scope via USE association from
|
|
|
|
multiple modules, the name must refer to a generic interface; PGI
|
|
|
|
allows a name to be a procedure from one module and a generic interface
|
|
|
|
from another.
|
2019-08-03 06:42:54 +08:00
|
|
|
* Type parameter declarations must come first in a derived type definition;
|
|
|
|
some compilers allow them to follow `PRIVATE`, or be intermixed with the
|
|
|
|
component declarations.
|
2019-09-17 00:34:10 +08:00
|
|
|
* Wrong argument types in calls to specific intrinsics that have different names than the
|
|
|
|
related generics. Some accepted exceptions are listed above in the allowed extensions.
|
2019-09-17 16:54:51 +08:00
|
|
|
PGI, Intel, and XLF support this in ways that are not numerically equivalent.
|
2019-09-17 00:34:10 +08:00
|
|
|
PGI converts the arguments while Intel and XLF replace the specific by the related generic.
|
2019-07-11 06:03:02 +08:00
|
|
|
|
2020-09-11 21:17:19 +08:00
|
|
|
## Preprocessing behavior
|
|
|
|
|
2019-07-11 06:03:02 +08:00
|
|
|
* The preprocessor is always run, whatever the filename extension may be.
|
|
|
|
* We respect Fortran comments in macro actual arguments (like GNU, Intel, NAG;
|
|
|
|
unlike PGI and XLF) on the principle that macro calls should be treated
|
|
|
|
like function references. Fortran's line continuation methods also work.
|
2021-02-18 02:24:14 +08:00
|
|
|
|
|
|
|
## Standard features not silently accepted
|
|
|
|
|
|
|
|
* Fortran explicitly ignores type declaration statements when they
|
|
|
|
attempt to type the name of a generic intrinsic function (8.2 p3).
|
|
|
|
One can declare `CHARACTER::COS` and still get a real result
|
|
|
|
from `COS(3.14159)`, for example. f18 will complain when a
|
|
|
|
generic intrinsic function's inferred result type does not
|
|
|
|
match an explicit declaration. This message is a warning.
|