diff --git a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake --- a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake +++ b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake @@ -5,10 +5,6 @@ # Initialize ALL_CPU_FEATURES as empty list. set(ALL_CPU_FEATURES "") -if(LIBC_TARGET_ARCHITECTURE_IS_GPU) - return() -endif() - if(${LIBC_TARGET_ARCHITECTURE_IS_X86}) set(ALL_CPU_FEATURES SSE2 SSE4_2 AVX AVX2 AVX512F AVX512BW FMA) set(LIBC_COMPILE_OPTIONS_NATIVE -march=native) @@ -26,6 +22,10 @@ # # ) function(cpu_supports output_var features) + if(LIBC_TARGET_ARCHITECTURE_IS_GPU) + unset(${output_var} PARENT_SCOPE) + return() + endif() _intersection(var "${LIBC_CPU_FEATURES}" "${features}") if("${var}" STREQUAL "${features}") set(${output_var} TRUE PARENT_SCOPE) diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt --- a/libc/config/gpu/entrypoints.txt +++ b/libc/config/gpu/entrypoints.txt @@ -56,19 +56,8 @@ # stdlib.h entrypoints libc.src.stdlib.abs - libc.src.stdlib.atoi - libc.src.stdlib.atof - libc.src.stdlib.atol - libc.src.stdlib.atoll libc.src.stdlib.labs libc.src.stdlib.llabs - libc.src.stdlib.strtod - libc.src.stdlib.strtof - libc.src.stdlib.strtol - libc.src.stdlib.strtold - libc.src.stdlib.strtoll - libc.src.stdlib.strtoul - libc.src.stdlib.strtoull # stdlib.h entrypoints libc.src.stdlib._Exit diff --git a/libc/docs/gpu/support.rst b/libc/docs/gpu/support.rst --- a/libc/docs/gpu/support.rst +++ b/libc/docs/gpu/support.rst @@ -85,17 +85,17 @@ Function Name Available RPC Required ============= ========= ============ abs |check| -atoi |check| -atof |check| -atol |check| -atoll |check| +atoi +atof +atol +atoll labs |check| llabs |check| -strtod |check| -strtof |check| -strtol |check| -strtold |check| -strtoll |check| -strtoul |check| -strtoull |check| +strtod +strtof +strtol +strtold +strtoll +strtoul +strtoull ============= ========= ============ diff --git a/libc/test/CMakeLists.txt b/libc/test/CMakeLists.txt --- a/libc/test/CMakeLists.txt +++ b/libc/test/CMakeLists.txt @@ -22,7 +22,7 @@ return() endif() -if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU) +if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX) add_subdirectory(src) add_subdirectory(utils) endif() diff --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt --- a/libc/test/UnitTest/CMakeLists.txt +++ b/libc/test/UnitTest/CMakeLists.txt @@ -138,3 +138,12 @@ target_compile_options(${lib} PRIVATE -fno-exceptions -fno-rtti) target_link_libraries(${lib} LibcUnitTest) endforeach() + +# The GPU needs these flags applied to override the system triple. +if(LIBC_TARGET_ARCHITECTURE_IS_GPU) + foreach(lib LibcMemoryHelpers) + target_include_directories(${lib} PRIVATE ${LIBC_BUILD_DIR}/include) + target_compile_options(${lib} + PRIVATE ${LIBC_HERMETIC_TEST_COMPILE_OPTIONS} -ffreestanding -nostdlib -nostdlib++) + endforeach() +endif() 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 @@ -9,7 +9,7 @@ if(MATH_UNITTEST_NEED_MPFR) if(NOT LIBC_TESTS_CAN_USE_MPFR) - message("WARNING: Math test ${name} will be skipped as MPFR library is not available.") + message(VERBOSE "Math test ${name} will be skipped as MPFR library is not available.") return() endif() endif() diff --git a/libc/test/src/__support/CMakeLists.txt b/libc/test/src/__support/CMakeLists.txt --- a/libc/test/src/__support/CMakeLists.txt +++ b/libc/test/src/__support/CMakeLists.txt @@ -54,15 +54,18 @@ libc.src.__support.CPP.string_view ) -add_libc_test( - arg_list_test - SUITE - libc-support-tests - SRCS - arg_list_test.cpp - DEPENDS - libc.src.__support.arg_list -) +# The GPU does not support varargs currently. +if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU) + add_libc_test( + arg_list_test + SUITE + libc-support-tests + SRCS + arg_list_test.cpp + DEPENDS + libc.src.__support.arg_list + ) +endif() add_libc_test( uint_test diff --git a/libc/test/src/__support/File/CMakeLists.txt b/libc/test/src/__support/File/CMakeLists.txt --- a/libc/test/src/__support/File/CMakeLists.txt +++ b/libc/test/src/__support/File/CMakeLists.txt @@ -1,6 +1,7 @@ -if(NOT (TARGET libc.src.__support.threads.mutex)) +if(NOT (TARGET libc.src.__support.threads.mutex) OR LIBC_TARGET_ARCHITECTURE_IS_GPU) # Not all platforms have a mutex implementation. If mutex is unvailable, - # we just skip everything about files. + # we just skip everything about files. The GPU does not currently support + # files as well. return() endif() diff --git a/libc/test/src/__support/blockstore_test.cpp b/libc/test/src/__support/blockstore_test.cpp --- a/libc/test/src/__support/blockstore_test.cpp +++ b/libc/test/src/__support/blockstore_test.cpp @@ -90,10 +90,11 @@ populate_and_iterate<4, 10, true>(); } -TEST_F(LlvmLibcBlockStoreTest, Back) { - back_test(); - back_test(); -} +TEST_F(LlvmLibcBlockStoreTest, Back) { back_test(); } + +// FIXME: Combing this test with the above test makes the AMDGPU backend +// generate code which hangs. This should be fixed in the clang compiler. +TEST_F(LlvmLibcBlockStoreTest, BackReverse) { back_test(); } TEST_F(LlvmLibcBlockStoreTest, Empty) { empty_test(); diff --git a/libc/test/src/errno/CMakeLists.txt b/libc/test/src/errno/CMakeLists.txt --- a/libc/test/src/errno/CMakeLists.txt +++ b/libc/test/src/errno/CMakeLists.txt @@ -1,4 +1,4 @@ -if(NOT LLVM_LIBC_FULL_BUILD) +if(NOT LLVM_LIBC_FULL_BUILD OR LIBC_TARGET_ARCHITECTURE_IS_GPU) return() endif() diff --git a/libc/test/src/stdio/CMakeLists.txt b/libc/test/src/stdio/CMakeLists.txt --- a/libc/test/src/stdio/CMakeLists.txt +++ b/libc/test/src/stdio/CMakeLists.txt @@ -318,6 +318,10 @@ libc.src.stdio.setvbuf ) +if(LIBC_TARGET_ARCHITECTURE_IS_GPU) + return() +endif() + add_subdirectory(printf_core) add_subdirectory(scanf_core) add_subdirectory(testdata) diff --git a/libc/test/src/string/StrchrTest.h b/libc/test/src/string/StrchrTest.h --- a/libc/test/src/string/StrchrTest.h +++ b/libc/test/src/string/StrchrTest.h @@ -120,7 +120,7 @@ } void findsLastBehindFirstNullTerminator() { - const char src[6] = {'a', 'a', '\0', 'b', '\0', 'c'}; + static const char src[6] = {'a', 'a', '\0', 'b', '\0', 'c'}; // 'b' is behind a null terminator, so should not be found. ASSERT_STREQ(Func(src, 'b'), nullptr); // Same goes for 'c'.