Skip to content

DEBUG build doesn't disable optimization or enable runtime checks for ICON (Intel, [GNU]) #137

Description

@s-poll

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    New features

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions