diff options
author | Alex Brachet <abrachet@google.com> | 2023-04-11 01:16:21 +0000 |
---|---|---|
committer | Alex Brachet <abrachet@google.com> | 2023-04-11 01:17:11 +0000 |
commit | a0a141fcbe1dfd35032fa5c052e6906180a37fb1 (patch) | |
tree | b0380bfd1294508f196cc6bca28e743e706743a3 /libc | |
parent | 82ca29ce54d3b7d8e47aa151e0ce3dff37727c1a (diff) | |
download | llvm-a0a141fcbe1dfd35032fa5c052e6906180a37fb1.zip llvm-a0a141fcbe1dfd35032fa5c052e6906180a37fb1.tar.gz llvm-a0a141fcbe1dfd35032fa5c052e6906180a37fb1.tar.bz2 |
[libc] Add {,r}index
Differential Revision: https://reviews.llvm.org/D147464
Diffstat (limited to 'libc')
-rw-r--r-- | libc/config/linux/aarch64/entrypoints.txt | 2 | ||||
-rw-r--r-- | libc/config/linux/arm/entrypoints.txt | 2 | ||||
-rw-r--r-- | libc/config/linux/riscv64/entrypoints.txt | 2 | ||||
-rw-r--r-- | libc/config/linux/x86_64/entrypoints.txt | 2 | ||||
-rw-r--r-- | libc/spec/bsd_ext.td | 10 | ||||
-rw-r--r-- | libc/src/string/CMakeLists.txt | 20 | ||||
-rw-r--r-- | libc/src/string/index.cpp | 20 | ||||
-rw-r--r-- | libc/src/string/index.h | 18 | ||||
-rw-r--r-- | libc/src/string/rindex.cpp | 20 | ||||
-rw-r--r-- | libc/src/string/rindex.h | 18 | ||||
-rw-r--r-- | libc/test/src/string/CMakeLists.txt | 34 | ||||
-rw-r--r-- | libc/test/src/string/index_test.cpp | 14 | ||||
-rw-r--r-- | libc/test/src/string/rindex_test.cpp | 14 |
13 files changed, 170 insertions, 6 deletions
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index 6fb3206..7d76e83 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -33,6 +33,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.string.bcmp libc.src.string.bcopy libc.src.string.bzero + libc.src.string.index libc.src.string.memccpy libc.src.string.memchr libc.src.string.memcmp @@ -41,6 +42,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.string.mempcpy libc.src.string.memrchr libc.src.string.memset + libc.src.string.rindex libc.src.string.stpcpy libc.src.string.stpncpy libc.src.string.strcasecmp diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt index 4ae8b0f..5ed49d0 100644 --- a/libc/config/linux/arm/entrypoints.txt +++ b/libc/config/linux/arm/entrypoints.txt @@ -24,6 +24,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.string.bcmp libc.src.string.bcopy libc.src.string.bzero + libc.src.string.index libc.src.string.memccpy libc.src.string.memchr libc.src.string.memcmp @@ -32,6 +33,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.string.mempcpy libc.src.string.memrchr libc.src.string.memset + libc.src.string.rindex libc.src.string.stpcpy libc.src.string.stpncpy libc.src.string.strcasecmp diff --git a/libc/config/linux/riscv64/entrypoints.txt b/libc/config/linux/riscv64/entrypoints.txt index 0c59d91..936949f 100644 --- a/libc/config/linux/riscv64/entrypoints.txt +++ b/libc/config/linux/riscv64/entrypoints.txt @@ -33,6 +33,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.string.bcmp libc.src.string.bcopy libc.src.string.bzero + libc.src.string.index libc.src.string.memccpy libc.src.string.memchr libc.src.string.memcmp @@ -41,6 +42,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.string.mempcpy libc.src.string.memrchr libc.src.string.memset + libc.src.string.rindex libc.src.string.stpcpy libc.src.string.stpncpy libc.src.string.strcasecmp diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 13c788d..9e450ea 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -33,6 +33,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.string.bcmp libc.src.string.bcopy libc.src.string.bzero + libc.src.string.index libc.src.string.memccpy libc.src.string.memchr libc.src.string.memcmp @@ -41,6 +42,7 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.string.mempcpy libc.src.string.memrchr libc.src.string.memset + libc.src.string.rindex libc.src.string.stpcpy libc.src.string.stpncpy libc.src.string.strcasecmp diff --git a/libc/spec/bsd_ext.td b/libc/spec/bsd_ext.td index 3420c20..3829e57 100644 --- a/libc/spec/bsd_ext.td +++ b/libc/spec/bsd_ext.td @@ -39,6 +39,16 @@ def BsdExtensions : StandardSpec<"BSDExtensions"> { RetValSpec<IntType>, [ArgSpec<ConstCharPtr>, ArgSpec<ConstCharPtr>, ArgSpec<SizeTType>] >, + FunctionSpec< + "index", + RetValSpec<CharPtr>, + [ArgSpec<ConstCharPtr>, ArgSpec<IntType>] + >, + FunctionSpec< + "rindex", + RetValSpec<CharPtr>, + [ArgSpec<ConstCharPtr>, ArgSpec<IntType>] + >, ] >; diff --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt index f6980ca..d719fad 100644 --- a/libc/src/string/CMakeLists.txt +++ b/libc/src/string/CMakeLists.txt @@ -32,6 +32,16 @@ add_entrypoint_object( ) add_entrypoint_object( + index + SRCS + index.cpp + HDRS + index.h + DEPENDS + .memory_utils.strchr_implementation +) + +add_entrypoint_object( memccpy SRCS memccpy.cpp @@ -68,6 +78,16 @@ add_entrypoint_object( ) add_entrypoint_object( + rindex + SRCS + rindex.cpp + HDRS + rindex.h + DEPENDS + .memory_utils.strchr_implementation +) + +add_entrypoint_object( stpcpy SRCS stpcpy.cpp diff --git a/libc/src/string/index.cpp b/libc/src/string/index.cpp new file mode 100644 index 0000000..109b1ec --- /dev/null +++ b/libc/src/string/index.cpp @@ -0,0 +1,20 @@ +//===-- Implementation of index -------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/string/index.h" + +#include "src/__support/common.h" +#include "src/string/memory_utils/strchr_implementations.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(char *, index, (const char *src, int c)) { + return strchr_implementation(src, c); +} + +} // namespace __llvm_libc diff --git a/libc/src/string/index.h b/libc/src/string/index.h new file mode 100644 index 0000000..7b24610 --- /dev/null +++ b/libc/src/string/index.h @@ -0,0 +1,18 @@ +//===-- Implementation header for index -------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_STRING_INDEX_H +#define LLVM_LIBC_SRC_STRING_INDEX_H + +namespace __llvm_libc { + +char *index(const char *src, int c); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_STRING_INDEX_H diff --git a/libc/src/string/rindex.cpp b/libc/src/string/rindex.cpp new file mode 100644 index 0000000..7f2f874 --- /dev/null +++ b/libc/src/string/rindex.cpp @@ -0,0 +1,20 @@ +//===-- Implementation of rindex ------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/string/rindex.h" + +#include "src/__support/common.h" +#include "src/string/memory_utils/strchr_implementations.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(char *, rindex, (const char *src, int c)) { + return strrchr_implementation(src, c); +} + +} // namespace __llvm_libc diff --git a/libc/src/string/rindex.h b/libc/src/string/rindex.h new file mode 100644 index 0000000..976d6ba --- /dev/null +++ b/libc/src/string/rindex.h @@ -0,0 +1,18 @@ +//===-- Implementation header for rindex ------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_STRING_RINDEX_H +#define LLVM_LIBC_SRC_STRING_RINDEX_H + +namespace __llvm_libc { + +char *rindex(const char *src, int c); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_STRING_RINDEX_H diff --git a/libc/test/src/string/CMakeLists.txt b/libc/test/src/string/CMakeLists.txt index ed9d38a..6bb4c56 100644 --- a/libc/test/src/string/CMakeLists.txt +++ b/libc/test/src/string/CMakeLists.txt @@ -14,6 +14,23 @@ add_libc_unittest( LibcMemoryHelpers ) +add_header_library( + strchr_test_support + HDRS + StrchrTest.h +) + +add_libc_unittest( + index_test + SUITE + libc_string_unittests + SRCS + index_test.cpp + DEPENDS + libc.src.string.index + .strchr_test_support +) + add_libc_unittest( memccpy_test SUITE @@ -55,6 +72,17 @@ add_libc_unittest( ) add_libc_unittest( + rindex_test + SUITE + libc_string_unittests + SRCS + rindex_test.cpp + DEPENDS + libc.src.string.rindex + .strchr_test_support +) + +add_libc_unittest( stpcpy_test SUITE libc_string_unittests @@ -84,12 +112,6 @@ add_libc_unittest( libc.src.string.strcat ) -add_header_library( - strchr_test_support - HDRS - StrchrTest.h -) - add_libc_unittest( strchr_test SUITE diff --git a/libc/test/src/string/index_test.cpp b/libc/test/src/string/index_test.cpp new file mode 100644 index 0000000..22202f0 --- /dev/null +++ b/libc/test/src/string/index_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for index -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "StrchrTest.h" + +#include "src/string/index.h" +#include "test/UnitTest/Test.h" + +STRCHR_TEST(Index, __llvm_libc::index) diff --git a/libc/test/src/string/rindex_test.cpp b/libc/test/src/string/rindex_test.cpp new file mode 100644 index 0000000..1e59696 --- /dev/null +++ b/libc/test/src/string/rindex_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for rindex ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "StrchrTest.h" + +#include "src/string/rindex.h" +#include "test/UnitTest/Test.h" + +STRRCHR_TEST(Rindex, __llvm_libc::rindex) |