Skip to content
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

[flang] fix build on FreeBSD after 4762c6557d15 #86204

Merged
merged 2 commits into from
Apr 9, 2024

Conversation

brooksdavis
Copy link
Contributor

The HUGE definition collides with the HUGE macro from math.h. Unlike the fix in 3149c93 (#84478) (largely reverted in f95710c), add another #undef HUGE since there is no practical way to make FreeBSD's headers not define HUGE and still define XSI interfaces such as isascii or strnlen.

Fixes #86038

The HUGE definition collides with the HUGE macro from math.h.  Unlike
the fix in 3149c93 (llvm#84478) (largely reverted in f95710c), add
another #undef HUGE since there is no practical way to make FreeBSD's
headers not define HUGE and still define XSI interfaces such as isascii or
strnlen.

Fixes llvm#86038
@llvmbot llvmbot added the flang Flang issues not falling into any other category label Mar 21, 2024
@klausler klausler requested review from luporl and removed request for klausler March 21, 2024 21:53
Copy link
Contributor

@luporl luporl left a comment

Choose a reason for hiding this comment

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

If there is no practical way to make FreeBSD's headers not define HUGE and still define XSI interfaces such as isascii or strnlen, then there's not much choice but to undef HUGE.

A possibly better option would be to include <cmath> and undef HUGE in flang/lib/Decimal/big-radix-floating-point.h, to avoid issues with other sources using its HUGE definition in the future. By doing this in every header file that declares a HUGE symbol, it should be possible to avoid hitting this issue again.

flang/lib/Decimal/decimal-to-binary.cpp Outdated Show resolved Hide resolved
Update comments above `#undef HUGE` to reflect the fact that all major
BSD versions (I checked DragonFly, FreeBSD, NetBSD, and OpenBSD) leak
the HUGE macro from math.h to various degrees.
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 22, 2024

@llvm/pr-subscribers-flang-semantics

Author: Brooks Davis (brooksdavis)

Changes

The HUGE definition collides with the HUGE macro from math.h. Unlike the fix in 3149c93 (#84478) (largely reverted in f95710c), add another #undef HUGE since there is no practical way to make FreeBSD's headers not define HUGE and still define XSI interfaces such as isascii or strnlen.

Fixes #86038


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

4 Files Affected:

  • (modified) flang/include/flang/Evaluate/integer.h (+1-1)
  • (modified) flang/include/flang/Evaluate/real.h (+1-1)
  • (modified) flang/lib/Decimal/decimal-to-binary.cpp (+4)
  • (modified) flang/lib/Evaluate/fold-implementation.h (+1-1)
diff --git a/flang/include/flang/Evaluate/integer.h b/flang/include/flang/Evaluate/integer.h
index 7395645701265d..b62e2bcb90f2f3 100644
--- a/flang/include/flang/Evaluate/integer.h
+++ b/flang/include/flang/Evaluate/integer.h
@@ -27,7 +27,7 @@
 #include <string>
 #include <type_traits>
 
-// Some environments, viz. glibc 2.17, allow the macro HUGE
+// Some environments, viz. glibc 2.17 and *BSD, allow the macro HUGE
 // to leak out of <math.h>.
 #undef HUGE
 
diff --git a/flang/include/flang/Evaluate/real.h b/flang/include/flang/Evaluate/real.h
index b7af0ff6b431c8..6f2466c9da6773 100644
--- a/flang/include/flang/Evaluate/real.h
+++ b/flang/include/flang/Evaluate/real.h
@@ -18,7 +18,7 @@
 #include <limits>
 #include <string>
 
-// Some environments, viz. glibc 2.17, allow the macro HUGE
+// Some environments, viz. glibc 2.17 and *BSD, allow the macro HUGE
 // to leak out of <math.h>.
 #undef HUGE
 
diff --git a/flang/lib/Decimal/decimal-to-binary.cpp b/flang/lib/Decimal/decimal-to-binary.cpp
index c5cdb72e355f62..1bcf6967cc40be 100644
--- a/flang/lib/Decimal/decimal-to-binary.cpp
+++ b/flang/lib/Decimal/decimal-to-binary.cpp
@@ -16,6 +16,10 @@
 #include <ctype.h>
 #include <utility>
 
+// Some environments, viz. glibc 2.17 and *BSD, allow the macro HUGE
+// to leak out of <math.h>.
+#undef HUGE
+
 namespace Fortran::decimal {
 
 template <int PREC, int LOG10RADIX>
diff --git a/flang/lib/Evaluate/fold-implementation.h b/flang/lib/Evaluate/fold-implementation.h
index 9dd8c3843465d5..c47ffb7a0f7011 100644
--- a/flang/lib/Evaluate/fold-implementation.h
+++ b/flang/lib/Evaluate/fold-implementation.h
@@ -39,7 +39,7 @@
 #include <type_traits>
 #include <variant>
 
-// Some environments, viz. glibc 2.17, allow the macro HUGE
+// Some environments, viz. glibc 2.17 and *BSD, allow the macro HUGE
 // to leak out of <math.h>.
 #undef HUGE
 

@brooksdavis
Copy link
Contributor Author

I'll leave a better fix to the flang developers. It appears that HUGE is de facto part of the math.h interface and POSIX should just define it if the definitions are reasonably well aligned.

@brooksdavis brooksdavis merged commit 788be0d into llvm:main Apr 9, 2024
5 checks passed
@brooksdavis brooksdavis deleted the flang-freebsd-HUGE-fix branch April 9, 2024 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flang failing on build on FreeBSD
4 participants