File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,15 @@ add_libc_fuzzer(
62
62
libc.src.math.nextafterl
63
63
)
64
64
65
+ add_libc_fuzzer (
66
+ asin_fuzz
67
+ NEED_MPFR
68
+ SRCS
69
+ asin_fuzz.cpp
70
+ DEPENDS
71
+ libc.src.math.asin
72
+ )
73
+
65
74
add_libc_fuzzer (
66
75
sin_fuzz
67
76
NEED_MPFR
Original file line number Diff line number Diff line change
1
+ // ===-- asin_fuzz.cpp -----------------------------------------------------===//
2
+ //
3
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
+ // See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ // ===----------------------------------------------------------------------===//
8
+ // /
9
+ // / Fuzzing test for llvm-libc asin implementation.
10
+ // /
11
+ // ===----------------------------------------------------------------------===//
12
+
13
+ #include " src/math/asin.h"
14
+ #include " utils/MPFRWrapper/mpfr_inc.h"
15
+ #include < math.h>
16
+
17
+ extern " C" int LLVMFuzzerTestOneInput (double x) {
18
+ // remove NaN and inf and values outside accepted range
19
+ if (isnan (x) || isinf (x) || x > 1 || x < -1 )
20
+ return 0 ;
21
+ // signed zeros already tested in unit tests
22
+ if (signbit (x) && x == 0.0 )
23
+ return 0 ;
24
+ mpfr_t input;
25
+ mpfr_init2 (input, 53 );
26
+ mpfr_set_d (input, x, MPFR_RNDN);
27
+ int output = mpfr_asin (input, input, MPFR_RNDN);
28
+ mpfr_subnormalize (input, output, MPFR_RNDN);
29
+ double to_compare = mpfr_get_d (input, MPFR_RNDN);
30
+
31
+ double result = LIBC_NAMESPACE::asin (x);
32
+
33
+ if (result != to_compare)
34
+ __builtin_trap ();
35
+
36
+ mpfr_clear (input);
37
+ return 0 ;
38
+ }
You can’t perform that action at this time.
0 commit comments