1 //===-- Template to diff single-input-single-output functions ---*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_FUZZING_STDLIB_STRING_PARSER_OUTPUT_DIFF_H
10 #define LLVM_LIBC_FUZZING_STDLIB_STRING_PARSER_OUTPUT_DIFF_H
12 #include "fuzzing/math/Compare.h"
17 template <typename T
> using StringInputSingleOutputFunc
= T (*)(const char *);
20 void StringParserOutputDiff(StringInputSingleOutputFunc
<T
> func1
,
21 StringInputSingleOutputFunc
<T
> func2
,
22 const uint8_t *data
, size_t size
) {
26 const char *x
= reinterpret_cast<const char *>(data
);
31 if (!ValuesEqual(result1
, result2
))
36 using StringToNumberFunc
= T (*)(const char *, char **, int);
39 void StringToNumberOutputDiff(StringToNumberFunc
<T
> func1
,
40 StringToNumberFunc
<T
> func2
, const uint8_t *data
,
45 const char *x
= reinterpret_cast<const char *>(data
+ 1);
46 int base
= data
[0] % 36;
47 base
= base
+ ((base
== 0) ? 0 : 1);
49 char *outPtr1
= nullptr;
50 char *outPtr2
= nullptr;
52 T result1
= func1(x
, &outPtr1
, base
);
53 T result2
= func2(x
, &outPtr2
, base
);
55 if (!(ValuesEqual(result1
, result2
) && (*outPtr1
== *outPtr2
)))
59 #endif // LLVM_LIBC_FUZZING_STDLIB_STRING_PARSER_OUTPUT_DIFF_H