fmt: fuzz, fix (remove extraneous + incorrect fill)

"blk + chunks" is often an overrun, plus the fill is unnecessary; we
throw blk away immediately.
This commit is contained in:
Charlotte 2023-06-28 11:51:23 +10:00 committed by Marcelina Kościelnicka
parent 9f9561379b
commit 2ae551c0af
4 changed files with 67 additions and 1 deletions

View File

@ -654,7 +654,6 @@ struct value : public expr_base<value<Bits>> {
}
std::copy(blk, blk + origLen, data);
std::fill(blk + origLen, blk + chunks, 0);
}
static chunk::type getShiftedBlock(const value<Bits> &num, size_t x, size_t y) {

2
tests/fmt/fuzz/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
fuzztest
build

View File

@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.14)
project(cxxrtl_division_fuzz)
set(CMAKE_CXX_STANDARD 17)
add_subdirectory(fuzztest)
enable_testing()
include(GoogleTest)
fuzztest_setup_fuzzing_flags()
include_directories(../../..)
add_executable(
x_test
x_test.cc
../../../libs/bigint/BigUnsigned.cc
)
link_fuzztest(x_test)
gtest_discover_tests(x_test)

42
tests/fmt/fuzz/x_test.cc Normal file
View File

@ -0,0 +1,42 @@
#include "fuzztest/fuzztest.h"
#include "gtest/gtest.h"
#include <sstream>
#include "backends/cxxrtl/cxxrtl.h"
#include "libs/bigint/BigUnsigned.hh"
using namespace cxxrtl_yosys;
void Formats128BitUnsignedIntegers(uint64_t x, uint64_t y) {
// Compare output to actual BigUnsigned.
value<64> vs;
value<128> v;
vs.set(x);
v = v.blit<127, 64>(vs);
vs.set(y);
v = v.blit<63, 0>(vs);
std::ostringstream oss;
oss << value_formatted<128>(v, false, false, ' ', 0, 10, false, false, false);
auto actual = oss.str();
BigUnsigned b(x);
b.bitShiftLeft(b, 64);
b.bitOr(b, y);
std::string expected;
if (b.isZero()) {
expected = "0";
} else {
while (!b.isZero()) {
expected += '0' + (b % 10).toInt();
b /= 10;
}
std::reverse(expected.begin(), expected.end());
}
EXPECT_EQ(actual, expected);
}
FUZZ_TEST(CxxrtlDivisionFuzz, Formats128BitUnsignedIntegers);