<div dir="auto">Hi Raphael,<div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">Did you communicate your intent to revert before pushing this change?</div><br><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Mon., Feb. 17, 2020, 11:00 a.m. Raphael Isemann via libcxx-commits, <<a href="mailto:libcxx-commits@lists.llvm.org">libcxx-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Author: Raphael Isemann<br>
Date: 2020-02-17T17:59:08+01:00<br>
New Revision: 23368bee15356c830d9c315fe2c4fe0c22f29906<br>
<br>
URL: <a href="https://github.com/llvm/llvm-project/commit/23368bee15356c830d9c315fe2c4fe0c22f29906" rel="noreferrer noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/23368bee15356c830d9c315fe2c4fe0c22f29906</a><br>
DIFF: <a href="https://github.com/llvm/llvm-project/commit/23368bee15356c830d9c315fe2c4fe0c22f29906.diff" rel="noreferrer noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/23368bee15356c830d9c315fe2c4fe0c22f29906.diff</a><br>
<br>
LOG: Revert "[libc++] Move abs and div into stdlib.h to fix header cycle."<br>
<br>
This reverts commit 82b47b2978405f802a33b00d046e6f18ef6a47be.<br>
<br>
This broke Clang and LLDB module builds without -fmodules-local-submodule-visbility.<br>
I'll revert this for now until we have a fix and reland once Clang<br>
can properly handle this code.<br>
<br>
See also the discussion in <a href="https://reviews.llvm.org/rG82b47b2978405f802a33b00d046e6f18ef6a47be" rel="noreferrer noreferrer" target="_blank">https://reviews.llvm.org/rG82b47b2978405f802a33b00d046e6f18ef6a47be</a><br>
<br>
Added: <br>
<br>
<br>
Modified: <br>
    libcxx/include/math.h<br>
    libcxx/include/stdlib.h<br>
<br>
Removed: <br>
<br>
<br>
<br>
################################################################################<br>
diff  --git a/libcxx/include/math.h b/libcxx/include/math.h<br>
index 1603d5748e2d..c9b4733e9c44 100644<br>
--- a/libcxx/include/math.h<br>
+++ b/libcxx/include/math.h<br>
@@ -297,6 +297,9 @@ long double    truncl(long double x);<br>
 #pragma GCC system_header<br>
 #endif<br>
<br>
+#define _LIBCPP_STDLIB_INCLUDE_NEXT<br>
+#include <stdlib.h><br>
+<br>
 #include_next <math.h><br>
<br>
 #ifdef __cplusplus<br>
@@ -305,7 +308,6 @@ long double    truncl(long double x);<br>
 // back to C++ linkage before including these C++ headers.<br>
 extern "C++" {<br>
<br>
-#include <stdlib.h><br>
 #include <type_traits><br>
 #include <limits><br>
<br>
@@ -758,12 +760,61 @@ isunordered(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT<br>
 #endif  // isunordered<br>
<br>
 // abs<br>
-//<br>
-// handled in stdlib.h<br>
+<br>
+#undef abs<br>
+#undef labs<br>
+#ifndef _LIBCPP_HAS_NO_LONG_LONG<br>
+#undef llabs<br>
+#endif<br>
+<br>
+// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined<br>
+#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)<br>
+inline _LIBCPP_INLINE_VISIBILITY long abs(long __x) _NOEXCEPT {<br>
+  return ::labs(__x);<br>
+}<br>
+#ifndef _LIBCPP_HAS_NO_LONG_LONG<br>
+inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {<br>
+  return ::llabs(__x);<br>
+}<br>
+#endif // _LIBCPP_HAS_NO_LONG_LONG<br>
+#endif // !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)<br>
+<br>
+<br>
+#if !(defined(_AIX) || defined(__sun__))<br>
+inline _LIBCPP_INLINE_VISIBILITY float abs(float __lcpp_x) _NOEXCEPT {<br>
+  return ::fabsf(__lcpp_x);<br>
+}<br>
+<br>
+inline _LIBCPP_INLINE_VISIBILITY double abs(double __lcpp_x) _NOEXCEPT {<br>
+  return ::fabs(__lcpp_x);<br>
+}<br>
+<br>
+inline _LIBCPP_INLINE_VISIBILITY long double<br>
+abs(long double __lcpp_x) _NOEXCEPT {<br>
+  return ::fabsl(__lcpp_x);<br>
+}<br>
+#endif // !(defined(_AIX) || defined(__sun__))<br>
<br>
 // div<br>
-//<br>
-// handled in stdlib.h<br>
+<br>
+#undef div<br>
+#undef ldiv<br>
+#ifndef _LIBCPP_HAS_NO_LONG_LONG<br>
+#undef lldiv<br>
+#endif<br>
+<br>
+// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined<br>
+#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)<br>
+inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {<br>
+  return ::ldiv(__x, __y);<br>
+}<br>
+#ifndef _LIBCPP_HAS_NO_LONG_LONG<br>
+inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,<br>
+                                             long long __y) _NOEXCEPT {<br>
+  return ::lldiv(__x, __y);<br>
+}<br>
+#endif // _LIBCPP_HAS_NO_LONG_LONG<br>
+#endif // _LIBCPP_MSVCRT / __sun__ / _AIX<br>
<br>
 // acos<br>
<br>
<br>
diff  --git a/libcxx/include/stdlib.h b/libcxx/include/stdlib.h<br>
index 812ea1024edf..1d6827587037 100644<br>
--- a/libcxx/include/stdlib.h<br>
+++ b/libcxx/include/stdlib.h<br>
@@ -7,12 +7,16 @@<br>
 //<br>
 //===----------------------------------------------------------------------===//<br>
<br>
-#if defined(__need_malloc_and_calloc)<br>
+#if defined(__need_malloc_and_calloc) || defined(_LIBCPP_STDLIB_INCLUDE_NEXT)<br>
<br>
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)<br>
 #pragma GCC system_header<br>
 #endif<br>
<br>
+#if defined(_LIBCPP_STDLIB_INCLUDE_NEXT)<br>
+#undef _LIBCPP_STDLIB_INCLUDE_NEXT<br>
+#endif<br>
+<br>
 #include_next <stdlib.h><br>
<br>
 #elif !defined(_LIBCPP_STDLIB_H)<br>
@@ -93,63 +97,7 @@ void *aligned_alloc(size_t alignment, size_t size);                       // C11<br>
 #include_next <stdlib.h><br>
<br>
 #ifdef __cplusplus<br>
-extern "C++" {<br>
-// abs<br>
-<br>
-#undef abs<br>
-#undef labs<br>
-#ifndef _LIBCPP_HAS_NO_LONG_LONG<br>
-#undef llabs<br>
-#endif<br>
-<br>
-// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined<br>
-#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)<br>
-inline _LIBCPP_INLINE_VISIBILITY long abs(long __x) _NOEXCEPT {<br>
-  return __builtin_labs(__x);<br>
-}<br>
-#ifndef _LIBCPP_HAS_NO_LONG_LONG<br>
-inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {<br>
-  return __builtin_llabs(__x);<br>
-}<br>
-#endif // _LIBCPP_HAS_NO_LONG_LONG<br>
-#endif // !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)<br>
-<br>
-#if !(defined(_AIX) || defined(__sun__))<br>
-inline _LIBCPP_INLINE_VISIBILITY float abs(float __lcpp_x) _NOEXCEPT {<br>
-  return __builtin_fabsf(__lcpp_x); // Use builtins to prevent needing math.h<br>
-}<br>
-<br>
-inline _LIBCPP_INLINE_VISIBILITY double abs(double __lcpp_x) _NOEXCEPT {<br>
-  return __builtin_fabs(__lcpp_x);<br>
-}<br>
-<br>
-inline _LIBCPP_INLINE_VISIBILITY long double<br>
-abs(long double __lcpp_x) _NOEXCEPT {<br>
-  return __builtin_fabsl(__lcpp_x);<br>
-}<br>
-#endif // !(defined(_AIX) || defined(__sun__))<br>
-<br>
-// div<br>
-<br>
-#undef div<br>
-#undef ldiv<br>
-#ifndef _LIBCPP_HAS_NO_LONG_LONG<br>
-#undef lldiv<br>
-#endif<br>
-<br>
-// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined<br>
-#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)<br>
-inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {<br>
-  return ::ldiv(__x, __y);<br>
-}<br>
-#ifndef _LIBCPP_HAS_NO_LONG_LONG<br>
-inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,<br>
-                                             long long __y) _NOEXCEPT {<br>
-  return ::lldiv(__x, __y);<br>
-}<br>
-#endif // _LIBCPP_HAS_NO_LONG_LONG<br>
-#endif // _LIBCPP_MSVCRT / __sun__ / _AIX<br>
-} // extern "C++"<br>
+#include <math.h><br>
 #endif  // __cplusplus<br>
<br>
 #endif  // _LIBCPP_STDLIB_H<br>
<br>
<br>
<br>
_______________________________________________<br>
libcxx-commits mailing list<br>
<a href="mailto:libcxx-commits@lists.llvm.org" target="_blank" rel="noreferrer">libcxx-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-commits" rel="noreferrer noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-commits</a><br>
</blockquote></div></div>