11 Commits

Author SHA1 Message Date
Joseph Huber
b209eda621
[libc] Define MB_LEN_MAX in limits.h (#102246)
Summary:
This is supposed to define the maximum bytes required to store a char in
any locale. There's some question about what this should be set to. I
believe because the proposed solution for `locale.h` is to only support
the default locale, we should do what `musl` does and set it to `4`
which covers up to UTF-32.

Fixes https://github.com/llvm/llvm-project/issues/79358
2024-08-07 07:59:44 -05:00
Nhat Nguyen
7f3c40a661
[libc] implement pathconf/fpathconf (#87165) 2024-07-07 11:20:49 -07:00
Joseph Huber
d6bbe2e20f
[libc] Fix definition of UINT_MAX in limits.h (#95279)
Summary:
Currently we use `(~0U)` for this definition, however the ~ operator
returns a different sign, meaning that preprocessor checks against this
value will fail. See https://godbolt.org/z/TrjaY1d8q where the
preprocessor thinks that it's not `0xffffffff` while the static
assertion thinks it is. This is because the latter does implicit
conversion but the preprocessor does not. This is now consistent with
other headers.
2024-06-12 15:29:10 -05:00
Nick Desaulniers
330793c91d
[libc] fix clang-tidy llvm-header-guard warnings (#82679)
Towards the goal of getting `ninja libc-lint` back to green, fix the numerous
instances of:

    warning: header guard does not follow preferred style [llvm-header-guard]

This is because many of our header guards start with `__LLVM` rather than
`LLVM`.

To filter just these warnings:

    $ ninja -k2000 libc-lint 2>&1 | grep llvm-header-guard

To automatically apply fixits:

    $ find libc/src libc/include libc/test -name \*.h | \
        xargs -n1 -I {} clang-tidy {} -p build/compile_commands.json \
        -checks='-*,llvm-header-guard' --fix --quiet

Some manual cleanup is still necessary as headers that were missing header
guards outright will have them inserted before the license block (we prefer
them after).
2024-02-28 12:53:56 -08:00
lntue
e9355b1b3e
[libc] Use __SIZEOF_LONG__ to define LONG_WIDTH instead of sizeof(long). (#79391)
The standard requires `limits.h` constants to be used in preprocessors.
So we use `__SIZEOF_LONG__` instead of `sizeof(long)` to define
`LONG_WIDTH`. The macro `__SIZEOF_LONG__` seems to be available on both
clang and gcc since at least version 9.
2024-01-24 20:02:03 -05:00
lntue
3a92b20cb0
[libc] Add backup definition for LONG_WIDTH in limits-macros.h. (#79375) 2024-01-24 17:04:11 -05:00
lntue
72ce629415
[libc] Add C23 limits.h header. (#78887) 2024-01-24 16:08:56 -05:00
Alfred Persson Forsberg
d3e045934a
Revert "[libc] Add limits.h"
limits.h currently interferes with Clang's limits.h. include_next
emits a warning because it is a GNU extension. Will re add this once
we figure out a good solution.

This reverts commits 13bbca8d694b4ef2ad03ec1805f07da8640c1a31,
002cba03298a7e8f0c1cadcb7996379e9ea5feff, and
0fb3066873fdfbe28dbb6409c58a8bff7cf208c6.
2023-08-17 06:21:50 +02:00
Alfred Persson Forsberg
13bbca8d69
[libc] [NFC] explain compiler macros in limits.h
Differential Revision: https://reviews.llvm.org/D158128
2023-08-17 01:23:30 +02:00
Alfred Persson Forsberg
002cba0329 [libc] limits.h: include compiler limits if not already included
The LLVM-libc build itself will override include paths and prefer it's
own limits.h over the compiler's limits.h. Because we rely on the
compiler limits.h for numerical limits in LLVM-libc it needs to be
include_next:ed if not already included. The other method to work
around this is to define all numeric macros in place.

Signed-off-by: Alfred Persson Forsberg <cat@catcream.org>

Reviewed By: thesamesam

Differential Revision: https://reviews.llvm.org/D158040
2023-08-16 02:59:21 +01:00
Alfred Persson Forsberg
0fb3066873 [libc] Add limits.h
This header contains implementation specific constants.

The compiler already provides its own limits.h with numerical limits
conforming to freestanding ISO C. But it is missing extensions like
POSIX, and does for example not include <linux/limits.h> which is
expected on a Linux system, therefore, an LLVM libc implementation of
limits.h is needed for hosted (__STDC_HOSTED__) environments.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D156961
2023-08-14 01:35:44 +01:00