Skip to content

Commit 431ea2d

Browse files
[libc] move bcmp, bzero, bcopy, index, rindex, strcasecmp, strncasecmp to strings.h (#118899)
docgen relies on the convention that we have a file foo.cpp in libc/src/\<header\>/. Because the above functions weren't in libc/src/strings/ but rather libc/src/string/, docgen could not find that we had implemented these. Rather than add special carve outs to docgen, let's fix up our sources for these 7 functions to stick with the existing conventions the rest of the codebase follows. Link: #118860 Fixes: #118875
1 parent 0fb0617 commit 431ea2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+365
-348
lines changed

libc/benchmarks/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ target_link_libraries(libc.benchmarks.memory_functions.opt_host
204204
PRIVATE
205205
libc-memory-benchmark
206206
libc.src.string.memcmp_opt_host.__internal__
207-
libc.src.string.bcmp_opt_host.__internal__
208207
libc.src.string.memcpy_opt_host.__internal__
209-
libc.src.string.memset_opt_host.__internal__
210-
libc.src.string.bzero_opt_host.__internal__
211208
libc.src.string.memmove_opt_host.__internal__
209+
libc.src.string.memset_opt_host.__internal__
210+
libc.src.strings.bcmp_opt_host.__internal__
211+
libc.src.strings.bzero_opt_host.__internal__
212212
benchmark_main
213213
)
214214
llvm_update_compile_flags(libc.benchmarks.memory_functions.opt_host)

libc/cmake/modules/LLVMLibCObjectRules.cmake

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,3 +452,41 @@ function(add_redirector_object target_name)
452452
BEFORE PRIVATE -fPIC ${LIBC_COMPILE_OPTIONS_DEFAULT}
453453
)
454454
endfunction(add_redirector_object)
455+
456+
# Helper to define a function with multiple implementations
457+
# - Computes flags to satisfy required/rejected features and arch,
458+
# - Declares an entry point,
459+
# - Attach the REQUIRE_CPU_FEATURES property to the target,
460+
# - Add the fully qualified target to `${name}_implementations` global property for tests.
461+
function(add_implementation name impl_name)
462+
cmake_parse_arguments(
463+
"ADD_IMPL"
464+
"" # Optional arguments
465+
"" # Single value arguments
466+
"REQUIRE;SRCS;HDRS;DEPENDS;COMPILE_OPTIONS;MLLVM_COMPILE_OPTIONS" # Multi value arguments
467+
${ARGN})
468+
469+
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
470+
# Note that '-mllvm' needs to be prefixed with 'SHELL:' to prevent CMake flag deduplication.
471+
foreach(opt IN LISTS ADD_IMPL_MLLVM_COMPILE_OPTIONS)
472+
list(APPEND ADD_IMPL_COMPILE_OPTIONS "SHELL:-mllvm ${opt}")
473+
endforeach()
474+
endif()
475+
476+
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
477+
# Prevent warning when passing x86 SIMD types as template arguments.
478+
# e.g. "warning: ignoring attributes on template argument ‘__m128i’ [-Wignored-attributes]"
479+
list(APPEND ADD_IMPL_COMPILE_OPTIONS "-Wno-ignored-attributes")
480+
endif()
481+
482+
add_entrypoint_object(${impl_name}
483+
NAME ${name}
484+
SRCS ${ADD_IMPL_SRCS}
485+
HDRS ${ADD_IMPL_HDRS}
486+
DEPENDS ${ADD_IMPL_DEPENDS}
487+
COMPILE_OPTIONS ${libc_opt_high_flag} ${ADD_IMPL_COMPILE_OPTIONS}
488+
)
489+
get_fq_target_name(${impl_name} fq_target_name)
490+
set_target_properties(${fq_target_name} PROPERTIES REQUIRE_CPU_FEATURES "${ADD_IMPL_REQUIRE}")
491+
set_property(GLOBAL APPEND PROPERTY "${name}_implementations" "${fq_target_name}")
492+
endfunction()

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,12 @@ function(add_integration_test test_name)
416416
libc.test.IntegrationTest.test
417417
# We always add the memory functions objects. This is because the
418418
# compiler's codegen can emit calls to the C memory functions.
419-
libc.src.string.bcmp
420-
libc.src.string.bzero
421419
libc.src.string.memcmp
422420
libc.src.string.memcpy
423421
libc.src.string.memmove
424422
libc.src.string.memset
423+
libc.src.strings.bcmp
424+
libc.src.strings.bzero
425425
)
426426

427427
if(libc.src.compiler.__stack_chk_fail IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
@@ -583,13 +583,13 @@ function(add_libc_hermetic test_name)
583583
libc.startup.${LIBC_TARGET_OS}.crt1
584584
# We always add the memory functions objects. This is because the
585585
# compiler's codegen can emit calls to the C memory functions.
586-
libc.src.string.bcmp
587-
libc.src.string.bzero
586+
libc.src.__support.StringUtil.error_to_string
588587
libc.src.string.memcmp
589588
libc.src.string.memcpy
590589
libc.src.string.memmove
591590
libc.src.string.memset
592-
libc.src.__support.StringUtil.error_to_string
591+
libc.src.strings.bcmp
592+
libc.src.strings.bzero
593593
)
594594

595595
if(libc.src.compiler.__stack_chk_fail IN_LIST TARGET_LLVMLIBC_ENTRYPOINTS)
@@ -766,3 +766,33 @@ function(add_libc_test test_name)
766766
endif()
767767
endif()
768768
endfunction(add_libc_test)
769+
770+
# Tests all implementations that can run on the target CPU.
771+
function(add_libc_multi_impl_test name suite)
772+
get_property(fq_implementations GLOBAL PROPERTY ${name}_implementations)
773+
foreach(fq_config_name IN LISTS fq_implementations)
774+
get_target_property(required_cpu_features ${fq_config_name} REQUIRE_CPU_FEATURES)
775+
cpu_supports(can_run "${required_cpu_features}")
776+
if(can_run)
777+
string(FIND ${fq_config_name} "." last_dot_loc REVERSE)
778+
math(EXPR name_loc "${last_dot_loc} + 1")
779+
string(SUBSTRING ${fq_config_name} ${name_loc} -1 target_name)
780+
add_libc_test(
781+
${target_name}_test
782+
SUITE
783+
${suite}
784+
COMPILE_OPTIONS
785+
${LIBC_COMPILE_OPTIONS_NATIVE}
786+
LINK_LIBRARIES
787+
LibcMemoryHelpers
788+
${ARGN}
789+
DEPENDS
790+
${fq_config_name}
791+
libc.src.__support.macros.sanitizer
792+
)
793+
get_fq_target_name(${fq_config_name}_test fq_target_name)
794+
else()
795+
message(STATUS "Skipping test for '${fq_config_name}' insufficient host cpu features '${required_cpu_features}'")
796+
endif()
797+
endforeach()
798+
endfunction()

libc/config/baremetal/arm/entrypoints.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ set(TARGET_LIBC_ENTRYPOINTS
3131
libc.src.setjmp.setjmp
3232

3333
# string.h entrypoints
34-
libc.src.string.bcmp
35-
libc.src.string.bcopy
36-
libc.src.string.bzero
37-
libc.src.string.index
3834
libc.src.string.memccpy
3935
libc.src.string.memchr
4036
libc.src.string.memcmp
@@ -45,10 +41,8 @@ set(TARGET_LIBC_ENTRYPOINTS
4541
libc.src.string.memrchr
4642
libc.src.string.memset
4743
libc.src.string.memset_explicit
48-
libc.src.string.rindex
4944
libc.src.string.stpcpy
5045
libc.src.string.stpncpy
51-
libc.src.string.strcasecmp
5246
libc.src.string.strcasestr
5347
libc.src.string.strcat
5448
libc.src.string.strchr
@@ -62,7 +56,6 @@ set(TARGET_LIBC_ENTRYPOINTS
6256
libc.src.string.strlcat
6357
libc.src.string.strlcpy
6458
libc.src.string.strlen
65-
libc.src.string.strncasecmp
6659
libc.src.string.strncat
6760
libc.src.string.strncmp
6861
libc.src.string.strncpy
@@ -76,6 +69,15 @@ set(TARGET_LIBC_ENTRYPOINTS
7669
libc.src.string.strtok_r
7770
libc.src.string.strxfrm
7871

72+
# strings.h entrypoints
73+
libc.src.strings.bcmp
74+
libc.src.strings.bcopy
75+
libc.src.strings.bzero
76+
libc.src.strings.index
77+
libc.src.strings.rindex
78+
libc.src.strings.strcasecmp
79+
libc.src.strings.strncasecmp
80+
7981
# inttypes.h entrypoints
8082
libc.src.inttypes.imaxabs
8183
libc.src.inttypes.imaxdiv

libc/config/baremetal/riscv/entrypoints.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ set(TARGET_LIBC_ENTRYPOINTS
2727
libc.src.errno.errno
2828

2929
# string.h entrypoints
30-
libc.src.string.bcmp
31-
libc.src.string.bcopy
32-
libc.src.string.bzero
33-
libc.src.string.index
3430
libc.src.string.memccpy
3531
libc.src.string.memchr
3632
libc.src.string.memcmp
@@ -41,10 +37,8 @@ set(TARGET_LIBC_ENTRYPOINTS
4137
libc.src.string.memrchr
4238
libc.src.string.memset
4339
libc.src.string.memset_explicit
44-
libc.src.string.rindex
4540
libc.src.string.stpcpy
4641
libc.src.string.stpncpy
47-
libc.src.string.strcasecmp
4842
libc.src.string.strcasestr
4943
libc.src.string.strcat
5044
libc.src.string.strchr
@@ -58,7 +52,6 @@ set(TARGET_LIBC_ENTRYPOINTS
5852
libc.src.string.strlcat
5953
libc.src.string.strlcpy
6054
libc.src.string.strlen
61-
libc.src.string.strncasecmp
6255
libc.src.string.strncat
6356
libc.src.string.strncmp
6457
libc.src.string.strncpy
@@ -72,6 +65,15 @@ set(TARGET_LIBC_ENTRYPOINTS
7265
libc.src.string.strtok_r
7366
libc.src.string.strxfrm
7467

68+
# strings.h entrypoints
69+
libc.src.strings.bcmp
70+
libc.src.strings.bcopy
71+
libc.src.strings.bzero
72+
libc.src.strings.index
73+
libc.src.strings.rindex
74+
libc.src.strings.strcasecmp
75+
libc.src.strings.strncasecmp
76+
7577
# inttypes.h entrypoints
7678
libc.src.inttypes.imaxabs
7779
libc.src.inttypes.imaxdiv

libc/config/darwin/arm/entrypoints.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ set(TARGET_LIBC_ENTRYPOINTS
2121
libc.src.errno.errno
2222

2323
# string.h entrypoints
24-
libc.src.string.bcmp
25-
libc.src.string.bcopy
26-
libc.src.string.bzero
2724
libc.src.string.memccpy
2825
libc.src.string.memchr
2926
libc.src.string.memcmp
@@ -35,7 +32,6 @@ set(TARGET_LIBC_ENTRYPOINTS
3532
libc.src.string.memset
3633
libc.src.string.stpcpy
3734
libc.src.string.stpncpy
38-
libc.src.string.strcasecmp
3935
libc.src.string.strcasestr
4036
libc.src.string.strcat
4137
libc.src.string.strchr
@@ -46,7 +42,6 @@ set(TARGET_LIBC_ENTRYPOINTS
4642
libc.src.string.strlcat
4743
libc.src.string.strlcpy
4844
libc.src.string.strlen
49-
libc.src.string.strncasecmp
5045
libc.src.string.strncat
5146
libc.src.string.strncmp
5247
libc.src.string.strncpy
@@ -62,6 +57,13 @@ set(TARGET_LIBC_ENTRYPOINTS
6257
libc.src.string.strdup
6358
libc.src.string.strndup
6459

60+
# strings.h entrypoints
61+
libc.src.strings.bcmp
62+
libc.src.strings.bcopy
63+
libc.src.strings.bzero
64+
libc.src.strings.strcasecmp
65+
libc.src.strings.strncasecmp
66+
6567
# inttypes.h entrypoints
6668
libc.src.inttypes.imaxabs
6769
libc.src.inttypes.imaxdiv

libc/config/darwin/x86_64/entrypoints.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ set(TARGET_LIBC_ENTRYPOINTS
1818
libc.src.ctype.toupper
1919

2020
# search.h entrypoints
21-
libc.src.search.lfind
21+
libc.src.search.lfind
2222

2323
# string.h entrypoints
24-
libc.src.string.bcmp
25-
libc.src.string.bzero
2624
libc.src.string.memccpy
2725
libc.src.string.memchr
2826
libc.src.string.memcmp
@@ -58,6 +56,10 @@ set(TARGET_LIBC_ENTRYPOINTS
5856
libc.src.string.strdup
5957
libc.src.string.strndup
6058

59+
# strings.h entrypoints
60+
libc.src.strings.bcmp
61+
libc.src.strings.bzero
62+
6163
# inttypes.h entrypoints
6264
libc.src.inttypes.imaxabs
6365
libc.src.inttypes.imaxdiv

libc/config/gpu/entrypoints.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ set(TARGET_LIBC_ENTRYPOINTS
3535
libc.src.ctype.toupper_l
3636

3737
# string.h entrypoints
38-
libc.src.string.bcmp
39-
libc.src.string.bcopy
40-
libc.src.string.bzero
41-
libc.src.string.index
4238
libc.src.string.memccpy
4339
libc.src.string.memchr
4440
libc.src.string.memcmp
@@ -48,10 +44,8 @@ set(TARGET_LIBC_ENTRYPOINTS
4844
libc.src.string.mempcpy
4945
libc.src.string.memrchr
5046
libc.src.string.memset
51-
libc.src.string.rindex
5247
libc.src.string.stpcpy
5348
libc.src.string.stpncpy
54-
libc.src.string.strcasecmp
5549
libc.src.string.strcasestr
5650
libc.src.string.strcat
5751
libc.src.string.strchr
@@ -66,7 +60,6 @@ set(TARGET_LIBC_ENTRYPOINTS
6660
libc.src.string.strlcat
6761
libc.src.string.strlcpy
6862
libc.src.string.strlen
69-
libc.src.string.strncasecmp
7063
libc.src.string.strncat
7164
libc.src.string.strncmp
7265
libc.src.string.strncpy
@@ -82,6 +75,15 @@ set(TARGET_LIBC_ENTRYPOINTS
8275
libc.src.string.strxfrm
8376
libc.src.string.strxfrm_l
8477

78+
# strings.h entrypoints
79+
libc.src.strings.bcmp
80+
libc.src.strings.bcopy
81+
libc.src.strings.bzero
82+
libc.src.strings.index
83+
libc.src.strings.rindex
84+
libc.src.strings.strcasecmp
85+
libc.src.strings.strncasecmp
86+
8587
# stdbit.h entrypoints
8688
libc.src.stdbit.stdc_bit_ceil_uc
8789
libc.src.stdbit.stdc_bit_ceil_ui

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ set(TARGET_LIBC_ENTRYPOINTS
4545
libc.src.sched.sched_yield
4646

4747
# string.h entrypoints
48-
libc.src.string.bcmp
49-
libc.src.string.bcopy
50-
libc.src.string.bzero
51-
libc.src.string.index
5248
libc.src.string.memccpy
5349
libc.src.string.memchr
5450
libc.src.string.memcmp
@@ -59,10 +55,8 @@ set(TARGET_LIBC_ENTRYPOINTS
5955
libc.src.string.memrchr
6056
libc.src.string.memset
6157
libc.src.string.memset_explicit
62-
libc.src.string.rindex
6358
libc.src.string.stpcpy
6459
libc.src.string.stpncpy
65-
libc.src.string.strcasecmp
6660
libc.src.string.strcasestr
6761
libc.src.string.strcat
6862
libc.src.string.strchr
@@ -77,7 +71,6 @@ set(TARGET_LIBC_ENTRYPOINTS
7771
libc.src.string.strlcat
7872
libc.src.string.strlcpy
7973
libc.src.string.strlen
80-
libc.src.string.strncasecmp
8174
libc.src.string.strncat
8275
libc.src.string.strncmp
8376
libc.src.string.strncpy
@@ -93,6 +86,15 @@ set(TARGET_LIBC_ENTRYPOINTS
9386
libc.src.string.strtok_r
9487
libc.src.string.strxfrm
9588

89+
# strings.h entrypoints
90+
libc.src.strings.bcmp
91+
libc.src.strings.bcopy
92+
libc.src.strings.bzero
93+
libc.src.strings.index
94+
libc.src.strings.rindex
95+
libc.src.strings.strcasecmp
96+
libc.src.strings.strncasecmp
97+
9698
# inttypes.h entrypoints
9799
libc.src.inttypes.imaxabs
98100
libc.src.inttypes.imaxdiv

0 commit comments

Comments
 (0)