From 1b56b9b2706a215b7154585fbf05bb210355ccc3 Mon Sep 17 00:00:00 2001 From: Demetrios Agourakis Date: Sat, 31 Oct 2026 12:14:55 -0300 Subject: [PATCH] Respect unmasked exceptions in shared test comparisons 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 --- test/test_power.cpp | 4 ++++ test/test_utils.hpp | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/test/test_power.cpp b/test/test_power.cpp index cdf8c146a..5a4aee437 100644 --- a/test/test_power.cpp +++ b/test/test_power.cpp @@ -49,6 +49,10 @@ struct power_test void test_power_functions() { +#if defined(__clang__) && !defined(__FAST_MATH__) + // This test deliberately unmasks floating-point exceptions below. +#pragma clang fp exceptions(strict) +#endif // pow { std::transform(lhs_input.cbegin(), lhs_input.cend(), rhs_input.cbegin(), expected.begin(), diff --git a/test/test_utils.hpp b/test/test_utils.hpp index f0d64a7df..b875c3e30 100644 --- a/test/test_utils.hpp +++ b/test/test_utils.hpp @@ -152,6 +152,11 @@ namespace detail template T safe_division(const T& lhs, const T& rhs) { +#if defined(__clang__) && !defined(__FAST_MATH__) + // Comparisons also run with FE_INVALID unmasked in the power tests. + // Do not speculate a division past the zero-denominator guard. +#pragma clang fp exceptions(strict) +#endif if (rhs == T(0)) { return (std::numeric_limits::max)();