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

@agourakis82 agourakis82 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

The power-test failure was addressed upstream by fb285a4. This revision removes the redundant power-test pragma and keeps the remaining fix in the shared safe_division helper.

On current master, Clang 18 with C++23, -O3 -march=x86-64-v3 can speculate a division past its zero-denominator guard. Runtime arrays return the expected values but raise FE_INVALID; with invalid-operation traps enabled, the process receives SIGFPE. A scoped Clang exception pragma preserves the existing guards without changing their arithmetic. It is disabled under fast-math and on WebAssembly, whose FP exceptions/status flags are not observable. No production headers change.

The regression is in the existing utility tests and covers float/double, zero and nonzero numerators over zero, and ordinary division. It restores the floating-point environment before assertions. Value checks run in fast-math too, using the existing project comparator for ordinary division in that profile.

Validation on the revised patch:

  • Same regression without the helper pragma: both float/double cases fail on FE_INVALID, while value checks pass. Restoring the pragma passes both. Separate native trap controls distinguish signal 8 from exit 0.
  • Complete utility test file: Clang 18 strict, GCC 13, AppleClang 21 and Clang 18 fast-math pass, with no excluded tests.
  • Full Clang 18 Release AVX2/C++23 suite: 446/446 cases, 178829 assertions, zero skips; CTest 1/1 passed.
  • Repository clang-format and diff checks pass.
  • WebAssembly portability: with Emscripten 4.0.21's exact Clang 22 and sysroot, the prior strict helper crashes compilation of four affected translation units; the target guard lets all four compile. These direct checks use C++23; the hosted workflow uses C++17 and remains the final build/browser-runtime gate. All wasm value checks remain enabled.

The preceding revision passed 19/20 upstream workflows, including Windows and sanitizer; Emscripten hit the compiler crash above. The revised head's CI is pending. Native controls and the utility tests were rerun after adding the target guard; the full native suite figures above are from before that target-only change.

Prepared with OpenAI Codex assistance, including implementation, validation and independent code review.

Keep the Clang strict exception scope in safe_division and cover zero denominators in the existing utility tests.

Assisted-by: Codex
Signed-off-by: Demetrios Agourakis <demetrios@agourakis.med.br>
@agourakis82
agourakis82 force-pushed the fix/test-comparison-fp-exceptions branch from 6a6c9e2 to 2828bb4 Compare November 15, 2026 20:59

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