[flang-commits] [flang] [flang] fix build on FreeBSD after 4762c6557d15 (PR #86204)

Brooks Davis via flang-commits flang-commits at lists.llvm.org
Fri Mar 22 10:40:20 PDT 2024


https://github.com/brooksdavis updated https://github.com/llvm/llvm-project/pull/86204

>From a805d8e5130cb073a787058e918962557d9d879a Mon Sep 17 00:00:00 2001
From: Brooks Davis <brooks at one-eyed-alien.net>
Date: Thu, 21 Mar 2024 21:39:46 +0000
Subject: [PATCH 1/2] [flang] fix build on FreeBSD after 4762c6557d15

The HUGE definition collides with the HUGE macro from math.h.  Unlike
the fix in 3149c934cb26 (#84478) (largely reverted in f95710c76519), 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
---
 flang/lib/Decimal/decimal-to-binary.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/flang/lib/Decimal/decimal-to-binary.cpp b/flang/lib/Decimal/decimal-to-binary.cpp
index c5cdb72e355f62..3d9e0673b93777 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, allow the macro HUGE
+// to leak out of <math.h>.
+#undef HUGE
+
 namespace Fortran::decimal {
 
 template <int PREC, int LOG10RADIX>

>From 109ca2e1e7b05f776e56300fd0e67524f0ca5b71 Mon Sep 17 00:00:00 2001
From: Brooks Davis <brooks at one-eyed-alien.net>
Date: Fri, 22 Mar 2024 17:31:45 +0000
Subject: [PATCH 2/2] [flang] *BSD leak HUGE macro

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.
---
 flang/include/flang/Evaluate/integer.h   | 2 +-
 flang/include/flang/Evaluate/real.h      | 2 +-
 flang/lib/Decimal/decimal-to-binary.cpp  | 2 +-
 flang/lib/Evaluate/fold-implementation.h | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

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 3d9e0673b93777..1bcf6967cc40be 100644
--- a/flang/lib/Decimal/decimal-to-binary.cpp
+++ b/flang/lib/Decimal/decimal-to-binary.cpp
@@ -16,7 +16,7 @@
 #include <ctype.h>
 #include <utility>
 
-// 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/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
 



More information about the flang-commits mailing list