Skip to content

Commit f3d7536

Browse files
committed
[libc++] Fix abs and div overload issue for compilers on AIX
Summary: AIX system's stdlib.h provide different overload of abs and div depending on compiler versions. For example, std::div(long, long) and std::abs(long) are not available from OS's stdlib.h when building with clang, but they are available when building with xlclang compiler. Therefore, we need to provide those extra overloads in libc++'s stdlib.h when OS's stdlib.h does not. Differential Revision: https://reviews.llvm.org/D99767
1 parent f9264ac commit f3d7536

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

libcxx/include/cmath

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,7 @@ using ::isunordered;
335335
using ::float_t;
336336
using ::double_t;
337337

338-
#ifndef _AIX
339338
using ::abs;
340-
#endif
341339

342340
using ::acos;
343341
using ::acosf;

libcxx/include/stdlib.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ extern "C++" {
103103
#endif
104104

105105
// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
106-
#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)
106+
#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__)
107107
inline _LIBCPP_INLINE_VISIBILITY long abs(long __x) _NOEXCEPT {
108108
return __builtin_labs(__x);
109109
}
@@ -112,9 +112,9 @@ inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {
112112
return __builtin_llabs(__x);
113113
}
114114
#endif // _LIBCPP_HAS_NO_LONG_LONG
115-
#endif // !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)
115+
#endif // !defined(_LIBCPP_MSVCRT) && !defined(__sun__)
116116

117-
#if !(defined(_AIX) || defined(__sun__))
117+
#if !defined(__sun__)
118118
inline _LIBCPP_INLINE_VISIBILITY float abs(float __lcpp_x) _NOEXCEPT {
119119
return __builtin_fabsf(__lcpp_x); // Use builtins to prevent needing math.h
120120
}
@@ -127,7 +127,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double
127127
abs(long double __lcpp_x) _NOEXCEPT {
128128
return __builtin_fabsl(__lcpp_x);
129129
}
130-
#endif // !(defined(_AIX) || defined(__sun__))
130+
#endif // !defined(__sun__)
131131

132132
// div
133133

@@ -138,7 +138,7 @@ abs(long double __lcpp_x) _NOEXCEPT {
138138
#endif
139139

140140
// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
141-
#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)
141+
#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__)
142142
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {
143143
return ::ldiv(__x, __y);
144144
}
@@ -148,7 +148,7 @@ inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
148148
return ::lldiv(__x, __y);
149149
}
150150
#endif // _LIBCPP_HAS_NO_LONG_LONG
151-
#endif // _LIBCPP_MSVCRT / __sun__ / _AIX
151+
#endif // _LIBCPP_MSVCRT / __sun__
152152
} // extern "C++"
153153
#endif // __cplusplus
154154

0 commit comments

Comments
 (0)