Skip to content

Commit 2e3ee31

Browse files
committed
[libc] Enable 'sscanf' on the GPU #100211
Summary: We can enable the sscanf function on the GPU now. This required adding the configs to the scanf list so that the GPU build didn't do float conversions.
1 parent 59e07f3 commit 2e3ee31

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

libc/config/gpu/entrypoints.txt

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ set(TARGET_LIBC_ENTRYPOINTS
186186
libc.src.stdio.sprintf
187187
libc.src.stdio.vsnprintf
188188
libc.src.stdio.vsprintf
189+
libc.src.stdio.sscanf
189190
libc.src.stdio.feof
190191
libc.src.stdio.ferror
191192
libc.src.stdio.fflush

libc/docs/gpu/support.rst

+5-4
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,11 @@ printf |check| |check|
234234
vprintf |check| |check|
235235
fprintf |check| |check|
236236
vfprintf |check| |check|
237-
sprintf |check| |check|
238-
snprintf |check| |check|
239-
vsprintf |check| |check|
240-
vsnprintf |check| |check|
237+
sprintf |check|
238+
snprintf |check|
239+
vsprintf |check|
240+
vsnprintf |check|
241+
sscanf |check|
241242
putchar |check| |check|
242243
fclose |check| |check|
243244
fopen |check| |check|

libc/test/src/stdio/CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,13 @@ add_libc_test(
261261
${use_system_file}
262262
)
263263

264+
if(LIBC_CONF_SCANF_DISABLE_FLOAT)
265+
list(APPEND sscanf_test_copts "-DLIBC_COPT_SCANF_DISABLE_FLOAT")
266+
endif()
267+
if(LIBC_CONF_SCANF_DISABLE_INDEX_MODE)
268+
list(APPEND sscanf_test_copts "-DLIBC_COPT_SCANF_DISABLE_INDEX_MODE")
269+
endif()
270+
264271
add_libc_test(
265272
sscanf_test
266273
SUITE
@@ -271,6 +278,8 @@ add_libc_test(
271278
libc.src.stdio.sscanf
272279
LINK_LIBRARIES
273280
LibcFPTestHelpers
281+
COMPILE_OPTIONS
282+
${sscanf_test_copts}
274283
)
275284

276285
add_libc_test(

libc/test/src/stdio/sscanf_test.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ TEST(LlvmLibcSScanfTest, IntConvNoWriteTests) {
226226
EXPECT_EQ(result, 0);
227227
}
228228

229+
#ifndef LIBC_COPT_SCANF_DISABLE_FLOAT
229230
TEST(LlvmLibcSScanfTest, FloatConvSimple) {
230231
int ret_val;
231232
float result = 0;
@@ -580,7 +581,9 @@ TEST(LlvmLibcSScanfTest, FloatConvNoWrite) {
580581
ret_val = LIBC_NAMESPACE::sscanf("Not a float", "%*f", &result);
581582
EXPECT_EQ(ret_val, 0);
582583
}
584+
#endif
583585

586+
#ifndef LIBC_COPT_SCANF_DISABLE_INDEX_MODE
584587
TEST(LlvmLibcSScanfTest, CurPosCombined) {
585588
int ret_val;
586589
int result = -1;
@@ -628,6 +631,7 @@ TEST(LlvmLibcSScanfTest, CurPosCombined) {
628631
EXPECT_EQ(ret_val, 1);
629632
EXPECT_EQ(result, 320);
630633
}
634+
#endif
631635

632636
TEST(LlvmLibcSScanfTest, PointerConvCombined) {
633637
int ret_val;

0 commit comments

Comments
 (0)