1 //===-- Unittests for feclearexcept with exceptions enabled ---------------===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "src/fenv/feclearexcept.h" 10 11 #include "src/__support/FPUtil/FEnvImpl.h" 12 #include "utils/UnitTest/Test.h" 13 14 #include <fenv.h> 15 #include <stdint.h> 16 17 TEST(LlvmLibcFEnvTest, ClearTest) { 18 uint16_t excepts[] = {FE_DIVBYZERO, FE_INVALID, FE_INEXACT, FE_OVERFLOW, 19 FE_UNDERFLOW}; 20 __llvm_libc::fputil::disable_except(FE_ALL_EXCEPT); 21 __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT); 22 23 for (uint16_t e : excepts) 24 ASSERT_EQ(__llvm_libc::fputil::test_except(e), 0); 25 26 __llvm_libc::fputil::raise_except(FE_ALL_EXCEPT); 27 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 __llvm_libc::feclearexcept(e1 | e2 | e3 | e4 | e5); 35 ASSERT_EQ(__llvm_libc::fputil::test_except(e1 | e2 | e3 | e4 | e5), 36 0); 37 // After clearing, we raise the exception again. 38 __llvm_libc::fputil::raise_except(e1 | e2 | e3 | e4 | e5); 39 } 40 } 41 } 42 } 43 } 44 } 45