Commit Graph

22 Commits

Author SHA1 Message Date
Michael Jones 1c92911e9e [libc] apply new lint rules
This patch applies the lint rules described in the previous patch. There
was also a significant amount of effort put into manually fixing things,
since all of the templated functions, or structs defined in /spec, were
not updated and had to be handled manually.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D114302
2021-12-07 10:49:47 -08:00
Siva Chandra Reddy d9bbad277c [libc][Obvious][NFC] A bunch of cosmetic cleanup.
* Added missing header guards.
* Fixed license header format in a few files.
* Renamed files to more suitable names.
2021-11-19 17:02:55 +00:00
Siva Chandra Reddy f362aea42d [libc][NFC] Move utils/CPP to src/__support/CPP.
The idea is to move all pieces related to the actual libc sources to the
"src" directory. This allows downstream users to ship and build just the
"src" directory.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D112653
2021-10-28 15:50:00 +00:00
Michael Jones 87c016078a [libc] add atof, strtof and strtod
Add the string to floating point conversion functions.
Long doubles aren't supported yet, but floats and doubles are. The
primary algorithm used is the Eisel-Lemire ParseNumberF64 algorithm,
with the Simple Decimal Conversion algorithm as backup.

Links for more information on the algorithms:

Number Parsing at a Gigabyte per Second, Software: Practice and
Experience 51 (8), 2021 (https://arxiv.org/abs/2101.11408)
https://nigeltao.github.io/blog/2020/eisel-lemire.html
https://nigeltao.github.io/blog/2020/parse-number-f64-simple.html

Differential Revision: https://reviews.llvm.org/D109261
2021-10-18 16:10:03 -07:00
Siva Chandra Reddy 5eb6b82729 [libc] Add an implementation of qsort.
A fuzzer for qsort has also been added.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D110382
2021-09-24 19:22:45 +00:00
Michael Jones c120edc7b3 [libc][nfc] move ctype_utils and FPUtils to __support
Some ctype functions are called from other libc functions (e.g. isspace
is used in atoi). By moving ctype_utils.h to __support it becomes easier
to include just the implementations of these functions. For these
reasons the implementation for isspace was moved into
ctype_utils as well.

FPUtils was moved to simplify the build order, and to clarify which
files are a part of the actual libc.

Many files were modified to accomodate these changes, mostly changing
the #include paths.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D107600
2021-08-06 17:29:41 +00:00
Siva Chandra Reddy b5d6da3587 [libc] Remove libc-fuzzer as a dependency to check-libc. 2021-06-10 05:06:03 +00:00
Siva Chandra Reddy 6666e0d7a2 [libc] Make FPBits a union.
This helps us avoid the uncomfortable reinterpret-casts. Avoiding the
reinterpret casts prevents us from tripping the sanitizers as well.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D100360
2021-04-13 09:21:35 -07:00
Siva Chandra Reddy 7f7b0dc4e1 [libc] Add implementations of nextafter[f|l] functions.
A differential fuzzer for these functions has also been added.
Along the way, a small correction has been done to the normal/subnormal
limits of x86 long double values.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D94109
2021-01-05 22:32:39 -08:00
Siva Chandra Reddy 4766a86cf2 [libc] Combine all math differential fuzzers into one target.
Also added diffing of a few more math functions. Combining the diff check
for all of these functions helps us meet the OSS fuzz bar of a minimum of
100 program edges.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D91817
2020-11-20 07:46:15 -08:00
Siva Chandra Reddy 892ed1f150 [libc] Add differential fuzzers for ldexp and remquo.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D91763
2020-11-19 08:32:05 -08:00
cgyurgyik e14a7ff762 [libc] Adds fuzz test for strstr and alphabetizes string fuzz CMakeList.
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D84611
2020-07-29 16:35:59 -04:00
cgyurgyik b07feef873 [libc] This commit fixes the strcmp fuzzing test. It uses a single input and
splits it into two by using the value of the first byte to determine the
length of the first string. Reviewed-by: PaulkaToast, Differential
Revision: https://reviews.llvm.org/D82427

Summary:
[libc] Since only one input is given, it is necessary to split the string into two containers so that they can be compared for the purposes of this fuzz test. This is done in the following manner:

1. Take the value of the first byte; this is size1. (Credits to @PaulkaToast for this idea).
2. size2 is the value of size - size1.
3. Copy the characters to new containers, data1 and data2 with corresponding sizes.
4. Add a null terminator to the first container, and verify the second container has a null terminator.
5. Verify output of strcmp.

A simpler alternative considered was simply splitting the input data into two, but this means the two strings are always within +- 1 character of each other. This above implementation avoids this.

ninja check-libc was run; no issues.

Reviewers: PaulkaToast, sivachandra

Reviewed By: PaulkaToast

Subscribers: mgorny, tschuett, ecnelises, libc-commits, PaulkaToast

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D82427
2020-06-28 12:50:04 -05:00
cgyurgyik 8bec88e638 Remove strcmp fuzz from CMakeList since it breaks build. 2020-06-23 12:52:36 -04:00
Simon Pilgrim f1c671925b Add stddef.h to fix missing size_t type build errors. 2020-06-23 13:12:18 +01:00
cgyurgyik 4ffe2b24f5 [libc] Add fuzz test for strcmp.
Summary:
Adds a fuzz test for string comparison.

This takes in two strings with associated lengths.
Verifies each string contains at least one character, and that the last character is the null terminator.
Then, finds the first instance where one of the following does not hold:
1. i < min(size1, size2)
2. s1[i] == s2[i]
3. s1[i] != '\0'

The result of strcmp is then compared to the value of the difference between s1[i] and s2[i]. For thoroughness, the operands are reversed and also checked.

Reviewers: sivachandra, PaulkaToast

Reviewed By: sivachandra, PaulkaToast

Subscribers: mgorny, tschuett, ecnelises, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D82247
2020-06-23 07:24:03 -04:00
cgyurgyik 5540765be6 Add strcmp fuzz test.
Reviewed-by: todo
Differential Revision: https://reviews.llvm.org/D82247
2020-06-23 07:20:39 -04:00
Siva Chandra Reddy e4767a6f14 [libc] Add fully-qualified target names.
Only targets setup by the special LLVM libc rules now have fully
qualified names. The naming style is similar to fully qualified names in
Python.

Reviewers: abrachet, PaulkaToast, phosek

Differential Revision: https://reviews.llvm.org/D77340
2020-04-10 18:01:52 -07: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
Paula Toth 90eb7be6a1 [libc] Fix memcpy to adhere to qualified calls.
Summary: Switched to using the new memcpy implementation.

Reviewers: sivachandra, abrachet, gchatelet

Reviewed By: abrachet, gchatelet

Subscribers: mgorny, MaskRay, tschuett, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D77277
2020-04-03 15:27:57 -07:00
Paula Toth 1fcfd30fae [libc] Add strlen implementation.
Summary: This should fix the call to a non internal libc function.

Reviewers: sivachandra, abrachet

Reviewed By: sivachandra

Subscribers: xbolva00, mgorny, MaskRay, tschuett, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D77279
2020-04-03 15:11:35 -07:00
Paula Toth a4f45ee73a [libc] Lay out framework for fuzzing libc functions.
Summary:
Added fuzzing test for strcpy and some documentation related to fuzzing.
This will be the first step in integrating this with oss-fuzz.

Reviewers: sivachandra, abrachet

Reviewed By: sivachandra, abrachet

Subscribers: gchatelet, abrachet, mgorny, MaskRay, tschuett, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D74091
2020-02-21 19:15:46 -08:00