1 //===-- Template to diff single-input-single-output functions ---*- C++ -*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_LIBC_FUZZING_STDLIB_STRING_PARSER_OUTPUT_DIFF_H 10 #define LLVM_LIBC_FUZZING_STDLIB_STRING_PARSER_OUTPUT_DIFF_H 11 12 #include "fuzzing/math/Compare.h" 13 14 #include <stddef.h> 15 #include <stdint.h> 16 17 template <typename T> using StringInputSingleOutputFunc = T (*)(const char *); 18 19 template <typename T> StringParserOutputDiff(StringInputSingleOutputFunc<T> func1,StringInputSingleOutputFunc<T> func2,const uint8_t * data,size_t size)20void StringParserOutputDiff(StringInputSingleOutputFunc<T> func1, 21 StringInputSingleOutputFunc<T> func2, 22 const uint8_t *data, size_t size) { 23 if (size < sizeof(T)) 24 return; 25 26 const char *x = reinterpret_cast<const char *>(data); 27 28 T result1 = func1(x); 29 T result2 = func2(x); 30 31 if (!ValuesEqual(result1, result2)) 32 __builtin_trap(); 33 } 34 35 #endif // LLVM_LIBC_FUZZING_STDLIB_STRING_PARSER_OUTPUT_DIFF_H 36