Problem
In cmake/BuildICON.cmake, the DEBUG branch only prepends -g:
if (CMAKE_BUILD_TYPE STREQUAL "DEBUG")
string(PREPEND ICON_CFLAGS "-g ")
string(PREPEND ICON_FCFLAGS "-g ")
Under the Intel compilers (ifort/ifx), the default optimization level is -O2, and since no -O flag is ever specified in this branch, -g is added on top of the implicit -O2 rather than replacing it. So a "DEBUG" build gives debug symbols but keeps full optimization, and enables none of Intel's runtime diagnostics (bounds checking, uninitialized-variable checks, floating-point exception trapping).
Proposed change
Add to the DEBUG branch for the Intel/IntelLLVM case:
-O0 -check bounds -check uninit -fpe0 -init=snan
so that CMAKE_BUILD_TYPE=DEBUG actually disables optimization and turns on array-bounds checking, uninitialized-variable checking, floating-point exception trapping, and NaN-initialization of otherwise-uninitialized memory.
Notes / caveats
- These flags materially slow down execution, so this should stay scoped to the
DEBUG build type only (RELEASE is unaffected).
- Checked whether the GNU env has a comparable gap:
- The optimization half does not apply to GNU because of gfortran's default (no
-O flag) is identical to explicit -O0 (confirmed via gfortran -Q --help=optimizers), so DEBUG's bare -g prepend doesn't silently leave optimization on the way it does under Intel.
- The runtime-checks half does apply equally: there is no
-fcheck=bounds, -ffpe-trap, -finit-real=snan, or -finit-integer=... anywhere in cmake/. The GNU FCFLAGS has warnings (-Wall, -Wconversion, …) and -fbacktrace but no runtime bounds/uninitialized/FPE checking. Worth adding the GNU equivalents (e.g. -fcheck=bounds -ffpe-trap=invalid,zero,overflow -finit-real=snan) to the DEBUG branch alongside the Intel fix.
- This was found as a side effect of investigating output differences; that investigation showed ICON is not bit-reproducible run-to-run in this MPI/OpenMP configuration even with an unmodified binary.
Problem
In
cmake/BuildICON.cmake, theDEBUGbranch only prepends-g:Under the Intel compilers (
ifort/ifx), the default optimization level is-O2, and since no-Oflag is ever specified in this branch,-gis added on top of the implicit-O2rather than replacing it. So a "DEBUG" build gives debug symbols but keeps full optimization, and enables none of Intel's runtime diagnostics (bounds checking, uninitialized-variable checks, floating-point exception trapping).Proposed change
Add to the
DEBUGbranch for the Intel/IntelLLVM case:so that
CMAKE_BUILD_TYPE=DEBUGactually disables optimization and turns on array-bounds checking, uninitialized-variable checking, floating-point exception trapping, and NaN-initialization of otherwise-uninitialized memory.Notes / caveats
DEBUGbuild type only (RELEASEis unaffected).-Oflag) is identical to explicit-O0(confirmed viagfortran -Q --help=optimizers), soDEBUG's bare-gprepend doesn't silently leave optimization on the way it does under Intel.-fcheck=bounds,-ffpe-trap,-finit-real=snan, or-finit-integer=...anywhere incmake/. The GNUFCFLAGShas warnings (-Wall,-Wconversion, …) and-fbacktracebut no runtime bounds/uninitialized/FPE checking. Worth adding the GNU equivalents (e.g.-fcheck=bounds -ffpe-trap=invalid,zero,overflow -finit-real=snan) to theDEBUGbranch alongside the Intel fix.