Skip to content

Fix MSan false positive: enlarge dummy buffer for SVE predicated loads#14

Merged
alexey-milovidov merged 2 commits intoClickHouse/v6.5.15from
fix-msan-no-sanitize
Mar 7, 2026
Merged

Fix MSan false positive: enlarge dummy buffer for SVE predicated loads#14
alexey-milovidov merged 2 commits intoClickHouse/v6.5.15from
fix-msan-no-sanitize

Conversation

@alexey-milovidov
Copy link
Copy Markdown
Member

Summary

simsimd_capabilities probes SIMD functions with n=0 to pre-initialize dispatch function pointers. SVE implementations use do { } while (i < n) loops that always execute the body once, even with n=0. MemorySanitizer instruments SVE predicated loads (svld1_f32 etc.) as full-width vector reads regardless of the predicate mask, so it reports use-of-uninitialized memory when the buffer is smaller than the SIMD register width.

Increase the dummy buffer from 8 bytes (double[1]) to 256 bytes (double[32]) to cover the widest possible SVE vector (2048 bits).

Also reverts the no_sanitize("memory") approach from types.h since it would leave output memory poisoned for callers.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98677&sha=a1b9d7f6170c510431fce962a869aa617d88d888&name_0=PR&name_1=Stress%20test%20%28arm_msan%29

alexey-milovidov and others added 2 commits March 6, 2026 22:39
MemorySanitizer cannot track data flow through SIMD intrinsics
(SVE, NEON, SSE, AVX), causing false-positive "use-of-uninitialized-value"
reports. For example, SVE predicated loads only access memory for active
lanes, but MSan sees the full vector width as a memory read, flagging
tail elements as uninitialized.

Add `__attribute__((no_sanitize("memory")))` to `SIMSIMD_PUBLIC` and
`SIMSIMD_DYNAMIC` macros when MSan is detected via `__has_feature`.
This disables MSan instrumentation for all SimSIMD functions, which is
appropriate since they are entirely SIMD code that MSan cannot analyze.

The previous approach of unpoisoning results after dispatch (in lib.c)
was insufficient because MSan aborts inside the function body before
the dispatch wrapper can unpoison the output.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
`simsimd_capabilities` probes SIMD functions with n=0 to pre-initialize
dispatch function pointers. SVE implementations use `do { } while (i < n)`
loops that always execute the body once, even with n=0. MemorySanitizer
instruments SVE predicated loads (`svld1_f32` etc.) as full-width vector
reads regardless of the predicate mask, so it reports use-of-uninitialized
memory when the buffer is smaller than the SIMD register width.

Increase the dummy buffer from 8 bytes (`double[1]`) to 256 bytes
(`double[32]`) to cover the widest possible SVE vector (2048 bits).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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