- Literal transliteration of `Statement.closedForm` plus an equivalent summarised implementation - Borrowed input keys (`std::string_view` / `std::span`) and owned result keys (`std::string`) - Golden-vector test, differential/safety fuzzers, and a nanobench comparison The literal and summarised implementations agree on 40,000 Lean golden vectors, 18,971 sorted corpus cases, and the readable fuzzer; the raw fuzzer runs both implementations under ASan/UBSan. `build/` and the generated `oracle/golden.txt` are ignored.
42 lines
1.5 KiB
C++
42 lines
1.5 KiB
C++
// libFuzzer safety harness: arbitrary (not necessarily readable) instances.
|
|
// Equivalence is only promised on readable inputs, so this harness merely runs
|
|
// both implementations under ASan/UBSan to catch memory-safety or UB issues in
|
|
// the defensive branches.
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
#include "../src/fast.h"
|
|
#include "../src/literal.h"
|
|
#include "readable_gen.h"
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data,
|
|
std::size_t size) {
|
|
cr::gen::Bytes bytes{data, size, 0};
|
|
for (int i = 0; i < 8; ++i) {
|
|
const std::size_t maxLen = 1 + bytes.u8() % 16;
|
|
// Owned selector keys and reported keys; the borrows below point here.
|
|
cr::OptKey beginKey = cr::gen::randomOptKey(bytes, maxLen);
|
|
cr::OptKey endKey = cr::gen::randomOptKey(bytes, maxLen);
|
|
cr::RangeRead r;
|
|
r.begin = cr::Selector{cr::optView(beginKey),
|
|
cr::gen::randomOffset(bytes)};
|
|
r.end_ = cr::Selector{cr::optView(endKey), cr::gen::randomOffset(bytes)};
|
|
r.reverse = (bytes.u8() & 1) != 0;
|
|
|
|
std::vector<cr::Key> keys;
|
|
const std::size_t n = bytes.u8() % 16;
|
|
keys.reserve(n);
|
|
for (std::size_t j = 0; j < n; ++j)
|
|
keys.push_back(cr::gen::randomKey(bytes, maxLen));
|
|
std::vector<cr::KeyView> views;
|
|
views.reserve(keys.size());
|
|
for (const cr::Key& k : keys) views.push_back(k);
|
|
cr::Result res{views, (bytes.u8() & 1) != 0};
|
|
|
|
(void)cr::literal::closedForm(r, res);
|
|
(void)cr::fast::closedForm(r, res);
|
|
}
|
|
return 0;
|
|
}
|