1 //===-- Unittests for feclearexcept, feraiseexcept and fetestexpect -------===//
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"
10 #include "src/fenv/feraiseexcept.h"
11 #include "src/fenv/fetestexcept.h"
13 #include "src/__support/FPUtil/FEnvImpl.h"
14 #include "test/UnitTest/Test.h"
18 TEST(LlvmLibcExceptionStatusTest
, RaiseAndTest
) {
19 // This test raises a set of exceptions and checks that the exception
20 // status flags are updated. The intention is really not to invoke the
21 // exception handler. Hence, we will disable all exceptions at the
23 __llvm_libc::fputil::disable_except(FE_ALL_EXCEPT
);
25 int excepts
[] = {FE_DIVBYZERO
, FE_INVALID
, FE_INEXACT
, FE_OVERFLOW
,
28 constexpr int ALL_EXCEPTS
=
29 FE_DIVBYZERO
| FE_INVALID
| FE_INEXACT
| FE_OVERFLOW
| FE_UNDERFLOW
;
31 for (int e
: excepts
) {
32 int r
= __llvm_libc::feraiseexcept(e
);
34 int s
= __llvm_libc::fetestexcept(e
);
37 r
= __llvm_libc::feclearexcept(e
);
39 s
= __llvm_libc::fetestexcept(e
);
43 for (int e1
: excepts
) {
44 for (int e2
: excepts
) {
46 int r
= __llvm_libc::feraiseexcept(e
);
48 int s
= __llvm_libc::fetestexcept(e
);
51 r
= __llvm_libc::feclearexcept(e
);
53 s
= __llvm_libc::fetestexcept(e
);
58 for (int e1
: excepts
) {
59 for (int e2
: excepts
) {
60 for (int e3
: excepts
) {
62 int r
= __llvm_libc::feraiseexcept(e
);
64 int s
= __llvm_libc::fetestexcept(e
);
67 r
= __llvm_libc::feclearexcept(e
);
69 s
= __llvm_libc::fetestexcept(e
);
75 for (int e1
: excepts
) {
76 for (int e2
: excepts
) {
77 for (int e3
: excepts
) {
78 for (int e4
: excepts
) {
79 int e
= e1
| e2
| e3
| e4
;
80 int r
= __llvm_libc::feraiseexcept(e
);
82 int s
= __llvm_libc::fetestexcept(e
);
85 r
= __llvm_libc::feclearexcept(e
);
87 s
= __llvm_libc::fetestexcept(e
);
94 for (int e1
: excepts
) {
95 for (int e2
: excepts
) {
96 for (int e3
: excepts
) {
97 for (int e4
: excepts
) {
98 for (int e5
: excepts
) {
99 int e
= e1
| e2
| e3
| e4
| e5
;
100 int r
= __llvm_libc::feraiseexcept(e
);
102 int s
= __llvm_libc::fetestexcept(e
);
105 r
= __llvm_libc::feclearexcept(e
);
107 s
= __llvm_libc::fetestexcept(e
);
115 int r
= __llvm_libc::feraiseexcept(ALL_EXCEPTS
);
117 int s
= __llvm_libc::fetestexcept(ALL_EXCEPTS
);
118 ASSERT_EQ(s
, ALL_EXCEPTS
);