1 //===-- Unittests for feclearexcept with exceptions enabled ---------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/fenv/feclearexcept.h"
11 #include "src/__support/FPUtil/FEnvImpl.h"
12 #include "test/UnitTest/Test.h"
17 TEST(LlvmLibcFEnvTest
, ClearTest
) {
18 uint16_t excepts
[] = {FE_DIVBYZERO
, FE_INVALID
, FE_INEXACT
, FE_OVERFLOW
,
20 LIBC_NAMESPACE::fputil::disable_except(FE_ALL_EXCEPT
);
21 LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT
);
23 for (uint16_t e
: excepts
)
24 ASSERT_EQ(LIBC_NAMESPACE::fputil::test_except(e
), 0);
26 LIBC_NAMESPACE::fputil::raise_except(FE_ALL_EXCEPT
);
28 for (uint16_t e1
: excepts
) {
29 for (uint16_t e2
: excepts
) {
30 for (uint16_t e3
: excepts
) {
31 for (uint16_t e4
: excepts
) {
32 for (uint16_t e5
: excepts
) {
33 // We clear one exception and test to verify that it was cleared.
34 LIBC_NAMESPACE::feclearexcept(e1
| e2
| e3
| e4
| e5
);
36 LIBC_NAMESPACE::fputil::test_except(e1
| e2
| e3
| e4
| e5
), 0);
37 // After clearing, we raise the exception again.
38 LIBC_NAMESPACE::fputil::raise_except(e1
| e2
| e3
| e4
| e5
);