[flang-commits] [flang] [flang] IEEE_ARITHMETIC and IEEE_EXCEPTIONS intrinsic module procedures (PR #74138)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Dec 1 12:45:20 PST 2023


================
@@ -0,0 +1,81 @@
+//===-- runtime/exceptions.cpp --------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// Map Fortran ieee_arithmetic module exceptions to fenv.h exceptions.
+
+#include "flang/Runtime/exceptions.h"
+#include "terminator.h"
+#include "flang/Runtime/magic-numbers.h"
+#include <cfenv>
+
+namespace Fortran::runtime {
+
+extern "C" {
+
+std::int32_t RTNAME(MapException)(int32_t except) {
+  Terminator terminator{__FILE__, __LINE__};
+
+  static constexpr int32_t mask = _FORTRAN_RUNTIME_IEEE_INVALID |
+      _FORTRAN_RUNTIME_IEEE_DENORM | _FORTRAN_RUNTIME_IEEE_DIVIDE_BY_ZERO |
+      _FORTRAN_RUNTIME_IEEE_OVERFLOW | _FORTRAN_RUNTIME_IEEE_UNDERFLOW |
+      _FORTRAN_RUNTIME_IEEE_INEXACT;
+  if (except != (except & mask))
----------------
klausler wrote:

Please always use braces on `if`, `while`, `for`, &c. in the runtime.

https://github.com/llvm/llvm-project/pull/74138


More information about the flang-commits mailing list