FLANG
fp-control.h
1//===-- include/flang/Common/fp-control.h -----------------------*- C++ -*-===//
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// FLANG_FP_TRAP_ON enables floating-point exception access in the
10// enclosing scope. It silences clang's -Wfenv-access warning on calls to
11// fenv.h primitives (feraiseexcept, fesetround, fetestexcept, ...).
12//
13// Use as a statement at the top of a function body:
14//
15// void f() {
16// FLANG_FP_TRAP_ON
17// feraiseexcept(FE_INVALID);
18// }
19//
20
21#ifndef FORTRAN_COMMON_FP_CONTROL_H_
22#define FORTRAN_COMMON_FP_CONTROL_H_
23
24#if defined(__clang__) && (__clang_major__ >= 10)
25// Clang >= 10 supports `#pragma clang fp exceptions(maytrap)`, which is the
26// local-scope equivalent of `-ffp-exception-behavior=maytrap` and is what the
27// -Wfenv-access diagnostic recommends.
28#define FLANG_FP_TRAP_ON _Pragma("clang fp exceptions(maytrap)")
29#else
30// Portable fallback for GCC, MSVC, or older clang.
31#define FLANG_FP_TRAP_ON _Pragma("STDC FENV_ACCESS ON")
32#endif
33
34#endif // FORTRAN_COMMON_FP_CONTROL_H_