Commit Graph

4032 Commits

Author SHA1 Message Date
Michael Jones
ed5cd8d464 [libc] Fix casts for arm32 after Wconversion (#129771)
Followup to #127523

There were some test failures on arm32 after enabling Wconversion. There
were some tests that were failing due to missing casts. Also I changed
BigInt's `safe_get_at` back to being signed since it needed the ability
to be negative.
2025-03-04 14:32:36 -08:00
Jorge Gorbe Moya
f9a6ea4489 [libc][bazel] Add BUILD targets for complex functions and tests. (#129618)
This involved a little bit of yak shaving because one of the new tests
depends on MPC, and we didn't have targets for it yet, so I ended up
needing to add a similar setup to what we have for MPFR.
2025-03-04 11:05:01 -08:00
Vinay Deshmukh
1e6e845d49 [libc] Enable -Wconversion for tests. (#127523)
Relates to: #119281
2025-03-04 10:24:35 -05:00
Dmitri Gribenko
9084d2a0a1 [libc] Add a missing include
This is a fixup for
da6d5fa79a.
2025-03-04 08:54:46 +01:00
OverMighty
d9ac5d0be6 [libc][docs] Add links to Peter Smith's FOSDEM 2025 talk (#129555) 2025-03-03 19:15:21 +01:00
Lukas Bergdoll
da6d5fa79a Add missing LIBC_INLINE to qsort_pivot.h (#126249)
Fixes #111495
2025-03-03 10:33:02 -05:00
Jorge Gorbe Moya
620953328d [libc] Fix warning in libc/utils/MPCWrapper/MPCUtils.h (#129349)
`cpp::is_complex_type_same<T1, T2>` is a function, so we need
parentheses in order to call it. Otherwise the expression is treated
like a function pointer which is always true in this boolean context.
2025-02-28 22:40:43 -05:00
Tristan Ross
9b6d0d7660 [libc] Add UEFI headers (#127126)
Originated from #120687

This PR simply adds the necessary headers for UEFI which defines all the
necessary types. This PR unlocks the ability to work on other PR's for
UEFI support.
2025-02-28 11:43:33 -05:00
PiJoules
7842954b9d [stdfix] Update function names (#129129)
The remaining math functions are `mulifx` (int * fx = int), `divifx`
(int / fx = int), `fxdivi` (int / int = fx), and `idivfx` (fx / fx =
int).
2025-02-27 13:51:37 -08:00
Michael Jones
64ae0a102f [libc] implement l64a (#129099)
Adds l64a, which generates the base 64 string expected by a64l.
2025-02-27 12:48:39 -08:00
PiJoules
9a32af25b4 [stdfix] Check fxbits as complete (#129107)
These were added in https://github.com/llvm/llvm-project/pull/114912 by
@smallp-o-p.
2025-02-27 12:04:06 -08:00
lntue
4fd762caa6 [libc] Fix sqrtf128 smoke test for riscv32. (#129094) 2025-02-27 13:55:22 -05:00
Krishna Pandey
f6bfa33cdb [libc][stdfix] Implement fixed point bitsfx functions in llvm libc (#128413)
Fixes #113359

---------

Signed-off-by: krishna2803 <kpandey81930@gmail.com>
2025-02-27 13:05:27 -05:00
Alexey Samsonov
829e2a5526 [libc][hdrgen] Allow to treat hdrgen Python code as a Python module. (#128955)
Move the hdrgen code under a subdirectory to treat it as a Python
module.

This mimics the structure used by llvm/utils/lit and
llvm/utils/mlgo-utils and simplifies integration of hdrgen to the build
system which rely on Python modules. In addition to that, it clarifies
which imports are coming from the hdrgen-specific helpers (e.g. "from
type import ..." becomes "from hdrgen.type import ...".

Leave the entrypoints (top-level main.py and yaml_to_classes.py) as-is:
they can keep being referred by the CMake build system w/o any changes.
2025-02-26 15:41:30 -08:00
Michael Jones
8beec9fc48 [libc] implement a64l (#128758)
Implement the posix function a64l.
Standard:
https://pubs.opengroup.org/onlinepubs/9799919799/functions/a64l.html
2025-02-25 13:57:13 -08:00
Michael Jones
f4a80180f1 [libc] Move fileno and fdopen to fullbuild only (#128762)
Both fileno and fdopen require interfacing with the opaque FILE struct,
so they shouldn't be enabled in overlay mode. This patch moves both into
fullbuild only on all platforms.

Fixes #128643
2025-02-25 13:56:20 -08:00
Alexey Samsonov
ab0e6fcaad [libc][cmake] Clean up dead code in add_gen_header (#128753)
DATA_FILES CMake argument never existed in the new YAML-based hdrgen
version of add_gen_header function, and thus its uses added in
b1fd6f0996 were always dead code.

Remove them to clean up the function implementation.

Co-authored-by: Alexey Samsonov <samsonov@google.com>
2025-02-25 10:58:44 -08:00
Joseph Huber
089f988f46 [libc] Fix defaulting the full build
Summary:
This was missing the architecture macros as they were defined just
below.
2025-02-25 07:27:23 -06:00
Joseph Huber
eabe2eb933 [libc] Remove special full build handling for GPU (#128572)
Summary:
Currently we default to non-fullbuild for all targets, but realistically
we should do this depending on the target OS. Some OS's like the GPU or
upcoming UEFI have no existing hosted system, so they cannot be built
with an overlay build. These are already errors so there's no reason to
complicate things and require passing it in through the runtimes build.
2025-02-24 15:49:17 -06:00
Joseph Huber
9bfe48695e [libc] Initial support for parsing SPIR-V for GPU libc (#128570)
Summary:
Some day we'd like to support this, add some initial support for parsing
the triple so it will at least attempt to build.
2025-02-24 15:18:53 -06:00
wldfngrs
3e284554a8 [libc][math][c23] Add acosf16() function (#127731)
- Implementation of acosf16 (inverse cosine) function for 16-bit inputs.
- Exhaustive tests across the 16-bit input range.
2025-02-23 19:46:46 +01:00
lntue
8ea6b735a6 [libc] Fix alignment issue for HermeticTestUtils.cpp. (#128426)
Full build precommit bots were failing due to mis-alignment of atomics
in hermetic tests. This PR enforces the alignment for the bump allocator
of hermetic test framework.

Fixes https://github.com/llvm/llvm-project/issues/128185.
2025-02-23 13:41:51 -05:00
Joseph Huber
559cb6ba63 [libc] Fix scanf dependencies on the GPU build
Summary:
The GPU build doesn't have `file` as a struct but does use these
targets. We need to add an escape for this.
2025-02-22 13:14:20 -06:00
Joseph Huber
6b3e7657cf [libc] Enable 'strftime' for the GPU targets (#128220)
Summary:
These should allow us to build with locale support for libcxx.
2025-02-21 16:29:15 -06:00
Michael Jones
3fad640f06 [libc] Skip scanf internals when no file available (#128097)
A temporary fix based on discussions in #128079

Currently, baremetal targets are failing to build because the scanf
internals require FILE* (either from the system's libc or our libc).
Normally we'd just turn off the broken entrypoint, but since the scanf
internals are built separately that doesn't work. This patch adds extra
conditions to building those internals, which we can hopefully remove
once we have a proper way to build scanf for embedded.
2025-02-21 12:26:23 -08:00
Petr Hosek
00637b7dfb [libc] Add strftime_l (#127767)
This is a (no-op) locale version of strftime.

Fixes: https://github.com/llvm/llvm-project/issues/106630
2025-02-21 10:50:32 -08:00
Alexey Samsonov
ad0c7da953 [libc] Add missing stdc_first_trailing_zero_ to stdbit.yaml (#128101)
These declarations were missing in the generated header. Make sure to
add them, otherwise <stdbit.h> inclusion fails, since the subsequently
included "stdbit-macros.h" expects these declarations to be present.

Co-authored-by: Alexey Samsonov <samsonov@google.com>
2025-02-21 08:24:59 -08:00
Michael Jones
5981335d75 [libc] Fix scanf cmake for targets without FILE (#128056)
Another followup fix to #121215

The new cmake wouldn't define the readerat all if the target wasn't GPU
or didn't have a definition of FILE. This patch rewrites the cmake to be
more general.

As a followup, I'd like to make `use_system_file` consistent between
/test and /src. Currently in /src it includes the `COMPILE_OPTIONS` and
in /test it does not.
2025-02-20 13:47:45 -08:00
Joseph Huber
d1dde17ab0 [libc] Fix failing NVPTX tests due to removed internal LLVM option
Summary:
This was removed but forgot to remove it in this one place. So it
errors.
2025-02-20 15:23:40 -06:00
Joseph Huber
87bf23216f [libc] Add missing dependencies on getc and ungetc for GPU (#128069)
Summary:
These are required because we don't use the `file` interface.
2025-02-20 15:11:37 -06:00
Michael Jones
b10ddfafca [libc] Fix missing includes in GPU scanf reader (#128049)
In #121215 the reader was reorganized and the definitions of the
internal getc and ungetc functions were moved, but the includes that the
GPU builder depends on were not. This patch moves the includes to the
correct new place.
2025-02-20 10:55:40 -08:00
Vinay Deshmukh
00f5aaf841 [libc]: Clean up unnecessary function pointers in scanf (#121215)
Resolves #115394

1. Move definitions of cross-platform `getc` `ungetc` to `reader.h`.
2. Remove function pointer members to define them once per platform in
`.h`
3. Built in overlay mode in macOS m1
4. Remove `reader.cpp` as it's empty now


Also, full build doesn't yet build on macos m1 AFAIK
2025-02-20 10:08:26 -08:00
Roland McGrath
86f0e6dc11 [libc] Add --json mode for hdrgen (#127847)
This adds a feature to hdrgen to emit JSON summaries of header
files for build system integration.  For now the summaries have
only the basic information about each header that is relevant for
build and testing purposes: the standards and includes lists.
2025-02-19 16:07:45 -08:00
Joseph Huber
6cc7ca084a [Clang] Fix cross-lane scan when given divergent lanes (#127703)
Summary:
The scan operation implemented here only works if there are contiguous
ones in the executation mask that can be used to propagate the result.
There are two solutions to this, one is to enter 'whole-wave-mode' and
forcibly turn them back on, or to do this serially. This implementation
does the latter because it's more portable, but checks to see if the
parallel fast-path is applicable.

Needs to be backported for correct behavior and because it fixes a
failing libc test.
2025-02-19 16:46:59 -06:00
Zaky Hermawan
ef49760fa9 [libc][POSIX][unistd] implement getsid (#127341)
Fixes https://github.com/llvm/llvm-project/issues/126603

---------

Signed-off-by: ZakyHermawan <zaky.hermawan9615@gmail.com>
2025-02-19 14:26:18 -08:00
c8ef
826af1757c [libc] add LLVM_LIBC_CAST macro. (#127319)
related: #127238

This patch adds a macro called `LLVM_LIBC_CAST`, similar to
`__BIONIC_CAST`, for type conversion in `endian.h`.
2025-02-19 23:28:11 +08:00
Fabian Ritter
a2f9ae1421 [AMDGPU] Replace gfx940 and gfx941 with gfx942 in offload and libclc (#125826)
gfx940 and gfx941 are no longer supported. This is one of a series of
PRs to remove them from the code base.

For SWDEV-512631 and SWDEV-512633
2025-02-19 09:56:04 +01:00
Petr Hosek
a2b4d4e756 Revert "[libc] Add strftime_l" (#127766)
Reverts llvm/llvm-project#127708
2025-02-19 00:39:33 -08:00
Petr Hosek
9072ba71ca [libc] Add strftime_l (#127708)
This is a (no-op) locale version of strftime.
2025-02-18 23:54:45 -08:00
Roland McGrath
8fe290efa6 [libc] Canonicalize generated fenv.h (#127363)
This removes the custom template for fenv.h by declaring all the
standard-specified macros using macro_header.
2025-02-17 17:06:59 -08:00
Joseph Huber
9a584b07d7 [Clang] Add handlers for 'match_any' and 'match_all' to gpuintrin.h (#127504)
Summary:
These helpers are very useful but currently absent. They allow the user
to get a bitmask representing the matches within the warp. I have made
an executive decision to drop the `predicate` return from `match_all`
because it's easily testable with `match_all() == __activemask()`.
2025-02-17 14:06:24 -06:00
Joseph Huber
0d2722c20d [libc][Docs] Add proper 'offload' build to use libc with offload
Summary:
Since this was added the offloading target now requires `offload`.

Fixes: https://github.com/llvm/llvm-project/issues/127458
2025-02-17 12:42:37 -06:00
Roland McGrath
2157aecfe4 [libc] Produce standard-compliant header guard macros in hdrgen (#127356)
Macros starting with alphabetic characters such as "LLVM" are in
the application name space and cannot be defined or used by a
conforming implementation's headers.  This fixes the headers that
are entirely generated, and the __llvm-libc-common.h header to
use a conforming macro name for the header guard.  That is, it
starts with "_LLVM_LIBC_" instead of "LLVM_LIBC_", as identifiers
starting with an underscore followed by a capital letter are in
the name space reserved for the implementation.

The remaining headers either will be fixed implicitly by removal
of their custom template files, or will need to be fixed by hand.
2025-02-15 17:36:44 -08:00
Roland McGrath
ed48398431 [libc] Fill out generated malloc.h and related stdlib.h extensions (#127293)
This updates the generated stdlib.h and malloc.h headers to
include the subsets of extenion functions declared by glibc that
are also supported by Scudo and that use only simple types.
Scudo's extensions not declared by glibc are omitted.  glibc's
extensions not implemented by Scudo are omitted.  The mallinfo
and mallinfo2 functions are omitted (at least for now) since they
need struct definitions for their return types.
2025-02-15 16:32:30 -08:00
lntue
70b95ca6db [libc][math] Fix sqrtf128 implicit conversions. (#127154)
This fixes rv32 buildbot failure from
https://github.com/llvm/llvm-project/pull/122578
2025-02-15 05:11:54 -05:00
Roland McGrath
68a82a2298 [libc] Elide extra space in hdrgen function declarations (#127287)
When the return type's rendering already doesn't end with an
identifier character, such as when it's `T *`, then idiomatic
syntax does not include a space before the `(` and arguments.
2025-02-14 17:09:58 -08:00
Roland McGrath
625cb5a185 [libc] Share hdrgen declarations between stdlib.h and malloc.h (#127278)
This uses the new merge_yaml_files feature in hdrgen to share the
source of truth for the malloc suite of functions declared in
both stdlib.h and in malloc.h (without either header including
the other).  It also modernizes the malloc.yaml definition a bit,
including dropping the custom template malloc.h.def file in favor
of using the explicit macros list to generate the includes.
2025-02-14 16:46:56 -08:00
Michael Jones
60af83506a [libc] Fix implicit cast warning in strftime (#127282)
Forgot to change a size_t to an int, which caused warnings on gcc but
not clang for some reason. Regardless, this patch fixes the issue.
2025-02-14 16:06:02 -08:00
Michael Jones
398f865499 [libc] Implement strftime (#122556)
Implements the posix-specified strftime conversions for the default
locale, along with comprehensive unit tests. This reuses a lot of design
from printf, as well as the printf writer.

Roughly based on #111305, but with major rewrites.
2025-02-14 15:56:55 -08:00
Roland McGrath
9f6e72bd0c [libc] Add merge_yaml_files feature to hdrgen (#127269)
This allows a sort of "include" mechanism in the YAML files.  A
file can have a "merge_yaml_files" list of paths (relative to the
containing file's location).  These are YAML files in the same
syntax, except they cannot have their own "header" entry.  Only
the lists (types, enums, macros, functions, objects) can appear.
The main YAML file is then processed just as if each of its lists
were the (sorted) union of each YAML file's corresponding list.

This will enable maintaining a single source of truth for each
function signature and other such details, where it is necessary
to generate the same declaration in more than one header.
2025-02-14 15:34:40 -08:00