diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -44,6 +44,15 @@ libc.src.string.strstr libc.src.string.strtok libc.src.string.strtok_r + + # stdlib.h entrypoints + libc.src.stdlib.atoi + libc.src.stdlib.atol + libc.src.stdlib.atoll + libc.src.stdlib.strtol + libc.src.stdlib.strtoll + libc.src.stdlib.strtoul + libc.src.stdlib.strtoull ) set(TARGET_LIBM_ENTRYPOINTS diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -44,6 +44,15 @@ libc.src.string.strstr libc.src.string.strtok libc.src.string.strtok_r + + # stdlib.h entrypoints + libc.src.stdlib.atoi + libc.src.stdlib.atol + libc.src.stdlib.atoll + libc.src.stdlib.strtol + libc.src.stdlib.strtoll + libc.src.stdlib.strtoul + libc.src.stdlib.strtoull ) set(TARGET_LIBM_ENTRYPOINTS @@ -157,15 +166,8 @@ libc.src.stdlib._Exit libc.src.stdlib.abort libc.src.stdlib.abs - libc.src.stdlib.atoi - libc.src.stdlib.atol - libc.src.stdlib.atoll libc.src.stdlib.labs libc.src.stdlib.llabs - libc.src.stdlib.strtol - libc.src.stdlib.strtoll - libc.src.stdlib.strtoul - libc.src.stdlib.strtoull # signal.h entrypoints libc.src.signal.raise diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt --- a/libc/config/windows/entrypoints.txt +++ b/libc/config/windows/entrypoints.txt @@ -44,6 +44,15 @@ libc.src.string.strstr libc.src.string.strtok libc.src.string.strtok_r + + # stdlib.h entrypoints + libc.src.stdlib.atoi + libc.src.stdlib.atol + libc.src.stdlib.atoll + libc.src.stdlib.strtol + libc.src.stdlib.strtoll + libc.src.stdlib.strtoul + libc.src.stdlib.strtoull ) set(TARGET_LIBM_ENTRYPOINTS diff --git a/libc/src/CMakeLists.txt b/libc/src/CMakeLists.txt --- a/libc/src/CMakeLists.txt +++ b/libc/src/CMakeLists.txt @@ -5,6 +5,7 @@ add_subdirectory(fenv) add_subdirectory(math) add_subdirectory(string) +add_subdirectory(stdlib) if(NOT LLVM_LIBC_FULL_BUILD) return() @@ -13,7 +14,6 @@ add_subdirectory(assert) add_subdirectory(signal) add_subdirectory(stdio) -add_subdirectory(stdlib) # TODO: Add this target conditional to the target OS. add_subdirectory(sys) add_subdirectory(threads) diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt --- a/libc/src/stdlib/CMakeLists.txt +++ b/libc/src/stdlib/CMakeLists.txt @@ -1,122 +1,126 @@ -if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) -endif() - add_entrypoint_object( - _Exit - ALIAS + atoi + SRCS + atoi.cpp + HDRS + atoi.h DEPENDS - .${LIBC_TARGET_OS}._Exit + libc.src.__support.str_conv_utils ) add_entrypoint_object( - abort + atol SRCS - abort.cpp + atol.cpp HDRS - abort.h + atol.h DEPENDS - libc.include.stdlib - libc.src.signal.raise - ._Exit + libc.src.__support.str_conv_utils ) add_entrypoint_object( - abs + atoll SRCS - abs.cpp + atoll.cpp HDRS - abs.h + atoll.h DEPENDS - libc.src.__support.integer_operations + libc.src.__support.str_conv_utils ) add_entrypoint_object( - atoi + strtol SRCS - atoi.cpp + strtol.cpp HDRS - atoi.h + strtol.h DEPENDS libc.src.__support.str_conv_utils ) add_entrypoint_object( - atol + strtoll SRCS - atol.cpp + strtoll.cpp HDRS - atol.h + strtoll.h DEPENDS libc.src.__support.str_conv_utils ) add_entrypoint_object( - atoll + strtoul SRCS - atoll.cpp + strtoul.cpp HDRS - atoll.h + strtoul.h DEPENDS libc.src.__support.str_conv_utils ) add_entrypoint_object( - labs + strtoull SRCS - labs.cpp + strtoull.cpp HDRS - labs.h + strtoull.h DEPENDS - libc.src.__support.integer_operations + libc.src.__support.str_conv_utils ) +if(NOT LLVM_LIBC_FULL_BUILD) + return() +endif() + +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) +endif() + add_entrypoint_object( - llabs - SRCS - llabs.cpp - HDRS - llabs.h + _Exit + ALIAS DEPENDS - libc.src.__support.integer_operations + .${LIBC_TARGET_OS}._Exit ) add_entrypoint_object( - strtol + abort SRCS - strtol.cpp + abort.cpp HDRS - strtol.h + abort.h DEPENDS - libc.src.__support.str_conv_utils + libc.include.stdlib + libc.src.signal.raise + ._Exit ) add_entrypoint_object( - strtoll + abs SRCS - strtoll.cpp + abs.cpp HDRS - strtoll.h + abs.h DEPENDS - libc.src.__support.str_conv_utils + libc.src.__support.integer_operations ) add_entrypoint_object( - strtoul + labs SRCS - strtoul.cpp + labs.cpp HDRS - strtoul.h + labs.h DEPENDS - libc.src.__support.str_conv_utils + libc.src.__support.integer_operations ) add_entrypoint_object( - strtoull + llabs SRCS - strtoull.cpp + llabs.cpp HDRS - strtoull.h + llabs.h DEPENDS - libc.src.__support.str_conv_utils + libc.src.__support.integer_operations ) diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt --- a/libc/test/src/CMakeLists.txt +++ b/libc/test/src/CMakeLists.txt @@ -31,6 +31,7 @@ add_subdirectory(fenv) add_subdirectory(math) add_subdirectory(string) +add_subdirectory(stdlib) if(NOT LLVM_LIBC_FULL_BUILD) return() @@ -39,7 +40,6 @@ add_subdirectory(assert) add_subdirectory(signal) add_subdirectory(stdio) -add_subdirectory(stdlib) add_subdirectory(sys) add_subdirectory(threads) add_subdirectory(time) diff --git a/libc/test/src/stdlib/CMakeLists.txt b/libc/test/src/stdlib/CMakeLists.txt --- a/libc/test/src/stdlib/CMakeLists.txt +++ b/libc/test/src/stdlib/CMakeLists.txt @@ -1,96 +1,130 @@ add_libc_testsuite(libc_stdlib_unittests) add_libc_unittest( - _Exit_test + atoi_test SUITE libc_stdlib_unittests SRCS - _Exit_test.cpp + atoi_test.cpp DEPENDS - libc.include.stdlib - libc.src.stdlib._Exit + libc.src.stdlib.atoi ) add_libc_unittest( - abort_test + atol_test SUITE libc_stdlib_unittests SRCS - abort_test.cpp + atol_test.cpp DEPENDS - libc.include.stdlib - libc.include.signal - libc.src.stdlib.abort - libc.src.stdlib._Exit - libc.src.signal.raise + libc.src.stdlib.atol ) add_libc_unittest( - abs_test + atoll_test SUITE libc_stdlib_unittests SRCS - abs_test.cpp + atoll_test.cpp DEPENDS - libc.src.stdlib.abs + libc.src.stdlib.atoll ) add_libc_unittest( - labs_test + strtol_test SUITE libc_stdlib_unittests SRCS - labs_test.cpp + strtol_test.cpp DEPENDS - libc.src.stdlib.labs + libc.src.stdlib.strtol ) add_libc_unittest( - llabs_test + strtoll_test SUITE libc_stdlib_unittests SRCS - llabs_test.cpp + strtoll_test.cpp DEPENDS - libc.src.stdlib.llabs + libc.src.stdlib.strtoll ) add_libc_unittest( - strtol_test + strtoul_test SUITE libc_stdlib_unittests SRCS - strtol_test.cpp + strtoul_test.cpp DEPENDS - libc.src.stdlib.strtol + libc.src.stdlib.strtoul ) add_libc_unittest( - strtoll_test + strtoull_test SUITE libc_stdlib_unittests SRCS - strtoll_test.cpp + strtoull_test.cpp DEPENDS - libc.src.stdlib.strtoll + libc.src.stdlib.strtoull ) +if(NOT LLVM_LIBC_FULL_BUILD) + return() +endif() + add_libc_unittest( - strtoul_test + _Exit_test SUITE libc_stdlib_unittests SRCS - strtoul_test.cpp + _Exit_test.cpp DEPENDS - libc.src.stdlib.strtoul + libc.include.stdlib + libc.src.stdlib._Exit ) add_libc_unittest( - strtoull_test + abort_test SUITE libc_stdlib_unittests SRCS - strtoull_test.cpp + abort_test.cpp DEPENDS - libc.src.stdlib.strtoull + libc.include.stdlib + libc.include.signal + libc.src.stdlib.abort + libc.src.stdlib._Exit + libc.src.signal.raise +) + +add_libc_unittest( + abs_test + SUITE + libc_stdlib_unittests + SRCS + abs_test.cpp + DEPENDS + libc.src.stdlib.abs +) + +add_libc_unittest( + labs_test + SUITE + libc_stdlib_unittests + SRCS + labs_test.cpp + DEPENDS + libc.src.stdlib.labs +) + +add_libc_unittest( + llabs_test + SUITE + libc_stdlib_unittests + SRCS + llabs_test.cpp + DEPENDS + libc.src.stdlib.llabs ) diff --git a/libc/test/src/stdlib/atol_test.cpp b/libc/test/src/stdlib/atol_test.cpp --- a/libc/test/src/stdlib/atol_test.cpp +++ b/libc/test/src/stdlib/atol_test.cpp @@ -46,7 +46,7 @@ ASSERT_EQ(__llvm_libc::atol(hexadecimal), 0l); const char *octal = "010"; - ASSERT_EQ(__llvm_libc::atol(hexadecimal), 10l); + ASSERT_EQ(__llvm_libc::atol(octal), 10l); const char *decimal_point = "5.9"; ASSERT_EQ(__llvm_libc::atol(decimal_point), 5l); diff --git a/libc/test/src/stdlib/atoll_test.cpp b/libc/test/src/stdlib/atoll_test.cpp --- a/libc/test/src/stdlib/atoll_test.cpp +++ b/libc/test/src/stdlib/atoll_test.cpp @@ -41,10 +41,10 @@ ASSERT_EQ(__llvm_libc::atoll(all_together), 110ll); const char *biggest_long_long = "9223372036854775807"; - ASSERT_EQ(__llvm_libc::atoll(biggest_int), LLONG_MAX); + ASSERT_EQ(__llvm_libc::atoll(biggest_long_long), LLONG_MAX); const char *smallest_long_long = "-9223372036854775808"; - ASSERT_EQ(__llvm_libc::atoll(smallest_int), LLONG_MIN); + ASSERT_EQ(__llvm_libc::atoll(smallest_long_long), LLONG_MIN); } TEST(LlvmLibcAToLLTest, NonBaseTenWholeNumbers) { @@ -52,10 +52,10 @@ ASSERT_EQ(__llvm_libc::atoll(hexadecimal), 0ll); const char *octal = "010"; - ASSERT_EQ(__llvm_libc::atoll(hexadecimal), 10ll); + ASSERT_EQ(__llvm_libc::atoll(octal), 10ll); const char *decimal_point = "5.9"; - ASSERT_EQ(__llvm_libc::atol(decimal_point), 5l); + ASSERT_EQ(__llvm_libc::atoll(decimal_point), 5ll); } TEST(LlvmLibcAToLLTest, NotNumbers) {