[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
GitOrigin-RevId: f3d7536b24f1d65c09de4899a51d9fdda83c3b1d
diff --git a/include/cmath b/include/cmath
index 138ae6f..9c493ce 100644
--- a/include/cmath
+++ b/include/cmath
@@ -335,9 +335,7 @@
using ::float_t;
using ::double_t;
-#ifndef _AIX
using ::abs;
-#endif
using ::acos;
using ::acosf;
diff --git a/include/stdlib.h b/include/stdlib.h
index 812ea10..9ce0485 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -103,7 +103,7 @@
#endif
// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
-#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)
+#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__)
inline _LIBCPP_INLINE_VISIBILITY long abs(long __x) _NOEXCEPT {
return __builtin_labs(__x);
}
@@ -112,9 +112,9 @@
return __builtin_llabs(__x);
}
#endif // _LIBCPP_HAS_NO_LONG_LONG
-#endif // !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)
+#endif // !defined(_LIBCPP_MSVCRT) && !defined(__sun__)
-#if !(defined(_AIX) || defined(__sun__))
+#if !defined(__sun__)
inline _LIBCPP_INLINE_VISIBILITY float abs(float __lcpp_x) _NOEXCEPT {
return __builtin_fabsf(__lcpp_x); // Use builtins to prevent needing math.h
}
@@ -127,7 +127,7 @@
abs(long double __lcpp_x) _NOEXCEPT {
return __builtin_fabsl(__lcpp_x);
}
-#endif // !(defined(_AIX) || defined(__sun__))
+#endif // !defined(__sun__)
// div
@@ -138,7 +138,7 @@
#endif
// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
-#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)
+#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__)
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {
return ::ldiv(__x, __y);
}
@@ -148,7 +148,7 @@
return ::lldiv(__x, __y);
}
#endif // _LIBCPP_HAS_NO_LONG_LONG
-#endif // _LIBCPP_MSVCRT / __sun__ / _AIX
+#endif // _LIBCPP_MSVCRT / __sun__
} // extern "C++"
#endif // __cplusplus