Reland [libc++] Move abs and div into stdlib.h to fix header cycle.
authorEric Fiselier <eric@efcs.ca>
Sat, 15 Feb 2020 23:55:07 +0000 (18:55 -0500)
committerRaphael Isemann <teemperor@gmail.com>
Fri, 8 May 2020 19:52:27 +0000 (21:52 +0200)
commitc490c5e81ac90cbf079c7cee18cd56171f1e27af
tree2f9287fe8ad57e659d0f214e4e74b710e84a3412
parent465f5648ee271c9ded9401cee58c84532c4a5c46
Reland [libc++] Move abs and div into stdlib.h to fix header cycle.

This commit should will break libc++ without local submodule visibility, but
the LLVM+modules bots are now all using this mode. Before the Green Dragon
LLDB bot was failing to compile with a libc++ built with this commit as LSV
was disabled on macOS.

Original summary:

libc++ is careful to not fracture overload sets. When one overload
is visible to a user, all of them should be. Anything less causes
subtle bugs and ODR violations.

Previously, in order to support ::abs and ::div being supplied by
both <cmath> and <cstdlib> we had to do awful things that make
<math.h> and <stdlib.h> have header cycles and be non-modular.
This really breaks with modules.

Specifically the problem was that in C++ ::abs introduces overloads
for floating point numbers, these overloads forward to ::fabs,
which are defined in math.h. Therefore ::abs needed to be in math.h
too. But this required stdlib.h to include math.h and math.h to
include stdlib.h.

To avoid these problems the definitions have been moved to stddef.h
(which math includes), and the floating point overloads of ::abs
have been changed to call __builtin_fabs, which both Clang and GCC
support.
libcxx/include/math.h
libcxx/include/stdlib.h