Introduce llvm::sys::path::home_directory.
[oota-llvm.git] / include / llvm / Support / FEnv.h
1 //===- llvm/Support/FEnv.h - Host floating-point exceptions ------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file provides an operating system independent interface to
11 // floating-point exception interfaces.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_SUPPORT_FENV_H
16 #define LLVM_SUPPORT_FENV_H
17
18 #include "llvm/Config/config.h"
19 #include <cerrno>
20 #ifdef HAVE_FENV_H
21 #include <fenv.h>
22 #endif
23
24 // FIXME: Clang's #include handling apparently doesn't work for libstdc++'s
25 // fenv.h; see PR6907 for details.
26 #if defined(__clang__) && defined(_GLIBCXX_FENV_H)
27 #undef HAVE_FENV_H
28 #endif
29
30 namespace llvm {
31 namespace sys {
32
33 /// llvm_fenv_clearexcept - Clear the floating-point exception state.
34 static inline void llvm_fenv_clearexcept() {
35 #if defined(HAVE_FENV_H) && HAVE_DECL_FE_ALL_EXCEPT
36   feclearexcept(FE_ALL_EXCEPT);
37 #endif
38   errno = 0;
39 }
40
41 /// llvm_fenv_testexcept - Test if a floating-point exception was raised.
42 static inline bool llvm_fenv_testexcept() {
43   int errno_val = errno;
44   if (errno_val == ERANGE || errno_val == EDOM)
45     return true;
46 #if defined(HAVE_FENV_H) && HAVE_DECL_FE_ALL_EXCEPT && HAVE_DECL_FE_INEXACT
47   if (fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT))
48     return true;
49 #endif
50   return false;
51 }
52
53 } // End sys namespace
54 } // End llvm namespace
55
56 #endif