Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[libc] Updated exp fuzz tests#148912

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sribee8 merged 5 commits intollvm:mainfromsribee8:update-exp-fuzz
Jul 16, 2025
Merged

Conversation

sribee8
Copy link
Contributor

Fuzz tests were previously in the wrong format, updated them to correct format.

Fuzz tests were previously in the wrong format, updated them to correct format.
@llvmbotllvmbot added the libc labelJul 15, 2025
@sribee8sribee8 requested a review fromlntueJuly 15, 2025 17:54
@llvmbot
Copy link
Member

@llvm/pr-subscribers-libc

Author: None (sribee8)

Changes

Fuzz tests were previously in the wrong format, updated them to correct format.


Full diff:https://github.com/llvm/llvm-project/pull/148912.diff

4 Files Affected:

  • (modified) libc/fuzzing/math/exp10_fuzz.cpp (+24-14)
  • (modified) libc/fuzzing/math/exp2_fuzz.cpp (+25-14)
  • (modified) libc/fuzzing/math/exp_fuzz.cpp (+25-14)
  • (modified) libc/fuzzing/math/expm1_fuzz.cpp (+25-14)
diff --git a/libc/fuzzing/math/exp10_fuzz.cpp b/libc/fuzzing/math/exp10_fuzz.cppindex 2baef03a264a4..3dba9b129521f 100644--- a/libc/fuzzing/math/exp10_fuzz.cpp+++ b/libc/fuzzing/math/exp10_fuzz.cpp@@ -12,27 +12,37 @@  #include "src/math/exp10.h" #include "utils/MPFRWrapper/mpfr_inc.h"+#include <cstdint>+#include <cstring>+#include <iostream> #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;+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {   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);+  for (size_t i = 0; i < size / sizeof(double); ++i) {+    double x;+    std::memcpy(&x, data, sizeof(double)); // 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;-  double result = LIBC_NAMESPACE::exp10(x);+    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);-  if (result != to_compare)-    __builtin_trap();+    double result = LIBC_NAMESPACE::exp10(x);+    if (result != to_compare) {+      std::cout << std::hexfloat << "Failing input: " << x << std::endl;+      std::cout << std::hexfloat << "Failing output: " << result << std::endl;+      std::cout << std::hexfloat << "Expected: " << to_compare << std::endl;+      __builtin_trap();+    }+  }   mpfr_clear(input);   return 0; }diff --git a/libc/fuzzing/math/exp2_fuzz.cpp b/libc/fuzzing/math/exp2_fuzz.cppindex 8a2959047a6ca..3c2f58915fa50 100644--- a/libc/fuzzing/math/exp2_fuzz.cpp+++ b/libc/fuzzing/math/exp2_fuzz.cpp@@ -12,27 +12,38 @@  #include "src/math/exp2.h" #include "utils/MPFRWrapper/mpfr_inc.h"+#include <cstdint>+#include <cstring>+#include <iostream> #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;+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {   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);+  for (size_t i = 0; i < size / sizeof(double); ++i) {+    double x;+    std::memcpy(&x, data, sizeof(double));+    // 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;-  double result = LIBC_NAMESPACE::exp2(x);+    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);-  if (result != to_compare)-    __builtin_trap();+    double result = LIBC_NAMESPACE::exp2(x);+    if (result != to_compare) {+      std::cout << std::hexfloat << "Failing input: " << x << std::endl;+      std::cout << std::hexfloat << "Failing output: " << result << std::endl;+      std::cout << std::hexfloat << "Expected: " << to_compare << std::endl;+      __builtin_trap();+    }+  }   mpfr_clear(input);   return 0; }diff --git a/libc/fuzzing/math/exp_fuzz.cpp b/libc/fuzzing/math/exp_fuzz.cppindex 97bc12dfa64c9..13a81623d5c02 100644--- a/libc/fuzzing/math/exp_fuzz.cpp+++ b/libc/fuzzing/math/exp_fuzz.cpp@@ -12,27 +12,38 @@  #include "src/math/exp.h" #include "utils/MPFRWrapper/mpfr_inc.h"+#include <cstdint>+#include <cstring>+#include <iostream> #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;+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {   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);+  for (size_t i = 0; i < size / sizeof(double); ++i) {+    double x;+    std::memcpy(&x, data, sizeof(double));+    // 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;-  double result = LIBC_NAMESPACE::exp(x);+    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);-  if (result != to_compare)-    __builtin_trap();+    double result = LIBC_NAMESPACE::exp(x);+    if (result != to_compare) {+      std::cout << std::hexfloat << "Failing input: " << x << std::endl;+      std::cout << std::hexfloat << "Failing output: " << result << std::endl;+      std::cout << std::hexfloat << "Expected: " << to_compare << std::endl;+      __builtin_trap();+    }+  }   mpfr_clear(input);   return 0; }diff --git a/libc/fuzzing/math/expm1_fuzz.cpp b/libc/fuzzing/math/expm1_fuzz.cppindex db507bb02b1d7..464d799565747 100644--- a/libc/fuzzing/math/expm1_fuzz.cpp+++ b/libc/fuzzing/math/expm1_fuzz.cpp@@ -12,27 +12,38 @@  #include "src/math/expm1.h" #include "utils/MPFRWrapper/mpfr_inc.h"+#include <cstdint>+#include <cstring>+#include <iostream> #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;+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {   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);+  for (size_t i = 0; i < size / sizeof(double); ++i) {+    double x;+    std::memcpy(&x, data, sizeof(double));+    // 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;-  double result = LIBC_NAMESPACE::expm1(x);+    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);-  if (result != to_compare)-    __builtin_trap();+    double result = LIBC_NAMESPACE::expm1(x);+    if (result != to_compare) {+      std::cout << std::hexfloat << "Failing input: " << x << std::endl;+      std::cout << std::hexfloat << "Failing output: " << result << std::endl;+      std::cout << std::hexfloat << "Expected: " << to_compare << std::endl;+      __builtin_trap();+    }+  }   mpfr_clear(input);   return 0; }

@github-actionsGitHub Actions
Copy link

github-actionsbot commentedJul 16, 2025
edited
Loading

✅ With the latest revision this PR passed the C/C++ code formatter.

@sribee8sribee8 merged commit82451d0 intollvm:mainJul 16, 2025
17 of 19 checks passed
@sribee8sribee8 deleted the update-exp-fuzz branchJuly 16, 2025 18:36
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@lntuelntuelntue approved these changes

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@sribee8@llvmbot@lntue

[8]ページ先頭

©2009-2025 Movatter.jp