18 Commits

Author SHA1 Message Date
William Huynh
0c622d72fc
[libc] Add _Returns_twice to C++ code (#153602)
Fixes issue with `<csetjmp>` which requires `_Returns_twice` but in C++
mode
2025-08-19 09:28:23 +01: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
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
Petr Hosek
b0d7820805
[libc] Move __LLVM_LIBC__ define to __llvm-libc-common.h (#126877)
Relying on features.h is problematic since codebases are free to have
such a header on their search path, which breaks compilation. libc
should instead provide a more standard way of getting __LLVM_LIBC__.
Since __llvm-libc-common.h is included from all libc headers, defining
__LLVM_LIBC__ there ensures that this define is available whenever any
of the standard header is included.
2025-02-12 11:37:07 -08:00
Alan Zhao
fd4c4ed712
[libc] Add returns_twice attribute to setjmp(3) (#124370)
This is to ensure that calls to `setjmp(3)` result in correct code
generation that respects `setjmp(3)`'s `returns_twice` behavior.
Otherwise, we might run into bugs (for example, Clang may perform
tail-call optimization on this function if `-fno-builtins` is set
(#122840)).

---------

Co-authored-by: Nick Desaulniers <nick.desaulniers@gmail.com>
2025-02-05 14:37:03 -08:00
Roland McGrath
a4e87da963
[libc] Make headers compatible with C++ < 11 (#123260)
C++11 introduced `noexcept`, but `throw()` can be used in older
versions of the language.
2025-01-16 19:21:40 -08:00
Roland McGrath
ce33a48efd
[libc] Keep headers compatible with -std=c89 mode (#121981)
C89 doesn't have the `restrict` keyword.  When in `-std=c89`
mode, GNU-compatible compilers require the `__restrict` spelling.
2025-01-07 12:13:24 -08:00
Roland McGrath
4010e0c45b
[libc] Use __attribute__((__noreturn__)) for _Noreturn in C < 11 (#121252)
When in modes like C99, the _Noreturn keyword is not available in
C.  But GNU-compatible compilers have a `noreturn` attribute with
the same effect on function declarations.
2025-01-02 16:57:31 -08:00
Roland McGrath
0b91d77bf4
[libc] Use __attribute__((__nothrow__)) for __NOEXCEPT in C (#114653)
Consistent with glibc headers, where `noexcept` is used in C++
(or `throw()` in older C++ which llvm-libc doesn't support) in
the public function declarations, `__attribute__((__nothrow__))` is
used in C for compilers that support it.
2024-12-17 12:18:37 -08:00
Roland McGrath
1c602c5fe5
[libc] Define away __restrict in C++ without GNU extensions (#114655)
The C99 restrict keyword is spelled __restrict in the libc
headers so it can be parsed by C++ compilers with GNU extensions
that recognize it.  When GNU extensions are not available in C++
2024-11-04 11:23:27 -08: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
Michael Jones
9b8a64b88d [libc] add noexcept to external function headers
To improve code generation for C++ code that directly includes our
headers, the external function definitions will now be marked noexcept.
This may not be necessary for the internal definitions since we build
with the -fno-exceptions flag.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D141095
2023-01-06 11:43:43 -08:00
Siva Chandra Reddy
dd33f9cdef [libc] Make the errno macro resolve to the thread local variable directly.
With modern architectures having a thread pointer and language supporting
thread locals, there is no reason to use a function intermediary to access
the thread local errno value.

The entrypoint corresponding to errno has been replaced with an object
library as there is no formal entrypoint for errno anymore.

Reviewed By: jeffbailey, michaelrj

Differential Revision: https://reviews.llvm.org/D120920
2022-03-04 17:29:49 +00:00
Siva Chandra Reddy
32a50c6b93 [libc][NFC] Add a static assert for futex size. 2022-03-01 22:56:56 +00:00
Siva Chandra Reddy
1137255585 [libc] Add a class "Atomic" as a simple equivalent of std::atomic.
Only the methods currently required by the libc have been added.
Most of the existing uses of atomic operations have been switched over
to this new class. A future change will clean up the rest of uses.

This change now allows building mutex and condition variable code with a
C++ compiler which does not have stdatomic.h, for example g++.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D120642
2022-02-28 23:51:44 +00:00
Paula Toth
66d00feb18 [libc][NFC] Make all top of file comments consistent.
Summary:
Made all header files consistent based of this documentation: https://llvm.org/docs/CodingStandards.html#file-headers.
And did the same for all source files top of file comments.

Reviewers: sivachandra, abrachet

Reviewed By: sivachandra, abrachet

Subscribers: MaskRay, tschuett, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D77533
2020-04-08 10:18:37 -07:00
Alex Brachet
a499d68056 [libc] Create abort and _Exit
This revision creates abort and _Exit implementations

Differential Revision: https://reviews.llvm.org/D74949
2020-03-05 14:21:18 -05:00
Siva Chandra
4380647e79 Add few docs and implementation of strcpy and strcat.
Summary:
This patch illustrates some of the features like modularity we want
in the new libc. Few other ideas like different kinds of testing, redirectors
etc are not yet present.

Reviewers: dlj, hfinkel, theraven, jfb, alexshap, jdoerfert

Subscribers: mgorny, dexonsmith, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D67867

llvm-svn: 373764
2019-10-04 17:30:54 +00:00