79 Commits

Author SHA1 Message Date
Joseph Huber
db6b7a84e6
[libc][NFC] Strip all training whitespace and missing newlines (#124163) 2025-01-23 12:02:54 -06:00
Lukas Bergdoll
a738d81cd2
[libc] Improve qsort (with build fix) (#121482) 2025-01-05 06:10:41 +08:00
Petr Hosek
51a0919412
[libc] Exclude FreeListHeap test and fuzzer on GPU (#120137)
FreeListHeap uses the _end symbol which conflicts with the _end symbol
defined by GPU start.cpp files so for now we exclude the test and the
fuzzer on GPU.
2024-12-16 13:28:42 -08:00
Petr Hosek
7bf3137c39
[libc] Breakup freelist_malloc into separate files (#119806)
This better matches the structure we use for the rest of libc.
2024-12-16 10:30:27 -08:00
Nick Desaulniers
431ea2d076
[libc] move bcmp, bzero, bcopy, index, rindex, strcasecmp, strncasecmp to strings.h (#118899)
docgen relies on the convention that we have a file foo.cpp in
libc/src/\<header\>/. Because the above functions weren't in libc/src/strings/
but rather libc/src/string/, docgen could not find that we had implemented
these.

Rather than add special carve outs to docgen, let's fix up our sources for
these 7 functions to stick with the existing conventions the rest of the
codebase follows.

Link: #118860
Fixes: #118875
2024-12-10 08:58:45 -08:00
Chuvak
3709c2d15a
[libc] Fix wrong name in Compare.h (#117223)
Fix for some mistakes in source code found using PVS Studio.

Inspired by: https://pvs-studio.com/en/blog/posts/cpp/1188/

Fixed:
- [Bug 5](https://pvs-studio.com/en/blog/posts/cpp/1188/#IDF23EA2CEAB)
2024-11-21 18:29:08 -05:00
Daniel Thornburgh
385961d7b2 Reapply "[libc] Use best-fit binary trie to make malloc logarithmic (#117065)"
This reverts commit 93b83642ee34d0092b94776728dad0117c2b72a1.

 - Correct riscv32 assumption about alignment (bit of a hack).
 - Fix test case where the largest_small and smallest sizes are the
   same.
2024-11-21 15:26:24 -08:00
Daniel Thornburgh
93b83642ee Revert "[libc] Use best-fit binary trie to make malloc logarithmic (#117065)"
This reverts commit b05600d96f46697e21f6b1b7ad901391326243a8.
riscv32 unit test still broken
2024-11-21 11:56:05 -08:00
Daniel Thornburgh
b05600d96f Reapply "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
- Fix assertion expressions.
 - Fix incorrect small size in freestore_test.
 - There may only be one small size for high alignment and small
   pointers (riscv32).
 - Don't rely on stack alignment in FreeList test.
2024-11-21 11:30:51 -08:00
Daniel Thornburgh
9be475af81
Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
Reverts llvm/llvm-project#106259

Unit tests break on AArch64.
2024-11-20 14:00:07 -08:00
Daniel Thornburgh
c3207c31fc
[libc] Use best-fit binary trie to make malloc logarithmic (#106259)
This reworks the free store implementation in libc's malloc to use a
dlmalloc-style binary trie of circularly linked FIFO free lists. This
data structure can be maintained in logarithmic time, but it still
permits a relatively small implementation compared to other
logarithmic-time ordered maps.

The implementation doesn't do the various bitwise tricks or
optimizations used in actual dlmalloc; it instead optimizes for
(relative) readability and minimum code size. Specific optimization can
be added as necessary given future profiling.
2024-11-20 13:54:00 -08:00
Schrodinger ZHU Yifan
e59582b6f8
[libc] avoid type-punning with inactive union member (#116685) 2024-11-18 16:04:41 -05:00
RoseZhang03
2d95dee0c0
[libc] math fuzzing MPFR include statement (#102358)
Updated the include statement for MPFR
2024-08-07 21:12:40 +00:00
RoseZhang03
0142bd6b15
[libc] created tan function fuzzer (#101570)
Also edited file header formatting on sin_fuz and cos_fuzz
2024-08-01 23:19:47 +00:00
RoseZhang03
b45d36299e
[libc] added cos function fuzzing test (#101556) 2024-08-01 21:59:55 +00:00
RoseZhang03
83e6d872cf
[libc] heap_sort_fuzz deleted unnecessary includes (#101535)
Including src/__suppot/macros/config.h is unnecessary
2024-08-01 17:56:31 +00:00
Michael Jones
3497211d80
[libc] Fix math fuzzers (#101529)
Fix minor typos that accumulated while the math fuzzers were disabled.
2024-08-01 10:40:11 -07:00
RoseZhang03
90065da6d5
[libc] created fuzz test for sin function (#101411)
Verifies that sin function output is correct by comparing with MPFR
output. NaN and inf are not tested (as our output will vary compared to
MPFR), and signed zeroes are already tested in unit tests.
2024-08-01 17:31:04 +00:00
RoseZhang03
4ad2628ec9
[libc] fuzz test for heap_sort (#100826)
Made a fuzz test for heap_sort based off of qsort_fuzz implementation
2024-07-30 20:09:15 +00:00
lntue
dfdef2cbf7
[libc] Fix the remaining isnan and isinf in tests. (#100969)
Fixes https://github.com/llvm/llvm-project/issues/100964
2024-07-28 21:37:01 -07:00
Petr Hosek
5ff3ff33ff
[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98597)
This is a part of #97655.
2024-07-12 09:28:41 -07:00
Mehdi Amini
ce9035f5bd
Revert "[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration" (#98593)
Reverts llvm/llvm-project#98075

bots are broken
2024-07-12 09:12:13 +02:00
Petr Hosek
3f30effe1b
[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98075)
This is a part of #97655.
2024-07-11 12:35:22 -07:00
Schrodinger ZHU Yifan
0e5ff6251f
[libc] add hashtable fuzzing (#87949) 2024-05-02 15:36:10 -04:00
Guillaume Chatelet
09efe848cf
[libc][NFC] Rename UInt.h to big_int.h and UInt128.h to uint128.h for consistency (#87808) 2024-04-06 10:39:55 +02: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
Guillaume Chatelet
71c3f5d617
[reland][libc] Refactor BigInt (#87613)
This is a reland of #86137 with a fix for platforms / compiler that do
not support trivially constructible int128 types.
2024-04-04 11:41:27 +02:00
Guillaume Chatelet
12735916bd
Revert "[libc] Refactor BigInt" (#87612)
Reverts llvm/llvm-project#86137

Some aarch64 compilers seem to consider that `uint128_t` is not
`is_trivially_constructible` which prevents `bit_cast`-ing.
2024-04-04 11:10:30 +02:00
Guillaume Chatelet
a2306b65d2
[libc] Refactor BigInt (#86137)
This patch moves most of the multiprecision logic to the `multiword`
namespace and simplifies some logic in `BigInt`. It also fully
implements the mask and count functions and increases test coverage.

`math_extras.h` is also reworked to make it more concise.
2024-04-04 10:27:08 +02:00
Michael Jones
5d56b34807
[libc] Remove direct math.h includes (#85324)
Reland of #84991

A downstream overlay mode user ran into issues with the isnan macro not
working in our sources with a specific libc configuration. This patch
replaces the last direct includes of math.h with our internal
math_macros.h, along with the necessary build system changes.
2024-03-18 14:19:33 -07: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
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
Michael Jones
8e3b60540c
[libc] Add fixed point support to printf (#82707)
This patch adds the r, R, k, and K conversion specifiers to printf, with
accompanying tests. They are guarded behind the
LIBC_COPT_PRINTF_DISABLE_FIXED_POINT flag as well as automatic fixed
point support detection.
2024-02-27 11:03:20 -08:00
Guillaume Chatelet
6b02d2f863
[reland][libc] Remove unnecessary FPBits functions and properties (#79128)
- reland #79113
- Fix aarch64 RISC-V build
2024-01-23 13:48:03 +01:00
Guillaume Chatelet
b524eed925
Revert "[libc] Remove unnecessary FPBits functions and properties" (#79118)
Reverts llvm/llvm-project#79113
It broke aarch64 build bot machines.
2024-01-23 11:51:18 +01:00
Guillaume Chatelet
3bc86bf3bf
[libc] Remove unnecessary FPBits functions and properties (#79113)
This patch reduces the surface of `FPBits`.
2024-01-23 11:48:28 +01:00
Guillaume Chatelet
1ee93ac099
[libc] Add memcmp / bcmp fuzzers (#77741) 2024-01-11 11:06:46 +01:00
Guillaume Chatelet
c09e690556
[libc][NFC] Remove FloatProperties (#76508)
Access is now done through `FPBits` exclusively.
This patch also renames a few internal structs and uses `T` instead of
`FP` as a template parameter.
2024-01-03 09:51:58 +01:00
Guillaume Chatelet
c23991478a
[libc][NFC] Integrate FloatProperties into FPBits (#76506)
`FloatProperties` is always included when `FPBits` is. This will help
further refactoring.
2023-12-28 15:42:47 +01:00
Guillaume Chatelet
3546f4da19
[libc][NFC] Rename MANTISSA_WIDTH in FRACTION_LEN (#75489)
This one might be a bit controversial since the terminology has been
introduced from the start but I think `FRACTION_LEN` is a better name
here. AFAICT it really is "the number of bits after the decimal dot when
the number is in normal form."

`MANTISSA_WIDTH` is less precise as it's unclear whether we take the
leading bit into account.
This patch also renames most of the properties to use the `_LEN` suffix
and fixes useless casts or variables.
2023-12-15 13:57:35 +01:00
michaelrj-google
8a47ad4b67
[libc] Add simple long double to printf float fuzz (#68449)
Recent testing has uncovered some hard-to-find bugs in printf's long
double support. This patch adds an extra long double path to the fuzzer
with minimal extra effort. While a more thorough long double fuzzer
would be useful, it would need to handle the non-standard cases of 80
bit long doubles such as unnormal and pseudo-denormal numbers. For that
reason, a standalone long double fuzzer is left for future development.
2023-10-16 13:32:34 -07:00
Guillaume Chatelet
b6bc9d72f6
[libc] Mass replace enclosing namespace (#67032)
This is step 4 of
https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079
2023-09-26 11:45:04 +02:00
Joseph Huber
e0be78be42
[libc] Template the printf / scanf parser class (#66277)
Summary:
The parser class for stdio currently accepts different argument
providers. In-tree this is only used for a fuzzer test, however, the
proposed implementation of the GPU handling of printf / scanf will
require custom argument handlers. This makes the current approach of
using a preprocessor macro messier. This path proposed folding this
logic into a template instantiation. The downside to this is that
because the implementation of the parser class is placed into an
implementation file we need to manually instantiate the needed templates
which will slightly bloat binary size. Alternatively we could remove the
implementation file, or key off of the `libc` external packaging macro
so it is not present in the installed version.
2023-09-21 17:02:26 -05:00
Michael Jones
e7866ea212 [libc] Add fuzzing for printf floats
To guarantee accuracy for all potential float values, this patch adds a
fuzzer to compare the results for float conversions from our printf
against MPFR's.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D156495
2023-08-15 16:23:24 -07:00
Michael Jones
2ff8094e32 [libc] Set min precision for strtofloat fuzz
MPFR has a minimum precision of 2, but the strtofloat fuzz sometimes
would request a precision of 1 for the case of the minimum subnormal.
This patch tells the fuzzer to ignore any case where the precision would
go below 2.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D155130
2023-07-18 16:28:22 -07:00
Michael Jones
2cb4731902 [libc] adjust strtofloat precision for subnormals
Subnormal floating point numbers have a lower effective precision than
normal floating point numbers. This can cause issues for the fuzz test
since the MPFR floats have a constant precision regardless of the
exponent, and the precision must match exactly or else create rounding
errors. To solve this problem, the precision of the MPFR floats is
dynamically calculated.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D154909
2023-07-11 11:27:19 -07:00
Michael Jones
cfbcbc8f88 [libc] fix MPFR rounding problems in fuzz test
The accuracy for the MPFR numbers in the strtofloat fuzz test was set
too high, causing rounding issues when rounding to a smaller final
result.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D154150
2023-07-05 10:53:40 -07:00
Michael Jones
ae3b59e623 [libc] Use MPFR for strtofloat fuzzing
The previous string to float tests didn't check correctness, but due to
the atof differential test proving unreliable the strtofloat fuzz test
has been changed to use MPFR for correctness checking. Some minor bugs
have been found and fixed as well.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D150905
2023-05-22 11:04:53 -07:00
Michael Jones
377b82a088 [libc] add exception to atof differential fuzz
The differential fuzzer for atof found a bug in glibc's handling of
hexadecimal rounding. Since we can't easily update glibc and we want to
avoid false positives when running the fuzzer, I've added an exception
to skip all hexadecimal subnormal cases.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D149359
2023-04-28 13:50:40 -07:00
Michael Jones
62e7bdd22a [libc] use vars in string to num fuzz targets
The string to integer and string to float standalone fuzz targets just
ran the functions and didn't do anything with the output. This was
intentional, since they are intended to be used with sanitizers to
detect buffer overflow bugs. Not using the variables was causing compile
warnings, so this patch adds trivial checks to use the variables.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D144208
2023-02-27 13:21:35 -08:00