Skip to content

Commit e0be78b

Browse files
authored
[libc] Template the printf / scanf parser class (llvm#66277)
Summary: The parser class for stdio currently accepts different argument providers. In-tree this is only used for a fuzzer test, however, the proposed implementation of the GPU handling of printf / scanf will require custom argument handlers. This makes the current approach of using a preprocessor macro messier. This path proposed folding this logic into a template instantiation. The downside to this is that because the implementation of the parser class is placed into an implementation file we need to manually instantiate the needed templates which will slightly bloat binary size. Alternatively we could remove the implementation file, or key off of the `libc` external packaging macro so it is not present in the installed version.
1 parent f66f354 commit e0be78b

File tree

13 files changed

+637
-757
lines changed

13 files changed

+637
-757
lines changed

libc/fuzzing/stdio/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ add_libc_fuzzer(
33
SRCS
44
printf_parser_fuzz.cpp
55
DEPENDS
6-
libc.src.stdio.printf_core.mock_parser
7-
COMPILE_OPTIONS
8-
-DLIBC_COPT_MOCK_ARG_LIST
6+
libc.src.stdio.printf_core.parser
97
)
108

119
add_libc_fuzzer(

libc/fuzzing/stdio/printf_parser_fuzz.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
///
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef LIBC_COPT_MOCK_ARG_LIST
14-
#error The printf Parser Fuzzer must be compiled with LIBC_COPT_MOCK_ARG_LIST, and the parser itself must also be compiled with that option when it's linked against the fuzzer.
15-
#endif
16-
1713
#include "src/__support/arg_list.h"
1814
#include "src/stdio/printf_core/parser.h"
1915

@@ -37,7 +33,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
3733

3834
auto mock_arg_list = internal::MockArgList();
3935

40-
auto parser = printf_core::Parser(in_str, mock_arg_list);
36+
auto parser =
37+
printf_core::Parser<internal::MockArgList>(in_str, mock_arg_list);
4138

4239
int str_percent_count = 0;
4340

libc/src/stdio/printf_core/CMakeLists.txt

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,8 @@ add_header_library(
88
libc.src.__support.FPUtil.fp_bits
99
)
1010

11-
add_object_library(
11+
add_header_library(
1212
parser
13-
SRCS
14-
parser.cpp
15-
HDRS
16-
parser.h
17-
DEPENDS
18-
.core_structs
19-
libc.src.__support.arg_list
20-
libc.src.__support.ctype_utils
21-
libc.src.__support.str_to_integer
22-
libc.src.__support.CPP.bit
23-
libc.src.__support.CPP.optional
24-
libc.src.__support.CPP.string_view
25-
libc.src.__support.CPP.type_traits
26-
libc.src.__support.common
27-
)
28-
29-
add_object_library(
30-
mock_parser
31-
SRCS
32-
parser.cpp
3313
HDRS
3414
parser.h
3515
DEPENDS
@@ -42,8 +22,6 @@ add_object_library(
4222
libc.src.__support.CPP.string_view
4323
libc.src.__support.CPP.type_traits
4424
libc.src.__support.common
45-
COMPILE_OPTIONS
46-
-DLIBC_COPT_MOCK_ARG_LIST
4725
)
4826

4927
add_object_library(

0 commit comments

Comments
 (0)