summaryrefslogtreecommitdiff
path: root/libc/fuzzing
diff options
context:
space:
mode:
authorSiva Chandra Reddy <sivachandra@google.com>2021-01-03 22:33:48 -0800
committerSiva Chandra Reddy <sivachandra@google.com>2021-01-05 22:32:39 -0800
commit7f7b0dc4e15fac5f91f8f6dcc7f91c9025f41ae0 (patch)
treed4b5b63690e551bb5f8e81e56270aa5b43f3c3d7 /libc/fuzzing
parent993d8ac5cb935b78fb136c25a7e4bae18852f429 (diff)
downloadllvm-7f7b0dc4e15fac5f91f8f6dcc7f91c9025f41ae0.tar.gz
[libc] Add implementations of nextafter[f|l] functions.
A differential fuzzer for these functions has also been added. Along the way, a small correction has been done to the normal/subnormal limits of x86 long double values. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D94109
Diffstat (limited to 'libc/fuzzing')
-rw-r--r--libc/fuzzing/math/CMakeLists.txt12
-rw-r--r--libc/fuzzing/math/Compare.h1
-rw-r--r--libc/fuzzing/math/nextafter_differential_fuzz.cpp26
3 files changed, 39 insertions, 0 deletions
diff --git a/libc/fuzzing/math/CMakeLists.txt b/libc/fuzzing/math/CMakeLists.txt
index 7c710fcecfdb..af9a5d30765e 100644
--- a/libc/fuzzing/math/CMakeLists.txt
+++ b/libc/fuzzing/math/CMakeLists.txt
@@ -48,3 +48,15 @@ add_libc_fuzzer(
libc.utils.FPUtil.fputil
libc.utils.CPP.standalone_cpp
)
+
+add_libc_fuzzer(
+ nextafter_differential_fuzz
+ SRCS
+ nextafter_differential_fuzz.cpp
+ HDRS
+ TwoInputSingleOutputDiff.h
+ DEPENDS
+ libc.src.math.nextafter
+ libc.src.math.nextafterf
+ libc.src.math.nextafterl
+)
diff --git a/libc/fuzzing/math/Compare.h b/libc/fuzzing/math/Compare.h
index 62ab6c791070..11d54650f66f 100644
--- a/libc/fuzzing/math/Compare.h
+++ b/libc/fuzzing/math/Compare.h
@@ -10,6 +10,7 @@
#define LLVM_LIBC_FUZZING_MATH_COMPARE_H
#include "utils/CPP/TypeTraits.h"
+#include "utils/FPUtil/FPBits.h"
template <typename T>
__llvm_libc::cpp::EnableIfType<__llvm_libc::cpp::IsFloatingPointType<T>::Value,
diff --git a/libc/fuzzing/math/nextafter_differential_fuzz.cpp b/libc/fuzzing/math/nextafter_differential_fuzz.cpp
new file mode 100644
index 000000000000..f4a7891df2aa
--- /dev/null
+++ b/libc/fuzzing/math/nextafter_differential_fuzz.cpp
@@ -0,0 +1,26 @@
+//===-- nextafter_differential_fuzz.cpp
+//---------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// Differential fuzz test for llvm-libc nextafter implementation.
+///
+//===----------------------------------------------------------------------===//
+
+#include "fuzzing/math/TwoInputSingleOutputDiff.h"
+
+#include "src/math/nextafter.h"
+#include "src/math/nextafterf.h"
+#include "src/math/nextafterl.h"
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ TwoInputSingleOutputDiff<float, float>(&__llvm_libc::nextafterf,
+ &::nextafterf, data, size);
+ TwoInputSingleOutputDiff<double, double>(&__llvm_libc::nextafter,
+ &::nextafter, data, size);
+ return 0;
+}