Commit Graph

99 Commits

Author SHA1 Message Date
lntue
22b1f1bc69 [libc] Remove #ifdef __cplusplus part from include/llvm-libc-macros/math-macros.h. (#87864)
Now with the proxy header `hdr/math_macros.h`, the header
`include/llvm-libc-macros/math-macros.h` will not be included in overlay
mode, and the extra definitions for `__cplusplus` mode is not needed any
more.
2024-04-08 19:26:12 -04:00
lntue
5748ad84e5 [libc] Add proxy header math_macros.h. (#87598)
Context: https://github.com/llvm/llvm-project/pull/87017

- Add proxy header `libc/hdr/math_macros.h` that will:
  - include `<math.h>` in overlay mode,
- include `"include/llvm-libc-macros/math-macros.h"` in full build mode.
- Its corresponding CMake target `libc.hdr.math_macros` will only depend
on `libc.include.math` and `libc.include.llvm-libc-macros.math_macros`
in full build mode.
- Replace all `#include "include/llvm-libc-macros/math-macros.h"` with
`#include "hdr/math_macros.h"`.
- Add dependency to `libc.hdr.math_macros` CMake target when using
`add_fp_unittest`.
- Update the remaining dependency.
- Update bazel overlay: add `libc:hdr_math_macros` target, and replacing
all dependency on `libc:llvm_libc_macros_math_macros` with
`libc:hdr_math_macros`.
2024-04-05 18:21:16 -04: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
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
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
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
lntue
cf68c0427d [libc] Ignore -Winclude-next-absolute-path warning in float-macros.h (#83513) 2024-02-29 21:08:17 -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
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
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
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
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
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
Nick Desaulniers
5a7a8f73c7 [libc] fix type generic stdc_leading_zeros for GCC (#79917)
GCC does not support _Generic in C++ mode. Use inline function definitions with
function overloading in __cplusplus mode.
2024-01-29 16:40:03 -08:00
Nick Desaulniers
7bc5eaa02f [libc] implement stdc_leading_zeros_u* for stdbit.h (#79669)
- stdbit.stdc_leading_zeros_uc
- stdbit.stdc_leading_zeros_us
- stdbit.stdc_leading_zeros_ui
- stdbit.stdc_leading_zeros_ul
- stdbit.stdc_leading_zeros_ull

Test via:
$ ninja libc-stdbit-tests libc_include_tests
2024-01-29 15:47:55 -08:00
Schrodinger ZHU Yifan
2e1e27c7c3 [libc] adjust linux's mman.h definitions (#79652)
Use definitions from `<linux/mman.h>` to dispatch arch-specific flag
values.
For example, `MCL_CURRENT/MCL_FUTURE/MCL_ONFAULT` are different on
different architectures.
2024-01-26 19:29:28 -05: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
Petr Hosek
c0a74ad90c [libc] Use QUEUE_TYPEOF in STAILQ_LAST (#79011)
This is to ensure this macro is compatible with both C and C++.
2024-01-22 10:25:06 -08:00
lntue
ce8fcad5f4 [libc] Fix float.h header to include the system float.h first and add more definitions. (#78857) 2024-01-20 14:44:51 -05:00
lntue
c80d68a676 [libc] Add float.h header. (#78737) 2024-01-19 12:04:34 -05:00
Petr Hosek
dbc0955314 [libc] Provide sys/queue.h (#78081)
This header first appeared in 4.4BSD and is provided by a number of C
libraries including Newlib. Several of our embedded projects use this
header and so to make LLVM libc a drop-in replacement, we need to
provide it as well.

For the initial commit, we only implement singly linked variants (SLIST
and STAILQ). The doubly linked variants (LIST, TAILQ and CIRCLEQ) can be
implemented in the future as needed.
2024-01-18 21:45:58 -08:00
Nick Desaulniers
eaa11526c8 [libc] fix -Wmacro-redefined (#75261)
When building with compiler-rt enabled, warnings such as the following
are
observed:


llvm-project/llvm/build/projects/compiler-rt/../libc/include/llvm-libc-macros/linux/sys-stat-macros.h:46:9:
    warning: 'S_IXOTH' macro redefined [-Wmacro-redefined]
    #define S_IXOTH 00001
            ^

llvm-project/llvm/build/projects/compiler-rt/../libc/include/llvm-libc-macros/linux/fcntl-macros.h:61:9:
    note: previous definition is here
    #define S_IXOTH 01
            ^
It looks like we have these multiply defined. Deduplicate these flags;
users
should expect to find them in sys/stat.h. S_FIFO was wrong anyways
(should
have been S_IFIFO).
2023-12-13 08:39:39 -08:00
alfredfo
74b0465fe9 [libc] Add simple features.h with implementation macro (#69402)
In the future this should probably be autogenerated so it defines
library version.

See: Discussion in #libc
https://discord.com/channels/636084430946959380/636732994891284500/1163979080979460176
2023-10-19 04:08:13 +02:00
Jeff Bailey
c618e13161 [libc] Pull more definitions from linux/stat.h (#67071)
For file handling, we need more definitions from
linux/stat.h, so this pulls them in. It also adjusts other definitions
to match the kernel's exactly [NFC] so that it's easy to verify that
there's been no divergence one day when it's time to use linux/stat.h
directly.

Tested:
check-libc
2023-09-21 22:34:54 -07:00