Skip to content

Commit d5333f2

Browse files
vdonaldsontstellar
authored andcommitted
[flang] Build fix (llvm#125087)
Reinstate a preprocessor define for a nonstandard exception. [124978](llvm#124978 (comment)) (cherry picked from commit 7fa1257)
1 parent b23297a commit d5333f2

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

flang/runtime/exceptions.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
#include <cfenv>
1414
#if defined(__aarch64__) && !defined(_WIN32)
1515
#include <fpu_control.h>
16-
#elif defined(__x86_64__)
16+
#elif defined(__x86_64__) && !defined(_WIN32)
1717
#include <xmmintrin.h>
1818
#endif
1919

20-
// fenv.h may not define exception macros.
20+
// File fenv.h usually, but not always, defines standard exceptions as both
21+
// enumerator values and preprocessor #defines. Some x86 environments also
22+
// define a nonstandard __FE_DENORM enumerator, but without a corresponding
23+
// #define, which makes it more difficult to determine if it is present or not.
2124
#ifndef FE_INVALID
2225
#define FE_INVALID 0
2326
#endif
@@ -33,6 +36,12 @@
3336
#ifndef FE_INEXACT
3437
#define FE_INEXACT 0
3538
#endif
39+
#if FE_INVALID == 1 && FE_DIVBYZERO == 4 && FE_OVERFLOW == 8 && \
40+
FE_UNDERFLOW == 16 && FE_INEXACT == 32
41+
#define __FE_DENORM 2
42+
#else
43+
#define __FE_DENORM 0
44+
#endif
3645

3746
namespace Fortran::runtime {
3847

@@ -44,11 +53,7 @@ uint32_t RTNAME(MapException)(uint32_t excepts) {
4453
Terminator terminator{__FILE__, __LINE__};
4554

4655
static constexpr uint32_t v{FE_INVALID};
47-
#if __x86_64__
48-
static constexpr uint32_t s{__FE_DENORM}; // nonstandard, not a #define
49-
#else
50-
static constexpr uint32_t s{0};
51-
#endif
56+
static constexpr uint32_t s{__FE_DENORM};
5257
static constexpr uint32_t z{FE_DIVBYZERO};
5358
static constexpr uint32_t o{FE_OVERFLOW};
5459
static constexpr uint32_t u{FE_UNDERFLOW};

0 commit comments

Comments
 (0)