Skip to content

Preserve exception semantics in shared test comparisons - #1440

Open
agourakis82 wants to merge 1 commit into
xtensor-stack:masterfrom
agourakis82:fix/test-comparison-fp-exceptions
Open

agourakis82 wants to merge 1 commit into
xtensor-stack:masterfrom
agourakis82:fix/test-comparison-fp-exceptions

Conversation

@agourakis82

Copy link
Copy Markdown

The existing power tests unmask invalid-operation exceptions, but the shared comparison helper is compiled with Clang's default assumption that exceptions remain masked. In an optimized CLANG64 build, safe_division is vectorized into a speculative vdivps on a guarded zero-denominator path. The comparison then raises STATUS_FLOAT_INVALID_OPERATION (0xC0000090), which MSYS2 presents as exit 127.

This adds scoped #pragma clang fp exceptions(strict) to safe_division and the power-test function. All expressions, division guards, exception-mask operations and assertions remain unchanged. The shared helper receives the same contract across translation units. The pragmas are disabled for GCC and fast-math profiles; no production headers or workflows change.

Validation uses native C++23:

  • Paired Windows qualification: the retained unmodified base and Preserve signed imaginary zero in complex sqrt #1433 merge binaries fail with 0xC0000090. Fresh full, multi-translation-unit builds with this exact patch pass: base 430 cases / 151245 assertions, merge 432 / 152205. Native and original MSYS launches both return zero after the fix. No tests are excluded in these full runs.
  • Fault trace: diagnostic copy records CHECK_BATCH_EQ, first element offset, and the faulting comparison instruction. Independent standalone pow probes pass with invalid exceptions unmasked.
  • GCC qualification: 430 / 150621 pass.
  • Upstream-style Clang 20 Debug fast-math/UBSan profile: both unmodified and patched sources pass 422 / 296465, retaining identical existing integer-overflow UBSan diagnostics. This is not a sanitizer-clean claim.

An additional exploratory Clang 18 Release combined ASan/UBSan fast-math run is not green: it reports three API assertion failures and integer-overflow diagnostics. That is a different profile and is not represented as passing validation or repaired here.

This is a fresh fork-run diagnosis, separate from official upstream CI and maintainer review. It reproduces the symptom reported on #1433 and on master; it does not recover the historical job's missing native status. The original sqrt patch remains separate.

Prepared with OpenAI Codex assistance, including independent source and diagnostic review.

The power tests unmask invalid operations. Give Clang a strict exception contract in guarded safe_division and the trapping test function so vectorization cannot introduce a division on a zero-denominator path.

Preserve all numerical expressions, guards, exception masks and assertions. GCC and fast-math profiles retain their existing compilation behavior.

Assisted-by: OpenAI Codex
@agourakis82
agourakis82 marked this pull request as ready for review November 2, 2026 10:33

This branch has not been deployed

No deployments
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