[libc] Template the printf / scanf parser class (#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.
This commit is contained in:
@@ -3,9 +3,7 @@ add_libc_fuzzer(
|
||||
SRCS
|
||||
printf_parser_fuzz.cpp
|
||||
DEPENDS
|
||||
libc.src.stdio.printf_core.mock_parser
|
||||
COMPILE_OPTIONS
|
||||
-DLIBC_COPT_MOCK_ARG_LIST
|
||||
libc.src.stdio.printf_core.parser
|
||||
)
|
||||
|
||||
add_libc_fuzzer(
|
||||
|
||||
@@ -10,10 +10,6 @@
|
||||
///
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LIBC_COPT_MOCK_ARG_LIST
|
||||
#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.
|
||||
#endif
|
||||
|
||||
#include "src/__support/arg_list.h"
|
||||
#include "src/stdio/printf_core/parser.h"
|
||||
|
||||
@@ -37,7 +33,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
|
||||
auto mock_arg_list = internal::MockArgList();
|
||||
|
||||
auto parser = printf_core::Parser(in_str, mock_arg_list);
|
||||
auto parser =
|
||||
printf_core::Parser<internal::MockArgList>(in_str, mock_arg_list);
|
||||
|
||||
int str_percent_count = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user