File tree Expand file tree Collapse file tree 3 files changed +53
-4
lines changed Expand file tree Collapse file tree 3 files changed +53
-4
lines changed Original file line number Diff line number Diff line change @@ -70,3 +70,12 @@ add_libc_fuzzer(
7070 DEPENDS
7171 libc.src.math.sin
7272)
73+
74+ add_libc_fuzzer(
75+ cos_fuzz
76+ NEED_MPFR
77+ SRCS
78+ cos_fuzz.cpp
79+ DEPENDS
80+ libc.src.math.cos
81+ )
Original file line number Diff line number Diff line change 1+ // ===-- cos_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 cos implementation.
10+ // /
11+ // ===----------------------------------------------------------------------===//
12+
13+ #include " src/math/cos.h"
14+ #include < math.h>
15+ #include < mpfr.h>
16+
17+ extern " C" int LLVMFuzzerTestOneInput (const double x) {
18+ // remove NaN and inf as preconditions
19+ if (isnan (x))
20+ return 0 ;
21+ if (isinf (x))
22+ return 0 ;
23+ // signed zeros already tested in unit tests
24+ if (signbit (x) && x == 0.0 )
25+ return 0 ;
26+ mpfr_t input;
27+ mpfr_init2 (input, 53 );
28+ mpfr_set_d (input, x, MPFR_RNDN);
29+ int output = mpfr_cos (input, input, MPFR_RNDN);
30+ mpfr_subnormalize (input, output, MPFR_RNDN);
31+ double to_compare = mpfr_get_d (input, MPFR_RNDN);
32+
33+ double result = LIBC_NAMESPACE::cos (x);
34+
35+ if (result != to_compare)
36+ __builtin_trap ();
37+
38+ mpfr_clear (input);
39+ return 0 ;
40+ }
Original file line number Diff line number Diff line change 1111// ===----------------------------------------------------------------------===//
1212
1313#include " src/math/sin.h"
14- #include < cmath >
14+ #include < math.h >
1515#include < mpfr.h>
1616
1717extern " C" int LLVMFuzzerTestOneInput (const double x) {
1818 // remove NaN and inf as preconditions
19- if (std:: isnan (x))
19+ if (isnan (x))
2020 return 0 ;
21- if (std:: isinf (x))
21+ if (isinf (x))
2222 return 0 ;
2323 // signed zeros already tested in unit tests
24- if (std:: signbit (x) && x == 0.0 )
24+ if (signbit (x) && x == 0.0 )
2525 return 0 ;
2626 mpfr_t input;
2727 mpfr_init2 (input, 53 );
You can’t perform that action at this time.
0 commit comments