Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
3cc3aa2
feat: create suppressions file with grouping
m-clare Jul 13, 2025
9a38098
feat: isolate macOS ubsan errors in sep task/supp
m-clare Jul 13, 2025
d657dc3
chore: briefly enable workflow dispatch control
m-clare Jul 13, 2025
ff3bc29
fix: specific version
m-clare Jul 13, 2025
6468c8f
fix: env root for suppressions file
m-clare Jul 13, 2025
fe13708
fix: meson flag and path
m-clare Jul 13, 2025
11f79ad
fix: try relative path
m-clare Jul 13, 2025
f92456c
fix: additional failure in CI
m-clare Jul 13, 2025
fc8fb25
chore: disable temporarily to capture addt errors
m-clare Jul 13, 2025
cb560a0
fix: github workspace for explicit path...
m-clare Jul 13, 2025
bec1588
fix: function runtime errors, halt_on_error enable
m-clare Jul 13, 2025
354a36c
fix: try to capture fatal error in CI
m-clare Jul 13, 2025
ecdb77f
fix: remove manual dispatch + halt_on_error
m-clare Jul 13, 2025
d4b93b8
fix: function dispact on bit_generator
m-clare Jul 13, 2025
88b5141
fix: uncaught pointer issue
m-clare Jul 13, 2025
3568347
fix: generalize random ignore
m-clare Jul 13, 2025
86e5b50
fix: missing convert datatype
m-clare Jul 13, 2025
b4e9a91
fix: another missing multiarray flagged
m-clare Jul 13, 2025
86b959c
fix: another multiarray test
m-clare Jul 13, 2025
6e6d262
fix: generalize to ignore multiarray functions
m-clare Jul 13, 2025
5d49912
fix: flush umath as well
m-clare Jul 13, 2025
b9071f6
chore: ignore all function errors for now
m-clare Jul 13, 2025
8b47eba
feat: test against ubuntu
m-clare Jul 20, 2025
603fef8
fix: add linux suppressions file
m-clare Jul 20, 2025
7e15fa7
chore: simplify ubuntu ubsan
m-clare Jul 31, 2025
56756ff
Merge branch 'main' into undefined-behavior-ubsan-suppressions
m-clare Jul 31, 2025
1acbbb5
chore: bump python version
m-clare Jul 31, 2025
f9ec386
fix: avoid rerunning clang ubsan for now
m-clare Jul 31, 2025
d34662f
fix: os tag
m-clare Jul 31, 2025
1cd752d
chore: rename supp file, rename steps
m-clare Jul 31, 2025
c186d57
fix: remove outdated supp file
m-clare Jul 31, 2025
2844d0a
feat: combine clang asan/ubsan jobs
m-clare Aug 2, 2025
78af625
fix: comment out for workflow test
m-clare Aug 2, 2025
53fa6ba
chore: remove fork trigger
m-clare Aug 2, 2025
69ed7f8
chore: remove autoindent for clarity
m-clare Aug 4, 2025
8107dd6
fix: remove other formatting changes
m-clare Aug 4, 2025
3eb6e75
fix: add in address sanitizer for ubuntu
m-clare Aug 4, 2025
9f65c1a
fix: add configure opts for asan
m-clare Aug 4, 2025
d1f1e00
fix: set asan options
m-clare Aug 4, 2025
dffec52
fix: address comments, clarifying supp file lang
m-clare Aug 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions .github/workflows/compiler_sanitizers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ permissions:
contents: read # to fetch code (actions/checkout)

jobs:
clang_ASAN:
clang_ASAN_UBSAN:
# To enable this workflow on a fork, comment out:
if: github.repository == 'numpy/numpy'
runs-on: macos-latest
Expand Down Expand Up @@ -64,12 +64,14 @@ jobs:
pip uninstall -y pytest-xdist
- name: Build
run:
python -m spin build -j2 -- -Db_sanitize=address
python -m spin build -- -Db_sanitize=address,undefined -Db_lundef=false
- name: Test
run: |
# pass -s to pytest to see ASAN errors and warnings, otherwise pytest captures them
# Ignore test_casting_floatingpoint_errors on macOS for now - causes crash inside UBSAN
ASAN_OPTIONS=detect_leaks=0:symbolize=1:strict_init_order=true:allocator_may_return_null=1 \
python -m spin test -- -v -s --timeout=600 --durations=10
UBSAN_OPTIONS=halt_on_error=1:suppressions=${GITHUB_WORKSPACE}/tools/ci/ubsan_suppressions_arm64.txt \
python -m spin test -- -k "not test_casting_floatingpoint_errors" -v -s --timeout=600 --durations=10

clang_TSAN:
# To enable this workflow on a fork, comment out:
Expand All @@ -78,9 +80,9 @@ jobs:
container:
image: ghcr.io/nascheme/numpy-tsan:3.14t
options: --shm-size=2g # increase memory for large matrix ops

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Trust working directory and initialize submodules
run: |
git config --global --add safe.directory /__w/numpy/numpy
Expand All @@ -98,3 +100,42 @@ jobs:
python -m spin test \
`find numpy -name "test*.py" | xargs grep -l "import threading" | tr '\n' ' '` \
-- -v -s --timeout=600 --durations=10

ubuntu_UBSAN:
# To enable this workflow on a fork, comment out:
if: github.repository == 'numpy/numpy'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: recursive
fetch-tags: true
persist-credentials: false
- name: Set up pyenv
run: |
git clone https://github.com/pyenv/pyenv.git "$HOME/.pyenv"
PYENV_ROOT="$HOME/.pyenv"
PYENV_BIN="$PYENV_ROOT/bin"
PYENV_SHIMS="$PYENV_ROOT/shims"
echo "$PYENV_BIN" >> $GITHUB_PATH
echo "$PYENV_SHIMS" >> $GITHUB_PATH
echo "PYENV_ROOT=$PYENV_ROOT" >> $GITHUB_ENV
- name: Check pyenv is working
run: pyenv --version
- name: Build python with address sanitizer
run: |
CONFIGURE_OPTS="--with-address-sanitizer" pyenv install 3.14t
pyenv global 3.14t
- name: Install dependencies
run: |
pip install -r requirements/build_requirements.txt
pip install -r requirements/ci_requirements.txt
pip install -r requirements/test_requirements.txt
- name: Build numpy with UndefinedBehaviorSanitizer
run: python -m spin build -- -Db_sanitize=address,undefined -Db_lundef=false
- name: Test
run: |
# pass -s to pytest to see UBSAN errors and warnings, otherwise pytest captures them
ASAN_OPTIONS=detect_leaks=0:symbolize=1:strict_init_order=true:allocator_may_return_null=1 \
UBSAN_OPTIONS=halt_on_error=1:suppressions=${GITHUB_WORKSPACE}/tools/ci/ubsan_suppressions_x86_64.txt \
spin test -- -v -s --timeout=600 --durations=10
51 changes: 51 additions & 0 deletions tools/ci/ubsan_suppressions_arm64.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This file contains suppressions for the default (with GIL) build to prevent runtime errors
# when numpy is built with -Db_sanitize=undefined for arm64 architecture
#
# reference: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#available-checks

# Per this prior discussion, integer overflow is not a concern
# https://github.com/numpy/numpy/issues/24209#issuecomment-2160154181
signed-integer-overflow:*

# all alignment runtime errors ignored in favor of this being tracked via TypeSanitizer
# otherwise ubsan may detect system file alignment errors outside numpy
alignment:*

# suggested fix for runtime error: use INT_MIN constant
shift-base:_core/src/umath/_rational_tests.c
# suggested fix for runtime error: check for overflow if signed
shift-base:_core/src/npymath/npy_math_internal.h

# suggested fix for runtime error: null check before loop
pointer-overflow:_core/src/common/simd/neon/memory.h
pointer-overflow:_core/src/multiarray/datetime_busdaycal.c
pointer-overflow:_core/src/multiarray/nditer_templ.c
pointer-overflow:_core/src/multiarray/nditer_constr.c
pointer-overflow:_core/src/umath/loops_arithm_fp.dispatch.c.src
pointer-overflow:_core/src/umath/loops_unary.dispatch.c.src
pointer-overflow:_core/src/umath/loops_unary_complex.dispatch.c.src
pointer-overflow:_core/src/umath/loops_unary_fp_le.dispatch.c.src
pointer-overflow:_core/src/umath/string_buffer.h
pointer-overflow:linalg/umath_linalg.cpp
pointer-overflow:numpy/random/bit_generator.pyx.c

float-cast-overflow:_core/src/multiarray/lowlevel_strided_loops.c.src

# flagged in CI - call to function through pointer to incorrect function type
# Many functions in the modules/files listed below cause undefined behavior in CI
# general disable this check until further investigation, but keep the specific files
# as a starting point for resolving the checks later
function:_core/src/*
function:numpy/random/*
# function:_core/src/common/cblasfunc.c
# function:_core/src/common/npy_argparse.c
# function:_core/src/multiarray/number.c
# function:_core/src/multiarray/ctors.c
# function:_core/src/multiarray/convert_datatype.c
# function:_core/src/multiarray/dtype_transfer.c
# function:_core/src/multiarray/dtype_traversal.c
# function:_core/src/multiarray/getset.c
# function:_core/src/multiarray/scalarapi.c
# function:_core/src/multiarray/scalartypes.c.src
# function:_core/src/umath/*
# function:numpy/random/*
31 changes: 31 additions & 0 deletions tools/ci/ubsan_suppressions_x86_64.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This file contains suppressions for the default (with GIL) build to prevent runtime errors
# when numpy is built with -Db_sanitize=undefined for x86_64 architecture
#
# reference: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#available-checks

# Per this prior discussion, integer overflow is not a concern
# https://github.com/numpy/numpy/issues/24209#issuecomment-2160154181
signed-integer-overflow:*

# all alignment runtime errors ignored in favor of this being tracked via TypeSanitizer
# otherwise ubsan may detect system file alignment errors outside numpy
alignment:*

# suggested fix for runtime error: replace left bit shift with LLONG_MIN constant
shift-base:_core/src/common/simd/sse/arithmetic.h
shift-base:_core/src/common/simd/avx2/arithmetic.h
# suggested fix for runtime error: use INT_MIN constant
shift-base:_core/src/umath/_rational_tests.c
# suggested fix for runtime error: check for overflow if signed
shift-base:_core/src/npymath/npy_math_internal.h


# suggested fix for runtime error: check that pointer is not null before calling function
nonnull-attribute:_core/src/multiarray/array_coercion.c
nonnull-attribute:_core/src/multiarray/ctors.c
nonnull-attribute:_core/src/multiarray/datetime_busdaycal.c
nonnull-attribute:_core/src/multiarray/scalarapi.c
nonnull-attribute:_core/src/multiarray/calculation.c

# suggested fix for runtime error: null check before loop
pointer-overflow:_core/src/multiarray/nditer_templ.c
Loading