[libc-commits] [libc] 9c7a370 - Reland "[libc] Add {,r}index"

Alex Brachet via libc-commits libc-commits at lists.llvm.org
Mon Apr 10 21:32:21 PDT 2023


Author: Alex Brachet
Date: 2023-04-11T04:30:50Z
New Revision: 9c7a3705050d0a581d1ae2402f52712f138c3760

URL: https://github.com/llvm/llvm-project/commit/9c7a3705050d0a581d1ae2402f52712f138c3760
DIFF: https://github.com/llvm/llvm-project/commit/9c7a3705050d0a581d1ae2402f52712f138c3760.diff

LOG: Reland "[libc] Add {,r}index"

Differential Revision: https://reviews.llvm.org/D147464

Added: 
    

Modified: 
    libc/config/linux/aarch64/entrypoints.txt
    libc/config/linux/arm/entrypoints.txt
    libc/config/linux/riscv64/entrypoints.txt
    libc/config/linux/x86_64/entrypoints.txt
    libc/spec/bsd_ext.td
    libc/src/string/CMakeLists.txt
    libc/test/src/string/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 6fb32065856d4..7d76e83d27a36 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 4ae8b0f44a8be..5ed49d03eb9c9 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 0c59d91cc0c50..936949f779af7 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 13c788df6400e..9e450eadc9d4e 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 3420c2098449f..3829e57e9765a 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 f6980ca632bb9..f51e68c99193d 100644
--- a/libc/src/string/CMakeLists.txt
+++ b/libc/src/string/CMakeLists.txt
@@ -31,6 +31,16 @@ add_entrypoint_object(
     bcopy.h
 )
 
+add_entrypoint_object(
+  index
+  SRCS
+    index.cpp
+  HDRS
+    index.h
+  DEPENDS
+    .string_utils
+)
+
 add_entrypoint_object(
   memccpy
   SRCS
@@ -67,6 +77,16 @@ add_entrypoint_object(
     memrchr.h
 )
 
+add_entrypoint_object(
+  rindex
+  SRCS
+    rindex.cpp
+  HDRS
+    rindex.h
+  DEPENDS
+    .string_utils
+)
+
 add_entrypoint_object(
   stpcpy
   SRCS

diff  --git a/libc/test/src/string/CMakeLists.txt b/libc/test/src/string/CMakeLists.txt
index ed9d38aa482a1..6bb4c562a239a 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
@@ -54,6 +71,17 @@ add_libc_unittest(
     libc.src.string.memrchr
 )
 
+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
@@ -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


        


More information about the libc-commits mailing list