[libc] Enable string to integer conversion functions in the default build
Adds atoi, atol, atoll, strtol, strtoll, strtoul, and strtoull to the
list of entrypoints for Windows and aarch64 linux, as well as moving
them out of the LLVM_LIBC_FULL_BUILD condition for x86_64 linux.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D108477
GitOrigin-RevId: eff11176c5ca6a9d1fa8b27a998ba811824669c6
diff --git a/config/linux/aarch64/entrypoints.txt b/config/linux/aarch64/entrypoints.txt
index 0bb899c..cbdb9d9 100644
--- a/config/linux/aarch64/entrypoints.txt
+++ b/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/config/linux/x86_64/entrypoints.txt b/config/linux/x86_64/entrypoints.txt
index 4fb4ad4..3640271 100644
--- a/config/linux/x86_64/entrypoints.txt
+++ b/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/config/windows/entrypoints.txt b/config/windows/entrypoints.txt
index 2809218..9194d3d 100644
--- a/config/windows/entrypoints.txt
+++ b/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/src/CMakeLists.txt b/src/CMakeLists.txt
index db27021..a02c310 100644
--- a/src/CMakeLists.txt
+++ b/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/src/stdlib/CMakeLists.txt b/src/stdlib/CMakeLists.txt
index cd2f2f1..bf1b637 100644
--- a/src/stdlib/CMakeLists.txt
+++ b/src/stdlib/CMakeLists.txt
@@ -1,36 +1,3 @@
-if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
- add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
-endif()
-
-add_entrypoint_object(
- _Exit
- ALIAS
- DEPENDS
- .${LIBC_TARGET_OS}._Exit
-)
-
-add_entrypoint_object(
- abort
- SRCS
- abort.cpp
- HDRS
- abort.h
- DEPENDS
- libc.include.stdlib
- libc.src.signal.raise
- ._Exit
-)
-
-add_entrypoint_object(
- abs
- SRCS
- abs.cpp
- HDRS
- abs.h
- DEPENDS
- libc.src.__support.integer_operations
-)
-
add_entrypoint_object(
atoi
SRCS
@@ -62,26 +29,6 @@
)
add_entrypoint_object(
- labs
- SRCS
- labs.cpp
- HDRS
- labs.h
- DEPENDS
- libc.src.__support.integer_operations
-)
-
-add_entrypoint_object(
- llabs
- SRCS
- llabs.cpp
- HDRS
- llabs.h
- DEPENDS
- libc.src.__support.integer_operations
-)
-
-add_entrypoint_object(
strtol
SRCS
strtol.cpp
@@ -120,3 +67,60 @@
DEPENDS
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(
+ _Exit
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}._Exit
+)
+
+add_entrypoint_object(
+ abort
+ SRCS
+ abort.cpp
+ HDRS
+ abort.h
+ DEPENDS
+ libc.include.stdlib
+ libc.src.signal.raise
+ ._Exit
+)
+
+add_entrypoint_object(
+ abs
+ SRCS
+ abs.cpp
+ HDRS
+ abs.h
+ DEPENDS
+ libc.src.__support.integer_operations
+)
+
+add_entrypoint_object(
+ labs
+ SRCS
+ labs.cpp
+ HDRS
+ labs.h
+ DEPENDS
+ libc.src.__support.integer_operations
+)
+
+add_entrypoint_object(
+ llabs
+ SRCS
+ llabs.cpp
+ HDRS
+ llabs.h
+ DEPENDS
+ libc.src.__support.integer_operations
+)
diff --git a/test/src/CMakeLists.txt b/test/src/CMakeLists.txt
index 5fc3fbb..04235da 100644
--- a/test/src/CMakeLists.txt
+++ b/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/test/src/stdlib/CMakeLists.txt b/test/src/stdlib/CMakeLists.txt
index 648d855..6aed171 100644
--- a/test/src/stdlib/CMakeLists.txt
+++ b/test/src/stdlib/CMakeLists.txt
@@ -1,6 +1,80 @@
add_libc_testsuite(libc_stdlib_unittests)
add_libc_unittest(
+ atoi_test
+ SUITE
+ libc_stdlib_unittests
+ SRCS
+ atoi_test.cpp
+ DEPENDS
+ libc.src.stdlib.atoi
+)
+
+add_libc_unittest(
+ atol_test
+ SUITE
+ libc_stdlib_unittests
+ SRCS
+ atol_test.cpp
+ DEPENDS
+ libc.src.stdlib.atol
+)
+
+add_libc_unittest(
+ atoll_test
+ SUITE
+ libc_stdlib_unittests
+ SRCS
+ atoll_test.cpp
+ DEPENDS
+ libc.src.stdlib.atoll
+)
+
+add_libc_unittest(
+ strtol_test
+ SUITE
+ libc_stdlib_unittests
+ SRCS
+ strtol_test.cpp
+ DEPENDS
+ libc.src.stdlib.strtol
+)
+
+add_libc_unittest(
+ strtoll_test
+ SUITE
+ libc_stdlib_unittests
+ SRCS
+ strtoll_test.cpp
+ DEPENDS
+ libc.src.stdlib.strtoll
+)
+
+add_libc_unittest(
+ strtoul_test
+ SUITE
+ libc_stdlib_unittests
+ SRCS
+ strtoul_test.cpp
+ DEPENDS
+ libc.src.stdlib.strtoul
+)
+
+add_libc_unittest(
+ strtoull_test
+ SUITE
+ libc_stdlib_unittests
+ SRCS
+ strtoull_test.cpp
+ DEPENDS
+ libc.src.stdlib.strtoull
+)
+
+if(NOT LLVM_LIBC_FULL_BUILD)
+ return()
+endif()
+
+add_libc_unittest(
_Exit_test
SUITE
libc_stdlib_unittests
@@ -54,43 +128,3 @@
DEPENDS
libc.src.stdlib.llabs
)
-
-add_libc_unittest(
- strtol_test
- SUITE
- libc_stdlib_unittests
- SRCS
- strtol_test.cpp
- DEPENDS
- libc.src.stdlib.strtol
-)
-
-add_libc_unittest(
- strtoll_test
- SUITE
- libc_stdlib_unittests
- SRCS
- strtoll_test.cpp
- DEPENDS
- libc.src.stdlib.strtoll
-)
-
-add_libc_unittest(
- strtoul_test
- SUITE
- libc_stdlib_unittests
- SRCS
- strtoul_test.cpp
- DEPENDS
- libc.src.stdlib.strtoul
-)
-
-add_libc_unittest(
- strtoull_test
- SUITE
- libc_stdlib_unittests
- SRCS
- strtoull_test.cpp
- DEPENDS
- libc.src.stdlib.strtoull
-)
diff --git a/test/src/stdlib/atol_test.cpp b/test/src/stdlib/atol_test.cpp
index a2e0444..7290ef1 100644
--- a/test/src/stdlib/atol_test.cpp
+++ b/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/test/src/stdlib/atoll_test.cpp b/test/src/stdlib/atoll_test.cpp
index c716367..74c8621 100644
--- a/test/src/stdlib/atoll_test.cpp
+++ b/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) {