-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
Conversation
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
There was a problem hiding this 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.
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.
@llvm/pr-subscribers-flang-semantics Author: Brooks Davis (brooksdavis) ChangesThe 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:
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
|
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. |
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