-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[libc] exp fuzz tests #148086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[libc] exp fuzz tests #148086
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Created fuzz tests for exp functions
@llvm/pr-subscribers-libc Author: None (sribee8) ChangesCreated fuzz tests for exp functions Full diff: https://github.com/llvm/llvm-project/pull/148086.diff 5 Files Affected:
diff --git a/libc/fuzzing/math/CMakeLists.txt b/libc/fuzzing/math/CMakeLists.txt
index e3c29651917fc..bf2be5c0b3cea 100644
--- a/libc/fuzzing/math/CMakeLists.txt
+++ b/libc/fuzzing/math/CMakeLists.txt
@@ -62,6 +62,42 @@ add_libc_fuzzer(
libc.src.math.nextafterl
)
+add_libc_fuzzer(
+ exp_fuzz
+ NEED_MPFR
+ SRCS
+ exp_fuzz.cpp
+ DEPENDS
+ libc.src.math.exp
+)
+
+add_libc_fuzzer(
+ exp10_fuzz
+ NEED_MPFR
+ SRCS
+ exp10_fuzz.cpp
+ DEPENDS
+ libc.src.math.exp10
+)
+
+add_libc_fuzzer(
+ exp2_fuzz
+ NEED_MPFR
+ SRCS
+ exp2_fuzz.cpp
+ DEPENDS
+ libc.src.math.exp2
+)
+
+add_libc_fuzzer(
+ expm1_fuzz
+ NEED_MPFR
+ SRCS
+ expm1_fuzz.cpp
+ DEPENDS
+ libc.src.math.expm1
+)
+
add_libc_fuzzer(
asin_fuzz
NEED_MPFR
diff --git a/libc/fuzzing/math/exp10_fuzz.cpp b/libc/fuzzing/math/exp10_fuzz.cpp
new file mode 100644
index 0000000000000..2baef03a264a4
--- /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;
+}
diff --git a/libc/fuzzing/math/exp2_fuzz.cpp b/libc/fuzzing/math/exp2_fuzz.cpp
new file mode 100644
index 0000000000000..8a2959047a6ca
--- /dev/null
+++ b/libc/fuzzing/math/exp2_fuzz.cpp
@@ -0,0 +1,38 @@
+//===-- exp2_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 exp2 implementation.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/math/exp2.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_exp2(input, input, MPFR_RNDN);
+ mpfr_subnormalize(input, output, MPFR_RNDN);
+ double to_compare = mpfr_get_d(input, MPFR_RNDN);
+
+ double result = LIBC_NAMESPACE::exp2(x);
+
+ if (result != to_compare)
+ __builtin_trap();
+
+ mpfr_clear(input);
+ return 0;
+}
diff --git a/libc/fuzzing/math/exp_fuzz.cpp b/libc/fuzzing/math/exp_fuzz.cpp
new file mode 100644
index 0000000000000..97bc12dfa64c9
--- /dev/null
+++ b/libc/fuzzing/math/exp_fuzz.cpp
@@ -0,0 +1,38 @@
+//===-- exp_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 exp implementation.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/math/exp.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_exp(input, input, MPFR_RNDN);
+ mpfr_subnormalize(input, output, MPFR_RNDN);
+ double to_compare = mpfr_get_d(input, MPFR_RNDN);
+
+ double result = LIBC_NAMESPACE::exp(x);
+
+ if (result != to_compare)
+ __builtin_trap();
+
+ mpfr_clear(input);
+ return 0;
+}
diff --git a/libc/fuzzing/math/expm1_fuzz.cpp b/libc/fuzzing/math/expm1_fuzz.cpp
new file mode 100644
index 0000000000000..db507bb02b1d7
--- /dev/null
+++ b/libc/fuzzing/math/expm1_fuzz.cpp
@@ -0,0 +1,38 @@
+//===-- expm1_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 expm1 implementation.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/math/expm1.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_expm1(input, input, MPFR_RNDN);
+ mpfr_subnormalize(input, output, MPFR_RNDN);
+ double to_compare = mpfr_get_d(input, MPFR_RNDN);
+
+ double result = LIBC_NAMESPACE::expm1(x);
+
+ if (result != to_compare)
+ __builtin_trap();
+
+ mpfr_clear(input);
+ return 0;
+}
|
lntue
approved these changes
Jul 11, 2025
bassiounix
pushed a commit
to bassiounix/llvm-project
that referenced
this pull request
Jul 14, 2025
Created fuzz tests for exp functions --------- Co-authored-by: Sriya Pratipati <[email protected]>
bassiounix
pushed a commit
to bassiounix/llvm-project
that referenced
this pull request
Jul 14, 2025
Created fuzz tests for exp functions --------- Co-authored-by: Sriya Pratipati <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Created fuzz tests for exp functions