Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

updateCoverage

fuzz.updateCoverage
fn updateCoverage() error

File

lib/build-web/fuzz.zig:310

Code

fn updateCoverage() error{OutOfMemory}!void {
    if (recent_coverage_update.items.len == 0) return;
    const want_file = (selected_source_location orelse return).ptr().file;

    var covered: std.ArrayList(SourceLocationIndex) = .empty;
    defer covered.deinit(gpa);

    // This code assumes 64-bit elements, which is incorrect if the executable
    // being fuzzed is not a 64-bit CPU. It also assumes little-endian which
    // can also be incorrect.
    comptime assert(abi.fuzz.CoverageUpdateHeader.trailing[0] == .pc_bits_usize);
    const n_bitset_elems = (coverage_source_locations.items.len + @bitSizeOf(u64) - 1) / @bitSizeOf(u64);
    const covered_bits = std.mem.bytesAsSlice(
        u64,
        recent_coverage_update.items[@sizeOf(abi.fuzz.CoverageUpdateHeader)..][0 .. n_bitset_elems * @sizeOf(u64)],
    );
    var sli: SourceLocationIndex = @fromBackingInt(@intCast(0));
    for (covered_bits) |elem| {
        try covered.ensureUnusedCapacity(gpa, 64);
        for (0..@bitSizeOf(u64)) |i| {
            if ((elem & (@as(u64, 1) << @intCast(i))) != 0) {
                if (sli.ptr().file == want_file) {
                    covered.appendAssumeCapacity(sli);
                }
            }
            sli = @fromBackingInt(@intCast(@backingInt(sli) + 1));
        }
    }

    js.updateCoverage(covered.items.ptr, covered.items.len);
}