summaryrefslogtreecommitdiff
path: root/include/llvm/Support/FEnv.h
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2010-11-29 18:16:10 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2010-11-29 18:16:10 +0000
commit1f6efa3996dd1929fbc129203ce5009b620e6969 (patch)
tree6b782914982f90d3a983bcefef98b8ef68ab2961 /include/llvm/Support/FEnv.h
parent9363f739cdc3bd02e8516a25de0090f52ae12fbb (diff)
downloadllvm-1f6efa3996dd1929fbc129203ce5009b620e6969.tar.gz
llvm-1f6efa3996dd1929fbc129203ce5009b620e6969.tar.bz2
llvm-1f6efa3996dd1929fbc129203ce5009b620e6969.tar.xz
Merge System into Support.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120298 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/FEnv.h')
-rw-r--r--include/llvm/Support/FEnv.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/include/llvm/Support/FEnv.h b/include/llvm/Support/FEnv.h
new file mode 100644
index 0000000000..042e43928b
--- /dev/null
+++ b/include/llvm/Support/FEnv.h
@@ -0,0 +1,56 @@
+//===- llvm/System/FEnv.h - Host floating-point exceptions ------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file provides an operating system independent interface to
+// floating-point exception interfaces.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SYSTEM_FENV_H
+#define LLVM_SYSTEM_FENV_H
+
+#include "llvm/Config/config.h"
+#include <cerrno>
+#ifdef HAVE_FENV_H
+#include <fenv.h>
+#endif
+
+// FIXME: Clang's #include handling apparently doesn't work for libstdc++'s
+// fenv.h; see PR6907 for details.
+#if defined(__clang__) && defined(_GLIBCXX_FENV_H)
+#undef HAVE_FENV_H
+#endif
+
+namespace llvm {
+namespace sys {
+
+/// llvm_fenv_clearexcept - Clear the floating-point exception state.
+static inline void llvm_fenv_clearexcept() {
+#ifdef HAVE_FENV_H
+ feclearexcept(FE_ALL_EXCEPT);
+#endif
+ errno = 0;
+}
+
+/// llvm_fenv_testexcept - Test if a floating-point exception was raised.
+static inline bool llvm_fenv_testexcept() {
+ int errno_val = errno;
+ if (errno_val == ERANGE || errno_val == EDOM)
+ return true;
+#ifdef HAVE_FENV_H
+ if (fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT))
+ return true;
+#endif
+ return false;
+}
+
+} // End sys namespace
+} // End llvm namespace
+
+#endif