[llvm-bugs] [Bug 47208] New: When _XOPEN_SOURCE is set, <cstdlib> and <ctime> started to fail on macOS, missing ::aligned_alloc and ::timespec_get

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Aug 17 08:37:59 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47208

            Bug ID: 47208
           Summary: When _XOPEN_SOURCE is set,<cstdlib> and <ctime>
                    started to fail on macOS, missing ::aligned_alloc and
                    ::timespec_get
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: stephan.bergmann.secondary at googlemail.com
                CC: ldionne at apple.com, llvm-bugs at lists.llvm.org,
                    mclow.lists at gmail.com

On macOS, with recent LLVM 12 trunk commit
<https://github.com/llvm/llvm-project/commit/67dfba96296b37f7bac9b4a68572288bc44b63b2>
" [libc++] Provide std::aligned_alloc and std::timespec_get on Apple
platforms":

> $ cat test.cc
> #include <cstdlib>
> #include <ctime>

> $ .../llvm/inst/bin/clang++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -std=c++17 -fsyntax-only test.cc

> $ .../llvm/inst/bin/clang++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -std=c++17 -fsyntax-only test.cc -D_XOPEN_SOURCE=600
> In file included from test.cc:1:
> .../llvm/inst/bin/../include/c++/v1/cstdlib:158:9: error: no member named 'aligned_alloc' in the global namespace
> using ::aligned_alloc;
>       ~~^
> In file included from test.cc:2:
> .../llvm/inst/bin/../include/c++/v1/ctime:76:9: error: no member named 'timespec_get' in the global namespace; did you mean 'timespec'?
> using ::timespec_get;
>       ~~^
> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/sys/_types/_timespec.h:33:1: note: 'timespec' declared here
> _STRUCT_TIMESPEC
> ^
> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/sys/_types/_timespec.h:29:40: note: expanded from macro '_STRUCT_TIMESPEC'
> #define _STRUCT_TIMESPEC        struct timespec
>                                        ^
> 2 errors generated.

...and similarly for other values of _XOPEN_SOURCE, like 700.  I noticed that
when building ICU 67.1 as part of building recent master LibreOffice, where
some place in the ICU sources sets _XOPEN_SOURCE to 600.

* One approach to fix this would be to make the condition in libcxx match the
condition in Apple's SDK headers, with something like

> diff --git a/libcxx/include/__config b/libcxx/include/__config
> index d7b6a2acaef..fb5ca54493b 100644
> --- a/libcxx/include/__config
> +++ b/libcxx/include/__config
> @@ -327,6 +327,10 @@
>  #  define _LIBCPP_USING_DEV_RANDOM
>  #endif
>  
> +#if defined(__APPLE__)
> +#  include <sys/cdefs.h>
> +#endif
> +
>  #if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
>  #  include <endian.h>
>  #  if __BYTE_ORDER == __LITTLE_ENDIAN
> @@ -383,7 +387,8 @@
>  #  elif defined(__APPLE__)
>       // timespec_get and aligned_alloc were introduced in macOS 10.15 and
>       // aligned releases
> -#    if (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101500 || \
> +#    if __DARWIN_C_LEVEL >= __DARWIN_C_FULL && \
> +        (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101500 || \
>           __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 130000 || \
>           __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 130000 || \
>           __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 60000)

* Another approach could be to change Apple's SDK headers, so that for C++
::aligned_alloc and ::timespec_get would get declared regardless of any
_XOPEN_SOURCE?

* And yet another approach could be to declare that _XOPEN_SOURCE must not be
defined when compiling C++ source (after all, at least technically it is an
identifier that is reserved to the implementation), and instead fix ICU.

Thoughts how to proceed?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200817/8d5e9947/attachment.html>


More information about the llvm-bugs mailing list