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