743 Commits

Author SHA1 Message Date
Michael Jones
7aec387dbe [libc][NFC] add an atof test for a fuzz failure
The differential fuzzer found that glibc and our libc disagree on the
result for "0x30000002222225p-1077", with ours being rounded up and
theirs rounded down. Ours is more correct for the nearest rounding mode,
so only a test is added.

Reviewed By: lntue, sivachandra

Differential Revision: https://reviews.llvm.org/D145821
2023-03-14 11:42:57 -07:00
Joseph Huber
022f2fa3ad [libc] Remove dummy archive and file from integration test
This doesn't seem to be used anymore after recent changes that removed
the `--sysroot` method for the integration tests.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D146040
2023-03-14 09:30:05 -05:00
Siva Chandra Reddy
547e345666 [libc] Make libc_errno point to internal errno for non-public builds.
The macro llvmlibc_errno has also been removed. This change completes
the switch to using a hermetic errno for unit tests.

Fixes #61037

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D146005
2023-03-14 04:21:56 +00:00
Siva Chandra Reddy
55612b8ec4 [libc] Switch sys/stat implementations over to libc_errno.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D146004
2023-03-14 04:02:45 +00:00
Siva Chandra Reddy
7e6462d90c [libc][NFC] Switch nanosleep_test and getcwd_test to libc_errno. 2023-03-14 01:25:47 +00:00
Siva Chandra Reddy
67de5381a3 [libc][NFC] Switch unistd.h tests to libc_errno. 2023-03-14 00:52:33 +00:00
Siva Chandra Reddy
af783db7fd [libc][NFC] Switch sys/*.h tests over to libc_errno. 2023-03-13 23:44:52 +00:00
Siva Chandra Reddy
40c443e28b [libc][NFC] Switch mman.h tests to libc_errno and update Bazel build. 2023-03-13 22:46:51 +00:00
Siva Chandra Reddy
0b70f95c16 [libc][NFC] Switch startup tests to libc_errno. 2023-03-13 22:22:01 +00:00
Siva Chandra Reddy
30d894239a [libc][NFC] Switch string and errno tests to libc_errno. 2023-03-13 22:22:00 +00:00
Siva Chandra Reddy
adff2b291c [libc][NFC] Switch all uses of errno in math and math tests to libc_errno. 2023-03-13 22:22:00 +00:00
Siva Chandra Reddy
2869d31a7a [libc] Enable integration tests when built with gcc. 2023-03-13 07:47:00 +00:00
Siva Chandra Reddy
5b1ad43c2b [libc] Declare __dso_handle in the integration test instead of startup.
Fixes #61355. The __dso_handle decl was introduced incorrectly into the startup
objects during the integration test cleanup which moved the integration tests
away from using an artificial sysroot to using -nostdlib. Having it in the
startup creates the duplicate symbol error when one does not use -nostdlib.
Since this is an integration test only problem, it is meaningful to keep it in
the integration test anyway.

Differential Revision: https://reviews.llvm.org/D145898
2023-03-13 07:47:00 +00:00
Siva Chandra Reddy
5d69233453 [libc][NFC] Reduce the number of threads created in cnd_test to 1000 form 10000.
The high number of 10000 threads was choking bot builders running on boards with
very small memory.
2023-03-12 07:08:58 +00:00
Siva Chandra
6f8dfeee06 [libc] Add riscv64 fenv implementation and enable the fenv.h functions.
Reviewed By: mikhail.ramalho

Differential Revision: https://reviews.llvm.org/D145560
2023-03-08 10:49:24 -03:00
Alex Brachet
d05093a7cf [libc] Fix integer conversion error in test 2023-03-07 17:49:47 +00:00
Tue Ly
31c39439a8 [libc][math] Switch math functions to use libc_errno and fix some errno and floating point exceptions.
Switch math functions to use libc_errno and fix some errno and
floating point exceptions

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145349
2023-03-07 00:51:16 -05:00
Siva Chandra Reddy
d49b993f0d [libc][NFC] Switch dirent, fcntl, inttypes and sched to use libc_errno.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D145222
2023-03-06 22:24:51 +00:00
Siva Chandra Reddy
ae8e1b8fc3 [libc] Add arm 32 FEnvImpl.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145347
2023-03-06 15:57:37 +00:00
Siva Chandra Reddy
7abf6c2524 [libc] Switch signal and termios to libc_errno.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D145274
2023-03-05 03:58:54 +00:00
Siva Chandra Reddy
43de233e29 [libc][NFC] Remove allocator definition in the api-test.
The integration tests already have allocators so we will get all of them
from there.
2023-03-05 00:25:02 +00:00
Michael Jones
04a9c62554 [libc] move stdlib and stdio to new errno pattern
Fixes https://github.com/llvm/llvm-project/issues/61071

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145191
2023-03-03 11:15:36 -08:00
Raman Tenneti
b98c1906d6 [libc][NFC] Switch use of errno in src/time and test/src/time to libc_errno.
Switch use of errno in src/time and test/src/time to libc_errno.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145192
2023-03-02 14:41:19 -08:00
Michael Jones
8350494a61 [libc] disable integration tests when using gcc
The integration tests were failing to build under GCC due to missing
compile options for using LLVM's libc++ and compiler-rt.

This should unblock https://github.com/llvm/llvm-project/issues/60467

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D145128
2023-03-02 13:39:55 -08:00
Jeff Bailey
81b39145bd [libc] Fix mismatch in exception decl
When running the libc tests under vscode, I got an error about a
mismatches exception declaration for strerror.  Since string.h
seems to be getting included transitively anyway, just include
it and rely on its definition.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D144803
2023-03-01 20:56:59 +00:00
Michael Jones
b39f1e5c13 [libc] Fix printf %f rounding condition
When running the tbin2dec tests I found a rounding error in my code.
Upon inspection I realized it was due to a lack of parenthesis when
calculating the number of trailing digits. This patch fixes that mistake
and adds unit tests to catch regressions in future.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145011
2023-03-01 10:57:26 -08:00
Michael Jones
2dd527b6f8 [libc] fix strtofloat test with 128 bit floats
Differential Revision: https://reviews.llvm.org/D144991
2023-02-28 10:59:03 -08:00
Michael Jones
cb3c41c285 [libc] Refactor string to float return values
The internal implementation of the string to float function previously
used pointer arguments for returning several values. Additionally it
set errno in several unexpected places. Now all of that goes through
return structs. For readability I also moved the function away from raw
pointer arithmetic towards proper indexing. I also added support for
rounding modes.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D144597
2023-02-28 10:50:43 -08:00
Michael Jones
8f0814f5dc [libc] Clarify printf percent conversion behavior.
Almost all printf conversions ending in '%' are undefined, but they're
traditionally treated as if the complete conversion specifier is "%%".
This patch modifies the parser to more closely match that behavior.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D144679
2023-02-24 13:29:30 -08:00
Siva Chandra Reddy
bfeef8b794 [libc] Add a linting target named "libc-lint".
Lint targets for individual entrypoints have also been cleaned up. The
target "libc-lint" depends on the individual lint targets.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D144705
2023-02-24 19:55:43 +00:00
Tue Ly
198292f26c [libc][math] Fix floating point exception testing macros in FPMatcher.h for
aarch64.
2023-02-24 13:43:33 -05:00
Tue Ly
0aa9593c2f [libc][math] Set floating point exceptions for exp*f, sinhf, and coshf.
Set FE_OVERFLOW and FE_UNDERFLOW for expf, exp2f, exp10f, expm1f, sinhf
and coshf.

Reviewed By: sivachandra, renyichen

Differential Revision: https://reviews.llvm.org/D144340
2023-02-24 12:56:39 -05:00
Siva Chandra Reddy
17a2434bd6 [libc] Introduce a target named libc-unit-tests to run just the unit tests.
The target "check-libc" now runs all enabled tests which, depending on
the build mode, includes the unit tests, the integration tests and the api
test.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D144663
2023-02-24 02:53:36 +00:00
Michael Jones
bf279f903b [libc] Prevent printf index mode crashes
The posix standard defines an alternate mode for printf where the
conversions also have an index that describes which argument to select.
Due to how variadic arguments work in C, to reach the nth argument all
n-1 previous arguments must be read with their correct types. If the
format string does not specify the types for a continuous set of
arguments, then the arguments after the discontinuity cannot be safely
read. This patch causes all conversions requesting an argument that
comes after a gap be treated as raw (i.e. the conversion string is
printed literally).

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D143782
2023-02-22 16:27:26 -08:00
Raman Tenneti
d0d6d78bbd [libc] Implement ntohl and ntohs
Per spec:

https://pubs.opengroup.org/onlinepubs/9699919799/functions/ntohl.html
https://pubs.opengroup.org/onlinepubs/9699919799/functions/ntohs.html

Co-authored-by: Jeff Bailey <jbailey@google.com>

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D144506
2023-02-22 10:40:38 -08:00
Jeff Bailey
9ad0ac8eb3 [libc] Add Month enum, refactor mktime_test
Introduce Month enum.

Use designated initializers instead of comments to ensure that tm_data
is initialized correctly.  Use Month enum for initializing .tm_mon to
avoid off-by-one errors.

Co-authored-by: Raman Tenneti <rtenneti@google.com>

Reviewed By: rtenneti

Differential Revision: https://reviews.llvm.org/D144357
2023-02-21 17:24:33 +00:00
Raman Tenneti
fbe210dc7a [libc] Implement htonl and htons
Per spec:
* https://pubs.opengroup.org/onlinepubs/9699919799/functions/htonl.html
* https://pubs.opengroup.org/onlinepubs/9699919799/functions/htons.html

Also adds UInt16Type and UInt32Type to spec.td

Co-authored-by: Jeff Bailey <jbailey@google.com>

Reviewed By: sivachandra, jeffbailey, rtenneti

Differential Revision: https://reviews.llvm.org/D143795
2023-02-16 10:12:18 -08:00
Alex Brachet
d9a04d1d54 [libc] Support running tests for Pigweed
Differential Revision: https://reviews.llvm.org/D144146
2023-02-16 16:39:09 +00:00
Guillaume Chatelet
c3228714cc [libc][NFC] Make tuning macros start with LIBC_COPT_
Rename preprocessor definitions that control tuning of llvm libc.

Differential Revision: https://reviews.llvm.org/D143913
2023-02-15 10:00:16 +00:00
Tue Ly
ae2d8b4971 [libc][math] Update exceptional cases for logf, log10f, log2f, log1pf.
Properly set floating point exceptions and add more exceptional
values for non-FMA x86-64 targets.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D143699
2023-02-10 14:08:50 -05:00
Guillaume Chatelet
737e1cd161 [libc] Move likely/unlikely to the optimization header 2023-02-10 15:31:28 +00:00
Guillaume Chatelet
e2f8c55664 [libc][NFC] separate macros in several targets 2023-02-09 10:51:19 +00:00
Guillaume Chatelet
c53e15e841 [libc][NFC] Move compiler_features.h to properties subfolder 2023-02-09 09:26:38 +00:00
Guillaume Chatelet
f100ec2517 [libc][NFC] Move architectures.h to properties subfolder 2023-02-09 09:20:46 +00:00
Siva Chandra Reddy
eb8e1bf92b [libc][obvious] Fix build. 2023-02-09 06:07:44 +00:00
Renyi Chen
6cb14adbfa [libc][math] Implement scalbn, scalbnf, scalbnl.
Implement scalbn via `fptuil::ldexp` for `FLT_RADIX==2` case.
"unimplemented" otherwise.

Reviewed By: lntue, sivachandra

Differential Revision: https://reviews.llvm.org/D143116
2023-02-09 05:55:34 +00:00
Guillaume Chatelet
a2569a76e0 [libc][NFC] Rename macros 2023-02-07 20:43:33 +00:00
Guillaume Chatelet
e2263f1459 [libc][NFC] Move code to sanitizer.h + more consistent naming 2023-02-07 20:43:33 +00:00
Siva Chandra Reddy
af1315c28f [libc][NFC] Move UnitTest and IntegrationTest to the 'test' directory.
This part of the effort to make all test related pieces into the `test`
directory. This helps is excluding test related pieces in a straight
forward manner if LLVM_INCLUDE_TESTS is OFF. Future patches will also move
the MPFR wrapper and testutils into the 'test' directory.
2023-02-07 19:45:51 +00:00
Guillaume Chatelet
f6d9972291 [libc][NFC] Rename compiler_feature macros 2023-02-07 11:13:43 +00:00