Skip to content

Commit f058e2f

Browse files
committed
guard on math_errhandling & MATH_ERR{NO,EXCEPT} in fp assertions
1 parent b78e0a6 commit f058e2f

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

libc/test/UnitTest/ErrnoSetterMatcher.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ static ErrnoSetterMatcherBuilder<RetT> returns(internal::Comparator<RetT> cmp) {
189189

190190
// Used to check that `LIBC_NAMESPACE::libc_errno` was 0 or a specific
191191
// errno after executing `expr_or_statement` from a state where
192-
// `LIBC_NAMESPACE::libc_errno` was 0.
192+
// `LIBC_NAMESPACE::libc_errno` was 0. This is generic, so does not check
193+
// `math_errhandling & MATH_ERRNO` before errno matching, see FPTest.h for
194+
// assertions that check this.
193195
//
194196
// Expects `expected` to be convertible to int type.
195197
//

libc/test/UnitTest/FPExceptMatcher.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,10 @@ class FPExceptCallableMatcher : public Matcher<bool> {
147147
expr_or_statement; \
148148
int expected_ = (expected); \
149149
int mask_ = expected_ ? expected_ : FE_ALL_EXCEPT; \
150-
EXPECT_FP_EXCEPT_EQUAL(expected_, \
151-
LIBC_NAMESPACE::fputil::test_except(mask_)); \
150+
if (math_errhandling & MATH_ERREXCEPT) { \
151+
EXPECT_FP_EXCEPT_EQUAL(expected_, \
152+
LIBC_NAMESPACE::fputil::test_except(mask_)); \
153+
} \
152154
} while (0)
153155

154156
#else // !LIBC_TEST_HAS_MATCHERS()

libc/test/UnitTest/FPTest.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,11 @@ struct FPTest : public ErrnoSafeTest, public FEnvSafeTest {
9292
// were set
9393
#define EXPECT_ERRNO_FP_EXCEPT(expected_errno, expected_fexn, \
9494
expr_or_statement) \
95-
EXPECT_FP_EXCEPT((expected_fexn), \
96-
EXPECT_ERRNO((expected_errno), expr_or_statement))
95+
EXPECT_FP_EXCEPT((expected_fexn), EXPECT_ERRNO((expected_errno), { \
96+
expr_or_statement; \
97+
if (!(math_errhandling & MATH_ERRNO)) \
98+
break; \
99+
}))
97100

98101
#define EXPECT_NO_ERRNO_FP_EXCEPT(expr_or_statement) \
99102
EXPECT_ERRNO_FP_EXCEPT(0, 0, expr_or_statement)

0 commit comments

Comments
 (0)