434 Commits

Author SHA1 Message Date
Shourya Goel
9f0758405b
reland: [libc] Added transitive bindings for OffsetType (#87680)
Followup to issues addressed here: #87397
2024-04-05 12:11:44 -07:00
Michael Jones
5264c22ef1
[libc] Temporary math macros fix (#87681)
Downstream's having some issues due to math-macros.h issues. These will
be fixed properly soon.

See https://github.com/llvm/llvm-project/issues/87683 for tracking this
tech debt.
2024-04-04 14:28:56 -07:00
Gulfem Savrun Yeniceri
e8aaa3eaed Revert "[libc] Added transitive bindings for OffsetType (#87397)"
This reverts commit 3ee93f486293420852fb9ec95af9c5f54cecdb08
because it broke Fuchsia Clang toolchain builders:
https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8751633430491432833/+/u/clang/build/stdout
2024-04-04 04:12:36 +00:00
Shourya Goel
3ee93f4862
[libc] Added transitive bindings for OffsetType (#87397)
Adding OffTType to fcntl.h and stdio.h 's Macro lists in libc/spec/posix.td as
mentioned here: #87266
2024-04-03 14:16:57 -07:00
Joseph Huber
7327014b49
[libc] Implement temporary printf on the GPU (#85331)
Summary:
This patch adds a temporary implementation that uses a struct-based
interface in lieu of varargs support. Once varargs support exists we
will move this implementation to the "real" printf implementation.

Conceptually, this patch has the client copy over its format string and
arguments to the server. The server will then scan the format string
searching for any specifiers that are actually a string. If it is a
string then we will send the pointer back to the server to tell it to
copy it back. This copied value will then replace the pointer when the
final formatting is done.

This will require a built-in extension to the varargs support to get
access to the underlying struct. The varargs used on the GPU will simply
be a struct wrapped in a varargs ABI.
2024-04-02 16:25:18 -05:00
Michael Jones
d5f06342a3
[libc] add flag for FP_*LOGB0/NAN values (#86723)
These values vary by system, this flag allows you to toggle their value.
2024-03-27 15:09:57 -07:00
Schrodinger ZHU Yifan
05dc5d927b
[libc] add statvfs/fstatvfs (#86169)
fixes #86449
2024-03-25 13:37:50 -04:00
OverMighty
b282259711
[libc][math][c23] Add {,u}fromfp{,x}{,f,l,f128} functions (#86003)
Fixes #85279.

cc @lntue
2024-03-25 10:26:22 -04:00
Nick Desaulniers
cdbec7baf1
[libc] fix up the use of angle includes in include/ (#86027)
Performed en-masse via:

    $ grep -rn "#include <ll" libc/include -l | \
      xargs perl -pi -e 's/#include <ll(.*)>/#include "ll$1"/'
    $ grep -rn "#include <__" libc/include -l | \
      xargs perl -pi -e 's/#include <__(.*)>/#include "__$1"/'

Link: #83463
Link: #83210
2024-03-22 08:24:08 -07:00
Roland McGrath
c56211b243
[libc] Make math-macros.h C++-friendly (#86206)
The isfinite, isnan, and isinf "functions" are specified by C99..C23 to
be macros that act as type-generic functions. Defining them as their
__builtin_* counterparts works fine for this. However, in C++ the
identifiers need to be usable in different contexts, such as being
declared inside a C++ namespace. So define inline constexpr template
functions for them under `#ifdef __cplusplus`.
2024-03-21 18:11:31 -04:00
Petr Hosek
d6722bcbd6
[libc] Move EOF macro to stdio-macros.h (#85159)
libc++ char_traits.h assumes EOF is always available

See #85158 for more details.
2024-03-15 10:56:39 -07:00
Petr Hosek
e25bf70d50
[libc] Add an empty definition of mbstate_t (#84993)
We expect to eventually provide a complete implementation, but having an
empty definition is necessary to unblock the use of libc++ in embedded
environments.

See #84884 for more details.
2024-03-12 21:26:58 -07:00
Petr Hosek
bb5921e2a2
[libc] Include FP_* macros in math.h (#84996)
These are used unconditionally by libc++ math.h.

This is related to issue #84879.
2024-03-12 17:01:29 -07:00
Nick Desaulniers
f0c0ddae45
[libc] implement the final macros for stdbit.h support (#84798)
Relevant sections of n3096:
- 7.18.1p1
- 7.18.2
2024-03-12 08:39:17 -07:00
Michael Flanders
75b0d384fb
[libc][stdbit][c23] adds implementation of stdc_bit_ceil functions (#84657)
Closes #84652.

Based on #84233.
2024-03-10 12:53:28 -04:00
Michael Flanders
35b784379e
[libc][stdbit][c23] fixes typos in bit_width, bit_floor C type-generic macros (#84659)
Fixes #84658.

Assuming these were typos in the first place.

I am unsure of the best way to ensure that both sides of the
preprocessor condition in
`libc/include/llvm-libc-macros/stdbit-macros.h` are tested. Could
someone point me in the right direction for adding test coverage to the
non `__cplusplus` branch? Or maybe it is being tested and I've missed
it.
2024-03-10 01:46:39 -05:00
Schrodinger ZHU Yifan
29afd64615
[libc][c23] make inttypes.h compat with c23 (#84493) 2024-03-08 10:36:22 -05:00
Nick Desaulniers
101a13df71
[libc][stdbit] implement stdc_bit_floor (C23) (#84233) 2024-03-07 08:38:04 -08:00
Nick Desaulniers
041638c429
[libc][stdbit] implement stdc_bit_width (C23) (#83892) 2024-03-05 09:49:41 -08:00
Joseph Huber
c996023f9a
[libc] Provide an implementation of the 'stdint.h' header (#83353)
Summary:
I've noticed one problem is that the user includes `stdint.h` the
compiler will do `#include_next <stdint.h>` potentially into a
conflicting implementation on systems with multiple headers installed.
The `clang` header is standards compliant and works with `clang` and
`gcc` which are both of our targets, so I simply copied it here. This
has the effect of including `stdint.h` on clang / LLVM libc behaving the
same as `-ffreestanding`.
2024-03-04 12:23:11 -06:00
Guillaume Chatelet
07f8efa22e
[libc][NFC] Don't expose how float16 and float128 types are provided (#83818)
Umbrella bug #83182
2024-03-04 15:55:01 +01:00
lntue
cf68c0427d
[libc] Ignore -Winclude-next-absolute-path warning in float-macros.h (#83513) 2024-02-29 21:08:17 -05:00
lntue
73aab2f697
[libc] Revert https://github.com/llvm/llvm-project/pull/83199 since it broke Fuchsia. (#83374)
With some header fix forward for GPU builds.
2024-02-29 14:43:53 -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
Joseph Huber
04e8653f18
[libc] Add "include/" to the LLVM include directories (#83199)
Summary:
Recent changes added an include path in the float128 type that used the
internal `libc` path to find the macro. This doesn't work once it's
installed because we need to search from the root of the install dir.
This patch adds "include/" to the include path so that our inclusion
of installed headers always match the internal use.
2024-02-27 17:45:15 -06:00
Nick Desaulniers
06bcd9da16
[libc][stdbit] implement stdc_has_single_bit (C23) (#83168) 2024-02-27 13:45:37 -08:00
Joseph Huber
fd42044649
[libc] Re-Enable GPU tests and fix math exception handling (#83172)
Summary:
A lot of these tests failed previously and were disabled. However we
have fixed some things since then and many of these seem to pass.
Additionally, the last remaining math tests that failed seemed to be due
to the exception handling. For now we just set it to be 'errno'.

These pass locally when tested on a gfx1030, gfx90a, and sm_89
architecture. Hopefully these pass correctly on the sm_60 bot as I've
had things fail on that one only before.
2024-02-27 13:51:01 -06:00
lntue
aa95aa69b9
[libc][math][c23] Add C23 math functions ilogbf128, logbf128, and llogb(f|l|f128). (#82144) 2024-02-27 12:23:19 -05:00
Nick Desaulniers
d8406d48a8
[libc][stdbit] implement stdc_count_ones (C23) (#82444) 2024-02-26 09:25:24 -08:00
Nick Desaulniers
f70d5c0bc8
[libc][stdbit] implement stdc_count_zeros (C23) (#82437) 2024-02-26 09:23:15 -08:00
Joseph Huber
69c0b2febe
[libc][NFC] Remove all trailing spaces from libc (#82831)
Summary:
There are a lot of random training spaces on various lines. This patch
just got rid of all of them with `sed 's/\ \+$//g'.
2024-02-23 16:34:00 -06:00
Petr Hosek
5bd0c44bd0
[libc] Match the names of BSD sys/queue.h member names (#82696)
While these names are technically internal implemenetation detail,
there's an existing code which relies on these details and using
different names makes LLVM libc implementation incompatible. Since our
goal is for LLVM libc to be a drop in replacement, use the same name as
BSD sys/queue.h version.
2024-02-22 15:22:49 -08:00
Joseph Huber
47b7c91abe
[libc] Rework the GPU build to be a regular target (#81921)
Summary:
This is a massive patch because it reworks the entire build and
everything that depends on it. This is not split up because various bots
would fail otherwise. I will attempt to describe the necessary changes
here.

This patch completely reworks how the GPU build is built and targeted.
Previously, we used a standard runtimes build and handled both NVPTX and
AMDGPU in a single build via multi-targeting. This added a lot of
divergence in the build system and prevented us from doing various
things like building for the CPU / GPU at the same time, or exporting
the startup libraries or running tests without a full rebuild.

The new appraoch is to handle the GPU builds as strict cross-compiling
runtimes. The first step required
https://github.com/llvm/llvm-project/pull/81557 to allow the `LIBC`
target to build for the GPU without touching the other targets. This
means that the GPU uses all the same handling as the other builds in
`libc`.

The new expected way to build the GPU libc is with
`LLVM_LIBC_RUNTIME_TARGETS=amdgcn-amd-amdhsa;nvptx64-nvidia-cuda`.

The second step was reworking how we generated the embedded GPU library
by moving it into the library install step. Where we previously had one
`libcgpu.a` we now have `libcgpu-amdgpu.a` and `libcgpu-nvptx.a`. This
patch includes the necessary clang / OpenMP changes to make that not
break the bots when this lands.

We unfortunately still require that the NVPTX target has an `internal`
target for tests. This is because the NVPTX target needs to do LTO for
the provided version (The offloading toolchain can handle it) but cannot
use it for the native toolchain which is used for making tests.

This approach is vastly superior in every way, allowing us to treat the
GPU as a standard cross-compiling target. We can now install the GPU
utilities to do things like use the offload tests and other fun things.

Some certain utilities need to be built with 
`--target=${LLVM_HOST_TRIPLE}` as well. I think this is a fine
workaround as we
will always assume that the GPU `libc` is a cross-build with a
functioning host.

Depends on https://github.com/llvm/llvm-project/pull/81557
2024-02-22 15:29:29 -06:00
Schrodinger ZHU Yifan
96c5b8cbd1
[libc][c23] add definitions for stdckdint.h (#82059)
See docs at
- https://gustedt.gitlabpages.inria.fr/c23-library/#stdckdint
- https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3047.pdf (Ch7.10)

Compiler header:
-
450462cbac/clang/lib/Headers/stdckdint.h
- New version of GCC
(cd503b0616/gcc/ginclude/stdckdint.h)
also provides this.
2024-02-20 11:20:15 -05:00
lntue
95e8a7c863
[libc][stdfix] Use __FRACT_FBIT__ for fixed point support detection instead of compiler version. (#81820)
Now that `__FRACT_FBIT__` and related macros are added in
https://github.com/llvm/llvm-project/pull/81207, it is safer to use them
for fixed point support detection, so that codes that do not use fixed
point types will not fail to build when `-ffixed-point` is missing.
2024-02-15 07:26:30 -06:00
lntue
1301bc46ae
[libc] Add is_fixed_point type trait. (#81263) 2024-02-14 14:44:09 -05:00
Nick Desaulniers
6297479ff0
[libc][stdbit] implement stdc_first_trailing_one (C23) (#81768) 2024-02-14 11:10:48 -08:00
Nick Desaulniers
16e7d6842e
[libc][stdbit] implement stdc_first_trailing_zero (C23) (#81526) 2024-02-14 10:34:28 -08:00
Nick Desaulniers
60596716c2
[libc][stdbit] implement stdc_first_leading_one (C23) (#81502) 2024-02-14 09:16:00 -08:00
lntue
84277fe90f
[libc][stdfix] Generate stdfix.h header with fixed point precision macros according to ISO/IEC TR 18037:2008 standard, and add fixed point type support detection. (#81255)
Fixed point extension standard:
https://standards.iso.org/ittf/PubliclyAvailableStandards/c051126_ISO_IEC_TR_18037_2008.zip
2024-02-13 16:48:14 -05:00
Nick Desaulniers
d2d6b368a1
[libc][stdbit] implement stdc_first_leading_zero (C23) (#81340) 2024-02-12 08:31:53 -08:00
lntue
fbf43b0121
[libc] Only declare float128 math functions in the generated math.h if float128 type is supported. (#81010) 2024-02-08 20:13:27 -05:00
Nick Desaulniers
7760006d8d
[libc][stdbit] implement stdc_trailing_ones (C23) (#80459) 2024-02-07 02:56:24 -08:00
Schrodinger ZHU Yifan
ca1da36aec
[libc] add inttypes macros (#80726)
Standard file:
https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/

Notice that we are not quite the same as other implementations:
1. MUSL: https://github.com/bminor/musl/blob/master/include/inttypes.h
2. GLIBC:
bbd248ac0d/stdlib/inttypes.h (L57)
3. CheriBSD:
698d1636dd/sys/arm64/include/_inttypes.h

fixes #80186
2024-02-06 09:35:56 -05:00
Nick Desaulniers
d5a3de4aee
[libc][stdbit] implement stdc_trailing_zeros (C23) (#80344) 2024-02-06 06:27:03 -08:00
lntue
d4ef4b8189
[libc] Fix generated float128 header for aarch64 target. (#78017) 2024-02-05 07:44:51 -05:00
Nick Desaulniers
edbd93d370
[libc][stdbit] fix return types (#80337)
All of the functions I've previously implemented return an unsigned int; not
the parameter type.
2024-02-01 13:09:33 -08:00
Nick Desaulniers
6a3fde6d60
[libc] implement stdc_leading_ones (C23) (#80082) 2024-02-01 10:14:22 -08:00
lntue
28699e3856
[libc] Update libc_errno to work correctly in both overlay and full build modes. (#80177) 2024-02-01 12:16:28 -05:00
michaelrj-google
9f3854a01f
[reland][libc] add epoll_wait functions (#79635)
The epoll_wait functions are syscall wrappers that were requested by
upstream users. This patch adds them, as well as their header and types.

The tests are currently incomplete since they require epoll_create to
properly test epoll_wait. That will be added in a followup patch since
this one is already very large.
2024-01-30 10:07:47 -08:00