Coverage Report

Created: 2026-07-16 06:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/immer/extra/fuzzer/set-gc.cpp
Line
Count
Source
1
//
2
// immer: immutable data structures for C++
3
// Copyright (C) 2016, 2017, 2018 Juan Pedro Bolivar Puente
4
//
5
// This software is distributed under the Boost Software License, Version 1.0.
6
// See accompanying file LICENSE or copy at http://boost.org/LICENSE_1_0.txt
7
//
8
9
#include "fuzzer_input.hpp"
10
11
#include <immer/heap/gc_heap.hpp>
12
#include <immer/refcount/no_refcount_policy.hpp>
13
#include <immer/set.hpp>
14
15
#include <immer/algorithm.hpp>
16
17
#include <array>
18
19
using gc_memory = immer::memory_policy<immer::heap_policy<immer::gc_heap>,
20
                                       immer::no_refcount_policy,
21
                                       immer::default_lock_policy,
22
                                       immer::gc_transience_policy,
23
                                       false>;
24
25
struct colliding_hash_t
26
{
27
1.30M
    std::size_t operator()(std::size_t x) const { return x & ~15; }
28
};
29
30
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data,
31
                                      std::size_t size)
32
3.15k
{
33
3.15k
    auto guard = immer::gc_disable_guard{};
34
35
3.15k
    constexpr auto var_count = 4;
36
37
3.15k
    using set_t =
38
3.15k
        immer::set<size_t, colliding_hash_t, std::equal_to<>, gc_memory>;
39
40
3.15k
    auto vars = std::array<set_t, var_count>{};
41
42
529k
    auto is_valid_var = [&](auto idx) { return idx >= 0 && idx < var_count; };
43
44
165k
    return fuzzer_input{data, size}.run([&](auto& in) {
45
165k
        enum ops
46
165k
        {
47
165k
            op_insert,
48
165k
            op_erase,
49
165k
            op_insert_move,
50
165k
            op_erase_move,
51
165k
            op_iterate,
52
165k
            op_diff
53
165k
        };
54
165k
        auto src = read<char>(in, is_valid_var);
55
165k
        auto dst = read<char>(in, is_valid_var);
56
165k
        switch (read<char>(in)) {
57
87.0k
        case op_insert: {
58
87.0k
            auto value = read<size_t>(in);
59
87.0k
            vars[dst]  = vars[src].insert(value);
60
87.0k
            break;
61
0
        }
62
11.2k
        case op_erase: {
63
11.2k
            auto value = read<size_t>(in);
64
11.2k
            vars[dst]  = vars[src].erase(value);
65
11.2k
            break;
66
0
        }
67
5.73k
        case op_insert_move: {
68
5.73k
            auto value = read<size_t>(in);
69
5.73k
            vars[dst]  = std::move(vars[src]).insert(value);
70
5.73k
            break;
71
0
        }
72
1.09k
        case op_erase_move: {
73
1.09k
            auto value = read<size_t>(in);
74
1.09k
            vars[dst]  = std::move(vars[src]).erase(value);
75
1.09k
            break;
76
0
        }
77
3.60k
        case op_iterate: {
78
3.60k
            auto srcv = vars[src];
79
346k
            immer::for_each(srcv, [&](auto&& v) {
80
346k
                vars[dst] = std::move(vars[dst]).insert(v);
81
346k
            });
82
3.60k
            break;
83
0
        }
84
33.0k
        case op_diff: {
85
33.0k
            auto&& a = vars[src];
86
33.0k
            auto&& b = vars[dst];
87
33.0k
            diff(
88
33.0k
                a,
89
33.0k
                b,
90
184k
                [&](auto&& x) {
91
184k
                    assert(!a.count(x));
92
184k
                    assert(b.count(x));
93
184k
                },
94
223k
                [&](auto&& x) {
95
223k
                    assert(a.count(x));
96
223k
                    assert(!b.count(x));
97
223k
                },
98
33.0k
                [&](auto&& x, auto&& y) { assert(false); });
99
33.0k
        }
100
53.2k
        default:
101
53.2k
            break;
102
165k
        };
103
161k
        return true;
104
165k
    });
105
3.15k
}