diff options
author | sribee8 <sriya.pratipati@gmail.com> | 2025-07-14 16:36:24 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-14 16:36:24 +0000 |
commit | 1f97c9432d010c7c5eefc5ebe2648af2d9d5863d (patch) | |
tree | d7cdf463fd9c469c753200267e293765b9395b73 /libc/fuzzing/math/exp10_fuzz.cpp | |
parent | a76dfde9366d022307d9f45ec21b4016b46c9e0c (diff) | |
download | llvm-1f97c9432d010c7c5eefc5ebe2648af2d9d5863d.zip llvm-1f97c9432d010c7c5eefc5ebe2648af2d9d5863d.tar.gz llvm-1f97c9432d010c7c5eefc5ebe2648af2d9d5863d.tar.bz2 |
[libc] exp fuzz tests (#148086)
Created fuzz tests for exp functions
---------
Co-authored-by: Sriya Pratipati <sriyap@google.com>
Diffstat (limited to 'libc/fuzzing/math/exp10_fuzz.cpp')
-rw-r--r-- | libc/fuzzing/math/exp10_fuzz.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/libc/fuzzing/math/exp10_fuzz.cpp b/libc/fuzzing/math/exp10_fuzz.cpp new file mode 100644 index 0000000..2baef03 --- /dev/null +++ b/libc/fuzzing/math/exp10_fuzz.cpp @@ -0,0 +1,38 @@ +//===-- exp10_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 +// +//===----------------------------------------------------------------------===// +/// +/// Fuzzing test for llvm-libc exp10 implementation. +/// +//===----------------------------------------------------------------------===// + +#include "src/math/exp10.h" +#include "utils/MPFRWrapper/mpfr_inc.h" +#include <math.h> + +extern "C" int LLVMFuzzerTestOneInput(double x) { + // remove NaN and inf + if (isnan(x) || isinf(x)) + return 0; + // signed zeros already tested in unit tests + if (signbit(x) && x == 0.0) + return 0; + mpfr_t input; + mpfr_init2(input, 53); + mpfr_set_d(input, x, MPFR_RNDN); + int output = mpfr_exp10(input, input, MPFR_RNDN); + mpfr_subnormalize(input, output, MPFR_RNDN); + double to_compare = mpfr_get_d(input, MPFR_RNDN); + + double result = LIBC_NAMESPACE::exp10(x); + + if (result != to_compare) + __builtin_trap(); + + mpfr_clear(input); + return 0; +} |