Compiler flags comparison

Most compilers have a load of flags that perform similar operations to each other, like the optimization flags -O1, -O2 etc.

Does anyone know of a resource (like a huge table) where you can look for a compiler flag for one compiler and it shows you similar flags from the other languages? I spotted the nice optimization flags table in this fpm compiler flags issue, but not a lot else. Is having a standard interface to compiler flags something that fpm is exploring?

1 Like

Hey Sam,

There was an idea for a Universal Fortran compiler · Issue #475 · fortran-lang/fpm · GitHub.

Apart from the optimization flags I did a table of flags needed for preprocessing, and how to specify the source form (apologies for the inconsistent formatting and any potential mistakes):

Compiler Fixed-form Free-form Invoke (C) preprocessor
gfortran -ffixed-form -ffree-form -cpp
ifort -fixed -free -fpp
ifort (Windows) /fixed /free /fpp
nvfortran -Mfixed -Mfree -Mpreprocess
nagfor -fixed -free -fpp
Cray -f fixed -f free -eP, -eZ
IBM -qfixed -qfree, -k -qpreprocess
g95 -ffixed-form -ffree-form -cpp
flang -Mfixed -Mfreeform -Mpreprocess
oracle f95 -fixed -free -fpp or -xpp=fpp (cpp)

I also collected the file format extensions recognized that compilers recognize by default:

Compiler Fixed-form Fixed-form with preprocessor Free-form Free form with preprocessor
gfortran .f, .for, .ftn .fpp, .F, .FOR, .FPP, .FTN .f90, .f95, .f03, .f08 .F90, .F95, .F03, .F08
ifort .f, .for, .ftn, .i .fpp, .FPP, .F, .FOR, .FTN .f90, .i90 .F90
nvfortran .f .for .ftn .F .FOR .FTN .fpp .FPP .f90 .f95 .f03 .F90 .F95 .F03
nagfor .f, .for, .ftn .ff, .F .f90, .f95 .ff90, .ff95, .F90, .F95
Cray .f, .for .F, .FOR .f90, .f95, .f03, .f08, .f18, .ftn .F90, .F95, .F03, .F08, .F18, .FTN
IBM .f, .f77 .F, .F77 .f90, .f95, .f03, .f08 .F90, .F95, .F03, .F08
g95 .f, .for .F, .FOR .f90, .f95, .f03 .F90, .F95, .F03

I also collected a list of flags for “debug” builds:

  • Generate debugging information (should be used with a lower optimization level)
  • Enable backtrace of runtime errors
  • Run-time checks
    • gfortran -fcheck=[all,array-temps,bits,bounds,do,mem,pointer,recursion]
    • ifort -check=[arg_temp_created,assume,bounds,contiguous,format,output_conversion,pointers,shape,stack,udio_iostat,uninit,all]
    • NAG -C, -C=[alias,all,array,bits,calls,dangling,do,intovf,none,present,pointer,recursion,undefined]
5 Likes

I think it would be very useful to have those tables in the fpm documentation, right now they are partly embedded in source comments and some issues/discussion threads, which makes them hard to discover. The fpm docs might be just the right pace to provide a central reference, which we can improve as community.

3 Likes

Here is a source Jane and I use for speed and debug builds. https://polyhedron.com/?page_id=175
Their compiler tables go back many years.

3 Likes

I used g95 for many years with the following options:

-Wall -Wextra -Wimplicit-none -Werror=100,113,115,137,146,147,159,163 -ftrace=full -fbounds-check -freal=nan -fmodule-private -Wno=112,167

The numbers after -Werror turn certain warnings into errors. I forget what they correspond to, but if they are triggered, the g95 error messages make that clear.

1 Like

Thanks all, some really useful resources here. @awvwgk I agree, I think the fpm docs would be a great place for these to live.

The LLVM flang compiler has a comparison of many of the compiler options supported by various compilers. It may have some info of use to you.

Here’s a link to it in he f18-llvm-compiler fork:

4 Likes

That’s fantastic, thanks! I was initially looking for equivalents to GFortran’s fbackslash, which that table helpfully lists.