GFORTRAN(1)
๐ GFORTRAN(1) ยท 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...
Okay so this is only the most useful stuff, bestie. The rest is further down ๐
๐ DESCRIPTION ๐
Okay so gfortran supports every option that gcc supports, no cap. This page only covers the options that are specific to GNU Fortran, so you're not drowning in extra stuff ๐ซถ
Every GCC and GNU Fortran option works with both gfortran and gcc, and also with any other drivers that were built at the same time (like g++). Adding GNU Fortran to the GCC distribution means all the relevant drivers accept GNU Fortran options. It's giving teamwork ๐
Some options come in positive and negative forms. The negative form of -ffoo is -fno-foo. This manual only documents one of the two, whichever one isn't the default. So don't be confused when you only see one version ๐
๐ OPTIONS ๐
Here's the cheat sheet of every option specific to GNU Fortran, sorted into groups by type. The explanations come after the groups โจ
๐ฆ 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
These options control the details of the Fortran dialect the compiler accepts. Here they are, one by one ๐
-ffree-form,-ffixed-formโ These pick the layout of the source file. Free form came in with Fortran 90, while fixed form was the old-school way older Fortran programs were written. If you don't specify either one, the compiler figures out the source form from the file extension ๐-fall-intrinsicsโ This makes every intrinsic procedure work, including GNU's own extensions. It's super handy alongside-std=f95if you want standard compliance but still want the full set ofgfortranintrinsics. The catch is that-Wintrinsics-stdgets ignored, and no user-defined procedure that shares a name with an intrinsic will get called, unless it's explicitly declaredEXTERNAL๐-fd-lines-as-code,-fd-lines-as-commentsโ These give special treatment to lines starting withdorDin fixed form sources. With-fd-lines-as-code, they're treated as if the first column had a blank in it. With-fd-lines-as-comments, they're treated as comment lines ๐ฌ-fdecโ This turns on DEC compatibility mode, which enables extensions and other features that copy the default behavior of older compilers (like DEC's). Fair warning:
These features are non-standard, so avoid them at all costs. For the nitty-gritty on how GNU Fortran implements these extensions, check the full documentation.
Turning this on also flips on -fdollar-ok, -fcray-pointer, -fdec-structure, -fdec-intrinsic-ints, -fdec-static, and -fdec-math. And if -fd-lines-as-code or -fd-lines-as-comments aren't set, then -fdec also sets -fd-lines-as-comments ๐ซ
-fdec-structureโ This enables DEC"STRUCTURE"and"RECORD", plus"UNION","MAP", and the dot ('.') as a member separator (on top of'%'). It's here for compatibility only. Fortran 90 derived types are the better choice wherever you can use them ๐ท-fdec-intrinsic-intsโ This enables the B/I/J/K kind variants of existing integer functions, like BIAND, IIAND, JIAND, and so on. For the full list of intrinsics, check the full documentation ๐ข-fdec-mathโ This enables legacy math intrinsics like COTAN and the degree-valued trig functions (like TAND, ATAND, and so on) so older code keeps working ๐-fdec-staticโ This enables DEC-style STATIC and AUTOMATIC attributes, which let you explicitly set the storage of variables and other objects ๐งฑ-fdec-includeโ This letsINCLUDEbe parsed as a statement, as well as the regularINCLUDEline. When it's parsed as a statement,INCLUDEdoesn't have to sit on a single line and can use line continuations โ๏ธ-fdollar-okโ This lets$show up as a valid non-first character in a symbol name. Symbols that start with$still get rejected, because it's unclear which implicit typing rules should apply, since different vendors do it differently. Using$inIMPLICITstatements is also rejected ๐ซ-fbackslashโ This changes how backslashes work in string literals. Instead of being a single backslash character, they become "C-style" escape characters. These get expanded:"\a","\b","\f","\n","\r","\t","\v","\\", and"\0"become the ASCII alert, backspace, form feed, newline, carriage return, horizontal tab, vertical tab, backslash, and NUL characters, in that order. 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โ This sets the default accessibility of module entities toPRIVATE. Use-associated entities won't be accessible unless they're explicitly declaredPUBLIC๐-ffixed-line-length-nโ This sets the column after which characters get ignored in typical fixed-form lines in the source file. Unless you use-fno-pad-source, it also decides how far spaces are assumed (as if the line were padded out to that length) after the ends of short fixed-form lines. Popular values fornare 72 (the standard and the default), 80 (card image), and 132 (matching the "extended-source" options in some popular compilers).ncan also benone, which means the entire line is meaningful and continued character constants never get implicit spaces tacked on to fill out the line.-ffixed-line-length-0does the exact same thing as-ffixed-line-length-none๐-fno-pad-sourceโ Normally, fixed-form lines have spaces assumed (as if padded to that length) after the ends of short fixed-form lines. That doesn't happen if you use-ffixed-line-length-0,-ffixed-line-length-none, or-fno-pad-source. With any of those, continued character constants never get implicit spaces appended to fill out the line ๐ โโ๏ธ-ffree-line-length-nโ This sets the column after which characters get ignored in typical free-form lines in the source file. The default is 132.ncan benone, meaning the entire line is meaningful.-ffree-line-length-0means the same thing as-ffree-line-length-none๐-fmax-identifier-length=nโ This sets the maximum allowed identifier length. Typical values are 31 (Fortran 95) and 63 (Fortran 2003 and Fortran 2008) ๐ท๏ธ-fimplicit-noneโ This says no implicit typing is allowed, unless an explicitIMPLICITstatement overrides it. It's the same as addingimplicit noneto the start of every procedure ๐ค-fcray-pointerโ This enables the Cray pointer extension, which gives you C-like pointer functionality ๐-fopenaccโ This enables the OpenACC extensions. That includes OpenACC!$accdirectives in free form,c$acc,*$acc, and!$accdirectives in fixed form,!$conditional compilation sentinels in free form, andc$,*$, and!$sentinels in fixed form. When linking, it also makes sure the OpenACC runtime library gets linked in.
This is an experimental feature, so it's incomplete and subject to change in future versions of GCC. For more info, check https://gcc.gnu.org/wiki/OpenACC ๐งช
-fopenmpโ This enables the OpenMP extensions. That includes OpenMP!$ompdirectives in free form,c$omp,*$omp, and!$ompdirectives in fixed form,!$conditional compilation sentinels in free form, andc$,*$, and!$sentinels in fixed form. When linking, it also makes sure the OpenMP runtime library gets linked in. And heads up,-fopenmpimplies-frecursive๐งต-fno-range-checkโ okay so this one turns OFF the range checks when gfortran is folding constant expressions at compile time ๐. Normally it'll yell at you fora = 1. / 0, but with this flag no error shows up andajust gets+Infinityโจ. If a value lands outside the range of["-HUGE()":HUGE()], it gets swapped for-Infor+Inf, whichever fits. TheDATA i/Z'FFFFFFFF'/example is iconic: it'd normally overflow on most systems, but with-fno-range-checkit wraps around andiends up as-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 does not promote variables that already have an explicit kind declaration, so those stay as they are ๐ซถ-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 that's possible. If you also pass-fdefault-double-8, thenDOUBLE PRECISIONand double real constants won't get promoted. Unlike-freal-4-real-8,-fdefault-real-8doesn't touch variables with explicit kind declarations ๐-fdefault-real-10โ same energy as-fdefault-real-8, but the default real type becomes a 10 byte wide type ๐ฆ. It changes non-double real constants like1.0, and it bumpsDOUBLE PRECISIONand double real constants like1.d0up to 16 bytes if possible. Passing-fdefault-double-8along with it keepsDOUBLE PRECISIONand double real constants from being promoted. And just like before, it won't mess with variables that have explicit kind declarations, unlike-freal-4-real-10๐ง-fdefault-real-16โ sets the default real type to a 16 byte wide type ๐. It changes the kind of non-double real constants like1.0, and bumpsDOUBLE PRECISIONand double real constants like1.d0up to 16 bytes if possible. With-fdefault-double-8added,DOUBLE PRECISIONand double real constants stay put. Explicitly kinded variables are left alone, unlike with-freal-4-real-16โจ-fdefault-double-8โ setsDOUBLE PRECISIONand double real constants like1.d0to an 8 byte wide type ๐. If that's already the default, it does nothing. This option stops-fdefault-real-8,-fdefault-real-10, and-fdefault-real-16from promotingDOUBLE PRECISIONand double real constants like1.d0to 16 bytes, so it's the one to reach for when you want those to stay small ๐-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, bestie, because it may not suit your codes โ ๏ธ. The areas to watch 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, which you can produce with-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 all promote everyREAL(KIND=M)entity toREAL(KIND=N)๐. IfREAL(KIND=N)isn't available, you'll get an error. Every other real kind is unaffected. Same warning as before, babe: these may not suit your codes ๐. Watch out for calls to external procedures, alignment inEQUIVALENCEand/orCOMMON, generic interfaces, BOZ literal constant conversion, and I/O. Again, inspecting the intermediate representation from-fdump-tree-originalis suggested ๐ซถ-std=stdโ tell gfortran which standard your program is supposed to follow ๐. You can pickf95,f2003,f2008,f2018,gnu, orlegacy. The default isgnu, which is a superset of the latest Fortran standard that includes every GNU Fortran extension, though you'll get warnings for obsolete extensions that aren't recommended in new code ๐. Thelegacyvalue is basically the same but without those obsolete-extension warnings, which is useful for old non-standard programs ๐ง. Thef95,f2003,f2008, andf2018values enforce strict conformance to Fortran 95, Fortran 2003, Fortran 2008, and Fortran 2018 respectively. Anything beyond that standard gets 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's only there 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, these are all the preprocessor options ๐. Check out the section Preprocessing and conditional compilation for the deeper dive on preprocessing in gfortran ๐
-cpp,-nocppโ-cppturns preprocessing on ๐. The preprocessor gets called automatically if your file extension is.fpp,.FPP,.F,.FOR,.FTN,.F90,.F95,.F03, or.F08. Use-cppto manually enable preprocessing for any kind of Fortran file ๐.
To turn preprocessing OFF for files with any of those extensions, use the negative form, -nocpp ๐
โโ๏ธ.
The preprocessor runs in traditional mode ๐ฐ๏ธ. Any file-format restrictions, especially the line length limits, still apply to the preprocessed output, so it might be a good idea to use -ffree-line-length-none or -ffixed-line-length-none ๐
-dMโ instead of the normal output, you get a list of#definedirectives for every macro defined while the preprocessor runs, predefined ones included ๐ง. It's a super handy way to see what's predefined in your version of the preprocessor ๐. If you don't have a file called foo.f90, this command will show all the predefined macros:
touch foo.f90; gfortran -cpp -E -dM foo.f90
-dDโ like-dM, but with two differences ๐ . It leaves out 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 and not their expansions ๐ฆ-dUโ like-dDexcept only macros that get expanded, or whose definedness gets tested in preprocessor directives, are output ๐ฏ. The output is delayed until the macro is used or tested.#undefdirectives are also output for macros that were tested but were undefined at that time ๐-dIโ outputs#includedirectives alongside the result of preprocessing ๐ธ-fworking-directoryโ turns on generating linemarkers in the preprocessor output so the compiler knows the current working directory at preprocessing time ๐บ๏ธ. With this on, the preprocessor emits a second linemarker after the initial one, containing the current working directory followed by two slashes. If the directory is present in the preprocessed input, GCC uses it as the current working directory in some debugging information formats ๐. This is implicitly enabled when debugging information is on, but you can block that with the negated form,-fno-working-directory๐ซ. Heads up: if the-Pflag is in the command line, this option does nothing at all, because no#linedirectives get emitted whatsoever ๐ญ-idirafter dirโ searchesdirfor include files, but only AFTER all the directories given with-Iand the standard system directories have been exhausted ๐.dirgets 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โ setsprefixas the prefix for subsequent-iwithprefixoptions ๐ท๏ธ. If the prefix is a directory, include the final/๐-isysroot dirโ this one's like--sysroot, but it only applies to header files ๐. Check the--sysrootoption for more deets ๐-iquote dirโ searchesdirONLY for header files requested with#include "file"๐. They're not searched for#include <file>. This happens before all the-Idirectories and 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 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 system directories โจ. Ifdirbegins with=, then the=gets replaced by the sysroot prefix (see--sysrootand-isysroot) ๐ฟ-nostdincโ don't search the standard system directories for header files ๐ โโ๏ธ. Only the directories you specified with-Ioptions (plus the directory of the current file, if appropriate) 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 predicatepredicateand the answeranswer๐ง . This form is preferred over the older-A predicate(answer)form, which is still supported, because it doesn't use shell special characters ๐-A-predicate=answerโ cancels an assertion with the predicatepredicateand the answeranswerโ-Cโ don't discard comments ๐ฌ. All comments get passed through to the output file, EXCEPT for comments inside processed directives, which get deleted along with the directive ๐๏ธ
Okay so the -C option has some side effects, bestie ๐จ It makes the preprocessor treat comments as real tokens in their own right. A comment sitting at the start of what would be a directive line turns that line into an ordinary source line, because the first token on it is no longer a #. Chaotic, I know ๐
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 ๐ 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 -C side effects, -CC converts all C++-style comments inside a macro into C-style comments ๐ Why? So a later use of that macro can't accidentally comment out the rest of the source line. It's 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 the definition1๐ธ-Dname=definitionโ the contents ofdefinitionget tokenized and processed as if they showed up during translation phase three in a#definedirective ๐ง The big catch: embedded newline characters will truncate the definition.
If you're invoking the preprocessor from a shell (or something shell-like), you might need the shell's quoting syntax to protect characters like spaces that have a meaning in shell syntax ๐
Want a function-like macro on the command line? Write its argument list with surrounding parentheses before the equals sign (if any). 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 are 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 used, along with all the other normal activities ๐ Each name is indented to show how deep it sits in the#includestack.-Pโ inhibits generation of linemarkers in the preprocessor output ๐ฆ This might be useful when you're running the preprocessor on something that isn't C code and will be sent to a program that might 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 reporting that GNU Fortran cannot compile the relevant piece of source code ๐ The compiler keeps going to try to report further errors so you can debug, but it won't produce any compiled output.
Warnings are diagnostic messages about constructions that aren't inherently erroneous but are risky or suggest there's likely a bug in the program ๐ Unless -Werror is specified, they don't prevent your program from compiling.
You can request lots of specific warnings with options beginning -W, for example -Wimplicit to get warnings on implicit declarations. Each of these specific warning options also has a negative form beginning -Wno- to turn warnings off, for example -Wno-implicit. This manual only lists one of the two forms, whichever is not the default ๐ง
These options control the amount and kinds of errors and warnings GNU Fortran produces:
-fmax-errors=nโ caps the number of error messages atn, at which point GNU Fortran bails out instead of trying to keep going ๐ Ifnis0, there is no limit on the number of error messages 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 occur in GNU Fortran source files, such as use of\ein a character constant within a directive like"#include".
Valid Fortran programs should compile properly with or without this option. Without it, though, certain GNU extensions and traditional Fortran features are supported too. With this option, many of them get rejected ๐
Some users try to use -pedantic to check programs for conformance. They soon find it doesn't do quite what they wantโit finds some nonstandard practices, but not all. However, improvements to GNU Fortran in this area are welcome ๐
This should be used in conjunction with -std=f95, -std=f2003, -std=f2008 or -std=f2018.
-pedantic-errorsโ like-pedantic, except that errors are produced rather than warnings ๐ซ-Wallโ enables commonly used warning options pertaining to 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 initiated 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 and thus enabled by default.-Warray-temporariesโ warns about array temporaries generated by the compiler ๐๏ธ The information from this warning is sometimes useful in optimization, so you can avoid such temporaries.-Wc-binding-typeโ warns if a variable might not be C interoperable ๐ In particular, it warns if the variable has been declared using an intrinsic type with default kind instead of using 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 are 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 which may be problematic ๐ฌ This currently includes-Wcompare-reals,-Wunused-parameterand-Wdo-subscript.-Wfrontend-loop-interchangeโ enables warnings 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 as"EXTERNAL"๐ซ-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 an"EXTERNAL"procedure 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 a"q"exponent-letter ๐ข-Wsurprisingโ produces a warning when "suspicious" code constructs are encountered ๐ซข While technically legal, these usually indicate that an error has been made. This currently produces a warning under the following circumstances:- An INTEGER SELECT construct has a CASE that can never be matched as 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โ tabs are accepted as whitespace by default, 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.-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 which yield anUNDERFLOWduring compilation ๐ Enabled by default.-Wintrinsic-shadow: okay so this one warns if your own procedure or module procedure has the same name as an intrinsic ๐. Calls might not resolve to the one you actually meant, so you may need an explicit interface or anEXTERNALorINTRINSICdeclaration to get things back on track ๐. This is implied by-Wall๐ .-Wuse-without-only: warns if aUSEstatement has noONLYqualifier, which means it quietly imports every public entity from the module ๐ซฃ.-Wunused-dummy-argument: warns about unused dummy arguments ๐งน. This is implied by-Wall.-Wunused-parameter: this one is a plot twist ๐. Unlike gcc, gfortran doesn't use it for unused dummy arguments (that's-Wunused-dummy-argument). Instead it warns about unusedPARAMETERvalues. It's implied by-Wextraif-Wunusedor-Wallis also used.-Walign-commons: by default gfortran warns whenever variables inside aCOMMONblock get padded for proper alignment ๐. You can silence it with-Wno-align-commons, and see also-falign-commons.-Wfunction-elimination: warns if calls to impure functions get eliminated by the optimizations turned on by-ffrontend-optimize๐ซ . This is implied by-Wextra.-Wrealloc-lhs: warns when the compiler might insert allocation or reallocation code for an allocatable array of intrinsic type in an intrinsic assignment ๐. In hot loops, the Fortran 2003 reallocation feature can hurt performance ๐ฅฒ. If the array is already allocated with the correct shape, consider a whole-array array-spec like(:,:,:)on the left-hand side so the reallocation check gets skipped โจ. Heads up, the warning can show up even when the compiler would optimize the check away anyway, 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 any allocatable variable, and that includes scalars and derived types ๐งฉ.-Wcompare-reals: warns when you compare real or complex values for equality or inequality ๐. This is implied by-Wextra.-Wtarget-lifetime: warns if the pointer in a pointer assignment might outlive its target โณ. This is implied by-Wall.-Wzerotrip: warns if aDOloop is known at compile time to run zero times ๐. This is implied by-Wall.-Wdo-subscript: this one catches sneaky out-of-bounds vibes ๐. It warns if an array subscript inside aDOloop could go out of bounds, even when the compiler can't prove the statement actually runs. Something like this:
real a(3)
do i=1,4
if (condition(i)) then
a(i) = 1.2
end if
end do
This is implied by -Wextra.
-Werror: turns every warning into an error ๐ซ.
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 ๐ง. Hot tip: most of these are mainly for compiler nerds ๐ค.
-fdump-fortran-original: outputs the internal parse tree right after the source program gets translated into internal representation ๐ณ. It's mostly useful for debugging the GNU Fortran compiler itself. The output might change between releases, and it may also throw internal compiler errors for features that were only added recently ๐ญ.-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 it may also cause internal compiler errors for brand-new features ๐.-fdump-parse-tree: outputs the internal parse tree right after the source program gets translated into internal representation ๐ฒ. It's mostly for debugging the compiler itself, the output can change between releases, and it may also cause internal compiler errors for recently added features.
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 it may also trigger internal compiler errors for features that were only recently added ๐ซจ.-ffpe-trap=list: lets you turn on floating-point exception traps ๐ฅ. On most systems, when a floating-point exception happens and its trap is enabled, aSIGFPEsignal gets sent and the program is aborted, leaving behind a core file that's super useful for debugging ๐ฅ. Thelistis a comma-separated list (it can be empty) of these exceptions:invalid: an invalid floating-point operation, likeSQRT(-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 an operation ๐ซ๏ธdenormal: 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 IEEE 754, but it's available on some common architectures like x86 ๐ฅ๏ธ.
The first three exceptions (invalid, zero, and overflow) often point to serious errors. Unless your program has a plan for handling them, turning on traps for those three is probably a good idea ๐ซถ.
If you use the option more than once on the command line, the lists get joined together. So '"ffpe-trap="list1 "ffpe-trap="list2' is the same as "ffpe-trap="list1,list2 ๐งฉ.
Once you enable an exception, you can't disable it. There's no negative form, so choose wisely ๐.
Lots of floating-point operations lose precision because of rounding, so ffpe-trap=inexact is probably not very interesting in practice ๐ฅฑ.
By default, no exception traps are enabled ๐๏ธ.
-ffpe-summary=list: lets you pick which floating-point exceptions get their flag status printed toERROR_UNITwheneverSTOPorERROR STOPgets invoked ๐. Thelistcan benone,all, or a comma-separated list ofinvalid,zero,overflow,underflow,inexact, anddenormal. (Check-ffpe-trapfor what each of those exceptions means ๐.)
If you use the option more than once on the command line, only the last one counts ๐ซต.
By default, a summary for all exceptions except inexact gets shown ๐.
-fno-backtrace: when a serious runtime error pops up or a deadly signal gets emitted (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 option only matters when compiling the Fortran main program.
๐๏ธ Options for directory search ๐
These options control how GNU Fortran looks for files pulled in 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: affects how theINCLUDEdirective gets interpreted (and the#includedirective of the cpp preprocessor too) ๐บ๏ธ.
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 stuff like that ๐
.
This path is also used to search for .mod files when a USE statement needs previously compiled modules ๐ฆ.
-Jdir: specifies where to put.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: specifies where the pre-compiled intrinsic modules live, if they aren't in the default location the compiler expects ๐ .
๐ Influencing the linking step โ๏ธ
These options kick in 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 does nothing ๐ถ.
๐โโ๏ธ Influencing runtime behavior ๐
These options change how programs compiled with GNU Fortran behave at runtime ๐ฌ.
-fconvert=conversion: sets how data is represented in unformatted files ๐ง. Valid values forconversionarenative(the default),swap(swaps between big- and little-endian),big-endian(uses big-endian representation for unformatted files), andlittle-endian(uses little-endian representation for unformatted files) ๐.
This option only has an effect when it's used in the main program ๐. The CONVERT specifier and the GFORTRAN_CONVERT_UNIT environment variable both override the default set by -fconvert ๐ซก.
-frecord-marker=length: sets the length of record markers for unformatted files ๐. Valid values forlengthare4and8, and the default is4๐. This is different from earlier gfortran versions, which used a default record marker length of8on most systems ๐ฐ๏ธ. If you want to read or write files that work with earlier versions of gfortran, use-frecord-marker=8๐.-fmax-subrecord-length=length: sets 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 bestie, when this is on ๐, floating point zeros that have the sign bit set get written out as negative numbers in formatted output, and theSIGNintrinsic treats them as negative too ๐ฆ.-fno-sign-zerois the chill version ๐ธ. It doesn't print the negative sign of zero values (or values rounded to zero for I/O), and it treats zero as positive in theSIGNintrinsic, which keeps things compatible with Fortran 77 ๐. The default is-fsign-zeroโจ.
โจ Options for code generation conventions โจ
okay so these are machine-independent options that control the interface conventions used in code generation ๐ง. They're giving main character energy in the build process ๐ .
Most of them come in positive and negative forms. The negative form of -ffoo is -fno-foo. Below, only the non-default form is listed, so you figure out the other one by either removing no- or adding it ๐.
-fno-automaticโ treat each program unit (except those markedRECURSIVE) as if theSAVEstatement were specified for every local variable and array referenced in it. It doesn't affect common blocks. (Some Fortran compilers call this option-staticor-save.) The default,-fautomatic, uses the stack for local variables smaller than the value given by-fmax-stack-var-size. If you want no static memory at all, use-frecursive๐.- Local variables or arrays with an explicit
SAVEattribute are silently ignored unless you add the-pedanticoption ๐.
- Local variables or arrays with an explicit
-ff2cโ generate code that's compatible with code generated by g77 and f2c ๐ซถ. The g77 calling conventions (originally implemented in f2c) make functions that return defaultREALactually return the C typedouble. Functions that returnCOMPLEXsend their value back through an extra argument in the calling sequence, which points to where the return value gets stored. Under the default GNU calling conventions, those functions just return their results like GNU C would. 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 the generation of code that interfaces with the
libgfortranlibrary.
- This does not affect the generation of code that interfaces with the
Caution: It is not a good idea to mix Fortran code compiled with-ff2cwith code compiled with the default-fno-f2ccalling conventions ๐. CallingCOMPLEXor defaultREALfunctions between program parts compiled with different calling conventions 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โ do not transform the names of entities in the Fortran source file by appending underscores to them ๐.- With
-funderscoringin effect, GNU Fortran appends one underscore to external names with no underscores. This is done to stay compatible with code produced by many UNIX Fortran compilers ๐ฆ. - Using
-fno-underscoringis not recommended unless you're experimenting with things like integrating GNU Fortran into existing system environments (vis-ร -vis existing libraries, tools, and so on) ๐ง.
- With
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 this:
I = J() + MAX_COUNT (MY_VAR, LVAR)
is 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-underscoringlets you specify user-defined names directly while debugging and when interfacing GNU Fortran code with other languages ๐. - Just because the names match doesn't mean the interface GNU Fortran implements for an external name matches the interface another language implements for that same name ๐ซ . Getting code from GNU Fortran to link with code from another compiler using this or any other method can be only a small part of the solution. Getting the code from both compilers to agree on things other than naming can take serious effort, and unlike naming disagreements, linkers normally can't detect disagreements in those other areas ๐.
- With
-fno-underscoring, the lack of appended underscores introduces a very real possibility that a user-defined external name will conflict with a name in a system library. That could make finding unresolved-reference bugs quite difficult in some cases, since they might occur at program run time and only show up as buggy behavior then ๐ญ. - In future versions of GNU Fortran, the hope is to improve naming and linking so that debugging always involves using the names as they appear in the source. The names as seen by the linker may still be mangled to prevent accidental linking between procedures with incompatible interfaces โจ.
-fsecond-underscoreโ by default, GNU Fortran appends an underscore to external names. With this option, GNU Fortran appends two underscores to names that contain underscores, and one underscore to external names with no underscores. It also appends two underscores to internal names with underscores, to avoid naming collisions with external names ๐.- This option has no effect if
-fno-underscoringis in effect. It is implied by the-ff2coption ๐ธ. - With this option, an external name such as
MAX_COUNTis implemented as a reference to the link-time external symbolmax_count__, instead ofmax_count_. This is required for compatibility with g77 and f2c, and it's implied by using the-ff2coption ๐ซถ.
- This option has no effect if
-fcoarray=<keyword>โ pick how coarray support works ๐.noneโ disable coarray support. Using coarray declarations and image-control statements will produce a compile-time error. (Default) ๐ซsingleโ single-image mode, i.e.num_images()is always one ๐ง.libโ library-based coarray parallelization. A suitable GNU Fortran coarray library needs to be linked ๐ฅ.
-fcheck=<keyword>โ enable the generation of run-time checks ๐ก๏ธ. The argument should be a comma-delimited list of the keywords below. Prefixing a check withno-disables it if it was activated by a previous specification ๐ .allโ enable all run-time tests of-fcheckโจ.array-tempsโ warns at run time when, to pass an actual argument, a temporary array had to be generated. The info from this warning is sometimes useful for optimization, so you can avoid those temporaries ๐ฆ.- Note: The warning is only printed once per location.
boundsโ enable generation of run-time checks for array subscripts and against the declared minimum and maximum values. It also checks array indices for assumed and deferred shape arrays against the actual allocated bounds, and it makes sure all string lengths are equal for character array constructors without an explicit typespec ๐.- Some checks require that
-fcheck=boundsis set for the compilation of the main program. - Note: In the future this may also include other forms of checking, e.g., checking substring references.
- Some checks require that
doโ enable generation of run-time checks for invalid modification of loop iteration variables ๐.memโ enable generation of run-time checks for memory allocation ๐ง .- Note: This option does not affect explicit allocations using the
ALLOCATEstatement, which will always be checked.
- Note: This option does not affect explicit allocations using the
pointerโ enable generation of run-time checks for pointers and allocatables ๐.recursionโ enable generation of run-time checks for recursively called subroutines and functions that aren't marked as recursive. See also-frecursive๐.- Note: This check does not work for OpenMP programs, and it's disabled if used together with
-frecursiveand-fopenmp.
- Note: This check does not work for OpenMP programs, and it's disabled if used together with
Example: 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 warnings for generated array temporaries ๐.
-fbounds-checkโ deprecated alias for-fcheck=bounds๐ฅ.-ftail-call-workaround,-ftail-call-workaround=nโ okay, this one's a lot ๐ญ. Some C interfaces to Fortran code violate the gfortran ABI by omitting the hidden character length arguments as described in. This can lead to crashes, because pushing arguments for tail calls can overflow the stack ๐.- To provide a workaround for existing binary packages, 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=1or the equivalent plain-ftail-call-workaround, it's disabled only in gfortran procedures with character arguments that call implicitly prototyped procedures ๐งฉ. - Using this option can lead to problems, including crashes due to insufficient stack space ๐ฅบ.
- It is very strongly recommended to fix the code in question. The
-fc-prototypes-externaloption can be used to generate prototypes that conform to gfortran's ABI, for inclusion in the source code ๐ ๏ธ. - Support for this option will likely be withdrawn in a future release of gfortran ๐.
- The negative form,
-fno-tail-call-workaroundor the equivalent-ftail-call-workaround=0, can be used to disable this option ๐ . - The default is currently
-ftail-call-workaround. This will change in future releases ๐ฎ.
- To provide a workaround for existing binary packages, this option disables tail call optimization for gfortran procedures with character arguments. With
Warning: Relying on this option is risky bestie. Fix the source instead of leaning on the workaround ๐จ.
-fcheck-array-temporariesโ deprecated alias for-fcheck=array-temps๐ฅ.-fmax-array-constructor=nโ this option can be used to increase the upper limit permitted in array constructors ๐. The code below requires this option to expand the array at compile time ๐งฎ.
Here's what that example looks like in action ๐ง
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, bestie: This option can lead to long compile times and excessively large object files ๐ญ
The default value for n is 65535 ๐
-fmax-stack-var-size=n โจ
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 need recursive procedures that don't have the RECURSIVE attribute, or you're writing parallel programs, use -frecursive to allow it. And if you want the stack to never be used at all, -fno-automatic is your girl ๐
This option currently only touches local arrays with constant bounds, and it might not apply to every character variable. Future versions of GNU Fortran may improve this, so keep an eye out ๐
The default value for n is 32768 ๐ธ
-fstack-arrays ๐ฆ
This option tells the Fortran compiler to put all arrays of unknown size and array temporaries onto stack memory. Lowkey a big deal: if your program uses very large local arrays, you might have to raise your runtime stack memory limits on some operating systems ๐ญ
This flag is turned on by default at the -Ofast optimization level, unless -fmax-stack-var-size is specified ๐
-fpack-derived ๐
This tells GNU Fortran to pack derived type members as closely together as possible. Code compiled with this option is likely to be incompatible with code compiled without it, and it may run slower ๐
-frepack-arrays ๐ซถ
Sometimes GNU Fortran passes assumed shape array sections through a descriptor that describes a noncontiguous area of memory. This option adds code to the function prologue that repacks the data into a contiguous block at runtime โจ
This should make accesses to the array faster. However, it can add significant overhead to the function call, especially when the passed data is noncontiguous ๐ซ
-fshort-enums ๐
This one's for interoperability with C code that was compiled with the -fshort-enums option. It makes GNU Fortran choose the smallest INTEGER kind that a given enumerator set fits in, and then gives all of its enumerators that kind ๐ง
-fexternal-blas ๐ฅ
This makes gfortran generate calls to BLAS functions for some matrix operations, like MATMUL, instead of using its own algorithms. That only happens if the matrices involved are larger than a given limit (see -fblas-matmul-limit) ๐
This can be super profitable if an optimized vendor BLAS library is available. The BLAS library has to be specified at link time, so don't forget it ๐ซถ
-fblas-matmul-limit=n ๐
Only significant 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, while smaller ones are 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 function get inlined. This can increase code size if the size of the matrix can't be determined at compile time, because 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 ๐ธ
The default value for n is 30. The -fblas-matmul-limit option can be used to change this value ๐ฆ
-frecursive ๐ง
This allows indirect recursion by forcing all local arrays to be allocated on the stack. Heads up: this flag cannot 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 ๐
-finit-local-zero tells the compiler to initialize local INTEGER, REAL, and COMPLEX variables to zero, LOGICAL variables to false, and CHARACTER variables to a string of null bytes โจ
The finer-grained options are -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) ๐
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 -finit-local-zero ๐ซถ
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. For a signalling NaN, use -finit-real=snan. Be careful though: compile-time optimizations may convert them into a quiet NaN, and trapping needs to be enabled (e.g. via -ffpe-trap) ๐ฅ
The -finit-integer option parses the value into an integer of type INTEGER(kind=C_LONG) on the host. That value is then 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've 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 certain platforms this is mandatory, and on others it boosts performance ๐
If a COMMON block isn't declared with consistent data types everywhere, this padding can cause trouble. In that case, -fno-align-commons disables the automatic alignment ๐
. The same form of this option should be used for all files that share a COMMON block ๐ซถ
To avoid potential 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 all optimization levels, so the compiler doesn't do any re-association ๐
Using -fno-protect-parens lets the compiler reorder REAL and COMPLEX expressions to produce 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. It's 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, regardless of whether they're marked PURE or not ๐ค
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 performs front-end optimization, based on manipulating parts of the Fortran parse tree. It's enabled by default by any -O option except -O0 and -Og โจ
The optimizations enabled by this option 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, this option only affects FORALL and DO CONCURRENT statements with several forall triplets ๐ค
โจ ENVIRONMENT โจ
The gfortran compiler currently doesn't use any environment variables to control its operation, beyond the ones that affect the operation of gcc. So no secret switches here, 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 ๐
โ๏ธ 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.
Okay bestie, that's the whole page ๐ซถ It came from gcc-9 and was last dated 2022-05-27, so you're officially a GFORTRAN(1) expert now ๐๐โจ
๐ฆ where this page comes from
- ubuntu noble: gfortran-9-powerpc-linux-gnu 9.5.0-6ubuntu2.1cross1
- ubuntu noble: gfortran-9-powerpc-linux-gnu 9.5.0-6ubuntu2cross1
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms