GFORTRAN(1)
Okay bestie, gather round because we're doing GFORTRAN(1) today ๐ It's the GNU manual page for the gfortran compiler and it is lowkey iconic ๐ง
โจ 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...
Only the most main-character options are listed in that synopsis ๐ The rest are down below, so keep reading!
๐ธ DESCRIPTION ๐ธ
The gfortran command is giving gcc energy. It supports all the options that gcc supports, so you already know a lot of it โจ Only the options specific to GNU Fortran get documented here.
Every GCC and GNU Fortran option is accepted by both gfortran and gcc, plus any other drivers built at the same time, like g++. Adding GNU Fortran to the GCC distribution means all the relevant drivers accept GNU Fortran options. Slay ๐
Some options come in a positive and a negative flavor. The negative form of -ffoo is -fno-foo. This manual only documents one of the two, whichever one is not the default ๐
โจ OPTIONS โจ
Here is a summary of all the options specific to GNU Fortran, grouped by type. The explanations come in the following sections ๐
๐ Fortran Language Options
-fall-intrinsics -fbackslash -fcray-pointer -fd-lines-as-code
-fd-lines-as-comments -fdec -fdec-structure -fdec-intrinsic-ints
-fdec-static -fdec-math -fdec-include -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 -Wargument-mismatch -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-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
-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|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 -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
The following options control the details of the Fortran dialect the compiler accepts ๐
-ffree-form/-ffixed-formโ pick the layout your source file uses. Free form showed up in Fortran 90, while fixed form was the traditional choice for older Fortran programs. If you pass neither one, the source form gets figured out from the file extension ๐ง-fall-intrinsicsโ makes every intrinsic procedure acceptable, including the GNU-specific extensions. This can be useful with-std=f95if you want standard compliance but still want the full range ofgfortranintrinsics. The catch:-Wintrinsics-stdgets ignored, and no user-defined procedure with the same name as an intrinsic will be called, except when it's explicitly declaredEXTERNAL.-fd-lines-as-code/-fd-lines-as-commentsโ special treatment for lines starting withdorDin 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 turns on extensions and other features that mimic the default behavior of older compilers, like DEC's. For the details on GNU Fortran's version of these extensions, check the full documentation.- Other flags this switch turns on:
-fdollar-ok -fcray-pointer -fdec-structure -fdec-intrinsic-ints -fdec-static -fdec-math - If
-fd-lines-as-code/-fd-lines-as-commentsare unset, then-fdecalso sets-fd-lines-as-comments.
- Other flags this switch turns on:
๐จ Warning: these features are non-standard and should be avoided at all costs, bestie!
-fdec-structureโ enables DEC"STRUCTURE"and"RECORD", plus"UNION","MAP", and the dot ('.') as a member separator (in addition to'%'). This is only here for compatibility. 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... For a complete list of intrinsics, see the full documentation.-fdec-mathโ enables legacy math intrinsics such asCOTANand degree-valued trigonometric functions (likeTAND,ATAND, etc...) for compatibility with older code.-fdec-staticโ enables DEC-styleSTATICandAUTOMATICattributes, which explicitly specify the storage of variables and other objects.-fdec-includeโ enables parsingINCLUDEas a statement, in addition to parsing it as anINCLUDEline. When it's parsed as a statement,INCLUDEdoesn't have to sit on a single line and can use line continuations.-fdollar-okโ allows$as a valid non-first character in a symbol name. Symbols that start with$are still rejected, since it's unclear which implicit typing rules to apply (different vendors implement different rules). Using$inIMPLICITstatements is rejected too.-fbackslashโ changes how backslashes in string literals are read. Instead of a single backslash character, you get C-style escape characters. These expand:"\a","\b","\f","\n","\r","\t","\v","\\", and"\0"into the ASCII characters alert, backspace, form feed, newline, carriage return, horizontal tab, vertical tab, backslash, and NUL, respectively. On top of that,"\x"nn,"\u"nnnn, and"\U"nnnnnnnn(where eachnis a hexadecimal digit) get translated into the Unicode characters for those code points. Any other combination of a character preceded by\stays unexpanded.-fmodule-privateโ sets the default accessibility of module entities to"PRIVATE". Use-associated entities won't be accessible unless they're explicitly declared"PUBLIC"๐ฆ-ffixed-line-length-nโ sets the column after which characters get ignored in typical fixed-form lines in the source file. Unless-fno-pad-sourceis used, it also sets the column through which spaces are assumed (as if padded to that length) after the ends of short fixed-form lines.- Popular values for
ninclude72(the standard and the default),80(card image), and132(corresponding to"extended-source"options in some popular compilers). nmay also benone, meaning the entire line is meaningful, and continued character constants never get implicit spaces appended to fill out the line.-ffixed-line-length-0means the same thing as-ffixed-line-length-none.
- Popular values for
-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. That padding 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 get implicit spaces appended to fill out the line.-ffree-line-length-nโ sets the column after which characters get ignored in typical free-form lines in the source file. The default value is132.nmay benone, meaning the entire line is meaningful.-ffree-line-length-0means the same thing as-ffree-line-length-none.-fmax-identifier-length=nโ specifies the maximum allowed identifier length. Typical values are31(Fortran 95) and63(Fortran 2003 and Fortran 2008) โจ-fimplicit-noneโ no implicit typing is allowed, unless it's overridden by explicit"IMPLICIT"statements. This is the equivalent of adding"implicit none"to the start of every procedure.-fcray-pointerโ enables the Cray pointer extension, which provides C-like pointer functionality ๐ง-fopenaccโ enables the OpenACC extensions. That includes OpenACC"!$acc"directives in free form, and"c$acc",*$acc, and"!$acc"directives in fixed form. It also covers"!$"conditional compilation sentinels in free form, and"c$","*$", and"!$"sentinels in fixed form. When linking, it arranges for the OpenACC runtime library to be linked in.
โ ๏ธ Heads up: this is an experimental feature, incomplete, and subject to change in future versions of GCC. See https://gcc.gnu.org/wiki/OpenACC for more information.
-fopenmpโ enables the OpenMP extensions. That includes OpenMP"!$omp"directives in free form, and"c$omp",*$omp, and"!$omp"directives in fixed form. It also covers"!$"conditional compilation sentinels in free form, and"c$","*$", and"!$"sentinels in fixed form. When linking, it arranges for the OpenMP runtime library to be linked in. Also, the option-fopenmpimplies-frecursive๐-fno-range-checkโ okay bestie, this one lets you turn off the range police ๐จ During compilation, GNU Fortran normally checks the results of simplifying constant expressions and throws an error for stuff likea = 1. / 0. With this flag, no error shows up andajust gets+Infinity๐. If an expression lands outside the relevant range of["-HUGE()":"HUGE()"], it gets replaced with-Infor+Inf, whichever fits โจ. Same vibe withDATA i/Z'FFFFFFFF'/: that usually causes an integer overflow on most systems, but with-fno-range-checkthe value wraps around andigets initialized to-1instead ๐.-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 does not promote variables that have an explicit kind declaration ๐.-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 one bumps the default width ofDOUBLE PRECISIONand double real constants like1.d0up to 16 bytes if possible ๐. But if you pass-fdefault-double-8along withfdefault-real-8, thenDOUBLE PRECISIONand double real constants don't get promoted ๐ซถ. Unlike-freal-4-real-8,fdefault-real-8does not promote variables with explicit kind declarations ๐ .-fdefault-real-10โ sets the default real type to 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 give-fdefault-double-8along withfdefault-real-10, thenDOUBLE PRECISIONand double real constants are not promoted ๐. Unlike-freal-4-real-10,fdefault-real-10does not promote variables with explicit kind declarations ๐.-fdefault-real-16โ sets the default real type to a 16 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 pair it with-fdefault-double-8, thenDOUBLE PRECISIONand double real constants are not promoted ๐ซถ. Unlike-freal-4-real-16,fdefault-real-16does not promote variables with explicit kind declarations ๐ .-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 one also stops-fdefault-real-8,-fdefault-real-10, and-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.
โ ๏ธ This option should be used with care and may not be suitable for your codes! Areas of possible concern include 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. ๐ฅบ
-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 six are a whole family of promotion options ๐ฉต Each one promotes allREAL(KIND=M)entities toREAL(KIND=N)entities, depending on which pair you pick. IfREAL(KIND=N)isn't available, you'll get an error. Every other real kind type is left alone ๐ท
โ ๏ธ These options should be used with care and may not be suitable for your codes! Same vibe as before: watch out for 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๐
-std=stdโ this is where you tell the compiler which standard your program is supposed to follow ๐stdcan be one off95,f2003,f2008,f2018,gnu, orlegacy.gnuis the default ๐ It's a superset of the latest Fortran standard that includes all the extensions GNU Fortran supports. You'll still get warnings for obsolete extensions that aren't recommended in new code.legacyis basically the same asgnu, but without the warnings for obsolete extensions. It may be handy for old non-standard programs ๐งf95,f2003,f2008, andf2018are strict conformance to the Fortran 95, Fortran 2003, Fortran 2008, and Fortran 2018 standards, respectively ๐ง You get errors for every extension beyond the relevant language standard, and warnings for Fortran 77 features that are permitted but obsolescent in later standards ๐- The deprecated
-std=f2008tsoption is an alias for-std=f2018๐ฅ It's only there for backwards compatibility with earlier gfortran versions, so please don't use it anymore ๐ญ
-ftest-forall-tempโ this one's for test coverage ๐งช It enhances test coverage by forcing mostforallassignments to use a temporary ๐ฌ
๐ Enable and customize preprocessing ๐
Okay so these are all the preprocessor related options ๐ง Check out section Preprocessing and conditional compilation for more detailed information on preprocessing in gfortran ๐
-cpp,-nocppโ the preprocessor is the main character here ๐-cppturns preprocessing on. It gets invoked automatically if the file extension is.fpp,.FPP,.F,.FOR,.FTN,.F90,.F95,.F03, or.F08. Use this one to manually enable preprocessing for any kind of Fortran file ๐ซถ-nocppis the negative form, and it's how you disable preprocessing for files with any of the extensions listed above ๐ซ- The preprocessor runs in traditional mode โจ Any restrictions of the file format, especially the limits on line length, apply to preprocessed output too. So it might be advisable to use the
-ffree-line-length-noneor-ffixed-line-length-noneoptions ๐
-dMโ instead of the normal output, this spits out a list of#definedirectives for all the macros defined while the preprocessor was running, including the predefined ones ๐ฆ It's a great way to find out what's predefined in your version of the preprocessor ๐ Assuming you have no filefoo.f90, this command:
touch foo.f90; gfortran -cpp -E -dM foo.f90
will show all the predefined macros ๐
-dDโ like-dM, but with two differences ๐ฉต It doesn't include the predefined macros, and it outputs both the#definedirectives and the result of preprocessing. Both kinds of output go to the standard output file ๐ค-dNโ like-dD, but it only emits the macro names, not their expansions ๐ฌ-dUโ likedD, except only macros that are expanded, or whose definedness is tested in preprocessor directives, get output ๐ธ The output is delayed until the use or test of the macro. Also,#undefdirectives are output for macros that were tested but were undefined at the time ๐ง-dIโ outputs#includedirectives in addition to the result of preprocessing ๐-fworking-directoryโ this one helps the compiler know where you were working ๐บ๏ธ It enables generation of linemarkers in the preprocessor output, letting the compiler know the current working directory at the time of preprocessing. When it's on, the preprocessor emits a second linemarker after the initial one, with the current working directory followed by two slashes ๐ซ GCC uses that directory, when it's present in the preprocessed input, as the directory emitted as the current working directory in some debugging information formats ๐ This option is implicitly enabled if debugging information is enabled, but you can inhibit it with the negated form-fno-working-directory๐ โโ๏ธ If the-Pflag is in the command line, this option does nothing, since no#linedirectives get emitted whatsoever ๐ฅฒ-idirafter dirโ searchesdirfor include files, but only after all the directories specified with-Iand the standard system directories have been exhausted ๐ฐ๏ธdiris treated as a system include directory ๐๏ธ Ifdirbegins with=, then the=gets replaced by the sysroot prefix; see--sysrootand-isysroot๐-imultilib dirโ usesdiras a subdirectory of the directory containing target-specific C++ headers ๐งฉ-iprefix prefixโ specifiesprefixas the prefix for subsequent-iwithprefixoptions ๐ฏ If the prefix represents a directory, you should include the final/๐-isysroot dirโ this is like the--sysrootoption, but it only applies to header files ๐ See the--sysrootoption for more information ๐-iquote dirโ searchesdironly for header files requested with#include "file"๐ They're not searched for#include <file>. This happens before all directories specified by-Iand before the standard system directories ๐ช Ifdirbegins with=, then the=gets replaced by the sysroot prefix; see--sysrootand-isysrootโจ-isystem dirโ searchesdirfor header files, after all directories specified by-Ibut before the standard system directories ๐ซง It gets marked as a system directory, so it gets the same special treatment as the standard system directories ๐ฅฐ Ifdirbegins with=, then the=gets replaced by the sysroot prefix; see--sysrootand-isysroot๐ท-nostdincโ no standard system directories for header files, bestie ๐ Only the directories you've specified with-Ioptions (and the directory of the current file, if appropriate) are searched ๐-undefโ doesn't predefine any system-specific or GCC-specific macros ๐งผ The standard predefined macros stay defined ๐-Apredicate=answerโ makes an assertion with the predicatepredicateand the answeranswer๐ This form is preferred over the older form-A predicate(answer), which is still supported, because it doesn't use shell special characters ๐-A-predicate=answerโ cancels an assertion with the predicatepredicateand the answeranswer๐ซ๐-Cโ do not discard comments ๐ All comments are passed through to the output file, except for comments in processed directives, which get deleted along with the directive ๐๏ธ
Okay so the big thing about -C is that it comes with side effects ๐ It makes the preprocessor treat comments as tokens in their own right. That means a comment at the start of what would be a directive line turns the whole line into an ordinary source line, because the first token is no longer a # ๐ Wild, right?
Warning: this currently handles C-style comments only. The preprocessor does not yet recognize Fortran-style comments. ๐ญ
-CCโ Don't discard comments, not even during macro expansion ๐ซถ This is basically-C, except comments sitting inside a macro also get passed through to the output file wherever that macro gets expanded.
Besides the -C side effects, -CC converts all C++-style comments inside a macro into C-style comments. The reason is bestie-protective: a later use of that macro can't accidentally comment out the rest of the source line ๐
Lowkey genius. -CC is generally 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โ Predefinesnameas a macro, with definition1๐ธ-Dname=definitionโ The contents ofdefinitionget tokenized and processed as if they showed up during translation phase three in a#definedirective ๐ง Embedded newline characters will truncate the definition, so watch out for that.
If you're calling the preprocessor from a shell (or something shell-like), you may need the shell's quoting syntax to protect characters like spaces that mean something to the shell ๐
Want a function-like macro on the command line? Write its argument list in surrounding 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 -D and -U options ๐
-Hโ Prints the name of each header file used, on top of all the other normal stuff ๐ฆ Each name gets indented to show how deep it is in the#includestack.-Pโ Inhibits generation of linemarkers in the output from the preprocessor ๐งผ This might be useful when you're running the preprocessor on something that isn't C code and is going to a program that could get confused by the linemarkers.-Unameโ Cancels any previous definition ofname, whether it was built in or provided with a-Doption ๐๏ธ
๐จ Options to request or suppress errors and warnings ๐จ
Errors are diagnostic messages that report that the GNU Fortran compiler cannot compile the relevant piece of source code. The compiler keeps going so it can report more errors and help you debug, but it won't produce any compiled output ๐ค
Warnings are diagnostic messages that report constructions which aren't inherently erroneous but are risky, or that suggest there's probably a bug in the program. Unless -Werror is specified, they don't stop the program from compiling ๐
You can request lots of specific warnings with options that begin with -W. For example, -Wimplicit asks for warnings on implicit declarations. Each specific warning option also has a negative form beginning with -Wno- that turns the warnings off, like -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 ton. Once you hit that number, GNU Fortran bails out instead of trying to keep processing the source code ๐ Ifnis0, 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 ๐ This will generate module files for each module present in the code, but no other output file.-Wpedantic,-pedanticโ Issues warnings for uses of extensions to Fortran ๐ค-pedanticalso applies to C-language constructs where 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 properly with or without this option. Without it, certain GNU extensions and traditional Fortran features are supported too. With this option, lots of them get rejected ๐
Some users try to use -pedantic to check programs for conformance, and then they're like "wait, this isn't catching everything." It finds some nonstandard practices, but not all of them. Improvements to GNU Fortran in this area are still very welcome ๐ซถ
This should be used together with -std=f95, -std=f2003, -std=f2008 or -std=f2018.
-pedantic-errorsโ Like-pedantic, except errors get produced instead of warnings ๐ค-Wallโ Enables commonly used warning options for usage we recommend avoiding and that we believe are easy to avoid ๐ This currently 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.
The following 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: with no ampersand given in a continued character constant, GNU Fortran assumes continuation at the first non-comment, non-whitespace character after the ampersand that started the continuation.-Wargument-mismatchโ Warns about type, rank, and other mismatches between formal parameters and actual arguments to functions and subroutines ๐ฏ These warnings are recommended, so they're enabled by default.-Warray-temporariesโ Warns about array temporaries generated by the compiler ๐ฆ The info from this warning is sometimes useful in optimization, so you can avoid those temporaries.-Wc-binding-typeโ Warns if a variable might not be C interoperable ๐ In particular, it warns if the variable was declared using an intrinsic type with default kind instead of a kind parameter defined for C interoperability in the intrinsicISO_C_Bindingmodule. This option is implied by-Wall.-Wcharacter-truncationโ Warns when a character assignment will truncate the assigned string โ๏ธ-Wline-truncationโ Warns when a source code line will be truncated ๐ฌ This option is implied by-Wall. For free-form source code, the default is-Werror=line-truncation, so truncations get reported as errors.-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 ๐งฉ This option does not imply-Wconversion.-Wextraโ Enables some warning options for usages of language features that may be problematic ๐ซ This currently includes-Wcompare-reals,-Wunused-parameterand-Wdo-subscript.-Wfrontend-loop-interchangeโ Enables a warning for loop interchanges performed by the-ffrontend-loop-interchangeoption ๐-Wimplicit-interfaceโ Warns if a procedure is called without an explicit interface ๐ Note this only checks that an explicit interface is present. It does not 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 asEXTERNAL๐ซ-Winteger-divisionโ Warns if a constant integer division truncates its result ๐ As an 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 (with-std) and treats it as anEXTERNALprocedure because of this ๐ป-fall-intrinsicscan be used to never trigger this behavior and always link to the intrinsic, regardless of the selected standard.-Wreal-q-constantโ Produces a warning if a real-literal-constant contains aqexponent-letter ๐งฎ-Wsurprisingโ Produces a warning when "suspicious" code constructs show up ๐ฉ While technically legal, these usually mean an error has been made. This currently produces a warning under the following circumstances:- An
INTEGERSELECTconstruct has aCASEthat can never be matched, because its lower value is greater than its upper value. - A
LOGICALSELECTconstruct has threeCASEstatements. - A
TRANSFERspecifies 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
CHARACTERvariable is declared with negative length.
- An
-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 between1and9is supported.-Wtabswill cause a warning to be issued if a tab is encountered. Note,-Wtabsis active for-pedantic,-std=f95,-std=f2003,-std=f2008,-std=f2018and-Wall.-Wundefined-do-loopโ Warns if aDOloop with step either1or-1yields an underflow or an overflow during iteration of an induction variable of the loop ๐ข This option is implied by-Wall.-Wunderflowโ Produces a warning when numerical constant expressions are encountered that yield anUNDERFLOWduring compilation ๐ Enabled by default.-Wintrinsic-shadowโ ๐ Warns if a user-defined procedure or module procedure has the same name as an intrinsic. You might need an explicit interface or anEXTERNALorINTRINSICdeclaration so your calls get resolved to the intrinsic or procedure you actually want. Implied by-Wall.-Wuse-without-onlyโ ๐ซฃ Warns if aUSEstatement has noONLYqualifier, because then it quietly imports every public entity from the module.-Wunused-dummy-argumentโ ๐งน Warns about unused dummy arguments. Implied by-Wall.-Wunused-parameterโ ๐ Plot twist: this one is NOT like gcc's version. gfortran's version skips unused dummy arguments (that's-Wunused-dummy-argument) and goes after unusedPARAMETERvalues instead. Implied by-Wextraif-Wunusedor-Wallis also used.-Walign-commonsโ ๐งฑ By default, gfortran warns any time variables get padded for alignment inside aCOMMONblock. Turn that off with-Wno-align-commons. See also-falign-commons.-Wfunction-eliminationโ โ๏ธ Warns if calls to impure functions get eliminated by the optimizations enabled by-ffrontend-optimize. Implied by-Wextra.-Wrealloc-lhsโ ๐ Warns when the compiler might insert allocation or reallocation code for an allocatable array variable of intrinsic type in intrinsic assignments. In hot loops, the Fortran 2003 reallocation feature may hurt performance. If the array is already allocated with the correct shape, use a whole-array array-spec like(:,:,:)on the left-hand side to skip the reallocation check. Heads up: sometimes this warning shows up even when the compiler would optimize those checks away, like when the right-hand side has the same variable multiplied by a scalar. See also-frealloc-lhs.-Wrealloc-lhs-allโ ๐ฃ Warns whenever the compiler inserts allocation or reallocation code for an allocatable variable. That includes scalars and derived types.-Wcompare-realsโ โ๏ธ Warns when you compare real or complex values for equality or inequality. Implied by-Wextra.-Wtarget-lifetimeโ โณ Warns if the pointer in a pointer assignment might outlive its target. Implied by-Wall.-Wzerotripโ ๐ซฅ Warns if aDOloop is known at compile time to execute zero times. Implied by-Wall.-Wdo-subscriptโ ๐ฏ Warns if an array subscript inside aDOloop could lead to an out-of-bounds access, even when the compiler can't prove the statement actually runs. Here's the classic example:
real a(3)
do i=1,4
if (condition(i)) then
a(i) = 1.2
end if
end do
Implied by -Wextra.
-Werrorโ ๐จ Turns every warning into an error. No mercy.
Some of these have no effect when compiling programs written in Fortran. ๐
โจ Options for debugging your program or GNU Fortran โจ
Okay so GNU Fortran has a bunch of special options for debugging, either your program or the GNU Fortran compiler itself. ๐
-fdump-fortran-originalโ ๐งพ Outputs the internal parse tree after the source program gets translated into internal representation. Mostly useful for debugging the GNU Fortran compiler itself. The output might change between releases, and this option may also throw 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 throw internal compiler errors for features that were only recently added.-fdump-parse-treeโ ๐๏ธ Outputs the internal parse tree after the source program gets translated into internal representation. Mostly useful for debugging the GNU Fortran compiler itself. The output might change between releases, and this option may also throw internal compiler errors for features that were only recently added.
โ ๏ธ This option is deprecated; use -fdump-fortran-original instead.
-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 throw internal compiler errors for features that were only recently added.-ffpe-trap=listโ ๐ฅ Enables floating-point exception traps. On most systems, if a floating-point exception happens and its trap is enabled, aSIGFPEsignal gets sent and the program aborts, producing a core file that's super useful for debugging.listis a (possibly empty) comma-separated list of these exceptions:invalidโ invalid floating point operation, such asSQRT(-1.0)zeroโ division by zerooverflowโ overflow in a floating point operationunderflowโ underflow in a floating point operationinexactโ loss of precision during an operationdenormalโ an operation performed on a denormal value
The first five exceptions match the five IEEE 754 exceptions. The last one, denormal, isn't part of the IEEE 754 standard, but it's available on some common architectures like x86. โจ
The first three (invalid, zero, and overflow) often point to serious errors. Unless your program has a plan for dealing with them, enabling traps for those three is probably a good idea. ๐ซถ
If the option shows up more than once on the command line, the lists get joined: '"ffpe-trap="list1 "ffpe-trap="list2' is equivalent to "ffpe-trap="list1,list2.
๐ซ Once an exception is enabled, it can't be disabled. There's no negative form!
Lots of floating point operations lose precision because of rounding, so ffpe-trap=inexact is likely to be uninteresting in practice. ๐ด
By default, no exception traps are enabled. ๐ธ
-ffpe-summary=listโ ๐ Specifies a list of floating-point exceptions whose flag status gets printed toERROR_UNITwhenSTOPorERROR STOPis invoked.listcan benone,all, or a comma-separated list of these exceptions: invalid, zero, overflow, underflow, inexact and denormal. (Check-ffpe-trapfor descriptions of the exceptions.)
If the option is used more than once on the command line, only the last one gets used. ๐
By default, a summary for all exceptions except inexact is shown. ๐
-fno-backtraceโ ๐ When a serious runtime error happens or a deadly signal gets emitted (segmentation fault, illegal instruction, bus error, floating-point exception, and the other POSIX signals whose action is core), the Fortran runtime library tries to print a backtrace of the error.-fno-backtraceturns backtrace generation off. This only has influence when compiling the Fortran main program.
โจ Options for directory search โจ
These options affect how GNU Fortran searches for files named by the INCLUDE directive, and where it looks for previously compiled modules. ๐
They also affect the search paths cpp uses when it preprocesses Fortran source. ๐ง
-Idirโ ๐๏ธ These affect how theINCLUDEdirective gets interpreted, as well as the#includedirective of the cpp preprocessor.
Also, the general behavior of -I and INCLUDE is pretty much the same as -I with #include in the cpp preprocessor, when it comes to looking for header.gcc files and other things like that. ๐ค
This path is also used to search for .mod files when previously compiled modules are required by a USE statement.
-Jdirโ ๐ฆ Specifies where to put.modfiles for compiled modules. It also gets added to the list of directories searched by aUSEstatement.
The default is the current directory. ๐
-fintrinsic-modules-path dirโ ๐บ๏ธ Specifies the location of pre-compiled intrinsic modules, if they aren't in the default location the compiler expects.
โจ Influencing the linking step โจ
These options come into play when the compiler links object files into an executable output file. They're meaningless if the compiler isn't doing a link step. ๐
-static-libgfortranโ ๐ง On systems that provide libgfortran as both a shared and a static library, this forces the static version. If no shared version of libgfortran was built when the compiler was configured, this option has no effect.
โจ Influencing runtime behavior โจ
These options affect the runtime behavior of programs compiled with GNU Fortran. ๐โโ๏ธ
-fconvert=conversionโ ๐ Specifies the representation of data for unformatted files. Valid values forconversionare:nativeโ the defaultswapโ swap between big- and little-endianbig-endianโ use big-endian representation for unformatted fileslittle-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 override the default specified by -fconvert. ๐
-frecord-marker=lengthโ ๐ Specifies the length of record markers for unformatted files. Valid values forlengthare 4 and 8. Default is 4.
This is different from previous versions of gfortran, which specified a default record marker length of 8 on most systems. If you want to read or write files compatible with earlier versions of gfortran, use -frecord-marker=8. ๐ฐ๏ธ
-fmax-subrecord-length=lengthโ ๐งฉ Specifies the maximum length for a subrecord. The maximum permitted value forlengthis2147483639, which is also the default. It's only really useful for the gfortran testsuite. ๐งช-fsign-zeroโ okay, so when this is on ๐, floating point numbers that are zero but have the sign bit set get written out as negative numbers in formatted output, and theSIGNintrinsic treats them as negative.-fno-sign-zerois the chill alternative ๐: it doesn't print the negative sign of zero values (or values that round to zero for I/O), andSIGNtreats zero as a positive number, which keeps things compatible with Fortran 77. The default is-fsign-zeroโจ.
โจ Options for code generation conventions โจ
These machine-independent options are the ones that control the interface conventions used in code generation ๐ง. They don't care what machine you're on, which is so iconic.
Most of them come in positive and negative forms, so the negative form of -ffoo is -fno-foo. In the list below, only the non-default form is shown, so you can figure out the other one by removing or adding the no- ๐
.
-fno-automaticโ this one treats every program unit (except the ones marked asRECURSIVE) like theSAVEstatement was written for every local variable and array in it ๐. It doesn't touch common blocks. (Some Fortran compilers call this option-staticor-save, fun fact ๐ธ.) The default is-fautomatic, which puts local variables smaller than the value given by-fmax-stack-var-sizeon the stack. If you want zero static memory, use-frecursiveinstead.- Local variables or arrays with an explicit
SAVEattribute get silently ignored unless you add the-pedanticoption ๐.
- Local variables or arrays with an explicit
-ff2cโ this generates code that plays nicely with code fromg77andf2c๐ฆ.- Here's the tea โ:
g77(which started out inf2c) needs functions that return defaultREALto actually return the C typedouble, and functions that returnCOMPLEXto hand back their value through an extra argument in the calling sequence, which is a pointer to where the return value should go. With the default GNU calling conventions, those functions just return their results like GNU C would: defaultREALfunctions returnfloat, andCOMPLEXfunctions return the GNU C typecomplex. This option also implies-fsecond-underscore, unless you explicitly ask for-fno-second-underscore. - This does not change the code that talks to the
libgfortranlibrary ๐.
- Here's the tea โ:
Caution: mixing Fortran code built with-ff2cand code built with the default-fno-f2ccalling conventions is not a good idea. If you callCOMPLEXor defaultREALfunctions across parts that were compiled with different conventions, it 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 changing the names of entities in your Fortran source by adding underscores to them ๐.- With
-funderscoringin effect, GNU Fortran adds one underscore to external names that don't already have any. This is done so the code matches what a lot of UNIX Fortran compilers produce ๐ซถ. - > Caution: GNU Fortran's default behavior is incompatible with
f2candg77. If you want object files built with GNU Fortran to be compatible with object code from those tools, please use the-ff2coption ๐ . - Using
-fno-underscoringis not recommended unless you're experimenting with things like fitting GNU Fortran into existing system environments (think existing libraries, tools, and so on) ๐. - Here's an example. Say
j()andmax_count()are external functions, whilemy_varandlvarare local variables. With-funderscoring, a statement like this:
- With
I = J() + MAX_COUNT (MY_VAR, LVAR)
is implemented as something like this:
i = j_() + max_count__(&my_var__, &lvar);
With -fno-underscoring, the very same statement is implemented as:
i = j() + max_count(&my_var, &lvar);
-fno-underscoringlets you use your own names directly while debugging, and when you're interfacing GNU Fortran code with other languages ๐ง.- Just because the names match doesn't mean the interface GNU Fortran uses for an external name matches the interface some other language uses for that same name ๐คจ. Getting GNU Fortran code to link with code from another compiler this way (or any other way) can be just a small part of the job. Getting both compilers to agree on things other than naming can take serious effort, and unlike naming disagreements, linkers normally can't detect those other mismatches ๐.
- Also, with
-fno-underscoring, the lack of appended underscores creates a very real chance that a user-defined external name will clash with a name in a system library. That could make unresolved-reference bugs super 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 the naming and linking situation so debugging always uses the names exactly 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 adds an underscore to external names. With this option, names that contain underscores get two underscores appended, and external names without underscores get one underscore ๐. Internal names with underscores also get two underscores, so they don't collide with external names.- This option does nothing if
-fno-underscoringis in effect. It's implied by the-ff2coption ๐ซถ. - With this option, an external name like
MAX_COUNTbecomes a reference to the link-time external symbolmax_count__, instead ofmax_count_. This is required for compatibility withg77andf2c, and it's implied by using-ff2c๐.
- This option does nothing if
-fcoarray=<keyword>โ this picks how coarray support works ๐. The keyword is one of these:noneโ coarray support is disabled, so using coarray declarations and image-control statements gives a compile-time error. (This is the default ๐.)singleโ single-image mode, meaningnum_images()is always one ๐ฆ.libโ library-based coarray parallelization. You need to link a suitable GNU Fortran coarray library for this one ๐ง.
-fcheck=<keyword>โ this turns on run-time checks โญ. The argument has to be a comma-delimited list of the keywords below. Puttingno-in front of a check turns it off if an earlier specification turned it on ๐ .allโ enables all the run-time tests of-fcheck๐.array-tempsโ warns at run time when a temporary array had to be generated to pass an actual argument. The info from this warning can be handy for optimization, since you can avoid those temporaries ๐ธ.- Heads up: this warning only prints once per location โจ.
boundsโ enables run-time checks for array subscripts and 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 are equal for character array constructors that don't have an explicit typespec ๐ง.- Some checks require
-fcheck=boundsto be set when compiling the main program ๐. - Note: in the future, this may also cover other kinds of checking, like checking substring references ๐ฎ.
- Some checks require
doโ enables run-time checks for invalid modification of loop iteration variables ๐.memโ enables run-time checks for memory allocation ๐ง .- Note: this doesn't affect explicit allocations using the
ALLOCATEstatement, because those are always checked ๐ฏ.
- Note: this doesn't affect explicit allocations using the
pointerโ enables run-time checks for pointers and allocatables ๐.recursionโ enables 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, and it's disabled if you use it together with
-frecursiveand-fopenmp๐.
- Note: this check doesn't work for OpenMP programs, and it's disabled if you use it together with
Example time ๐
. Assuming you have a file foo.f90, the command:
gfortran -fcheck=all,no-array-temps foo.f90
will compile the file with all checks enabled as specified above, except for the warnings about generated array temporaries โจ.
-fbounds-checkโ this is a deprecated alias for-fcheck=bounds๐. Bye-bye, old friend ๐ฅ.-ftail-call-workaround,-ftail-call-workaround=nโ some C interfaces to Fortran code break the gfortran ABI by leaving out the hidden character length arguments as described in (the reference got cut off here, bestie ๐ญ). This can lead to crashes, because pushing arguments for tail calls can overflow the stack ๐.- To give existing binary packages a workaround, this option disables tail call optimization for gfortran procedures with character arguments ๐ฉน.
- With
-ftail-call-workaround=2, tail call optimization is disabled in all gfortran procedures with character arguments. - With
-ftail-call-workaround=1(or plain-ftail-call-workaround, which is equivalent), it's disabled only in gfortran procedures with character arguments that call implicitly prototyped procedures.
- With
- Using this option can lead to problems, including crashes from insufficient stack space ๐ฌ.
- It is very strongly recommended that you fix the code in question instead ๐ซถ. The
-fc-prototypes-externaloption can generate prototypes that conform to the gfortran ABI, which you can include in your source code โจ. - Support for this option will likely be withdrawn in a future release of gfortran ๐.
- The negative form,
-fno-tail-call-workaroundor equivalently-ftail-call-workaround=0, can be used to turn this option off ๐ . - The default is currently
-ftail-call-workaround, but this will change in future releases ๐ธ.
- To give existing binary packages a workaround, this option disables tail call optimization for gfortran procedures with character arguments ๐ฉน.
-fcheck-array-temporariesโ this is a deprecated alias for-fcheck=array-temps๐.-fmax-array-constructor=nโ this can be used to raise the upper limit allowed in array constructors ๐. The code below requires this option so the array can be expanded at compile time ๐งฉ.
The example above is what the sample -fmax-array-constructor is about: a 100000-element constant array built with an implied DO loop. Bestie, fair warning, the compile times get wild.
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 long compile times and excessively large object files. Be careful, bestie ๐
The default value for n is 65535 ๐ธ
-fmax-stack-var-size=n
okay so this one sets the size, in bytes, of the biggest array that's allowed to live on the stack. If an array goes over that size, it gets static memory instead, except inside procedures marked RECURSIVE ๐ฆ If you want recursive procedures that don't have the RECURSIVE attribute, or you're writing parallel programs, pair it with -frecursive. If you want to never use the stack at all, reach for -fno-automatic โจ
This option currently only affects local arrays declared with constant bounds, and it might not apply to every character variable. Future versions of GNU Fortran may improve this behavior, so keep an eye out ๐
The default value for n is 32768 ๐
-fstack-arrays
this flag tells the Fortran compiler to put every array of unknown size and every array temporary onto stack memory ๐ฅ If your program uses really big local arrays, you might have to raise your runtime stack limits on some operating systems. This flag is enabled by default at optimization level -Ofast, unless -fmax-stack-var-size is specified ๐
-fpack-derived
this one packs derived type members as tightly as possible ๐ฆ Code compiled with it is likely to be incompatible with code compiled without it, and it may run slower. Be careful with that combo, it's a whole thing ๐
-frepack-arrays
sometimes GNU Fortran passes assumed shape array sections through a descriptor that points at a noncontiguous chunk of memory ๐งฉ This option adds code to the function prologue that repacks the data into a contiguous block at runtime. The result should be faster array accesses, but it can add significant overhead to the function call, especially when the data being passed is noncontiguous. So it's a trade-off, babe ๐
-fshort-enums
this one is for interoperability with C code that was compiled with -fshort-enums ๐ซถ It makes GNU Fortran choose the smallest INTEGER kind that a given enumerator set will fit in, and then gives all of its enumerators that kind.
-fexternal-blas
with this on, gfortran will generate calls to BLAS functions for some matrix operations, like MATMUL, instead of using its own algorithms, as long as the matrices are bigger than a given limit (see -fblas-matmul-limit) ๐ฅ This can be super profitable if you have an optimized vendor BLAS library available. The BLAS library has to be specified at link time, so don't forget that step ๐ซ
-fblas-matmul-limit=n
this only matters when -fexternal-blas is in effect ๐ Matrix multiplication of matrices with a size larger than, or equal to, n gets handled by calls to BLAS functions, and everything smaller is handled by 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 n is 30 ๐
-finline-matmul-limit=n
when front-end optimization is active, some calls to the MATMUL intrinsic get inlined โจ This can bloat your code size if the size of the matrix can't be figured out at compile time, since code for both cases gets generated. Setting -finline-matmul-limit=0 disables inlining in all cases. Setting it to a value of n produces inline code for matrices with a size up to n. If the matrices aren't square, the size comparison uses the geometric mean of the dimensions of the argument and result matrices, same energy as before ๐ง
The default value for n is 30. The -fblas-matmul-limit option can be used to change this value ๐
-frecursive
this lets you allow indirect recursion by forcing all local arrays to be allocated on the stack ๐ It can't be used together with -fmax-stack-var-size= or -fno-automatic, so pick a lane ๐ฃ๏ธ
-finit-local-zero, -finit-derived, -finit-integer=n, -finit-real=<zero|inf|-inf|nan|snan>, -finit-logical=<true|false>, -finit-character=n
these are the initialization crew ๐ง -finit-local-zero tells the compiler to set local INTEGER, REAL, and COMPLEX variables to zero, LOGICAL variables to false, and CHARACTER variables to a string of null bytes.
If you want finer-grained control, you've got -finit-integer=n, -finit-real=<zero|inf|-inf|nan|snan> (which also initializes the real and imaginary parts of local COMPLEX variables), -finit-logical=<true|false>, and -finit-character=n, where n is an ASCII character value. Main character energy ๐
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 as they would be with -finit-local-zero ๐ฆ
Heads up, these options do not initialize:
- objects with the
POINTERattribute - allocatable arrays
- variables that appear in an
EQUIVALENCEstatement
(These limitations may be removed in future releases, so no promises yet ๐)
Note that -finit-real=nan initializes REAL and COMPLEX variables with a quiet NaN. If you want a signalling NaN, use -finit-real=snan. Be warned though: compile-time optimizations may convert those into quiet NaN, and trapping needs to be enabled (for example via -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 the Fortran code, which might wrap around if the value is too large for the kind ๐ญ
Finally, enabling any of the -finit-* options will silence warnings that would have been emitted by -Wuninitialized for the affected local variables ๐คซ
-falign-commons
by default, gfortran enforces proper alignment of all variables in a COMMON block by padding them as needed ๐งฑ On some platforms this is mandatory, and on others it boosts performance. If a COMMON block isn't declared with consistent data types everywhere, that padding can cause trouble, and -fno-align-commons can be used to turn automatic alignment off. Use the same form of this option for all files that share a COMMON block. To dodge alignment issues in COMMON blocks, it's recommended to order objects from largest to smallest ๐
-fno-protect-parens
by default, the parentheses in expressions are honored at every optimization level, so the compiler doesn't re-associate anything ๐ซง Using -fno-protect-parens lets the compiler reorder REAL and COMPLEX expressions to make faster code. For the re-association optimization, -fno-signed-zeros and -fno-trapping-math need to be in effect too. The parentheses protection is enabled by default, unless -Ofast is 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 option is enabled by default, except when -std=f95 is given. See also -Wrealloc-lhs ๐
-faggressive-function-elimination
functions with identical argument lists get eliminated within statements, whether or not they're marked PURE ๐ช 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 one performs front-end optimization by manipulating parts of the Fortran parse tree ๐ณ It's enabled by default by any -O option except -O0 and -Og. The optimizations this option 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)) - short-circuiting of logical operators (
.AND.and.OR.)
It can be deselected by specifying -fno-frontend-optimize ๐
โโ๏ธ
-ffrontend-loop-interchange
this attempts to interchange loops in the Fortran front end where it's profitable ๐ It's enabled by default by any -O option. At the moment, it only affects FORALL and DO CONCURRENT statements with several forall triplets ๐ง
โจ ENVIRONMENT โจ
The gfortran compiler doesn't currently use any environment variables to control its operation, beyond the ones that affect the operation of gcc. So if you're hunting for gfortran-specific env vars, you're out of luck, bestie ๐ฅฒ
๐ BUGS ๐
For instructions on reporting bugs, see <file:///usr/share/doc/gcc-9/README.Bugs> ๐ชฒ
๐ SEE ALSO ๐
gpl(7), gfdl(7), fsf-funding(7), cpp(1), gcov(1), gcc(1), as(1), ld(1), gdb(1), dbx(1), and the Info entries for gcc, cpp, gfortran, as, ld, binutils and gdb ๐
๐โโ๏ธ AUTHOR ๐โโ๏ธ
See the Info entry for gfortran for contributors to GCC and GNU Fortran. The whole squad is listed there ๐ซถ
โ๏ธ COPYRIGHT โ๏ธ
Copyright (c) 2004-2019 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with the Invariant Sections being "Funding Free Software", the Front-Cover Texts being (a) (see below), and with the Back-Cover Texts being (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! ๐ It's the gcc-9 build, dated 2022-05-27, and it's all GFORTRAN(1) ๐โจ Slay the compile times, and don't forget to init your locals ๐ฆ๐
๐ฆ where this page comes from
- ubuntu jammy: gfortran-9-alpha-linux-gnu 9.5.0-1ubuntu1~22.04cross1
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms