Skip to content

Commit 870baf7

Browse files
committed
[flang] Fix Darwin build after 4762c65
Select POSIX 2008 standard to avoid including Darwin extensions. Otherwise, Darwin's math.h header defines HUGE, which conflicts with Flang's HUGE function. This started happening after 4762c65 (llvm#82443), that added the "utility" include, which seems to include "math.h".
1 parent 4d478bc commit 870baf7

File tree

5 files changed

+10
-14
lines changed

5 files changed

+10
-14
lines changed

flang/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,14 @@ if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
413413

414414
endif()
415415

416+
# Clang on Darwin enables non-POSIX extensions by default, which allows the
417+
# macro HUGE to leak out of <math.h> even when it is never directly included,
418+
# conflicting with Flang's HUGE symbols.
419+
# Set _POSIX_C_SOURCE to avoid including these extensions.
420+
if (APPLE)
421+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_POSIX_C_SOURCE=200809")
422+
endif()
423+
416424
list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS)
417425

418426
# Determine HOST_LINK_VERSION on Darwin.

flang/include/flang/Evaluate/integer.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
#include <string>
2828
#include <type_traits>
2929

30-
// Some environments, viz. clang on Darwin, allow the macro HUGE
31-
// to leak out of <math.h> even when it is never directly included.
32-
#undef HUGE
33-
3430
namespace Fortran::evaluate::value {
3531

3632
// Implements an integer as an assembly of smaller host integer parts

flang/include/flang/Evaluate/real.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
#include <limits>
1919
#include <string>
2020

21-
// Some environments, viz. clang on Darwin, allow the macro HUGE
22-
// to leak out of <math.h> even when it is never directly included.
23-
#undef HUGE
24-
2521
namespace llvm {
2622
class raw_ostream;
2723
}

flang/lib/Evaluate/fold-implementation.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@
3939
#include <type_traits>
4040
#include <variant>
4141

42-
// Some environments, viz. clang on Darwin, allow the macro HUGE
43-
// to leak out of <math.h> even when it is never directly included.
44-
#undef HUGE
45-
4642
namespace Fortran::evaluate {
4743

4844
// Utilities

flang/lib/Evaluate/intrinsics-library.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ struct HostRuntimeLibrary<std::complex<HostT>, LibraryVersion::Libm> {
299299
/// Define libm extensions
300300
/// Bessel functions are defined in POSIX.1-2001.
301301

302-
// Remove float bessel functions for AIX as they are not supported
303-
#ifndef _AIX
302+
// Remove float bessel functions for AIX and Darwin as they are not supported
303+
#if !defined(_AIX) && !defined(__APPLE__)
304304
template <> struct HostRuntimeLibrary<float, LibraryVersion::LibmExtensions> {
305305
using F = FuncPointer<float, float>;
306306
using FN = FuncPointer<float, int, float>;

0 commit comments

Comments
 (0)