[libc-commits] [libc] [libc] Updated fuzz tests for trig functions (PR #148891)

via libc-commits libc-commits at lists.llvm.org
Tue Jul 15 10:59:44 PDT 2025


================
@@ -12,26 +12,39 @@
 
 #include "src/math/acos.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 and values outside accepted range
-  if (isnan(x) || isinf(x) || x > 1 || x < -1)
-    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_acos(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));
----------------
lntue wrote:

increase the data pointer after this, so that the next 8 bytes in the stream will be used in the next iteration:
```
  data += sizeof(double);
```

https://github.com/llvm/llvm-project/pull/148891


More information about the libc-commits mailing list