Compiler Flags

From Docswiki
Jump to navigation Jump to search

This page serves as documentation for the mysterious compiler flags: please keep it up to date. It includes a description of what each flag does and a list of flags in use for each compiler and each type of build. It's also a place to make comments on the suitability of flags.

CMake Build Types

CMake allows the specification of flags for three different build types:

  • Release For general usage. Can include optimisation options and disable some checks, so should run fastest.
  • Debug For debugging. Includes the debugging flag and turns off aggressive optimisation (which tends not to mix well with the debugging flag) for use with something like gdb.
  • Debug_slow It really means slow. This turns on every possible compiler and run time check, for situations where normal Debug isn't enough.

It is also possible to specify flags that are used for all three types.

GCC

Flags in Use

  • All: -ffixed-line-length-132 -ffree-line-length-0 -mcmodel=medium (only for NEWREAXFFOPTIM)
  • Release: -O3
  • Debug: -g -fbounds-check -Wunitialized -O -ftrapv -fno-automatic -fimplicit-none
  • Debug_slow: -g -fbounds-check -Wunitialized -O -ftrapv -fno-automatic -fimplicit-none

Description of Flags

  • -ffixed-line-length-132 Allow lines of up to 132 characters in fixed form source.
  • -ffree-line-length-0 Allow lines of unlimited length in free form source.
  • -mcmodel=medium This is only when building with NEWREAXFFOPTIM. The flag must be used to compile/link a program whose data and .bss sections exceed 2GB.
  • -O3 Use optimisation level 3, the highest available.
  • -g Debugging flag. Leave debugging symbols in machine code so a debugger can identify functions, variables and line numbers.
  • -fbounds-check Turns on runtime checking of the bounds of an array when accessing elements. NOTE The GCC documentation describes this as a deprecated alias for '-fcheck=bounds', so it may cease to work sometime.
  • -Wunitialized The compiler will issue warnings if it detects that a variable is uninitialised before its value is used. There are limitations, so check the GCC docs.
  • -O Turn on minimal optimisation. This is necessary for -Wunitialized. NOTE The GCC docs recommend -Og for debugging use.
  • -ftrapv The compiler creates a runtime trap when a variable overflow occurs.
  • -fimplicit-none No implicit typing is allowed, unless there is an explicit IMPLICIT statement. This is equivalent to putting IMPLICIT NONE everywhere there isn't already an IMPLICIT statement.

PGI

Flags in Use

  • All: -Mextend -mcmodel=medium (only for NEWREAXFFOPTIM)
  • Release: -O3 -Munroll -Mnoframe
  • Debug: -g -gopt -Mbounds -Mchkfpstk -Mchkptr -Mchkstk -traceback
  • Debug_slow: -g -gopt -Mbounds -Mchkfpstk -Mchkptr -Mchkstk -traceback

Description of Flags

  • -Mextend Allow 132 character lines.
  • -mcmodel=medium This is only when building with NEWREAXFFOPTIM. The flag must be used to compile/link a program whose data and .bss sections exceed 2GB.
  • -O3 Turn on aggressive optimisation. Note There is a level 4 too, but the performance difference is marginal.
  • -Munroll The compiler will unroll loops.
  • -Mnoframe The compiler is allowed to not set up a stack frame for functions, allowing for more efficient optimisation in some cases.
  • -g Debugging flag. Leave debugging symbols in machine code so a debugger can identify functions, variables and line numbers. Sets -O0 unless another -O is explicitly specified.
  • -gopt Same as -g, but doesn't affect optimisation level. 'NOTE This seems superfluous.
  • -Mbounds Same as -C.
  • -Mchkfpstk Enables runtime checks of the floating point unit (FPU) stack.
  • -Mchkptr Enables runtime checks for dereferencing the NULL pointer.
  • -Mchkstk Enables runtime checks for the available space in the stack when declaring local variables. Should prevent stack overflows.
  • -traceback Generate debugging information necessary for a runtime traceback.

Intel

Flags in Use

  • All: -132 -assume byterecl -heap-arrays 10 -mcmodel=medium (only for NEWREAXFFOPTIM)
  • Release: -O3
  • Debug: -traceback -debug all -check all,noarg_temp_created -diag-disable 8290,8291 -implicitnone
  • Debug_slow: -debug all -check all,noarg_temp_created -warn unused -fp-stack-check -ftrapuv -implicitnone

Description of Flags

  • -132 Allow lines of up to 132 characters in fixed form source.
  • -assume byterecl Assume that the record length unformatted output is 1 byte.
  • -heap-arrays 10 Arrays known at compile time to be smaller than 10KB will be put on the stack rather than the heap. Without this option, local arrays will all go on the stack, which has been known to cause a stack overflow for large databases in PATHSAMPLE.
  • -mcmodel=medium This is only when building with NEWREAXFFOPTIM. The flag must be used to compile/link a program whose data and .bss sections exceed 2GB.
  • -O3 Use optimisation level 3, the highest available.
  • -traceback Generate debugging information necessary for a runtime traceback.
  • -debug all Generate full debugging information.
  • -check all,noarg_temp_created Enables all runtime checks except arg_temp_created, that checks validity of function arguments when they are copied into temporary storage.
  • -diag-disable 8290,8291 Disable compiler diagnostic messages 8290 and 8291 (telling you that a floating point format specifier should have a total width somewhat greater than the width for fractional digits). NOTE If we actually want this, why is it only for Debug?
  • -implicitnone No implicit typing is allowed, unless there is an explicit IMPLICIT statement. This is equivalent to putting IMPLICIT NONE everywhere there isn't already an IMPLICIT statement.
  • -warn unused Enable compiler warnings when a variable is declared but never used.
  • -fp-stack-check Enables runtime checks of the floating point unit (FPU) stack.
  • -ftrapuv Initialises otherwise uninitialised local stack variables to an unusual value, to try to cause nearby runtime errors.

NAG

Flags in Use

  • All: -132 -kind=byte -maxcontin=6000 -mcmodel=medium (only for NEWREAXFFOPTIM)
  • Release: -O4 -mismatch_all
  • Debug: -g -ieee=stop -u
  • Debug_slow: -C=all -mtrace=all -gline -g -ieee=stop -u

Description of Flags

  • -132 Allow lines of up to 132 characters in fixed form source.
  • -kind=byte The KIND values for types give the amount of storage used (in bytes) rather than using sequential numbering.
  • -maxcontin=6000 The maximum number of sequential continuation lines is increased to 6000.
  • -mcmodel=medium This is only when building with NEWREAXFFOPTIM. The flag must be used to compile/link a program whose data and .bss sections exceed 2GB.
  • -mismatch_all Turns off checking of whether the argument types in a function call match the function declaration.
  • -O4 Use optimisation level 4, the highest available.
  • -g Debugging flag. Leave debugging symbols in machine code so a debugger can identify functions, variables and line numbers.
  • -u No implicit typing is allowed, unless there is an explicit IMPLICIT statement. This is equivalent to putting IMPLICIT NONE everywhere there isn't already an IMPLICIT statement.
  • -ieee=stop Enables all IEEE arithmetic facilities except non-stop arithmetic. Execution will stop on overflow, division by zero and invalid operands.
  • -C=all Enables all runtime checks, except for checking for undefined variables.
  • -mtrace=all Traces memory allocations and deallocations.
  • -gline Generate debugging information necessary for a runtime traceback.