Commit Graph

152 Commits

Author SHA1 Message Date
Roland McGrath
4e298c32d5 [libc] Make string tests compatible with the Fuchsia build
Some test code was doing loose conversions caught by compiler
warnings in  the Fuchsia build.  This included duplicated code
in a few tests that was reconsolidated with the existing header
file copy of the same functions.

The MemoryMatcher abstraction presumes gtest-style matcher support,
which is not available in Fuchsia's zxtest library.  It's avoided
in favor of simpler memory-comparing assertions.

Reviewed By: abrachet

Differential Revision: https://reviews.llvm.org/D146343
2023-03-20 10:22:52 -07:00
Siva Chandra Reddy
30d894239a [libc][NFC] Switch string and errno tests to libc_errno. 2023-03-13 22:22:00 +00:00
Alex Brachet
d05093a7cf [libc] Fix integer conversion error in test 2023-03-07 17:49:47 +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
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
Guillaume Chatelet
1ae4bd83ce [libc][NFC] Move compiler_features to macros folder 2023-02-07 10:40:13 +00:00
Guillaume Chatelet
1637351fd1 [libc][NFC] Rename architecture macros and move to macros folder 2023-02-07 10:20:22 +00:00
Alex Brachet
741021de32 [libc] Implement strcasestr
Differential Revision: https://reviews.llvm.org/D142518
2023-01-25 17:58:13 +00:00
Alex Brachet
e9d571d3b6 [libc] Implement str{,n}casecmp
Differential Revision: https://reviews.llvm.org/D141236
2023-01-11 05:38:33 +00:00
Guillaume Chatelet
f52ca0926c [libc] Add compiler, builtin and feature detection
This is a first step to support GCC. This patch adds support for builtin and feature detection.

Differential Revision: https://reviews.llvm.org/D139712
2022-12-13 13:01:11 +00:00
Siva Chandra Reddy
f340030577 [libc] Add custom operator new to handle allocation failures gracefully.
This patch adds the implementation of the custom operator new functions.
The implementation of the internal strdup has been updated to use
operator new for allocation.

We will make it a policy and document that all allocations have to go
through the libc's own operator new. A future change will also add
operator delete replacements and make it a policy that deallocations in
libc internal code have to go through those replacements.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D139584
2022-12-11 00:29:04 +00:00
Guillaume Chatelet
436c8f4420 [reland][libc] Add bcopy
Differential Revision: https://reviews.llvm.org/D138994
2022-12-01 10:07:04 +00:00
Guillaume Chatelet
c5fe7eb216 Revert D138994 "[libc] Add bcopy"
Broke build bot

This reverts commit 186a15f7a9.
2022-12-01 09:55:36 +00:00
Guillaume Chatelet
186a15f7a9 [libc] Add bcopy
Differential Revision: https://reviews.llvm.org/D138994
2022-12-01 09:52:10 +00:00
Guillaume Chatelet
534f4bca58 [libc] remove mem functions dead code
Let's wait a bit for https://reviews.llvm.org/D136595 to settle before
cleaning up. Just in case we would need to revert.

Differential Revision: https://reviews.llvm.org/D136673
2022-11-16 10:29:29 +00:00
Guillaume Chatelet
3635195e0d [libc] Improve testing of mem functions
This patch extracts the testing logic from `op_tests.cpp` into
`memory_check_utils.h` so we can reuse it for mem* function integration
tests.

This makes testing consistent and thorough.
For instance this catches a bug that got unnoticed during submission of
D136595 and D135134. Integration test for memcmp was only testing a
single size.

This also leverages ASAN to make sure that data is not read / written
outside permitted boundaries

Differential Revision: https://reviews.llvm.org/D136865
2022-11-02 08:55:46 +00:00
Michael Jones
f418f88824 [libc] add locale free strcoll
The strcoll function is intended to compare strings based on their
ordering in the current locale. Since the locale facilities have not yet
been added, a simple implementation that is the same as strcmp has been
added as a placeholder.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D136802
2022-10-28 11:13:07 -07:00
Guillaume Chatelet
d7917fdc0f [libc] Use cpp::byte instead of char in mem* functions
`cpp::byte` is better than `char` which -depending on platform- can be `signed char` or `unsigned char`.  This has introduced subtle arithmetic errors.
2022-10-24 10:30:32 +00:00
Guillaume Chatelet
55509b1136 [libc] Fix broken tests on arm32 2022-10-24 09:54:19 +00:00
Guillaume Chatelet
69090143f5 [libc] mem* framework v3
This version is more composable and also simpler at the expense of being more explicit and more verbose.

This patch provides rationale for the framework, implementation and unit tests but the functions themselves are still using the previous version. The change in implementation will come in a follow up patch.

Differential Revision: https://reviews.llvm.org/D136292
2022-10-24 09:13:46 +00:00
Guillaume Chatelet
3c438f6119 Revert D136292 "[libc] mem* framework v3"
This breaks llvm-libc build bots:
 - libc-x86_64-debian-dbg-asan
 - libc-x86_64-debian-fullbuild-dbg-asan
Address sanitizers fail with "AddressSanitizer: invalid alignment requested in aligned_alloc: 64, alignment must be a power of two and the requested size 0x41 must be a multiple of alignment (thread T0)"
 - libc-aarch64-ubuntu-dbg
 - libc-aarch64-ubuntu-fullbuild-dbg
https://lab.llvm.org/buildbot/#/builders/223/builds/8877/steps/7/logs/stdio
 - libc-arm32-debian-dbg
https://lab.llvm.org/buildbot/#/builders/229/builds/5201/steps/7/logs/stdio

This reverts commit 903cc71a82.
2022-10-20 13:59:05 +00:00
Guillaume Chatelet
903cc71a82 [libc] mem* framework v3
This version is more composable and also simpler at the expense of being more explicit and more verbose.

This patch provides rationale for the framework, implementation and unit tests but the functions themselves are still using the previous version. The change in implementation will come in a follow up patch.

Differential Revision: https://reviews.llvm.org/D136292
2022-10-20 13:44:07 +00:00
Guillaume Chatelet
3f81126a33 [libc][NFC] add missing static qualifiers in tests 2022-10-20 08:52:56 +00:00
Guillaume Chatelet
e4b4d0f74f [libc][NFC] remove unneeded -lpthread for utils_test 2022-10-20 08:48:50 +00:00
Guillaume Chatelet
a786096f9d [libc][NFC] Cleanup and document utils.h 2022-10-18 14:32:39 +00:00
Guillaume Chatelet
2e3b8b31ce [libc][NFC] Use ASSERT instead of EXPECT in tests 2022-10-18 14:32:39 +00:00
Sterling Augustine
d8415b02a5 Revert "[libc] New version of the mem* framework"
This reverts commit https://reviews.llvm.org/D135134 (b3f1d58a13)

That revision appears to have broken Arm memcpy in some subtle
ways. Am communicating with the original author to get a
good reproduction.
2022-10-14 12:32:20 -07:00
Guillaume Chatelet
b3f1d58a13 [libc] New version of the mem* framework
This version is more composable and also simpler at the expense of being more explicit and more verbose. It also provides minimal implementations for ARM platforms.

    Codegen can be checked here https://godbolt.org/z/chf1Y6eGM

    Differential Revision: https://reviews.llvm.org/D135134
2022-10-14 13:46:42 +00:00
Guillaume Chatelet
6d252a4888 Revert "[libc] New version of the mem* framework"
This reverts commit 9721687835.
2022-10-14 13:21:52 +00:00
Guillaume Chatelet
9721687835 [libc] New version of the mem* framework
This version is more composable and also simpler at the expense of being more explicit and more verbose. It also provides minimal implementations for ARM platforms.

Codegen can be checked here https://godbolt.org/z/x19zvE59v

Differential Revision: https://reviews.llvm.org/D135134
2022-10-14 12:42:54 +00:00
Guillaume Chatelet
4fed4b0943 Revert "[libc] New version of the mem* framework"
This reverts commit 98bf836f31.
2022-10-14 12:27:04 +00:00
Guillaume Chatelet
98bf836f31 [libc] New version of the mem* framework
This version is more composable and also simpler at the expense of being more explicit and more verbose. It also provides minimal implementations for ARM platforms.

Codegen can be checked here https://godbolt.org/z/x19zvE59v

Differential Revision: https://reviews.llvm.org/D135134
2022-10-14 12:25:03 +00:00
Guillaume Chatelet
9d1f6466e5 Revert "[libc] New version of the mem* framework"
This reverts commit d55f2d8ab0.
2022-10-13 14:49:58 +00:00
Guillaume Chatelet
d55f2d8ab0 [libc] New version of the mem* framework
This version is more composable and also simpler at the expense of being more explicit and more verbose. It also provides minimal implementations for ARM platforms.

Codegen can be checked here https://godbolt.org/z/x19zvE59v

Differential Revision: https://reviews.llvm.org/D135134
2022-10-13 14:44:03 +00:00
Guillaume Chatelet
e431731e08 Revert "[libc] New version of the mem* framework"
This reverts commit 4c19439d24.
2022-10-12 15:35:18 +00:00
Guillaume Chatelet
4c19439d24 [libc] New version of the mem* framework
This version is more composable and also simpler at the expense of being more explicit and more verbose.
This patch is not meant to be submitted but gives an idea of the change.
Codegen can be checked in https://godbolt.org/z/6z1dEoWbs by removing the "static inline" before individual functions.

Unittests are coming.

Suggested review order:
 - utils
 - op_base
 - op_builtin
 - op_generic
 - op_x86 / op_aarch64
 - *_implementations.h

Differential Revision: https://reviews.llvm.org/D135134
2022-10-12 15:26:26 +00:00
Michael Jones
07793f95c4 [libc] add strsignal and refactor message mapping
The logic for strsignal and strerror is very similar, so I've moved them
both to use a shared utility (MessageMapper) for the basic
functionality.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D135322
2022-10-07 11:11:53 -07:00
Michael Jones
a9f95b769e [libc] add strerror_r function
I've implemente the gnu variant of strerror_r since that seems to be the
one more relevant to what we're trying to do.

Differential Revision: https://reviews.llvm.org/D135227
2022-10-07 11:07:06 -07:00
Guillaume Chatelet
060a43ced2 [libc][NFC] Move alignment utils to utils.h 2022-09-29 13:51:35 +00:00
Guillaume Chatelet
2188cf9fa4 [libc][NFC] Remove new framework, a simpler one is coming 2022-09-26 12:42:38 +00:00
Michael Jones
42bcb35c0f [libc] add strerror
Strerror maps error numbers to strings. Additionally, a utility for
mapping errors to strings was added so that it could be reused for
perror and similar.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D134074
2022-09-20 16:23:36 -07:00
Guillaume Chatelet
c860fd3f25 [NFC][libc] Remove ArrayRef which is replaced with span 2022-08-22 10:52:28 +00:00
Guillaume Chatelet
22bc0fde55 [NFC][libc] Switch mem* tests from ArrayRef to span 2022-08-22 09:58:35 +00:00
Guillaume Chatelet
a1c42cb803 [reland][NFC][libc] Use span instead of ArrayRef 2022-08-22 08:22:38 +00:00
Guillaume Chatelet
70ca9a6600 Revert "[NFC][libc] Use span instead of ArrayRef"
This reverts commit e7b250b8a6.
2022-08-22 08:14:22 +00:00
Guillaume Chatelet
e7b250b8a6 [NFC][libc] Use span instead of ArrayRef 2022-08-22 08:09:57 +00:00