Skip to content

Enable -O0 and runtime diagnostics in DEBUG build for ICON - #138

Draft
s-poll wants to merge 1 commit into
masterfrom
dev-debug-runtime-checks
Draft

Enable -O0 and runtime diagnostics in DEBUG build for ICON#138
s-poll wants to merge 1 commit into
masterfrom
dev-debug-runtime-checks

Conversation

@s-poll

@s-poll s-poll commented Aug 7, 2026

Copy link
Copy Markdown
Member

Summary

CMAKE_BUILD_TYPE=DEBUG currently only adds -g to the ICON build. Under Intel, no -O level is set explicitly, so the compiler defaults to -O2 — the "debug" build is actually optimized and gets no runtime checking at all. This made a recent segfault in ecRad take roughly a day to isolate; -check bounds alone would have pointed at it in minutes.

This PR makes DEBUG a real debug build: unoptimized and instrumented with runtime diagnostics, for both compilers.

Solves #137

Changes

In cmake/BuildICON.cmake, the DEBUG branch now sets:

  • -O0 (explicit, both compilers) — closes the implicit -O2 gap under Intel
  • Bounds checking: -check bounds (Intel) / -fcheck=bounds (GNU)
  • Uninitialized-variable detection: -check uninit (Intel); on GNU there's no direct runtime-uninit-check equivalent, so this is approximated via NaN-poisoning + FP trapping below
  • FP exception trapping: -fpe0 (Intel) / -ffpe-trap=invalid,zero,overflow (GNU)
  • NaN-initialization of reals: -init=snan (Intel) / -finit-real=snan (GNU)

Flags are gated on CMAKE_Fortran_COMPILER_ID since the Intel spellings (-check, -init=) aren't recognized by gfortran.

RELEASE (and the unknown-build-type fallback) are unchanged.

Trade-off

These diagnostics cost wall-clock time - bounds checking in particular adds real per-access overhead in hot loops, on top of the much larger cost of dropping to -O0. That's expected and acceptable for a debug build; -fpe0/-ffpe-trap and the NaN-init are effectively free (one-time trap-mask/init cost, not per-operation).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant