Skip to content

Clang RelWithDebInfo builds with assertions enabled (missing -DNDEBUG) #191

Description

@robertodr

🤖 AI text below 🤖

What

cmake/compiler_flags/Clang.CXX.cmake:24-28 overwrites CMAKE_CXX_FLAGS_RELWITHDEBINFO with a flag
set that defines DEBUG and, crucially, does not define NDEBUG:

set(
  CMAKE_CXX_FLAGS_RELWITHDEBINFO
  "-O3 -g3 -DDEBUG -glldb -fno-limit-debug-info"
)

cmake/compiler_flags/GNU.CXX.cmake gets this right:

set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g3 -DNDEBUG")

Because the variable is overwritten rather than appended to, CMake's own default (which supplies
-DNDEBUG) is discarded.

Why this is a problem

Under Clang, RelWithDebInfo is an -O3 build with every assert live. Several sit on hot
paths:

  • cpp/monoprop/detail/operator/InvertedIndex.h, in fill_rows:
    assert(col.is_dense || std::ranges::is_sorted(col.set_rows));
    This runs for all 2 * NumModes columns on every fill_rows call, turning an O(new rows) append
    into O(columns × total rows) — so the cost per gate grows with the whole operator instead of with
    the newly inserted terms.
  • cpp/monoprop/detail/evolution/layer_build/Scan.h (the fused_scale_coeffs aliasing assert) and
    cpp/monoprop/detail/evolution/layer_build/Engine.h.

The flag set also carries -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer, i.e. this is
precisely the configuration someone reaches for when profiling. Any profile taken from a Clang
RelWithDebInfo build is currently measuring the assertions.

Suggested fix

Use -DNDEBUG in Clang's RelWithDebInfo, matching the GNU file:

set(
  CMAKE_CXX_FLAGS_RELWITHDEBINFO
  "-O3 -g3 -DNDEBUG -glldb -fno-limit-debug-info"
)

Two adjacent inconsistencies in the same file, worth folding in or splitting out as preferred:

  • Clang.CXX.cmake defines no CMAKE_CXX_FLAGS_COVERAGE, while GNU.CXX.cmake does
    (-O1 --coverage -g). .github/workflows/qa-analysis.yml sets
    SKBUILD_CMAKE_BUILD_TYPE: "Coverage", so a Clang leg of that job would build with no flags at all.
  • The Clang warning set is materially weaker than the GNU one: -Wextra, -Wconversion,
    -Wcast-align, -Wnon-virtual-dtor and -Wunused-parameter are GCC-only today.

Verification

Configure a Clang RelWithDebInfo tree and confirm NDEBUG appears in
build/*/compile_commands.json.


Found by a code-reading review of the repository at 29a8050. No build tree was available, so the
analysis is from source inspection and should be confirmed against a build.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions