Conversation
There was a problem hiding this comment.
Pull request overview
Adds an opt-in AddressSanitizer (ASan) configuration at the root CMake level so the entire build (including third-party) can be instrumented when using supported compilers.
Changes:
- Introduces
SOLTRACE_ENABLE_ASANCMake option (defaultOFF). - When enabled, applies
-fsanitize=address(and-fno-omit-frame-pointer) for supported compilers, with warnings for unsupported toolchains (e.g., MSVC).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CMakeLists.txt
Outdated
| elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") | ||
| message(STATUS "Enabling address sanitizer") |
There was a problem hiding this comment.
CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU" excludes AppleClang, so ASan won't be enabled on macOS even though AppleClang supports -fsanitize=address. Consider including AppleClang in the check (or using a more robust compiler-ID test) to match the PR description (“Clang or GCC”).
jmaack24
left a comment
There was a problem hiding this comment.
Would there be any objections to adding AppleClang to the compiler check? I tried this on my Mac and had issues using this with the GCC compiler, but AppleClang worked just fine.
|
Sure. It's probably a solid idea to just restrict this to Clang + AppleClang at the moment as Clang does a much better job at keeping the runtimes OK with ASAN active. Let me update the branch... |
AddressSanitizer is a great feature that helps catch memory safety issues early (heap/stack buffer overflows, use-after-free, etc.), and makes debugging crashes far easier during development.
This PR adds an opt-in AddressSanitizer build configuration controlled by a new CMake option:
SOLTRACE_ENABLE_ASAN(by default, this isOFF)When enabled and the project is built with Clang or GCC, the build will compile and link with
-fsanitize=address. Note that this is not supported on MSVC; in this case, CMake will skip the flags. This is added to the root CMake so that all code (including third-party) can be covered. ASan is not added to the CI matrix in this PR, but can be, later on.To enable ASan at configure time:
cmake -S . -B build-asan -DSOLTRACE_ENABLE_ASAN=ON -DCMAKE_BUILD_TYPE=Debug cmake --build build-asan ctest --test-dir build-asanNote that this will inflate execution time as it adds additional instrumentation to the code.