1<!--===- docs/Extensions.md
2
3   Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4   See https://llvm.org/LICENSE.txt for license information.
5   SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
7-->
8
9As a general principle, this compiler will accept by default and
10without complaint many legacy features, extensions to the standard
11language, and features that have been deleted from the standard,
12so long as the recognition of those features would not cause a
13standard-conforming program to be rejected or misinterpreted.
14
15Other non-standard features, which do conflict with the current
16standard specification of the Fortran programming language, are
17accepted if enabled by command-line options.
18
19Intentional violations of the standard
20======================================
21* Scalar `INTEGER` actual argument expressions (not variables!)
22  are converted to the kinds of scalar `INTEGER` dummy arguments
23  when the interface is explicit and the kinds differ.
24  This conversion allows the results of the intrinsics like
25  `SIZE` that (as mentioned below) may return non-default
26  `INTEGER` results by default to be passed.  A warning is
27  emitted when truncation is possible.
28* We are not strict on the contents of `BLOCK DATA` subprograms
29  so long as they contain no executable code, no internal subprograms,
30  and allocate no storage outside a named `COMMON` block.  (C1415)
31
32Extensions, deletions, and legacy features supported by default
33===============================================================
34* Tabs in source
35* `<>` as synonym for `.NE.` and `/=`
36* `$` and `@` as legal characters in names
37* Initialization in type declaration statements using `/values/`
38* Kind specification with `*`, e.g. `REAL*4`
39* `DOUBLE COMPLEX`
40* Signed complex literal constants
41* DEC `STRUCTURE`, `RECORD`, `UNION`, and `MAP`
42* Structure field access with `.field`
43* `BYTE` as synonym for `INTEGER(KIND=1)`
44* Quad precision REAL literals with `Q`
45* `X` prefix/suffix as synonym for `Z` on hexadecimal literals
46* `B`, `O`, `Z`, and `X` accepted as suffixes as well as prefixes
47* Triplets allowed in array constructors
48* Old-style `PARAMETER pi=3.14` statement without parentheses
49* `%LOC`, `%VAL`, and `%REF`
50* Leading comma allowed before I/O item list
51* Empty parentheses allowed in `PROGRAM P()`
52* Missing parentheses allowed in `FUNCTION F`
53* Cray based `POINTER(p,x)` and `LOC()` intrinsic (with `%LOC()` as
54  an alias)
55* Arithmetic `IF`.  (Which branch should NaN take? Fall through?)
56* `ASSIGN` statement, assigned `GO TO`, and assigned format
57* `PAUSE` statement
58* Hollerith literals and edit descriptors
59* `NAMELIST` allowed in the execution part
60* Omitted colons on type declaration statements with attributes
61* COMPLEX constructor expression, e.g. `(x+y,z)`
62* `+` and `-` before all primary expressions, e.g. `x*-y`
63* `.NOT. .NOT.` accepted
64* `NAME=` as synonym for `FILE=`
65* Data edit descriptors without width or other details
66* `D` lines in fixed form as comments or debug code
67* `CONVERT=` on the OPEN and INQUIRE statements
68* `DISPOSE=` on the OPEN and INQUIRE statements
69* Leading semicolons are ignored before any statement that
70  could have a label
71* The character `&` in column 1 in fixed form source is a variant form
72  of continuation line.
73* Character literals as elements of an array constructor without an explicit
74  type specifier need not have the same length; the longest literal determines
75  the length parameter of the implicit type, not the first.
76* Outside a character literal, a comment after a continuation marker (&)
77  need not begin with a comment marker (!).
78* Classic C-style /*comments*/ are skipped, so multi-language header
79  files are easier to write and use.
80* $ and \ edit descriptors are supported in FORMAT to suppress newline
81  output on user prompts.
82* REAL and DOUBLE PRECISION variable and bounds in DO loops
83* Integer literals without explicit kind specifiers that are out of range
84  for the default kind of INTEGER are assumed to have the least larger kind
85  that can hold them, if one exists.
86* BOZ literals can be used as INTEGER values in contexts where the type is
87  unambiguous: the right hand sides of assigments and initializations
88  of INTEGER entities, and as actual arguments to a few intrinsic functions
89  (ACHAR, BTEST, CHAR).  But they cannot be used if the type would not
90  be known (e.g., `IAND(X'1',X'2')`).
91* BOZ literals can also be used as REAL values in some contexts where the
92  type is unambiguous, such as initializations of REAL parameters.
93* EQUIVALENCE of numeric and character sequences (a ubiquitous extension)
94* Values for whole anonymous parent components in structure constructors
95  (e.g., `EXTENDEDTYPE(PARENTTYPE(1,2,3))` rather than `EXTENDEDTYPE(1,2,3)`
96   or `EXTENDEDTYPE(PARENTTYPE=PARENTTYPE(1,2,3))`).
97* Some intrinsic functions are specified in the standard as requiring the
98  same type and kind for their arguments (viz., ATAN with two arguments,
99  ATAN2, DIM, HYPOT, MAX, MIN, MOD, and MODULO);
100  we allow distinct types to be used, promoting
101  the arguments as if they were operands to an intrinsic `+` operator,
102  and defining the result type accordingly.
103* DOUBLE COMPLEX intrinsics DREAL, DCMPLX, DCONJG, and DIMAG.
104* INT_PTR_KIND intrinsic returns the kind of c_intptr_t.
105* Restricted specific conversion intrinsics FLOAT, SNGL, IDINT, IFIX, DREAL,
106  and DCMPLX accept arguments of any kind instead of only the default kind or
107  double precision kind. Their result kinds remain as specified.
108* Specific intrinsics AMAX0, AMAX1, AMIN0, AMIN1, DMAX1, DMIN1, MAX0, MAX1,
109  MIN0, and MIN1 accept more argument types than specified. They are replaced by
110  the related generics followed by conversions to the specified result types.
111* When a scalar CHARACTER actual argument of the same kind is known to
112  have a length shorter than the associated dummy argument, it is extended
113  on the right with blanks, similar to assignment.
114* When a dummy argument is `POINTER` or `ALLOCATABLE` and is `INTENT(IN)`, we
115  relax enforcement of some requirements on actual arguments that must otherwise
116  hold true for definable arguments.
117* Assignment of `LOGICAL` to `INTEGER` and vice versa (but not other types) is
118  allowed.  The values are normalized.
119* An effectively empty source file (no program unit) is accepted and
120  produces an empty relocatable output file.
121* A `RETURN` statement may appear in a main program.
122* DATA statement initialization is allowed for procedure pointers outside
123  structure constructors.
124
125Extensions supported when enabled by options
126--------------------------------------------
127* C-style backslash escape sequences in quoted CHARACTER literals
128  (but not Hollerith) [-fbackslash]
129* Logical abbreviations `.T.`, `.F.`, `.N.`, `.A.`, `.O.`, and `.X.`
130  [-flogical-abbreviations]
131* `.XOR.` as a synonym for `.NEQV.` [-fxor-operator]
132* The default `INTEGER` type is required by the standard to occupy
133  the same amount of storage as the default `REAL` type.  Default
134  `REAL` is of course 32-bit IEEE-754 floating-point today.  This legacy
135  rule imposes an artificially small constraint in some cases
136  where Fortran mandates that something have the default `INTEGER`
137  type: specifically, the results of references to the intrinsic functions
138  `SIZE`, `LBOUND`, `UBOUND`, `SHAPE`, and the location reductions
139  `FINDLOC`, `MAXLOC`, and `MINLOC` in the absence of an explicit
140  `KIND=` actual argument.  We return `INTEGER(KIND=8)` by default in
141  these cases when the `-flarge-sizes` option is enabled.
142* Treat each specification-part like is has `IMPLICIT NONE`
143  [-fimplicit-none-type-always]
144* Ignore occurrences of `IMPLICIT NONE` and `IMPLICIT NONE(TYPE)`
145  [-fimplicit-none-type-never]
146
147Extensions and legacy features deliberately not supported
148---------------------------------------------------------
149* `.LG.` as synonym for `.NE.`
150* `REDIMENSION`
151* Allocatable `COMMON`
152* Expressions in formats
153* `ACCEPT` as synonym for `READ *`
154* `TYPE` as synonym for `PRINT`
155* `ARRAY` as synonym for `DIMENSION`
156* `VIRTUAL` as synonym for `DIMENSION`
157* `ENCODE` and `DECODE` as synonyms for internal I/O
158* `IMPLICIT AUTOMATIC`, `IMPLICIT STATIC`
159* Default exponent of zero, e.g. `3.14159E`
160* Characters in defined operators that are neither letters nor digits
161* `B` suffix on unquoted octal constants
162* `Z` prefix on unquoted hexadecimal constants (dangerous)
163* `T` and `F` as abbreviations for `.TRUE.` and `.FALSE.` in DATA (PGI/XLF)
164* Use of host FORMAT labels in internal subprograms (PGI-only feature)
165* ALLOCATE(TYPE(derived)::...) as variant of correct ALLOCATE(derived::...) (PGI only)
166* Defining an explicit interface for a subprogram within itself (PGI only)
167* USE association of a procedure interface within that same procedure's definition
168* NULL() as a structure constructor expression for an ALLOCATABLE component (PGI).
169* Conversion of LOGICAL to INTEGER in expressions.
170* IF (integer expression) THEN ... END IF  (PGI/Intel)
171* Comparsion of LOGICAL with ==/.EQ. rather than .EQV. (also .NEQV.) (PGI/Intel)
172* Procedure pointers in COMMON blocks (PGI/Intel)
173* Underindexing multi-dimensional arrays (e.g., A(1) rather than A(1,1)) (PGI only)
174* Legacy PGI `NCHARACTER` type and `NC` Kanji character literals
175* Using non-integer expressions for array bounds (e.g., REAL A(3.14159)) (PGI/Intel)
176* Mixing INTEGER types as operands to bit intrinsics (e.g., IAND); only two
177  compilers support it, and they disagree on sign extension.
178* Module & program names that conflict with an object inside the unit (PGI only).
179* When the same name is brought into scope via USE association from
180  multiple modules, the name must refer to a generic interface; PGI
181  allows a name to be a procedure from one module and a generic interface
182  from another.
183* Type parameter declarations must come first in a derived type definition;
184  some compilers allow them to follow `PRIVATE`, or be intermixed with the
185  component declarations.
186* Wrong argument types in calls to specific intrinsics that have different names than the
187  related generics. Some accepted exceptions are listed above in the allowed extensions.
188  PGI, Intel, and XLF support this in ways that are not numerically equivalent.
189  PGI converts the arguments while Intel and XLF replace the specific by the related generic.
190
191Preprocessing behavior
192======================
193* The preprocessor is always run, whatever the filename extension may be.
194* We respect Fortran comments in macro actual arguments (like GNU, Intel, NAG;
195  unlike PGI and XLF) on the principle that macro calls should be treated
196  like function references.  Fortran's line continuation methods also work.
197