GFORTRAN(1)
๐ GFORTRAN(1) โ GNU Manual ๐
Part 1 of 7, straight from the GNU manual ๐ง
๐ธ NAME ๐ธ
gfortran โ the GNU Fortran compiler ๐
โจ SYNOPSIS โจ
gfortran [-c|-S|-E]
[-g] [-pg] [-Olevel]
[-Wwarn...] [-pedantic]
[-Idir...] [-Ldir...]
[-Dmacro[=defn]...] [-Umacro]
[-foption...]
[-mmachine-option...]
[-o outfile] infile...
Quick heads up: that synopsis only shows the most useful options ๐ . The rest are waiting for you down below โจ.
๐ DESCRIPTION ๐
Okay so, the gfortran command supports every option that gcc supports ๐ฆ. Only the options that are specific to GNU Fortran get documented here, so you're not missing a mountain of stuff ๐ซถ.
Every GCC and GNU Fortran option is accepted by both gfortran and gcc, plus any other drivers built at the same time, like g++ ๐. That's because adding GNU Fortran to the GCC distribution means all the relevant drivers accept GNU Fortran options. Main character energy, honestly โจ.
Some options come in positive and negative forms. So the negative version of -ffoo is -fno-foo ๐. This manual only documents whichever form isn't the default ๐
.
๐ OPTIONS ๐
Here's the vibe check of every GNU Fortran option, grouped by type ๐ . Explanations live in the sections that follow ๐ฆ.
๐ซ Fortran Language Options
-fall-intrinsics -fallow-argument-mismatch -fallow-invalid-boz
-fbackslash -fcray-pointer -fd-lines-as-code -fd-lines-as-comments
-fdec -fdec-char-conversions -fdec-structure -fdec-intrinsic-ints
-fdec-static -fdec-math -fdec-include -fdec-format-defaults
-fdec-blank-format-item -fdefault-double-8 -fdefault-integer-8
-fdefault-real-8 -fdefault-real-10 -fdefault-real-16 -fdollar-ok
-ffixed-line-length-n -ffixed-line-length-none -fpad-source
-ffree-form -ffree-line-length-n -ffree-line-length-none
-fimplicit-none -finteger-4-integer-8 -fmax-identifier-length
-fmodule-private -ffixed-form -fno-range-check -fopenacc -fopenmp
-freal-4-real-10 -freal-4-real-16 -freal-4-real-8 -freal-8-real-10
-freal-8-real-16 -freal-8-real-4 -std=std -ftest-forall-temp
๐ Preprocessing Options
-A-question[=answer] -Aquestion=answer -C -CC -Dmacro[=defn] -H -P
-Umacro -cpp -dD -dI -dM -dN -dU -fworking-directory -imultilib dir
-iprefix file -iquote -isysroot dir -isystem dir -nocpp -nostdinc
-undef
๐จ Error and Warning Options
-Waliasing -Wall -Wampersand -Warray-bounds -Wc-binding-type
-Wcharacter-truncation -Wconversion -Wdo-subscript
-Wfunction-elimination -Wimplicit-interface -Wimplicit-procedure
-Wintrinsic-shadow -Wuse-without-only -Wintrinsics-std
-Wline-truncation -Wno-align-commons -Wno-overwrite-recursive
-Wno-tabs -Wreal-q-constant -Wsurprising -Wunderflow
-Wunused-parameter -Wrealloc-lhs -Wrealloc-lhs-all
-Wfrontend-loop-interchange -Wtarget-lifetime -fmax-errors=n
-fsyntax-only -pedantic -pedantic-errors
๐ Debugging Options
-fbacktrace -fdump-fortran-optimized -fdump-fortran-original
-fdebug-aux-vars -fdump-fortran-global -fdump-parse-tree
-ffpe-trap=list -ffpe-summary=list
๐ Directory Options
-Idir -Jdir -fintrinsic-modules-path dir
๐ Link Options
-static-libgfortran
๐ Runtime Options
-fconvert=conversion -fmax-subrecord-length=length
-frecord-marker=length -fsign-zero
๐ค Interoperability Options
-fc-prototypes -fc-prototypes-external
๐ Code Generation Options
-faggressive-function-elimination -fblas-matmul-limit=n
-fbounds-check -ftail-call-workaround -ftail-call-workaround=n
-fcheck-array-temporaries
-fcheck=<all|array-temps|bits|bounds|do|mem|pointer|recursion>
-fcoarray=<none|single|lib> -fexternal-blas -ff2c
-ffrontend-loop-interchange -ffrontend-optimize -finit-character=n
-finit-integer=n -finit-local-zero -finit-derived
-finit-logical=<true|false> -finit-real=<zero|inf|-inf|nan|snan>
-finline-matmul-limit=n -finline-arg-packing
-fmax-array-constructor=n -fmax-stack-var-size=n -fno-align-commons
-fno-automatic -fno-protect-parens -fno-underscoring
-fsecond-underscore -fpack-derived -frealloc-lhs -frecursive
-frepack-arrays -fshort-enums -fstack-arrays
๐ฆ Options controlling Fortran dialect
These options tweak the exact flavour of Fortran the compiler accepts ๐ :
-ffree-form,-ffixed-formโ pick the layout of your source file ๐. Free form showed up in Fortran 90, while fixed form is what older Fortran programs were traditionally written in. If you specify neither, the source form is determined by the file extension โจ.-fall-intrinsicsโ accepts every intrinsic procedure, including the GNU-specific extensions ๐. It's great alongside-std=if you want standard-compliance but still want the full intrinsic buffet. Heads up:-Wintrinsics-stdgets ignored, and no user-defined procedure sharing a name with an intrinsic will be called, unless it's explicitly declaredEXTERNAL๐.-fallow-argument-mismatchโ some code calls external procedures with mismatched arguments, either between the call and the procedure definition or between different calls ๐ฌ. That code is non-conforming and usually gets flagged as an error. This option downgrades the error to a warning, which can only be turned off by disabling all warnings with-w. Only a single occurrence per argument gets flagged. It's implied by-std=legacy.
Using this option is strongly discouraged ๐. You can write standard-conforming code that allows different argument types by using an explicit interface and TYPE(*).
-fallow-invalid-bozโ a BOZ literal constant can show up in a limited number of contexts in standard-conforming Fortran ๐ข. This option downgrades the error to a warning and lets a BOZ literal constant appear where the Fortran standard would otherwise prohibit it ๐.-fd-lines-as-code,-fd-lines-as-commentsโ special treatment for lines beginning with "d" or "D" in fixed-form sources ๐ฌ. With-fd-lines-as-code, they're treated as if the first column held a blank. With-fd-lines-as-comments, they're treated as comment lines.-fdecโ DEC compatibility mode ๐ฐ. It enables extensions and other features that mimic the default behavior of older compilers, like DEC's. For details on GNU Fortran's implementation of these extensions, check the full documentation. Other flags enabled by this switch are:-fdollar-ok,-fcray-pointer,-fdec-char-conversions,-fdec-structure,-fdec-intrinsic-ints,-fdec-static,-fdec-math,-fdec-include,-fdec-blank-format-item, and-fdec-format-defaults. If-fd-lines-as-code/-fd-lines-as-commentsare unset, then-fdecalso sets-fd-lines-as-comments.
These features are non-standard and should be avoided at all costs ๐ซ.
-fdec-char-conversionsโ lets you use character literals in assignments andDATAstatements for non-character variables ๐.-fdec-structureโ enables DECSTRUCTUREandRECORD, plusUNION,MAP, and the dot (.) as a member separator, on top of%๐งฑ. This is provided for compatibility only, so Fortran 90 derived types should be used instead wherever possible.-fdec-intrinsic-intsโ enables B/I/J/K kind variants of existing integer functions, likeBIAND,IIAND,JIAND, etc... ๐ข. Check the full documentation for a complete list of intrinsics.-fdec-mathโ enables legacy math intrinsics likeCOTANand degree-valued trigonometric functions, likeTAND,ATAND, etc... ๐, for compatibility with older code.-fdec-staticโ enables DEC-styleSTATICandAUTOMATICattributes to explicitly specify the storage of variables and other objects ๐ฆ.-fdec-includeโ enables parsing ofINCLUDEas a statement in addition to parsing it as an INCLUDE line ๐. When parsed as an INCLUDE statement, it doesn't have to be on a single line and can use line continuations.-fdec-format-defaultsโ enables format specifiersF,G, andIto be used without width specifiers. Default widths get used instead ๐.-fdec-blank-format-itemโ enables a blank format item at the end of a format specification, i.e. nothing following the final comma ๐ซง.-fdollar-okโ allows$as a valid non-first character in a symbol name ๐ฒ. Symbols that start with$are rejected, since it's unclear which implicit typing rules to apply (different vendors implement different rules). Using$inIMPLICITstatements is also rejected.-fbackslashโ changes how backslashes in string literals are read, from a single backslash character to "C-style" escape characters ๐ง. The following combinations get expanded:"\a"(alert),"\b"(backspace),"\f"(form feed),"\n"(newline),"\r"(carriage return),"\t"(horizontal tab),"\v"(vertical tab),"\\"(backslash), and"\0"(NUL). Additionally,"\x"nn,"\u"nnnnand"\U"nnnnnnnn(where each n is a hexadecimal digit) are translated into the Unicode characters for those code points ๐. All other combinations of a character preceded by\stay unexpanded.-fmodule-privateโ sets the default accessibility of module entities toPRIVATE๐. Use-associated entities won't be accessible unless they're explicitly declaredPUBLIC.-ffixed-line-length-nโ sets the column after which characters are ignored in typical fixed-form lines in the source file ๐. Unless-fno-pad-sourceis used, spaces are assumed (as if padded to that length) after the ends of short fixed-form lines. Popular values for n include72(the standard and the default),80(card image), and132(corresponding to "extended-source" options in some popular compilers). n may also benone, meaning the entire line is meaningful and continued character constants never have implicit spaces appended to fill out the line.-ffixed-line-length-0means the same thing as-ffixed-line-length-none.-fno-pad-sourceโ by default, fixed-form lines have spaces assumed (as if padded to that length) after the ends of short fixed-form lines ๐งฝ. This doesn't happen if-ffixed-line-length-0,-ffixed-line-length-none, or-fno-pad-sourceis used. With any of those options, continued character constants never have implicit spaces appended to fill out the line.-ffree-line-length-nโ okay so this one sets the column where the compiler starts ignoring characters on typical free-form lines in your source file. The default is 132 ๐ . You can passnonefornif you want the whole line to count, and-ffree-line-length-0is exactly the same as-ffree-line-length-none๐ง-fmax-identifier-length=nโ this caps how long an identifier can be ๐. Typical values are 31 (Fortran 95) and 63 (Fortran 2003 and later) โจ-fimplicit-noneโ bestie, this one bans implicit typing ๐ โโ๏ธ. The only exceptions are explicitIMPLICITstatements. It's the same as puttingimplicit noneat the top of every procedure, so it's giving strict ๐-fcray-pointerโ turns on the Cray pointer extension, which gives you C-like pointer functionality ๐ฆ-fopenaccโ enables the OpenACC extensions ๐ฅ. In free form that covers!$accdirectives, plus the!$conditional compilation sentinels. In fixed form you getc$acc,*$accand!$accdirectives, plus thec$,*$and!$sentinels. When you link, it also makes sure the OpenACC runtime library gets linked in ๐ธ-fopenmpโ enables the OpenMP extensions ๐. Free form gets!$ompdirectives and the!$sentinels. Fixed form getsc$omp,*$ompand!$ompdirectives, plus thec$,*$and!$sentinels. Linking also pulls in the OpenMP runtime library. Heads up that-fopenmpimplies-frecursive๐ซถ-fno-range-checkโ this turns off range checking on the results of simplifying constant expressions at compile time ๐งฎ. Normally GNU Fortran throws an error on something likea = 1. / 0. With this flag there's no error, andagets+Infinity. If an expression lands outside the relevant range of-HUGE():HUGE(), it's replaced by-Infor+Inf, whichever fits. Same deal withDATA i/Z'FFFFFFFF'/, which overflows an integer on most systems. With this flag the value wraps around, andiends up initialized to -1 ๐-fdefault-integer-8โ sets the default integer and logical types to an 8-byte-wide type ๐. It also changes the kind of integer constants like42. Unlike-finteger-4-integer-8, it leaves variables with an explicit kind declaration alone ๐-fdefault-real-8โ sets the default real type to an 8-byte-wide type ๐. It also changes the kind of non-double real constants like1.0. This flag bumps the default width ofDOUBLE PRECISIONand double real constants like1.d0up to 16 bytes if that's possible. If you pass-fdefault-double-8alongsidefdefault-real-8, thenDOUBLE PRECISIONand double real constants don't get promoted. Unlike-freal-4-real-8,fdefault-real-8leaves variables with explicit kind declarations alone ๐-fdefault-real-10โ same vibe as-fdefault-real-8, but the default real type becomes a 10-byte-wide type โญ. It also changes the kind of non-double real constants like1.0. It bumps the default width ofDOUBLE PRECISIONand double real constants like1.d0up to 16 bytes if possible. If you pass-fdefault-double-8along withfdefault-real-10, thenDOUBLE PRECISIONand double real constants aren't promoted. Unlike-freal-4-real-10,fdefault-real-10leaves variables with explicit kind declarations alone ๐ฆ-fdefault-real-16โ once more, but with a 16-byte-wide default real type ๐ง. It also changes the kind of non-double real constants like1.0. It bumps the default width ofDOUBLE PRECISIONand double real constants like1.d0up to 16 bytes if possible. If you pass-fdefault-double-8withfdefault-real-16, thenDOUBLE PRECISIONand double real constants aren't promoted. Unlike-freal-4-real-16,fdefault-real-16leaves variables with explicit kind declarations alone ๐-fdefault-double-8โ sets theDOUBLE PRECISIONtype and double real constants like1.d0to an 8-byte-wide type ๐ธ. If that's already the default, it does nothing. This flag also stops-fdefault-real-8,-fdefault-real-10and-fdefault-real-16from promotingDOUBLE PRECISIONand double real constants like1.d0to 16 bytes โจ-finteger-4-integer-8โ promotes allINTEGER(KIND=4)entities toINTEGER(KIND=8)entities ๐ฅ. IfKIND=8isn't available, you'll get an error. Be careful with this one, because it may not suit your code ๐ญ
Be careful with-finteger-4-integer-8! The areas of concern are calls to external procedures, alignment inEQUIVALENCEand/orCOMMON, generic interfaces, BOZ literal constant conversion, and I/O. It's suggested that you inspect the intermediate representation of the translated Fortran code, produced by-fdump-tree-original, before you trust it ๐
-freal-4-real-8,-freal-4-real-10,-freal-4-real-16,-freal-8-real-4,-freal-8-real-10,-freal-8-real-16โ these promote allREAL(KIND=M)entities toREAL(KIND=N)entities ๐. IfREAL(KIND=N)isn't available, you'll get an error. The-freal-4-flags also change the default real kind, and the-freal-8-flags change the double-precision real kind. Every other real-kind type is untouched. The promotion also applies to real literal constants of default and double-precision kind, with a specified kind number of 4 or 8 respectively. Heads up though:-fdefault-real-8,-fdefault-real-10,-fdefault-real-10, and-fdefault-double-8take precedence for the default and double-precision real kinds, both for real literal constants and for declarations without a kind number ๐ง . ForREAL(KIND=KIND(1.0)), the literal may get promoted and then the result may get promoted again. Lastly, these options should be used with care and may not suit your code. The areas of concern are calls to external procedures, alignment inEQUIVALENCEand/orCOMMON, generic interfaces, BOZ literal constant conversion, I/O, and calls to intrinsic procedures when passing a value to thekind=dummy argument. It's suggested that you inspect the intermediate representation of the translated Fortran code, produced by-fdump-fortran-originalor-fdump-tree-original, too ๐-std=stdโ tells the compiler which standard your program is supposed to follow ๐. Your choices aref95,f2003,f2008,f2018,gnu, orlegacy. The default isgnu, which is a superset of the latest Fortran standard and includes every extension GNU Fortran supports. You'll still get warnings for obsolete extensions that aren't recommended in new code ๐. Thelegacyvalue is the same, minus the warnings for obsolete extensions, so it's handy for old non-standard programs ๐ง.f95,f2003,f2008andf2018mean strict conformance to Fortran 95, Fortran 2003, Fortran 2008 and Fortran 2018 respectively. Any extension beyond the relevant standard throws an error, and Fortran 77 features that are allowed but obsolescent in later standards get warnings. The deprecated-std=f2008tsis an alias for-std=f2018. It only exists for backwards compatibility with earlier gfortran versions, so please don't use it anymore ๐ซ-ftest-forall-tempโ boosts test coverage by forcing mostforallassignments to use a temporary ๐งช
โจ Enable and customize preprocessing โจ
Okay, so many Fortran compilers, GNU Fortran included, let you pass your source code through a C preprocessor (CPP, sometimes called the Fortran preprocessor, or FPP) for conditional compilation ๐ง. For GNU Fortran that's the GNU C Preprocessor in traditional mode ๐. On systems with case-preserving file names, the preprocessor runs automatically if the filename extension is .F, .FOR, .FTN, .fpp, .FPP, .F90, .F95, .F03 or .F08. To run it manually on any file, use -cpp. To turn it off for files where it would otherwise run automatically, use -nocpp ๐
If a preprocessed file pulls in another file with the Fortran INCLUDE statement, that included file is not preprocessed ๐
โโ๏ธ. If you want included files preprocessed, use the equivalent preprocessor statement #include instead ๐ซถ
When GNU Fortran invokes the preprocessor, __GFORTRAN__ gets defined ๐. You can use the macros __GNUC__, __GNUC_MINOR__ and __GNUC_PATCHLEVEL__ to figure out the compiler version ๐ฅ. For the full details, see Top,,Overview,cpp,The C Preprocessor ๐
GNU Fortran supports several INTEGER and REAL kind types on top of the ones the Fortran standard requires ๐. Which kind types you get depends on your architecture ๐ง . These predefined preprocessor macros let you conditionally include code for those extra kinds: __GFC_INT_1__, __GFC_INT_2__, __GFC_INT_8__, __GFC_INT_16__, __GFC_REAL_10__, and __GFC_REAL_16__ ๐
CPP is the de facto standard for preprocessing Fortran code, but Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines Conditional Compilation ๐ฆ. It isn't widely used, and GNU Fortran doesn't directly support it ๐ญ. If you need it, you can use the program coco to preprocess those files, and you'll find it at <http://www.daniellnagle.com/coco.html> ๐ธ
The following options control preprocessing of Fortran code ๐:
-cpp,-nocppโ-cppenables preprocessing. The preprocessor runs automatically for.fpp,.FPP,.F,.FOR,.FTN,.F90,.F95,.F03and.F08files, but use this flag to turn it on manually for any kind of Fortran file โจ.-nocppis the negative form, and it turns preprocessing off for files with any of those extensions ๐. The preprocessor runs in traditional mode, so any file-format restrictions (especially the line length limits) also apply to the preprocessed output. That means you might want-ffree-line-length-noneor-ffixed-line-length-none๐-dMโ instead of the normal output, this generates a list of#definedirectives for every macro defined while the preprocessor runs, predefined ones included ๐ง. It's a sneaky way to find out what's predefined in your version of the preprocessor ๐. Assuming you have no filefoo.f90, this command shows all the predefined macros:
touch foo.f90; gfortran -cpp -E -dM foo.f90
-dDโ Okay so this one is like-dMbut with two big differences ๐ . It skips the predefined macros, and it spits out both the#definedirectives and the result of preprocessing. Both kinds of output land in the standard output file ๐จ๏ธโจ.-dNโ Basically-dD, but it only shows the macro names and skips their expansions ๐ฆ.-dUโ Also like-dD, but way more selective ๐. It only outputs macros that get expanded, or macros whose definedness gets tested in preprocessor directives. The output is delayed until that use or test happens, and#undefdirectives also show up for macros that were tested but were undefined at that moment ๐.-dIโ Outputs#includedirectives on top of the preprocessing result ๐ง.-fworking-directoryโ This one is giving main character energy ๐. It turns on linemarkers in the preprocessor output so the compiler knows the current working directory at preprocessing time. When it's on, the preprocessor emits a second linemarker after the initial one, containing the current working directory followed by two slashes. GCC will use that directory, if it's in the preprocessed input, as the working directory in some debugging information formats ๐ธ. It's implicitly enabled when debugging information is on, but you can shut it off with the negated form-fno-working-directory. If-Pis in the command line, this option does nothing at all, because no#linedirectives get emitted whatsoever ๐.-idirafter dirโ Searches dir for include files, but only after every directory from-Iand the standard system directories have been exhausted ๐. dir gets treated as a system include directory. If dir begins with=, that=gets swapped out for the sysroot prefix. See--sysrootand-isysroot๐ซถ.-imultilib dirโ Uses dir as a subdirectory of the directory that holds the target-specific C++ headers ๐.-iprefix prefixโ Sets prefix as the prefix for later-iwithprefixoptions. If the prefix is a directory, make sure you include the final/๐.-isysroot dirโ Basically the--sysrootoption, but it only applies to header files. Check out the--sysrootoption for the full scoop โจ.-iquote dirโ Only searches dir for header files requested with"#include "file"". These don't get searched for#include <file>. It happens before all the-Idirectories and the standard system directories ๐. If dir begins with=, the=gets replaced by the sysroot prefix. See--sysrootand-isysroot๐.-isystem dirโ Searches dir for header files, after all the-Idirectories but before the standard system directories ๐ฅ. It gets marked as a system directory, so it gets the same special treatment as the standard ones. If dir begins with=, that=is replaced by the sysroot prefix. See--sysrootand-isysroot๐.-nostdincโ Don't search the standard system directories for header files. Only the directories you gave with-Ioptions (plus the directory of the current file, if that applies) get searched ๐ โโ๏ธ.-undefโ Don't predefine any system-specific or GCC-specific macros. The standard predefined macros stay defined ๐ท.-Apredicate=answerโ Makes an assertion with the predicate predicate and the answer answer ๐ฎ. This form is the preferred one over the older-A predicate(answer)form. The old one still works, but the new one is better because it doesn't use shell special characters ๐ .-A-predicate=answerโ Cancels an assertion with the predicate predicate and the answer answer ๐ซ.-Cโ Don't throw away comments! ๐ซง All comments get passed through to the output file, except comments inside processed directives. Those get deleted along with the directive ๐ญ.
You should be ready for side effects when you use -C, bestie โ ๏ธ. It makes the preprocessor treat comments as tokens in their own right. For example, a comment at the start of what would be a directive line turns that line into an ordinary source line, since the first token is no longer a # ๐.
Warning: this currently handles C-style comments only. The preprocessor does not yet recognize Fortran-style comments ๐.
-CCโ Don't throw away comments, even during macro expansion ๐ง. It's like-C, except comments inside macros also get passed through to the output file wherever that macro gets expanded โจ.
On top of the side effects of -C, the -CC option converts all C++-style comments inside a macro into C-style comments ๐ฆ. That's so using the macro later can't accidentally comment out the rest of the source line. -CC is mostly used to support lint comments ๐ซถ.
Warning: this currently handles C- and C++-style comments only. The preprocessor does not yet recognize Fortran-style comments ๐.
-Dnameโ Predefines name as a macro, with the definition1๐.-Dname=definitionโ The contents of definition get tokenized and processed as if they showed up during translation phase three in a#definedirective ๐ง. The definition gets cut off by any embedded newline characters ๐.
If you're calling the preprocessor from a shell (or something shell-like), you might need the shell's quoting syntax to protect characters like spaces that mean something in shell syntax ๐ธ.
If you want to define a function-like macro on the command line, write its argument list in parentheses before the equals sign (if there is one). Parentheses mean stuff to most shells, so you'll need to quote the option. With sh and csh, "-D'name(args...)=definition'" works ๐
.
-D and -U options get processed in the order you give them on the command line. All -imacros file and -include file options get processed after all the -D and -U options ๐ฅ.
-Hโ Prints the name of each header file that gets used, along with the other normal stuff ๐ฆ. Each name is indented to show how deep it is in the#includestack ๐.-Pโ Inhibits linemarker generation in the preprocessor output ๐. This can be useful when you're running the preprocessor on something that isn't C code and that's going to a program that might get confused by the linemarkers ๐.-Unameโ Cancels any previous definition of name, whether it was built in or provided with a-Doption ๐ซ.
๐จ Options to request or suppress errors and warnings
Errors are diagnostic messages that say the GNU Fortran compiler can't compile that piece of source code ๐ญ. The compiler keeps going anyway, trying to report more errors to help you debug, but it won't produce any compiled output ๐.
Warnings are diagnostic messages about constructions that aren't inherently wrong, but are risky or suggest there's probably a bug in your program ๐. Unless -Werror is specified, they don't stop the program from compiling ๐ซถ.
You can request lots of specific warnings with options that start with -W. For example, -Wimplicit asks for warnings about implicit declarations ๐ฎ. Each of these specific warning options also has a negative form that starts with -Wno-, which turns the warnings off. For example, -Wno-implicit ๐
โโ๏ธ. This manual only lists one of the two forms, whichever one isn't the default ๐ท.
These options control the amount and kinds of errors and warnings GNU Fortran produces ๐ธ:
-fmax-errors=nโ Limits the maximum number of error messages to n. Once that number is hit, GNU Fortran bails out instead of trying to keep processing the source code ๐ญ. If n is0, there's no limit on how many error messages get produced ๐ง.-fsyntax-onlyโ Checks the code for syntax errors, but doesn't actually compile it ๐ซง. It generates module files for each module in the code, but no other output file ๐ฆ.-Wpedantic,-pedanticโ Issues warnings for uses of extensions to Fortran โจ.-pedanticalso applies to C-language constructs when they show up in GNU Fortran source files, like using\ein a character constant inside a directive such as"#include"๐.
Valid Fortran programs should compile fine with or without this option ๐. Without it, certain GNU extensions and traditional Fortran features are supported too ๐. With it, lots of those get rejected ๐ซ.
Some people try to use -pedantic to check programs for conformance, and then they're shocked ๐ญ. It finds some nonstandard practices, but not all of them. Still, improvements to GNU Fortran in this area are very welcome ๐ซถ.
This should be used together with -std=f95, -std=f2003, -std=f2008 or -std=f2018 ๐
.
-pedantic-errorsโ Like-pedantic, except that you get errors instead of warnings ๐ฅ.-Wallโ Turns on commonly used warning options for usage that we recommend avoiding, and that we believe are easy to avoid ๐. Right now this includes-Waliasing,-Wampersand,-Wconversion,-Wsurprising,-Wc-binding-type,-Wintrinsics-std,-Wtabs,-Wintrinsic-shadow,-Wline-truncation,-Wtarget-lifetime,-Winteger-division,-Wreal-q-constant,-Wunusedand-Wundefined-do-loop๐.-Waliasingโ Warns about possible aliasing of dummy arguments ๐ฏโโ๏ธ. Specifically, it warns if the same actual argument is associated with a dummy argument withINTENT(IN)and a dummy argument withINTENT(OUT)in a call with an explicit interface ๐ฆ.
This example will trigger the warning ๐ง:
interface
subroutine bar(a,b)
integer, intent(in) :: a
integer, intent(out) :: b
end subroutine
end interface
integer :: a
call bar(a,a)
-Wampersandโ Warns about a missing ampersand in continued character constants ๐ท. The warning is given with-Wampersand,-pedantic,-std=f95,-std=f2003,-std=f2008and-std=f2018๐. Note: if there's no ampersand in a continued character constant, GNU Fortran assumes the continuation happens at the first non-comment, non-whitespace character after the ampersand that started the continuation ๐ซถ.-Warray-temporariesโ Warns about array temporaries the compiler generates ๐. The info from this warning is sometimes useful for optimization, so you can avoid those temporaries โญ.
Okay so this next batch is all about warnings ๐จ and the debugging flags ๐, and I'm obsessed with how many of them exist. Let's go, bestie ๐
-Wc-binding-typeโ โจ warns if a variable might not be C interoperable ๐ฆ. It's the vibe where you declare something with an intrinsic type using the default kind instead of a kind parameter from the intrinsicISO_C_Bindingmodule, and gfortran calls you out for it. This one is implied by-Wall.-Wcharacter-truncationโ ๐ heads up if a character assignment is going to chop off the string you're assigning โ๏ธ.-Wline-truncationโ ๐ warns when a source code line is about to get cut short. This is implied by-Wall. For free-form source code, the default is-Werror=line-truncation, so truncations get reported as errors instead ๐ญ.-Wconversionโ ๐ warns about implicit conversions that are likely to change the value of the expression after conversion. Implied by-Wall.-Wconversion-extraโ warns about implicit conversions between different types and kinds. It does not imply-Wconversion๐ โโ๏ธ.-Wextraโ ๐ซ turns on some warning options for language features that can be problematic. Right now that's-Wcompare-reals,-Wunused-parameterand-Wdo-subscript.-Wfrontend-loop-interchangeโ warns when you're using-ffrontend-loop-interchangeto do loop interchanges ๐.-Wimplicit-interfaceโ warns if a procedure is called without an explicit interface. Note that it only checks that an explicit interface is present. It doesn't check that the declared interfaces are consistent across program units ๐คทโโ๏ธ.-Wimplicit-procedureโ warns if a procedure is called that has neither an explicit interface nor has been declared as"EXTERNAL".-Winteger-divisionโ warns if a constant integer division truncates its result. For example,3/5evaluates to0๐.-Wintrinsics-stdโ warns if gfortran finds a procedure named like an intrinsic that isn't available in the currently selected standard (-std). Because of that, it treats it as an"EXTERNAL"procedure. Use-fall-intrinsicsif you want to never trigger this and always link to the intrinsic, no matter which standard is selected ๐ง.-Wno-overwrite-recursiveโ ๐ don't warn when-fno-automaticis used with-frecursive. Recursion will be broken if the relevant local variables don't have the attribute"AUTOMATIC"explicitly declared. Use this to shush the warning when you know recursion isn't broken. It's useful for build environments that use-Werror.-Wreal-q-constantโ warns if a real-literal-constant contains a"q"exponent-letter.-Wsurprisingโ ๐ warns when "suspicious" code constructs show up. They're technically legal, but they usually mean an error was made. Right now it fires under these circumstances:- An INTEGER SELECT construct has a CASE that can never be matched, since its lower value is greater than its upper value.
- A LOGICAL SELECT construct has three CASE statements.
- A TRANSFER specifies a source that is shorter than the destination.
- The type of a function result is declared more than once with the same type. If
-pedanticor standard-conforming mode is enabled, this is an error. - A
"CHARACTER"variable is declared with negative length.
-Wtabsโ ๐ by default, tabs are accepted as whitespace, but tabs are not members of the Fortran Character Set. For continuation lines, a tab followed by a digit between 1 and 9 is supported.-Wtabsmakes gfortran issue a warning whenever a tab is encountered. It's active for-pedantic,-std=f95,-std=f2003,-std=f2008,-std=f2018and-Wall.-Wundefined-do-loopโ warns if a DO loop with a step of either 1 or -1 yields an underflow or an overflow while the induction variable of the loop is iterating. This is implied by-Wall.-Wunderflowโ โ produces a warning when numerical constant expressions are encountered that yield an UNDERFLOW during compilation. Enabled by default.-Wintrinsic-shadowโ warns if a user-defined procedure or module procedure has the same name as an intrinsic. In that case, an explicit interface or an"EXTERNAL"or"INTRINSIC"declaration might be needed so calls get resolved to the procedure you actually want. This is implied by-Wall.-Wuse-without-onlyโ warns if aUSEstatement has noONLYqualifier, which means it implicitly imports all public entities of the used module.-Wunused-dummy-argumentโ warns about unused dummy arguments. Implied by-Wall.-Wunused-parameterโ ๐ค this one is different from gcc's meaning. gfortran's version doesn't warn about unused dummy arguments (for that, see-Wunused-dummy-argument). Instead, it warns about unused"PARAMETER"values.-Wunused-parameteris implied by-Wextraif-Wunusedor-Wallis also used.-Walign-commonsโ by default, gfortran warns about any variables being padded for proper alignment inside a"COMMON"block. You can turn this off with-Wno-align-commons. See also-falign-commons.-Wfunction-eliminationโ warns if any calls to impure functions are eliminated by the optimizations enabled by-ffrontend-optimize. Implied by-Wextra.-Wrealloc-lhsโ ๐ warns when the compiler might insert code for allocation or reallocation of an allocatable array variable of intrinsic type in intrinsic assignments. In hot loops, the Fortran 2003 reallocation feature may reduce performance. If the array is already allocated with the correct shape, consider using a whole-array array-spec (e.g."(:,:,:)") for the variable on the left-hand side to prevent the reallocation check. The warning can show up even when the compiler would optimize the reallocation checks away, for instance when the right-hand side contains the same variable multiplied by a scalar. See also-frealloc-lhs.-Wrealloc-lhs-allโ warns when the compiler inserts code for allocation or reallocation of an allocatable variable. This includes scalars and derived types.-Wcompare-realsโ warns when comparing real or complex types for equality or inequality. Implied by-Wextra.-Wtarget-lifetimeโ warns if the pointer in a pointer assignment might live longer than its target. Implied by-Wall.-Wzerotripโ warns if aDOloop is known to execute zero times at compile time. Implied by-Wall.-Wdo-subscriptโ ๐ง warns if an array subscript inside a DO loop could lead to an out-of-bounds access, even if the compiler can't prove the statement is actually executed. Here's the sort of situation it's talking about:
real a(3)
do i=1,4
if (condition(i)) then
a(i) = 1.2
end if
end do
This option is implied by -Wextra.
-Werrorโ ๐จ turns all warnings into errors.
Some of these have no effect when compiling programs written in Fortran.
๐ Options for debugging your program or GNU Fortran ๐
GNU Fortran has a bunch of special options for debugging either your program or the GNU Fortran compiler itself. Bestie, these are for the deep dives ๐ง โจ
-fdump-fortran-originalโ outputs the internal parse tree after the source program has been translated into internal representation. It's mostly useful for debugging the GNU Fortran compiler itself. The output might change between releases, and this option may also generate internal compiler errors for features that were only recently added.-fdump-fortran-optimizedโ outputs the parse tree after front-end optimization. Mostly useful for debugging the GNU Fortran compiler itself. The output might change between releases, and this option may also generate internal compiler errors for features that were only recently added.-fdump-parse-treeโ outputs the internal parse tree after the source program has been translated into internal representation. It's mostly useful for debugging the GNU Fortran compiler itself. The output might change between releases, and this option may also generate internal compiler errors for features that were only recently added.
โ ๏ธ This option is deprecated; use -fdump-fortran-original instead.
-fdebug-aux-varsโ ๐ renames internal variables created by the gfortran front end and makes them accessible to a debugger. Their names then start with upper-case letters followed by an underscore. This is useful for debugging the compiler's code generation together with-fdump-tree-original, and for debugging the executable program by using-gor-ggdb3.-fdump-fortran-globalโ outputs a list of the global identifiers after translating into middle-end representation. Mostly useful for debugging the GNU Fortran compiler itself. The output might change between releases, and this option may also generate internal compiler errors for features that were only recently added.-ffpe-trap=listโ ๐ฅ specifies a list of floating point exception traps to enable. On most systems, if a floating point exception occurs and the trap for that exception is enabled, aSIGFPEsignal is sent and the program is aborted, producing a core file that's useful for debugging.listis a (possibly empty) comma-separated list of the following exceptions:invalid(invalid floating point operation, such as"SQRT(-1.0)")zero(division by zero)overflow(overflow in a floating point operation)underflow(underflow in a floating point operation)inexact(loss of precision during operation)denormal(operation performed on a denormal value)
The first five exceptions correspond to the five IEEE 754 exceptions, whereas the last one (denormal) is not part of the IEEE 754 standard but is available on some common architectures such as x86.
The first three exceptions (invalid, zero, and overflow) often indicate serious errors. Unless the program has provisions for dealing with these, enabling traps for them is probably a good idea ๐.
If the option is used more than once on the command line, the lists will be joined: '"ffpe-trap="list1 "ffpe-trap="list2' is equivalent to "ffpe-trap="list1,list2.
Bestie, once you turn an exception trap on, it can't be turned off again ๐ญ There's no negative form, so choose wisely ๐
Many, if not most, floating point operations lose a little precision from rounding ๐ธ so ffpe-trap=inexact is honestly going to be super uninteresting in real life ๐ฅฑ
By default, no exception traps are enabled ๐ฆ
-ffpe-summary=listโ Okay, this one lets you pick which floating-point exceptions get their flag status printed toERROR_UNITwheneverSTOPorERROR STOPruns โจ Thelistcan benone,all, or a comma-separated list ofinvalid,zero,overflow,underflow,inexactanddenormal. (See-ffpe-trapfor what each exception means ๐ง) If you use this option more than once on the command line, only the last one counts ๐ By default, you get a summary for all exceptions exceptinexact๐-fno-backtraceโ So when a serious runtime error hits, or a deadly signal goes off (segmentation fault, illegal instruction, bus error, floating-point exception, and any other POSIX signal whose action is core) ๐ the Fortran runtime library tries to print a backtrace of the error.-fno-backtraceturns that backtrace generation off ๐ This only has an effect when compiling the Fortran main program.
๐ Options for directory search ๐
These options are all about how GNU Fortran hunts down files pulled in by the INCLUDE directive, and where it looks for previously compiled modules ๐
They also change the search paths that cpp uses when it preprocesses Fortran source ๐
-Idirโ These affect how theINCLUDEdirective gets interpreted (and the#includedirective in the cpp preprocessor too) ๐ซถ Also,-IandINCLUDEbasically behave the same as-Iwith#includein cpp, when it comes to looking for header.gcc files and other stuff like that. This path is also where it searches for .mod files when a previously compiled module is needed by aUSEstatement ๐ฆ-Jdirโ This one tells the compiler where to put the.modfiles for compiled modules ๐ It also gets added to the list of directories that aUSEstatement searches. The default is the current directory ๐-fintrinsic-modules-path dirโ Use this if the pre-compiled intrinsic modules aren't in the default spot the compiler expects ๐บ๏ธ
๐ Influencing the linking step ๐
These options only matter when the compiler links object files into an executable output file ๐ If there's no link step, they're meaningless ๐
-static-libgfortranโ On systems that ship libgfortran as both a shared and a static library, this forces the static version to be used ๐ง If no shared version of libgfortran got built when the compiler was configured, this option does absolutely nothing ๐คทโโ๏ธ
๐ธ Influencing runtime behavior ๐ธ
These options change how programs compiled with GNU Fortran behave at runtime โจ
-fconvert=conversionโ This sets how data is represented in unformatted files ๐ผ The valid values forconversionare:nativeโ the default ๐swapโ swap between big- and little-endian ๐big-endianโ use big-endian representation for unformatted files ๐little-endianโ use little-endian representation for unformatted files ๐
This option only has an effect when used in the main program ๐ฏ The CONVERT specifier and the GFORTRAN_CONVERT_UNIT environment variable both override whatever default -fconvert sets ๐
-frecord-marker=lengthโ This sets the length of record markers for unformatted files. Valid values are4and8, and the default is4๐ This is different from older gfortran versions, which defaulted to a record marker length of8on most systems. If you need to read or write files that are compatible with earlier versions of gfortran, use-frecord-marker=8๐ฐ๏ธ-fmax-subrecord-length=lengthโ This sets the maximum length for a subrecord ๐ The maximum permitted value forlengthis2147483639, which is also the default. Honestly, it's only really useful for the gfortran testsuite ๐งช-fsign-zeroโ When enabled, floating point zeros with the sign bit set get written as negative numbers in formatted output, and get treated as negative by theSIGNintrinsic โ-fno-sign-zeroskips printing the negative sign on zero values (or values rounded to zero for I/O), and treats zero as a positive number in theSIGNintrinsic. That's for compatibility with Fortran 77 ๐ฆ The default is-fsign-zero๐
๐ง Options for code generation conventions ๐ง
These machine-independent options control the interface conventions used in code generation ๐
Most of them come in both positive and negative forms, where the negative form of -ffoo is -fno-foo ๐ The list below only shows the form that is not the default. You can figure out the other form by removing no- or adding it ๐ง
-fno-automaticโ Treats each program unit (except the ones markedRECURSIVE) as if theSAVEstatement were specified for every local variable and array in it ๐ It doesn't affect common blocks. (Some Fortran compilers call this option-staticor-save.) The default, which is-fautomatic, puts local variables smaller than the value given by-fmax-stack-var-sizeon the stack ๐ฅ Use-frecursiveif you want no static memory at all ๐
Local variables or arrays that have an explicit SAVE attribute get silently ignored, unless you add the -pedantic option ๐ค
-ff2cโ This generates code that's compatible with code generated by g77 and f2c ๐ค The g77 calling conventions (originally from f2c) make functions that return defaultREALactually return the C typedouble, and functions that returnCOMPLEXsend their values back through an extra argument in the calling sequence that points to where the return value should be stored ๐ With the default GNU calling conventions, those functions just return their results like GNU C does: defaultREALfunctions return the C typefloat, andCOMPLEXfunctions return the GNU C typecomplex๐ซ This option also implies-fsecond-underscore, unless you explicitly ask for-fno-second-underscore๐ซง
This does not affect code that interfaces with the libgfortran library ๐
Caution: It's not a good idea to mix Fortran code compiled with-ff2cwith code compiled with the default-fno-f2ccalling conventions ๐ฌ If you callCOMPLEXor defaultREALfunctions between program parts that were compiled with different calling conventions, things will break at execution time ๐
Caution: This will break code that passes intrinsic functions of type defaultREALorCOMPLEXas actual arguments, because the library implementations use the-fno-f2ccalling conventions ๐จ
-fno-underscoringโ This stops GNU Fortran from transforming the names of entities in your Fortran source by appending underscores to them ๐
With -funderscoring in effect, GNU Fortran appends one underscore to external names that don't have any underscores already ๐ช This keeps things compatible with code produced by a lot of UNIX Fortran compilers ๐ง
Caution: GNU Fortran's default behavior is incompatible with f2c and g77 ๐ If you want object files from GNU Fortran to be compatible with object code made by these tools, please use -ff2c instead.
Using -fno-underscoring isn't recommended unless you're experimenting with things like plugging GNU Fortran into existing system environments (vis-a-vis existing libraries, tools, and so on) ๐งช
For example, with -funderscoring, and assuming that j() and max_count() are external functions while my_var and lvar are local variables, a statement like
I = J() + MAX_COUNT (MY_VAR, LVAR)
gets implemented as something akin to:
i = j_() + max_count__(&my_var__, &lvar);
With -fno-underscoring, the same statement is implemented as:
i = j() + max_count(&my_var, &lvar);
Using -fno-underscoring lets you use your own names directly while debugging, and when you're interfacing GNU Fortran code with other languages ๐ซถ
Heads up though: just because the names match doesn't mean the interface GNU Fortran uses for an external name matches the interface another language uses for that same name ๐ Getting code from GNU Fortran to link with code from some other compiler, by this method or any other, is only a small part of the overall solution ๐งฉ Getting both compilers' output to agree on everything other than naming can take serious effort, and unlike naming disagreements, linkers usually can't detect those other mismatches ๐ญ
Also, with -fno-underscoring, the lack of appended underscores makes it very real that a user-defined external name could clash with a name in a system library ๐ฅ That can make unresolved-reference bugs really hard to find, since they might only show up at program run time as weird buggy behavior ๐
In future versions of GNU Fortran, the hope is to improve naming and linking so debugging always uses the names as they appear in the source, even when the linker sees mangled names to stop accidental linking between procedures with incompatible interfaces ๐ฎ
-fsecond-underscoreโ By default, GNU Fortran appends an underscore to external names ๐ฑ If you use this option, GNU Fortran appends two underscores to names that already have underscores, and one underscore to external names with no underscores ๐ It also appends two underscores to internal names with underscores, so they don't collide with external names ๐ซง
This option has no effect if -fno-underscoring is in effect ๐
It's implied by the -ff2c option ๐
Otherwise, with this option, an external name such as MAX_COUNT gets implemented as a reference to the link-time external symbol max_count__, instead of max_count_ ๐ This is required for compatibility with g77 and f2c, and it's implied by the -ff2c option ๐
-fcoarray=<keyword>โ This picks which coarray support you get ๐ฆnoneโ Disables coarray support, so using coarray declarations and image-control statements produces a compile-time error ๐ซ (Default)
singleโ Single-image mode, sonum_images()is always one. Think solo act, no backup dancers ๐libโ Library-based coarray parallelization. You'll need to link a suitable GNU Fortran coarray library for this one โจ
๐ -fcheck=<keyword>
Turns on run-time checks. The argument is a comma-delimited list of the keywords below. Slap a no- in front of any check to switch it off, but only if an earlier specification turned it on ๐
allโ Turns on every run-time test that-fcheckoffers ๐array-tempsโ Warns at run time when a temporary array had to be made to pass an actual argument. This info can be handy for optimization, since it helps you dodge those temporaries ๐ฆ- Note: The warning only prints once per location, so don't panic when it goes quiet ๐
bitsโ Run-time checks for invalid arguments to the bit manipulation intrinsics ๐งboundsโ Run-time checks for array subscripts against the declared minimum and maximum values. It also checks array indices for assumed and deferred shape arrays against the actual allocated bounds, and makes sure all string lengths match for character array constructors that don't have an explicit typespec ๐ธ- Some checks need
-fcheck=boundsset when the main program gets compiled ๐ซถ - Note: Future versions might add other kinds of checking too, like checking substring references ๐ฎ
- Some checks need
doโ Run-time checks for invalid modification of loop iteration variables ๐memโ Run-time checks for memory allocation ๐- Note: This one does not touch explicit allocations made with the
ALLOCATEstatement. Those are always checked, no exceptions ๐
- Note: This one does not touch explicit allocations made with the
pointerโ Run-time checks for pointers and allocatables ๐recursionโ Run-time checks for recursively called subroutines and functions that aren't marked as recursive. See also-frecursive๐ฆ- Note: This check doesn't work for OpenMP programs. It also gets disabled if you use it together with
-frecursiveand-fopenmp๐ญ
- Note: This check doesn't work for OpenMP programs. It also gets disabled if you use it together with
Example: say you've got a file called foo.f90. This command:
gfortran -fcheck=all,no-array-temps foo.f90
will compile the file with every check turned on, except the warnings for generated array temporaries โจ
-fbounds-checkโ Deprecated alias for-fcheck=bounds. It's on its way out, so switch to the new spelling ๐ซถ-ftail-call-workaround,-ftail-call-workaround=nโ Okay, this one's a whole saga ๐ญ Some C interfaces to Fortran code break the gfortran ABI by leaving out the hidden character length arguments (the source text cuts off right at "as described in", so that's all the detail there is). This can cause crashes, because pushing arguments for tail calls can overflow the stack ๐- This option works around that for existing binary packages by turning off tail call optimization for gfortran procedures that have character arguments.
-ftail-call-workaround=2turns tail call optimization off in all gfortran procedures with character arguments.-ftail-call-workaround=1, or just plain-ftail-call-workaround, only does it for gfortran procedures with character arguments that call implicitly prototyped procedures.- Heads up: Using this can cause problems, including crashes from not having enough stack space ๐ญ
- It is very strongly recommended that you fix the code in question instead. The
-fc-prototypes-externaloption can generate prototypes that follow gfortran's ABI, so you can drop them into your source code ๐ธ - Support for this option will probably be withdrawn in a future gfortran release, so don't get too attached ๐ฅ
- To turn it off, use
-fno-tail-call-workaroundor-ftail-call-workaround=0๐ โโ๏ธ - Right now the default is
-ftail-call-workaround, but that's going to change in future releases โญ
-fcheck-array-temporariesโ Deprecated alias for-fcheck=array-temps. Same vibe, shorter spelling is the new move ๐-fmax-array-constructor=nโ Lets you raise the upper limit allowed in array constructors. The code below needs this option so it can expand the array at compile time ๐งฎ
program test
implicit none
integer j
integer, parameter :: n = 100000
integer, parameter :: i(n) = (/ (2*j, j = 1, n) /)
print '(10(I0,1X))', i
end program test
Caution: This option can lead to really long compile times and excessively large object files. Proceed with love but also with snacks ๐ฟ
The default value for n is 65535.
-fmax-stack-var-size=nโ Sets the size in bytes of the biggest array that can go on the stack. If an array is bigger than that, it uses static memory instead (except in procedures markedRECURSIVE) ๐งฑ- Use
-frecursiveto allow recursive procedures that don't have aRECURSIVEattribute, or for parallel programs ๐ - Use
-fno-automaticif you want to never use the stack ๐ซ - Note: This only affects local arrays declared with constant bounds, and it may not apply to every character variable. Future versions of GNU Fortran might improve this ๐ฑ
- The default value for
nis65536.
- Use
-fstack-arraysโ Puts all arrays of unknown size, plus array temporaries, onto stack memory. If your program uses super large local arrays, you might have to raise your runtime stack memory limits on some operating systems ๐ This flag is enabled by default at optimization level-Ofast, unless-fmax-stack-var-sizeis specified ๐๏ธ-fpack-derivedโ Tells GNU Fortran to pack derived type members as closely together as possible. Code built with this is likely to be incompatible with code built without it, and it may run slower ๐ข-frepack-arraysโ Sometimes GNU Fortran passes assumed shape array sections through a descriptor that describes a noncontiguous chunk of memory. This option adds code to the function prologue that repacks the data into a contiguous block at runtime ๐ฆ- Result: faster array accesses, but it can add a lot of overhead to the function call, especially when the passed data is noncontiguous ๐ฌ
-fshort-enumsโ Here for interop with C code that was compiled using-fshort-enums. GNU Fortran will pick the smallestINTEGERkind that an enumerator set fits into, then give all of its enumerators that kind ๐งธ-finline-arg-packingโ When you pass an assumed-shape argument of a procedure as an actual argument to an assumed-size or explicit size procedure (or to one without an explicit interface), the argument might have to be packed, meaning put into contiguous memory. Here's the classic example, a call tofooin:
subroutine foo(a)
real, dimension(*) :: a
end subroutine foo
subroutine bar(b)
real, dimension(:) :: b
call foo(b)
end subroutine bar
With -finline-arg-packing in effect, that packing is done by inline code. That means more optimization, but also a bigger code size ๐
- It's implied by any of the
-Ooptions, except when you're optimizing for size with-Os๐ง - If your code has a very large number of arguments that need packing, code size and compile time can get out of hand. In that case, disabling this option might be the better move ๐
- To find instances of packing, use
-Warray-temporaries๐
-fexternal-blasโ Makes gfortran call BLAS functions for some matrix operations, likeMATMUL, instead of using its own algorithms. This only happens when the matrices are bigger than a given limit (see-fblas-matmul-limit) ๐งฎ This can pay off if you have an optimized vendor BLAS library available. The BLAS library has to be specified at link time ๐-fblas-matmul-limit=nโ Only matters when-fexternal-blasis in effect. Matrix multiplications with a size larger than, or equal to,nget handled by BLAS calls, while smaller ones use gfortran's internal algorithms ๐ช If the matrices aren't square, the size comparison uses the geometric mean of the dimensions of the argument and result matrices ๐- The default value for
nis30.
- The default value for
-finline-matmul-limit=nโ When front-end optimization is active, some calls to theMATMULintrinsic function get inlined ๐ซ This can make your code bigger if the matrix size can't be figured out at compile time, since code for both cases gets generated ๐ซ-finline-matmul-limit=0turns inlining off in all cases ๐- Setting it to some value
nproduces inline code for matrices with a size up ton. If the matrices aren't square, the size comparison uses the geometric mean of the dimensions of the argument and result matrices ๐ - The default value for
nis30. The-fblas-matmul-limitoption can be used to change this value ๐
-frecursiveโ Allows indirect recursion by forcing all local arrays to be allocated on the stack ๐ This flag can't be used together with-fmax-stack-var-size=or-fno-automatic๐ โโ๏ธ-finit-local-zero,-finit-derived,-finit-integer=n,-finit-real=<zero|inf|-inf|nan|snan>,-finit-logical=<true|false>,-finit-character=nโ The initialization squad ๐ง-finit-local-zerotells the compiler to set localINTEGER,REAL, andCOMPLEXvariables to zero,LOGICALvariables to false, andCHARACTERvariables to a string of null bytes 0๏ธโฃ- For finer control, you've got
-finit-integer=n,-finit-real=<zero|inf|-inf|nan|snan>(which also initializes the real and imaginary parts of localCOMPLEXvariables),-finit-logical=<true|false>, and-finit-character=n. Herenis an ASCII character value for the character one ๐ก - With
-finit-derived, components of derived type variables get initialized according to these flags. Components whose type isn't covered by an explicit-finit-*flag get treated the same way as with-finit-local-zero๐งฌ - Not included: These options do not initialize:
- objects with the
POINTERattribute ๐ซ - allocatable arrays ๐ซ
- variables that show up in an
EQUIVALENCEstatement ๐ซ
- objects with the
(psst, these limitations might get removed in future releases ๐ธ)
okay so -finit-real=nan sets up REAL and COMPLEX variables with a quiet NaN โจ. If you want a signalling NaN, use -finit-real=snan instead. ngl though, compile-time optimizations can quietly turn those into quiet NaNs ๐, and trapping has to be enabled too (for example with -ffpe-trap) ๐ซถ
The -finit-integer option parses the value into an integer of type INTEGER(kind=C_LONG) on the host. That value then gets assigned to the integer variables in your Fortran code, and if it's too big for the kind, it can wrap around ๐ฌ
And last but not least, turning on any of the -finit-* options silences the warnings -Wuninitialized would've thrown for the affected local variables. main character energy ๐
-falign-commonsโ By default, gfortran pads every variable in aCOMMONblock so it's properly aligned ๐ . On some platforms this is mandatory, and on others it just boosts performance. If aCOMMONblock isn't declared with consistent data types everywhere, that padding can cause trouble, so-fno-align-commonslets you turn automatic alignment off. Use the same form of this option for every file that shares aCOMMONblock. To dodge alignment issues inCOMMONblocks, it's recommended to order objects from largest to smallest ๐-fno-protect-parensโ By default, parentheses in expressions are honored at every optimization level, so the compiler doesn't re-associate anything ๐ฆ. Using-fno-protect-parenslets it reorderREALandCOMPLEXexpressions for faster code. For that re-association to happen,-fno-signed-zerosand-fno-trapping-mathneed to be in effect. Parentheses protection is on by default, unless-Ofastis given.-frealloc-lhsโ An allocatable left-hand side of an intrinsic assignment gets automatically (re)allocated if it's either unallocated or has a different shape โจ. This is enabled by default, except when-std=f95is given. See also-Wrealloc-lhs.-faggressive-function-eliminationโ Functions with identical argument lists get eliminated within statements, whether or not they're markedPURE๐ง. For example, in:
a = f(b,c) + f(b,c)
there will only be a single call to f. This option only works if -ffrontend-optimize is in effect.
-ffrontend-optimizeโ This option does front-end optimization by manipulating parts of the Fortran parse tree ๐. It's enabled by default by any-Ooption except-O0and-Og. The optimizations it turns on include:- inlining calls to
MATMUL, - elimination of identical function calls within expressions,
- removing unnecessary calls to
TRIMin comparisons and assignments, - replacing
TRIM(a)witha(1:LEN_TRIM(a)), and - short-circuiting of logical operators (
.AND.and.OR.).
- inlining calls to
If you don't vibe with it, you can deselect it by specifying -fno-frontend-optimize.
-ffrontend-loop-interchangeโ This one attempts to interchange loops in the Fortran front end wherever it's profitable ๐ฅ. It's enabled by default by any-Ooption. Right now it only affectsFORALLandDO CONCURRENTstatements that have several forall triplets.
๐ ENVIRONMENT ๐
The gfortran compiler doesn't use any environment variables to control its operation beyond the ones that affect the operation of gcc. So just gcc's vibes ๐
๐ BUGS ๐
For instructions on reporting bugs, see <file:///usr/share/doc/gcc-12/README.Bugs> ๐
๐ SEE ALSO ๐
Here's your reading list, bestie ๐: gpl(7), gfdl(7), fsf-funding(7), cpp(1), gcov(1), gcc(1), as(1), ld(1), gdb(1), dbx(1), plus the Info entries for gcc, cpp, gfortran, as, ld, binutils and gdb ๐ง
โ๏ธ AUTHOR โ๏ธ
Check the Info entry for gfortran to see the contributors to GCC and GNU Fortran ๐ซถ
โ๏ธ COPYRIGHT โ๏ธ
Copyright (c) 2004-2022 Free Software Foundation, Inc. ๐
Okay, legal stuff, but it's actually cute: you're allowed to copy, distribute and/or modify this document under the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation. The Invariant Sections are "Funding Free Software", the Front-Cover Texts are (a) (see below), and the Back-Cover Texts are (b) (see below). A copy of the license is included in the gfdl(7) man page ๐
(a) The FSF's Front-Cover Text is:
A GNU Manual
(b) The FSF's Back-Cover Text is:
You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development.
That's the whole page, bestie! ๐ Source gcc-12, dated 2022-02-22, and you literally made it through the entire gfortran manual. You're so iconic ๐ ๐ธ
๐ฆ where this page comes from
- ubuntu jammy: gfortran-12-powerpc-linux-gnu 12-20220222-1ubuntu1cross1
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms