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). But they cannot be used if the type would not 97 be known (e.g., `IAND(X'1',X'2')`). 98* BOZ literals can also be used as REAL values in some contexts where the 99 type is unambiguous, such as initializations of REAL parameters. 100* EQUIVALENCE of numeric and character sequences (a ubiquitous extension) 101* Values for whole anonymous parent components in structure constructors 102 (e.g., `EXTENDEDTYPE(PARENTTYPE(1,2,3))` rather than `EXTENDEDTYPE(1,2,3)` 103 or `EXTENDEDTYPE(PARENTTYPE=PARENTTYPE(1,2,3))`). 104* Some intrinsic functions are specified in the standard as requiring the 105 same type and kind for their arguments (viz., ATAN with two arguments, 106 ATAN2, DIM, HYPOT, MAX, MIN, MOD, and MODULO); 107 we allow distinct types to be used, promoting 108 the arguments as if they were operands to an intrinsic `+` operator, 109 and defining the result type accordingly. 110* DOUBLE COMPLEX intrinsics DREAL, DCMPLX, DCONJG, and DIMAG. 111* INT_PTR_KIND intrinsic returns the kind of c_intptr_t. 112* Restricted specific conversion intrinsics FLOAT, SNGL, IDINT, IFIX, DREAL, 113 and DCMPLX accept arguments of any kind instead of only the default kind or 114 double precision kind. Their result kinds remain as specified. 115* Specific intrinsics AMAX0, AMAX1, AMIN0, AMIN1, DMAX1, DMIN1, MAX0, MAX1, 116 MIN0, and MIN1 accept more argument types than specified. They are replaced by 117 the related generics followed by conversions to the specified result types. 118* When a scalar CHARACTER actual argument of the same kind is known to 119 have a length shorter than the associated dummy argument, it is extended 120 on the right with blanks, similar to assignment. 121* When a dummy argument is `POINTER` or `ALLOCATABLE` and is `INTENT(IN)`, we 122 relax enforcement of some requirements on actual arguments that must otherwise 123 hold true for definable arguments. 124* Assignment of `LOGICAL` to `INTEGER` and vice versa (but not other types) is 125 allowed. The values are normalized. 126* An effectively empty source file (no program unit) is accepted and 127 produces an empty relocatable output file. 128* A `RETURN` statement may appear in a main program. 129* DATA statement initialization is allowed for procedure pointers outside 130 structure constructors. 131* Nonstandard intrinsic functions: ISNAN, SIZEOF 132* A forward reference to a default INTEGER scalar dummy argument is 133 permitted to appear in a specification expression, such as an array 134 bound, in a scope with IMPLICIT NONE(TYPE) if the name 135 of the dummy argument would have caused it to be implicitly typed 136 as default INTEGER if IMPLICIT NONE(TYPE) were absent. 137* OPEN(ACCESS='APPEND') is interpreted as OPEN(POSITION='APPEND') 138 to ease porting from Sun Fortran. 139 140### Extensions supported when enabled by options 141 142* C-style backslash escape sequences in quoted CHARACTER literals 143 (but not Hollerith) [-fbackslash] 144* Logical abbreviations `.T.`, `.F.`, `.N.`, `.A.`, `.O.`, and `.X.` 145 [-flogical-abbreviations] 146* `.XOR.` as a synonym for `.NEQV.` [-fxor-operator] 147* The default `INTEGER` type is required by the standard to occupy 148 the same amount of storage as the default `REAL` type. Default 149 `REAL` is of course 32-bit IEEE-754 floating-point today. This legacy 150 rule imposes an artificially small constraint in some cases 151 where Fortran mandates that something have the default `INTEGER` 152 type: specifically, the results of references to the intrinsic functions 153 `SIZE`, `STORAGE_SIZE`,`LBOUND`, `UBOUND`, `SHAPE`, and the location reductions 154 `FINDLOC`, `MAXLOC`, and `MINLOC` in the absence of an explicit 155 `KIND=` actual argument. We return `INTEGER(KIND=8)` by default in 156 these cases when the `-flarge-sizes` option is enabled. 157 `SIZEOF` and `C_SIZEOF` always return `INTEGER(KIND=8)`. 158* Treat each specification-part like is has `IMPLICIT NONE` 159 [-fimplicit-none-type-always] 160* Ignore occurrences of `IMPLICIT NONE` and `IMPLICIT NONE(TYPE)` 161 [-fimplicit-none-type-never] 162* Old-style `PARAMETER pi=3.14` statement without parentheses 163 [-falternative-parameter-statement] 164 165### Extensions and legacy features deliberately not supported 166 167* `.LG.` as synonym for `.NE.` 168* `REDIMENSION` 169* Allocatable `COMMON` 170* Expressions in formats 171* `ACCEPT` as synonym for `READ *` 172* `TYPE` as synonym for `PRINT` 173* `ARRAY` as synonym for `DIMENSION` 174* `VIRTUAL` as synonym for `DIMENSION` 175* `ENCODE` and `DECODE` as synonyms for internal I/O 176* `IMPLICIT AUTOMATIC`, `IMPLICIT STATIC` 177* Default exponent of zero, e.g. `3.14159E` 178* Characters in defined operators that are neither letters nor digits 179* `B` suffix on unquoted octal constants 180* `Z` prefix on unquoted hexadecimal constants (dangerous) 181* `T` and `F` as abbreviations for `.TRUE.` and `.FALSE.` in DATA (PGI/XLF) 182* Use of host FORMAT labels in internal subprograms (PGI-only feature) 183* ALLOCATE(TYPE(derived)::...) as variant of correct ALLOCATE(derived::...) (PGI only) 184* Defining an explicit interface for a subprogram within itself (PGI only) 185* USE association of a procedure interface within that same procedure's definition 186* NULL() as a structure constructor expression for an ALLOCATABLE component (PGI). 187* Conversion of LOGICAL to INTEGER in expressions. 188* IF (integer expression) THEN ... END IF (PGI/Intel) 189* Comparsion of LOGICAL with ==/.EQ. rather than .EQV. (also .NEQV.) (PGI/Intel) 190* Procedure pointers in COMMON blocks (PGI/Intel) 191* Underindexing multi-dimensional arrays (e.g., A(1) rather than A(1,1)) (PGI only) 192* Legacy PGI `NCHARACTER` type and `NC` Kanji character literals 193* Using non-integer expressions for array bounds (e.g., REAL A(3.14159)) (PGI/Intel) 194* Mixing INTEGER types as operands to bit intrinsics (e.g., IAND); only two 195 compilers support it, and they disagree on sign extension. 196* Module & program names that conflict with an object inside the unit (PGI only). 197* When the same name is brought into scope via USE association from 198 multiple modules, the name must refer to a generic interface; PGI 199 allows a name to be a procedure from one module and a generic interface 200 from another. 201* Type parameter declarations must come first in a derived type definition; 202 some compilers allow them to follow `PRIVATE`, or be intermixed with the 203 component declarations. 204* Wrong argument types in calls to specific intrinsics that have different names than the 205 related generics. Some accepted exceptions are listed above in the allowed extensions. 206 PGI, Intel, and XLF support this in ways that are not numerically equivalent. 207 PGI converts the arguments while Intel and XLF replace the specific by the related generic. 208 209## Preprocessing behavior 210 211* The preprocessor is always run, whatever the filename extension may be. 212* We respect Fortran comments in macro actual arguments (like GNU, Intel, NAG; 213 unlike PGI and XLF) on the principle that macro calls should be treated 214 like function references. Fortran's line continuation methods also work. 215 216## Standard features not silently accepted 217 218* Fortran explicitly ignores type declaration statements when they 219 attempt to type the name of a generic intrinsic function (8.2 p3). 220 One can declare `CHARACTER::COS` and still get a real result 221 from `COS(3.14159)`, for example. f18 will complain when a 222 generic intrinsic function's inferred result type does not 223 match an explicit declaration. This message is a warning. 224