🤖 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.
🤖 AI text below 🤖
What
cmake/compiler_flags/Clang.CXX.cmake:24-28overwritesCMAKE_CXX_FLAGS_RELWITHDEBINFOwith a flagset that defines
DEBUGand, crucially, does not defineNDEBUG:cmake/compiler_flags/GNU.CXX.cmakegets this right: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,
RelWithDebInfois an-O3build with everyassertlive. Several sit on hotpaths:
cpp/monoprop/detail/operator/InvertedIndex.h, infill_rows:assert(col.is_dense || std::ranges::is_sorted(col.set_rows));2 * NumModescolumns on everyfill_rowscall, turning an O(new rows) appendinto 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(thefused_scale_coeffsaliasing assert) andcpp/monoprop/detail/evolution/layer_build/Engine.h.The flag set also carries
-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer, i.e. this isprecisely the configuration someone reaches for when profiling. Any profile taken from a Clang
RelWithDebInfobuild is currently measuring the assertions.Suggested fix
Use
-DNDEBUGin Clang'sRelWithDebInfo, matching the GNU file:Two adjacent inconsistencies in the same file, worth folding in or splitting out as preferred:
Clang.CXX.cmakedefines noCMAKE_CXX_FLAGS_COVERAGE, whileGNU.CXX.cmakedoes(
-O1 --coverage -g)..github/workflows/qa-analysis.ymlsetsSKBUILD_CMAKE_BUILD_TYPE: "Coverage", so a Clang leg of that job would build with no flags at all.-Wextra,-Wconversion,-Wcast-align,-Wnon-virtual-dtorand-Wunused-parameterare GCC-only today.Verification
Configure a Clang
RelWithDebInfotree and confirmNDEBUGappears inbuild/*/compile_commands.json.Found by a code-reading review of the repository at
29a8050. No build tree was available, so theanalysis is from source inspection and should be confirmed against a build.