[libc++] Remove _LIBCPP_HAS_NO_LONG_LONG in favour of using_if_exists

_LIBCPP_HAS_NO_LONG_LONG was only defined on FreeBSD. Instead, use the
using_if_exists attribute to skip over declarations that are not available
on the base system. Note that there's an annoying limitation that we can't
conditionally define a function based on whether the base system provides
a function, so for example we still need preprocessor logic to define the
abs() and div() overloads.

Differential Revision: https://reviews.llvm.org/D108630
This commit is contained in:
Louis Dionne 2021-08-24 10:30:39 -04:00
parent d9eb6c7cf5
commit c137a0754c
4 changed files with 18 additions and 31 deletions

View File

@ -255,9 +255,6 @@
# else // _BYTE_ORDER == _LITTLE_ENDIAN
# define _LIBCPP_BIG_ENDIAN
# endif // _BYTE_ORDER == _LITTLE_ENDIAN
# ifndef __LONG_LONG_SUPPORTED
# define _LIBCPP_HAS_NO_LONG_LONG
# endif // __LONG_LONG_SUPPORTED
#endif // __FreeBSD__
#if defined(__NetBSD__) || defined(__OpenBSD__)

View File

@ -99,26 +99,18 @@ _LIBCPP_BEGIN_NAMESPACE_STD
using ::size_t _LIBCPP_USING_IF_EXISTS;
using ::div_t _LIBCPP_USING_IF_EXISTS;
using ::ldiv_t _LIBCPP_USING_IF_EXISTS;
#ifndef _LIBCPP_HAS_NO_LONG_LONG
using ::lldiv_t _LIBCPP_USING_IF_EXISTS;
#endif // _LIBCPP_HAS_NO_LONG_LONG
using ::atof _LIBCPP_USING_IF_EXISTS;
using ::atoi _LIBCPP_USING_IF_EXISTS;
using ::atol _LIBCPP_USING_IF_EXISTS;
#ifndef _LIBCPP_HAS_NO_LONG_LONG
using ::atoll _LIBCPP_USING_IF_EXISTS;
#endif // _LIBCPP_HAS_NO_LONG_LONG
using ::strtod _LIBCPP_USING_IF_EXISTS;
using ::strtof _LIBCPP_USING_IF_EXISTS;
using ::strtold _LIBCPP_USING_IF_EXISTS;
using ::strtol _LIBCPP_USING_IF_EXISTS;
#ifndef _LIBCPP_HAS_NO_LONG_LONG
using ::strtoll _LIBCPP_USING_IF_EXISTS;
#endif // _LIBCPP_HAS_NO_LONG_LONG
using ::strtoul _LIBCPP_USING_IF_EXISTS;
#ifndef _LIBCPP_HAS_NO_LONG_LONG
using ::strtoull _LIBCPP_USING_IF_EXISTS;
#endif // _LIBCPP_HAS_NO_LONG_LONG
using ::rand _LIBCPP_USING_IF_EXISTS;
using ::srand _LIBCPP_USING_IF_EXISTS;
using ::calloc _LIBCPP_USING_IF_EXISTS;
@ -137,14 +129,10 @@ using ::bsearch _LIBCPP_USING_IF_EXISTS;
using ::qsort _LIBCPP_USING_IF_EXISTS;
using ::abs _LIBCPP_USING_IF_EXISTS;
using ::labs _LIBCPP_USING_IF_EXISTS;
#ifndef _LIBCPP_HAS_NO_LONG_LONG
using ::llabs _LIBCPP_USING_IF_EXISTS;
#endif // _LIBCPP_HAS_NO_LONG_LONG
using ::div _LIBCPP_USING_IF_EXISTS;
using ::ldiv _LIBCPP_USING_IF_EXISTS;
#ifndef _LIBCPP_HAS_NO_LONG_LONG
using ::lldiv _LIBCPP_USING_IF_EXISTS;
#endif // _LIBCPP_HAS_NO_LONG_LONG
using ::mblen _LIBCPP_USING_IF_EXISTS;
using ::mbtowc _LIBCPP_USING_IF_EXISTS;
using ::wctomb _LIBCPP_USING_IF_EXISTS;

View File

@ -137,13 +137,9 @@ using ::wcstod _LIBCPP_USING_IF_EXISTS;
using ::wcstof _LIBCPP_USING_IF_EXISTS;
using ::wcstold _LIBCPP_USING_IF_EXISTS;
using ::wcstol _LIBCPP_USING_IF_EXISTS;
#ifndef _LIBCPP_HAS_NO_LONG_LONG
using ::wcstoll _LIBCPP_USING_IF_EXISTS;
#endif // _LIBCPP_HAS_NO_LONG_LONG
using ::wcstoul _LIBCPP_USING_IF_EXISTS;
#ifndef _LIBCPP_HAS_NO_LONG_LONG
using ::wcstoull _LIBCPP_USING_IF_EXISTS;
#endif // _LIBCPP_HAS_NO_LONG_LONG
using ::wcscpy _LIBCPP_USING_IF_EXISTS;
using ::wcsncpy _LIBCPP_USING_IF_EXISTS;
using ::wcscat _LIBCPP_USING_IF_EXISTS;

View File

@ -96,10 +96,14 @@ void *aligned_alloc(size_t alignment, size_t size); // C11
extern "C++" {
// abs
#undef abs
#undef labs
#ifndef _LIBCPP_HAS_NO_LONG_LONG
#undef llabs
#ifdef abs
# undef abs
#endif
#ifdef labs
# undef labs
#endif
#ifdef llabs
# undef llabs
#endif
// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
@ -107,11 +111,9 @@ extern "C++" {
inline _LIBCPP_INLINE_VISIBILITY long abs(long __x) _NOEXCEPT {
return __builtin_labs(__x);
}
#ifndef _LIBCPP_HAS_NO_LONG_LONG
inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {
return __builtin_llabs(__x);
}
#endif // _LIBCPP_HAS_NO_LONG_LONG
#endif // !defined(_LIBCPP_MSVCRT) && !defined(__sun__)
#if !defined(__sun__)
@ -131,10 +133,14 @@ abs(long double __lcpp_x) _NOEXCEPT {
// div
#undef div
#undef ldiv
#ifndef _LIBCPP_HAS_NO_LONG_LONG
#undef lldiv
#ifdef div
# undef div
#endif
#ifdef ldiv
# undef ldiv
#endif
#ifdef lldiv
# undef lldiv
#endif
// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
@ -142,12 +148,12 @@ abs(long double __lcpp_x) _NOEXCEPT {
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {
return ::ldiv(__x, __y);
}
#ifndef _LIBCPP_HAS_NO_LONG_LONG
#if !(defined(__FreeBSD__) && !defined(__LONG_LONG_SUPPORTED))
inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
long long __y) _NOEXCEPT {
return ::lldiv(__x, __y);
}
#endif // _LIBCPP_HAS_NO_LONG_LONG
#endif
#endif // _LIBCPP_MSVCRT / __sun__
} // extern "C++"
#endif // __cplusplus