-
Notifications
You must be signed in to change notification settings - Fork 439
Add ASAN CI build workflow #2914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JohanMabille
merged 22 commits into
xtensor-stack:master
from
Alex-PLACET:add_asan_ci_build
Jun 27, 2026
Merged
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
68a21c5
Fix substring calculation in CSV cell parsing and add lexical_cast fo…
Alex-PLACET b240aef
Merge remote-tracking branch 'upstream/master'
Alex-PLACET 1d158a9
Merge remote-tracking branch 'upstream/master'
Alex-PLACET 34ed69a
Merge remote-tracking branch 'upstream/master'
Alex-PLACET fd7ba8d
Merge remote-tracking branch 'upstream/master'
Alex-PLACET 151e1e5
Merge remote-tracking branch 'upstream/master'
Alex-PLACET 63f7b25
Add ASAN CI build
Alex-PLACET e4323ed
try fix
Alex-PLACET e36f2ea
fix
Alex-PLACET 72140fc
Enhance index_mapper with access control and add ASAN support in tests
Alex-PLACET fc4145a
Add support for multiple sanitizers in CI workflow
Alex-PLACET 7a0b0dd
try fix
Alex-PLACET 04b92c3
try fix
Alex-PLACET 146a3bc
Fix iterator dereference for null pointer and improve strided_data_en…
Alex-PLACET 236570c
Fix null pointer dereference in xstepper operator*
Alex-PLACET e38da90
try fix
Alex-PLACET 97dbc4a
Add memory sanitizer support for Clang in CMake configuration
Alex-PLACET f112a43
try fix
Alex-PLACET 721d43c
try fix
Alex-PLACET 1857804
Remove memory sanitizer support and related configurations
Alex-PLACET 7d113ee
Merge remote-tracking branch 'upstream/master' into add_asan_ci_build
Alex-PLACET 34032e5
revert iterator deref
Alex-PLACET File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| name: Sanitizers | ||
| on: | ||
| workflow_dispatch: | ||
| pull_request: | ||
| push: | ||
| branches: [master] | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
| defaults: | ||
| run: | ||
| shell: bash -e -l {0} | ||
| jobs: | ||
| build: | ||
| runs-on: ${{ matrix.os }} | ||
| name: sanitizer / ${{ matrix.sys.compiler }} ${{ matrix.sys.version }} / ${{ matrix.config.name }} / ${{ matrix.sys.name }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: [ubuntu-24.04] | ||
| sys: | ||
| - {compiler: clang, version: '21', name: asan, sanitizer: address} | ||
| - {compiler: clang, version: '21', name: lsan, sanitizer: leak} | ||
| - {compiler: clang, version: '21', name: ubsan, sanitizer: undefined} | ||
| config: | ||
| - {name: Debug} | ||
|
|
||
| steps: | ||
|
|
||
| - name: Install LLVM and Clang | ||
| if: matrix.sys.compiler == 'clang' | ||
| run: | | ||
| wget https://apt.llvm.org/llvm.sh | ||
| chmod +x llvm.sh | ||
| sudo ./llvm.sh ${{matrix.sys.version}} | ||
| sudo apt-get install -y clang-tools-${{matrix.sys.version}} | ||
| sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${{matrix.sys.version}} 200 | ||
| sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${{matrix.sys.version}} 200 | ||
| sudo update-alternatives --install /usr/bin/clang-scan-deps clang-scan-deps /usr/bin/clang-scan-deps-${{matrix.sys.version}} 200 | ||
| sudo update-alternatives --set clang /usr/bin/clang-${{matrix.sys.version}} | ||
| sudo update-alternatives --set clang++ /usr/bin/clang++-${{matrix.sys.version}} | ||
| sudo update-alternatives --set clang-scan-deps /usr/bin/clang-scan-deps-${{matrix.sys.version}} | ||
|
|
||
| - name: Checkout code | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Set conda environment | ||
| uses: mamba-org/setup-micromamba@main | ||
| with: | ||
| environment-name: myenv | ||
| environment-file: environment-dev.yml | ||
| init-shell: bash | ||
| cache-downloads: true | ||
|
|
||
| - name: Configure using CMake | ||
| run: | | ||
| export CC=clang | ||
| export CXX=clang++ | ||
| cmake -G Ninja \ | ||
| -Bbuild \ | ||
| -DCMAKE_BUILD_TYPE=${{matrix.config.name}} \ | ||
| -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX \ | ||
| -DBUILD_TESTS=ON \ | ||
| -DUSE_SANITIZER=${{ matrix.sys.sanitizer }} | ||
|
|
||
| - name: Build tests | ||
| working-directory: build | ||
| run: cmake --build . --config ${{matrix.config.name}} --target test_xtensor_lib --parallel 8 | ||
|
|
||
| - name: Run tests | ||
| working-directory: build | ||
| run: | | ||
| SAN=${{ matrix.sys.sanitizer }} | ||
| case "$SAN" in | ||
| address) | ||
| export ASAN_OPTIONS=log_path=asan_log_:alloc_dealloc_mismatch=0:halt_on_error=0:handle_abort=0 | ||
| export ASAN_SAVE_DUMPS=AsanDump.dmp | ||
| ;; | ||
| leak) | ||
| export LSAN_OPTIONS=log_path=lsan_log_:halt_on_error=0 | ||
| ;; | ||
| undefined) | ||
| export UBSAN_OPTIONS=log_path=ubsan_log_:halt_on_error=0:print_stacktrace=1 | ||
| ;; | ||
| esac | ||
| ctest -R ^xtest$ --output-on-failure | ||
|
|
||
| - name: Upload sanitizer log | ||
| if: always() | ||
| uses: actions/upload-artifact@v6 | ||
| with: | ||
| name: sanitizer-log-${{ matrix.sys.sanitizer }}-${{ matrix.sys.compiler }}-${{ matrix.sys.version }}-${{ matrix.config.name }}-${{ runner.os }} | ||
| path: '**/*san_log_*' | ||
| if-no-files-found: ignore | ||
|
|
||
| - name: Upload sanitizer dump | ||
| if: always() | ||
| uses: actions/upload-artifact@v6 | ||
| with: | ||
| name: sanitizer-dump-${{ matrix.sys.sanitizer }}-${{ matrix.sys.compiler }}-${{ matrix.sys.version }}-${{ matrix.config.name }}-${{ runner.os }} | ||
| path: '**/AsanDump.dmp' | ||
| if-no-files-found: ignore | ||
|
|
||
| - name: Return errors if sanitizer log content is not empty | ||
| if: always() | ||
| run: | | ||
| if [ -n "$(find build/test -name '*san_log_*' -type f -size +0 2>/dev/null)" ]; then | ||
| echo "Sanitizer detected errors. See the log for details." | ||
| exit 1 | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| set(AVALAIBLE_SANITIZERS "address;leak;memory;thread;undefined") | ||
| OPTION(USE_SANITIZER "Enable sanitizer(s). Options are: ${AVALAIBLE_SANITIZERS}. Case insensitive; multiple options delimited by comma or space possible." "") | ||
| string(TOLOWER "${USE_SANITIZER}" USE_SANITIZER) | ||
|
|
||
| if((CMAKE_BUILD_TYPE IN_LIST "Debug;RelWithDebInfo") AND USE_SANITIZER) | ||
| message(FATAL_ERROR "❌ Sanitizer only supported in Debug and RelWithDebInfo build types.") | ||
| endif() | ||
|
|
||
| if(USE_SANITIZER) | ||
| if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") | ||
| set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>") | ||
|
|
||
| if(USE_SANITIZER MATCHES "address") | ||
| list(APPEND SANITIZER_COMPILE_OPTIONS /fsanitize=address /D_DISABLE_VECTOR_ANNOTATION /D_DISABLE_STRING_ANNOTATION) | ||
| else() | ||
| message(FATAL_ERROR "❌ Sanitizer not supported by MSVC: ${USE_SANITIZER}. It only supports 'address'.") | ||
| endif() | ||
| elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") | ||
| if(USE_SANITIZER MATCHES "address") | ||
| list(APPEND SANITIZER_COMPILE_OPTIONS /fsanitize=address /D_DISABLE_VECTOR_ANNOTATION /D_DISABLE_STRING_ANNOTATION) | ||
| list(APPEND SANITIZER_LINK_LIBRARIES clang_rt.asan_dynamic-x86_64 clang_rt.asan_dynamic_runtime_thunk-x86_64) | ||
| else() | ||
| message(FATAL_ERROR "❌ Sanitizer not supported by Clang-MSVC: ${USE_SANITIZER}. It only supports 'address'.") | ||
| endif() | ||
| elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
| foreach(sanitizer ${USE_SANITIZER}) | ||
| if(NOT ${sanitizer} IN_LIST AVALAIBLE_SANITIZERS) | ||
| message(FATAL_ERROR "❌ Sanitizer not supported: ${sanitizer}. It should be one of: ${AVALAIBLE_SANITIZERS}.") | ||
| endif() | ||
| list(APPEND SANITIZER_COMPILE_OPTIONS -fsanitize=${sanitizer}) | ||
| list(APPEND SANITIZER_LINK_OPTIONS -fsanitize=${sanitizer}) | ||
| if (${sanitizer} MATCHES "undefined") | ||
| list(APPEND SANITIZER_COMPILE_OPTIONS -fno-sanitize=signed-integer-overflow) | ||
| endif() | ||
| if (${sanitizer} MATCHES "memory") | ||
| list(APPEND SANITIZER_LINK_LIBRARIES -fsanitize-memory-track-origins -fPIE -pie) | ||
| list(APPEND SANITIZER_LINK_OPTIONS -fsanitize-memory-track-origins -fPIE -pie) | ||
| endif() | ||
| endforeach() | ||
| list(APPEND SANITIZER_COMPILE_OPTIONS -fno-omit-frame-pointer) | ||
| else() | ||
| message(FATAL_ERROR "❌ Sanitizer: Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}") | ||
| endif() | ||
|
|
||
| list(REMOVE_DUPLICATES SANITIZER_COMPILE_OPTIONS) | ||
| list(REMOVE_DUPLICATES SANITIZER_LINK_OPTIONS) | ||
| list(REMOVE_DUPLICATES SANITIZER_LINK_LIBRARIES) | ||
|
|
||
| message(STATUS "🔍 Using sanitizer: ${USE_SANITIZER}") | ||
| endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # MSan false positive: doctest reporter registration during static init | ||
| # doctest::String has internal padding that MSan flags as uninitialized | ||
| # when std::map compares keys during insert. | ||
| fun:*doctest::detail::registerReporterImpl* | ||
| src:*doctest/doctest.h |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should add this check here, since it severely hurts performance. Besides, this class is a "private" tool used for implementing iterators, not a public API, so we can guarantee in out code that we never call this operator when m_it is
null. Besides, this behavior is consistent with the implementation of standard iterators: