[all-commits] [llvm/llvm-project] c490c5: Reland [libc++] Move abs and div into stdlib.h to ...

Eric via All-commits all-commits at lists.llvm.org
Fri May 8 12:54:45 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: c490c5e81ac90cbf079c7cee18cd56171f1e27af
      https://github.com/llvm/llvm-project/commit/c490c5e81ac90cbf079c7cee18cd56171f1e27af
  Author: Eric Fiselier <eric at efcs.ca>
  Date:   2020-05-08 (Fri, 08 May 2020)

  Changed paths:
    M libcxx/include/math.h
    M libcxx/include/stdlib.h

  Log Message:
  -----------
  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.




More information about the All-commits mailing list