Skip to content

Commit bb38b48

Browse files
authored
[flang-rt] Set _POSIX_C_SOURCE on Darwin (#160130)
Clang on Darwin enables non-POSIX extensions by default. This causes some macros to leak, such as HUGE from <math.h>, which causes some conflicts with Flang symbols (but not with Flang-RT, for now). It also causes some Flang-RT extensions to be disabled, such as FDATE, that checks for _POSIX_C_SOURCE. Setting _POSIX_C_SOURCE avoids these issues. This is already being done in Flang, but it was not ported to Flang-RT. This also fixes check-flang-rt on Darwin, as NoArgv.FdateNotSupported is broken since the flang runtime was moved to flang-rt. Fixes #82036
1 parent eaf36c6 commit bb38b48

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

flang-rt/cmake/modules/AddFlangRT.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,15 @@ function (add_flangrt_library name)
251251
$<$<COMPILE_LANGUAGE:CXX>:-nogpulib -flto -fvisibility=hidden -Wno-unknown-cuda-version --cuda-feature=+ptx63>
252252
)
253253
elseif (APPLE)
254+
# Clang on Darwin enables non-POSIX extensions by default.
255+
# This causes some macros to leak, such as HUGE from <math.h>, which
256+
# causes some conflicts with Flang symbols (but not with Flang-RT, for
257+
# now).
258+
# It also causes some Flang-RT extensions to be disabled, such as fdate,
259+
# that checks for _POSIX_C_SOURCE.
260+
# Setting _POSIX_C_SOURCE avoids these issues.
254261
target_compile_options(${tgtname} PRIVATE
255-
$<$<COMPILE_LANGUAGE:CXX>:${DARWIN_osx_BUILTIN_MIN_VER_FLAG}>
262+
$<$<COMPILE_LANGUAGE:CXX>:${DARWIN_osx_BUILTIN_MIN_VER_FLAG} -D_POSIX_C_SOURCE=200809>
256263
)
257264
endif ()
258265

flang-rt/unittests/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ function(add_flangrt_dependent_libs target)
7878
instead falls back to builtins from Compiler-RT. Linking with ${tgtname}
7979
may result in a linker error.")
8080
endif ()
81+
elseif (APPLE)
82+
# Clang on Darwin enables non-POSIX extensions by default.
83+
# This causes some macros to leak, such as HUGE from <math.h>, which
84+
# causes some conflicts with Flang symbols (but not with Flang-RT, for
85+
# now).
86+
# It also causes some Flang-RT extensions to be disabled, such as fdate,
87+
# that checks for _POSIX_C_SOURCE.
88+
# Setting _POSIX_C_SOURCE avoids these issues.
89+
target_compile_options(${target} PRIVATE "-D_POSIX_C_SOURCE=200809")
8190
endif ()
8291
endfunction()
8392

0 commit comments

Comments
 (0)