Skip to content

build: CMake presets, multi-compiler CI matrix, and foundation OOB fix#10

Merged
benmandrew merged 4 commits into
mainfrom
benmandrew/build/cmake-presets-ci
Jun 13, 2026
Merged

build: CMake presets, multi-compiler CI matrix, and foundation OOB fix#10
benmandrew merged 4 commits into
mainfrom
benmandrew/build/cmake-presets-ci

Conversation

@benmandrew

Copy link
Copy Markdown
Owner

Summary

  • Add CMakePresets.json with debug, relwithdebinfo, and release presets. The debug preset builds with AddressSanitizer + UndefinedBehaviorSanitizer (-fno-sanitize-recover so findings fail the run) and hardened standard-library assertions (_GLIBCXX_ASSERTIONS / _LIBCPP_HARDENING_MODE), which catch out-of-bounds container access that ASan alone misses.
  • Rework the CI graph job into a build matrix over {gcc, clang} × {debug, release}, so both compilers and both build types are exercised. Compiler is selected via CC/CXX (presets stay compiler-agnostic), the FetchContent cache is keyed per compiler/preset, and ASLR entropy is lowered so ASan can map its shadow memory on newer Ubuntu runners.
  • Fix an out-of-bounds bug that the hardened-stdlib assertions immediately exposed.

The bug

waste_to_foundation and tableau_to_foundation both indexed the size-4 m_foundation_indices array with foundation_top, a card index (0..52), when linking a card pushed onto a foundation pile. It should store foundation_top directly as the moved card's "beneath" pointer:

// before
table.m_deck[moved] = table.m_foundation_indices[foundation_top];
// after
table.m_deck[moved] = foundation_top;

ASan missed it because the overrun index lands in adjacent in-object array members; the hardened libc++ assertion flagged it on the first test run. This corrupted the foundation-pile linkage, so it's a real logic fix, not just an analyzer complaint.

Testing

All 15 tests pass locally under the debug preset (ASan + UBSan + hardened libc++). Both compilers will be exercised by the new CI matrix.

Add CMakePresets.json with debug, relwithdebinfo and release presets.
The debug preset enables AddressSanitizer + UndefinedBehaviorSanitizer
(with -fno-sanitize-recover so findings fail the run) and hardened
standard-library assertions (_GLIBCXX_ASSERTIONS / _LIBCPP_HARDENING_MODE)
to catch out-of-bounds container access that ASan alone misses.

Rework the CI graph job into a build matrix over {gcc, clang} x
{debug, release} so both compilers and both build types are exercised.
The compiler is selected via CC/CXX so the presets stay compiler-agnostic,
the FetchContent cache is keyed per compiler/preset, and ASLR entropy is
lowered so ASan can map its shadow memory on newer Ubuntu runners.
When pushing a card onto a foundation pile, both waste_to_foundation
and tableau_to_foundation linked the moved card's "beneath" pointer to
m_foundation_indices[foundation_top]. foundation_top is a card index
(0..52) but m_foundation_indices is sized by suit (4), so this read far
out of bounds; it should store foundation_top (the previous foundation
top) directly.

AddressSanitizer did not catch this because the overrun index lands in
adjacent in-object array members. The hardened standard-library
assertions added with the debug preset flag it immediately.
-Wall/-Werror/-pedantic were appended to the global CMAKE_CXX_FLAGS, so
they leaked into third-party FetchContent builds (fmt, nlohmann_json,
Catch2). That broke the GCC debug build in CI: GCC 13's <regex> header
trips -Werror=maybe-uninitialized while compiling Catch2, code we don't
control.

Move the flags onto an INTERFACE library (rose_warnings) linked PUBLIC
from rose_lib, so only our own targets (rose_lib, rose, unittests) are
compiled with them. This also removes the need for the per-Catch2
-Wno-deprecated-literal-operator workaround, which existed for the same
reason under AppleClang.
With `on: [push, pull_request]` every PR ran the whole matrix twice
(once per event). Restrict the push trigger to the main branch so
branch pushes are covered only by the pull_request event, while pushes
to main (and the docker job gated on it) still run.
@benmandrew benmandrew merged commit fcd4340 into main Jun 13, 2026
5 checks passed
@benmandrew benmandrew deleted the benmandrew/build/cmake-presets-ci branch June 13, 2026 22:23
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