Skip to content

Commit c137a07

Browse files
committed
[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
1 parent d9eb6c7 commit c137a07

File tree

4 files changed

+18
-31
lines changed

4 files changed

+18
-31
lines changed

libcxx/include/__config

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,6 @@
255255
# else // _BYTE_ORDER == _LITTLE_ENDIAN
256256
# define _LIBCPP_BIG_ENDIAN
257257
# endif // _BYTE_ORDER == _LITTLE_ENDIAN
258-
# ifndef __LONG_LONG_SUPPORTED
259-
# define _LIBCPP_HAS_NO_LONG_LONG
260-
# endif // __LONG_LONG_SUPPORTED
261258
#endif // __FreeBSD__
262259

263260
#if defined(__NetBSD__) || defined(__OpenBSD__)

libcxx/include/cstdlib

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,18 @@ _LIBCPP_BEGIN_NAMESPACE_STD
9999
using ::size_t _LIBCPP_USING_IF_EXISTS;
100100
using ::div_t _LIBCPP_USING_IF_EXISTS;
101101
using ::ldiv_t _LIBCPP_USING_IF_EXISTS;
102-
#ifndef _LIBCPP_HAS_NO_LONG_LONG
103102
using ::lldiv_t _LIBCPP_USING_IF_EXISTS;
104-
#endif // _LIBCPP_HAS_NO_LONG_LONG
105103
using ::atof _LIBCPP_USING_IF_EXISTS;
106104
using ::atoi _LIBCPP_USING_IF_EXISTS;
107105
using ::atol _LIBCPP_USING_IF_EXISTS;
108-
#ifndef _LIBCPP_HAS_NO_LONG_LONG
109106
using ::atoll _LIBCPP_USING_IF_EXISTS;
110-
#endif // _LIBCPP_HAS_NO_LONG_LONG
111107
using ::strtod _LIBCPP_USING_IF_EXISTS;
112108
using ::strtof _LIBCPP_USING_IF_EXISTS;
113109
using ::strtold _LIBCPP_USING_IF_EXISTS;
114110
using ::strtol _LIBCPP_USING_IF_EXISTS;
115-
#ifndef _LIBCPP_HAS_NO_LONG_LONG
116111
using ::strtoll _LIBCPP_USING_IF_EXISTS;
117-
#endif // _LIBCPP_HAS_NO_LONG_LONG
118112
using ::strtoul _LIBCPP_USING_IF_EXISTS;
119-
#ifndef _LIBCPP_HAS_NO_LONG_LONG
120113
using ::strtoull _LIBCPP_USING_IF_EXISTS;
121-
#endif // _LIBCPP_HAS_NO_LONG_LONG
122114
using ::rand _LIBCPP_USING_IF_EXISTS;
123115
using ::srand _LIBCPP_USING_IF_EXISTS;
124116
using ::calloc _LIBCPP_USING_IF_EXISTS;
@@ -137,14 +129,10 @@ using ::bsearch _LIBCPP_USING_IF_EXISTS;
137129
using ::qsort _LIBCPP_USING_IF_EXISTS;
138130
using ::abs _LIBCPP_USING_IF_EXISTS;
139131
using ::labs _LIBCPP_USING_IF_EXISTS;
140-
#ifndef _LIBCPP_HAS_NO_LONG_LONG
141132
using ::llabs _LIBCPP_USING_IF_EXISTS;
142-
#endif // _LIBCPP_HAS_NO_LONG_LONG
143133
using ::div _LIBCPP_USING_IF_EXISTS;
144134
using ::ldiv _LIBCPP_USING_IF_EXISTS;
145-
#ifndef _LIBCPP_HAS_NO_LONG_LONG
146135
using ::lldiv _LIBCPP_USING_IF_EXISTS;
147-
#endif // _LIBCPP_HAS_NO_LONG_LONG
148136
using ::mblen _LIBCPP_USING_IF_EXISTS;
149137
using ::mbtowc _LIBCPP_USING_IF_EXISTS;
150138
using ::wctomb _LIBCPP_USING_IF_EXISTS;

libcxx/include/cwchar

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,9 @@ using ::wcstod _LIBCPP_USING_IF_EXISTS;
137137
using ::wcstof _LIBCPP_USING_IF_EXISTS;
138138
using ::wcstold _LIBCPP_USING_IF_EXISTS;
139139
using ::wcstol _LIBCPP_USING_IF_EXISTS;
140-
#ifndef _LIBCPP_HAS_NO_LONG_LONG
141140
using ::wcstoll _LIBCPP_USING_IF_EXISTS;
142-
#endif // _LIBCPP_HAS_NO_LONG_LONG
143141
using ::wcstoul _LIBCPP_USING_IF_EXISTS;
144-
#ifndef _LIBCPP_HAS_NO_LONG_LONG
145142
using ::wcstoull _LIBCPP_USING_IF_EXISTS;
146-
#endif // _LIBCPP_HAS_NO_LONG_LONG
147143
using ::wcscpy _LIBCPP_USING_IF_EXISTS;
148144
using ::wcsncpy _LIBCPP_USING_IF_EXISTS;
149145
using ::wcscat _LIBCPP_USING_IF_EXISTS;

libcxx/include/stdlib.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,24 @@ void *aligned_alloc(size_t alignment, size_t size); // C11
9696
extern "C++" {
9797
// abs
9898

99-
#undef abs
100-
#undef labs
101-
#ifndef _LIBCPP_HAS_NO_LONG_LONG
102-
#undef llabs
99+
#ifdef abs
100+
# undef abs
101+
#endif
102+
#ifdef labs
103+
# undef labs
104+
#endif
105+
#ifdef llabs
106+
# undef llabs
103107
#endif
104108

105109
// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
106110
#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__)
107111
inline _LIBCPP_INLINE_VISIBILITY long abs(long __x) _NOEXCEPT {
108112
return __builtin_labs(__x);
109113
}
110-
#ifndef _LIBCPP_HAS_NO_LONG_LONG
111114
inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {
112115
return __builtin_llabs(__x);
113116
}
114-
#endif // _LIBCPP_HAS_NO_LONG_LONG
115117
#endif // !defined(_LIBCPP_MSVCRT) && !defined(__sun__)
116118

117119
#if !defined(__sun__)
@@ -131,23 +133,27 @@ abs(long double __lcpp_x) _NOEXCEPT {
131133

132134
// div
133135

134-
#undef div
135-
#undef ldiv
136-
#ifndef _LIBCPP_HAS_NO_LONG_LONG
137-
#undef lldiv
136+
#ifdef div
137+
# undef div
138+
#endif
139+
#ifdef ldiv
140+
# undef ldiv
141+
#endif
142+
#ifdef lldiv
143+
# undef lldiv
138144
#endif
139145

140146
// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
141147
#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__)
142148
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {
143149
return ::ldiv(__x, __y);
144150
}
145-
#ifndef _LIBCPP_HAS_NO_LONG_LONG
151+
#if !(defined(__FreeBSD__) && !defined(__LONG_LONG_SUPPORTED))
146152
inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
147153
long long __y) _NOEXCEPT {
148154
return ::lldiv(__x, __y);
149155
}
150-
#endif // _LIBCPP_HAS_NO_LONG_LONG
156+
#endif
151157
#endif // _LIBCPP_MSVCRT / __sun__
152158
} // extern "C++"
153159
#endif // __cplusplus

0 commit comments

Comments
 (0)