Skip to content

[flang] Build fix #125087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2025
Merged

[flang] Build fix #125087

merged 1 commit into from
Jan 30, 2025

Conversation

vdonaldson
Copy link
Contributor

Reinstate a preprocessor define for a nonstandard exception.

124978

@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category labels Jan 30, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 30, 2025

@llvm/pr-subscribers-flang-runtime

Author: None (vdonaldson)

Changes

Reinstate a preprocessor define for a nonstandard exception.

124978


Full diff: https://github.com/llvm/llvm-project/pull/125087.diff

1 Files Affected:

  • (modified) flang/runtime/exceptions.cpp (+12-7)
diff --git a/flang/runtime/exceptions.cpp b/flang/runtime/exceptions.cpp
index b41c7cf438f569..257c71b51edb3d 100644
--- a/flang/runtime/exceptions.cpp
+++ b/flang/runtime/exceptions.cpp
@@ -13,11 +13,14 @@
 #include <cfenv>
 #if defined(__aarch64__) && !defined(_WIN32)
 #include <fpu_control.h>
-#elif defined(__x86_64__)
+#elif defined(__x86_64__) && !defined(_WIN32)
 #include <xmmintrin.h>
 #endif
 
-// fenv.h may not define exception macros.
+// File fenv.h usually, but not always, defines standard exceptions as both
+// enumerator values and preprocessor #defines. Some x86 environments also
+// define a nonstandard __FE_DENORM enumerator, but without a corresponding
+// #define, which makes it more difficult to determine if it is present or not.
 #ifndef FE_INVALID
 #define FE_INVALID 0
 #endif
@@ -33,6 +36,12 @@
 #ifndef FE_INEXACT
 #define FE_INEXACT 0
 #endif
+#if FE_INVALID == 1 && FE_DIVBYZERO == 4 && FE_OVERFLOW == 8 && \
+    FE_UNDERFLOW == 16 && FE_INEXACT == 32
+#define __FE_DENORM 2
+#else
+#define __FE_DENORM 0
+#endif
 
 namespace Fortran::runtime {
 
@@ -44,11 +53,7 @@ uint32_t RTNAME(MapException)(uint32_t excepts) {
   Terminator terminator{__FILE__, __LINE__};
 
   static constexpr uint32_t v{FE_INVALID};
-#if __x86_64__
-  static constexpr uint32_t s{__FE_DENORM}; // nonstandard, not a #define
-#else
-  static constexpr uint32_t s{0};
-#endif
+  static constexpr uint32_t s{__FE_DENORM};
   static constexpr uint32_t z{FE_DIVBYZERO};
   static constexpr uint32_t o{FE_OVERFLOW};
   static constexpr uint32_t u{FE_UNDERFLOW};

Copy link
Contributor

@brooksdavis brooksdavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems plausible to me and likely to fix FreeBSD builds, but far from my area of expertise.

Thanks,
Brooks

@rorth
Copy link
Collaborator

rorth commented Jan 30, 2025

Solaris/amd64 was broken the same. This patch restored the build.

@vdonaldson vdonaldson merged commit 7fa1257 into llvm:main Jan 30, 2025
11 checks passed
Copy link
Contributor

@jeanPerier jeanPerier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "by elimination logic" makes some sense and is valid with my configs. I think if you wanted something more robust, you could use cmake to try compiling a a file using __FE_DENORM and define a macro according to the compilation success/failure. Then that macro could be used here.

@h-vetinari
Copy link
Contributor

Can someone add this to the 20.x milestone please? Without that the following command will fail (and we need this for 20.1 release).

/cherry-pick 7fa1257

@h-vetinari
Copy link
Contributor

Ah, nevermind, I just saw this was already requested elsewhere, leading to the PR: #125213

@llvmbot
Copy link
Member

llvmbot commented Jan 31, 2025

Can someone add this to the 20.x milestone please? Without that the following command will fail (and we need this for 20.1 release).

/cherry-pick 7fa1257

Error: Command failed due to missing milestone.

swift-ci pushed a commit to swiftlang/llvm-project that referenced this pull request Feb 1, 2025
Reinstate a preprocessor define for a nonstandard exception.

[124978](llvm#124978 (comment))

(cherry picked from commit 7fa1257)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:runtime flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants