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 133### Extensions supported when enabled by options 134 135* C-style backslash escape sequences in quoted CHARACTER literals 136 (but not Hollerith) [-fbackslash] 137* Logical abbreviations `.T.`, `.F.`, `.N.`, `.A.`, `.O.`, and `.X.` 138 [-flogical-abbreviations] 139* `.XOR.` as a synonym for `.NEQV.` [-fxor-operator] 140* The default `INTEGER` type is required by the standard to occupy 141 the same amount of storage as the default `REAL` type. Default 142 `REAL` is of course 32-bit IEEE-754 floating-point today. This legacy 143 rule imposes an artificially small constraint in some cases 144 where Fortran mandates that something have the default `INTEGER` 145 type: specifically, the results of references to the intrinsic functions 146 `SIZE`, `STORAGE_SIZE`,`LBOUND`, `UBOUND`, `SHAPE`, and the location reductions 147 `FINDLOC`, `MAXLOC`, and `MINLOC` in the absence of an explicit 148 `KIND=` actual argument. We return `INTEGER(KIND=8)` by default in 149 these cases when the `-flarge-sizes` option is enabled. 150 `SIZEOF` and `C_SIZEOF` always return `INTEGER(KIND=8)`. 151* Treat each specification-part like is has `IMPLICIT NONE` 152 [-fimplicit-none-type-always] 153* Ignore occurrences of `IMPLICIT NONE` and `IMPLICIT NONE(TYPE)` 154 [-fimplicit-none-type-never] 155* Old-style `PARAMETER pi=3.14` statement without parentheses 156 [-falternative-parameter-statement] 157 158### Extensions and legacy features deliberately not supported 159 160* `.LG.` as synonym for `.NE.` 161* `REDIMENSION` 162* Allocatable `COMMON` 163* Expressions in formats 164* `ACCEPT` as synonym for `READ *` 165* `TYPE` as synonym for `PRINT` 166* `ARRAY` as synonym for `DIMENSION` 167* `VIRTUAL` as synonym for `DIMENSION` 168* `ENCODE` and `DECODE` as synonyms for internal I/O 169* `IMPLICIT AUTOMATIC`, `IMPLICIT STATIC` 170* Default exponent of zero, e.g. `3.14159E` 171* Characters in defined operators that are neither letters nor digits 172* `B` suffix on unquoted octal constants 173* `Z` prefix on unquoted hexadecimal constants (dangerous) 174* `T` and `F` as abbreviations for `.TRUE.` and `.FALSE.` in DATA (PGI/XLF) 175* Use of host FORMAT labels in internal subprograms (PGI-only feature) 176* ALLOCATE(TYPE(derived)::...) as variant of correct ALLOCATE(derived::...) (PGI only) 177* Defining an explicit interface for a subprogram within itself (PGI only) 178* USE association of a procedure interface within that same procedure's definition 179* NULL() as a structure constructor expression for an ALLOCATABLE component (PGI). 180* Conversion of LOGICAL to INTEGER in expressions. 181* IF (integer expression) THEN ... END IF (PGI/Intel) 182* Comparsion of LOGICAL with ==/.EQ. rather than .EQV. (also .NEQV.) (PGI/Intel) 183* Procedure pointers in COMMON blocks (PGI/Intel) 184* Underindexing multi-dimensional arrays (e.g., A(1) rather than A(1,1)) (PGI only) 185* Legacy PGI `NCHARACTER` type and `NC` Kanji character literals 186* Using non-integer expressions for array bounds (e.g., REAL A(3.14159)) (PGI/Intel) 187* Mixing INTEGER types as operands to bit intrinsics (e.g., IAND); only two 188 compilers support it, and they disagree on sign extension. 189* Module & program names that conflict with an object inside the unit (PGI only). 190* When the same name is brought into scope via USE association from 191 multiple modules, the name must refer to a generic interface; PGI 192 allows a name to be a procedure from one module and a generic interface 193 from another. 194* Type parameter declarations must come first in a derived type definition; 195 some compilers allow them to follow `PRIVATE`, or be intermixed with the 196 component declarations. 197* Wrong argument types in calls to specific intrinsics that have different names than the 198 related generics. Some accepted exceptions are listed above in the allowed extensions. 199 PGI, Intel, and XLF support this in ways that are not numerically equivalent. 200 PGI converts the arguments while Intel and XLF replace the specific by the related generic. 201 202## Preprocessing behavior 203 204* The preprocessor is always run, whatever the filename extension may be. 205* We respect Fortran comments in macro actual arguments (like GNU, Intel, NAG; 206 unlike PGI and XLF) on the principle that macro calls should be treated 207 like function references. Fortran's line continuation methods also work. 208 209## Standard features not silently accepted 210 211* Fortran explicitly ignores type declaration statements when they 212 attempt to type the name of a generic intrinsic function (8.2 p3). 213 One can declare `CHARACTER::COS` and still get a real result 214 from `COS(3.14159)`, for example. f18 will complain when a 215 generic intrinsic function's inferred result type does not 216 match an explicit declaration. This message is a warning. 217