[libcxx-commits] [PATCH] D138629: [libc++][math.h] Add double overloads

Aaron Ballman via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Nov 28 11:38:49 PST 2022


aaron.ballman added a comment.

In D138629#3949782 <https://reviews.llvm.org/D138629#3949782>, @ldionne wrote:

> 3. Why are builtins that are not reserved identifiers (e.g. `cos`, `sin`) disabled in freestanding mode? I'm asking generally, I know `cmath` is not part of Freestanding per se.

The user expectation is that freestanding mode is the minimal set of library facilities required by the language, so if the language doesn't require `cos`, then that identifier needs to remain available for the user to use for their own purposes. Sometimes this is so they can make their own replacement for whatever funky hardware they're on, but sometimes it's because the standard steals general purpose identifiers like `tan` (color name), `floor` (a noun), and `f16subf32` (er...).

> 4. More generally speaking, what's the purpose of `-fno-builtins`?

To disable all builtins regardless of whether you're in freestanding mode or not. Sometimes the builtins do things you don't want them to do and so you want to disable them (perhaps you don't like the behavior of `__builtin_memcpy` for some reason), and sometimes the builtins expose names you want to use (https://godbolt.org/z/cMxzojcr1).

> Sorry, this is kind of open-ended, but I feel like this is important to understand here.

No worries at all, these are great questions!

> Also, on a related but tangential note, @philnik and I were trying to wrap our heads around what's the purpose of compiler builtin headers. It looks like the order of includes in Clang (and GCC) is: C++ library headers > compiler builtin headers > C library headers. This is true on both Linux and Darwin, so it's not accidental, it's really by design. Now, some headers exist only in the builtin headers (e.g. `<stdbool.h>`), some only in the C library headers (e.g. `<stdio.h>`), and some in both (e.g. `<stdint.h>`). Can anyone shed light on the logic behind this?
>
> Is any of this documented anywhere?

I don't know if we document it anywhere, but my understanding of the situation is: there are headers the compiler has to provide because the compiler is the only thing that can implement it (think: `stdarg.h`), there are headers the compiler has to provide because they're in freestanding (think: `stdbool.h`), and finally there are all the rest of the headers which the compiler doesn't have to care about (think: `stdio.h`). Some header files do an `include_next` because the host header file may provide additional facilities (for example, `limits.h` may be extended by the POSIX headers).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138629/new/

https://reviews.llvm.org/D138629



More information about the libcxx-commits mailing list