Skip to content

Commit 26ef9a0

Browse files
committed
netlist: fix off-by-one bug
This fixes an off-by-one error in the netlist conversion.
1 parent 767623b commit 26ef9a0

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
KNOWNBUG
1+
CORE
22
verilog2.sv
33
--smv-netlist
44
^EXIT=0$
55
^SIGNAL=0$
66
--
77
--
8-
This throws an error.

src/trans-netlist/trans_to_netlist.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ void convert_trans_to_netlistt::add_equality_rec(
720720

721721
bv_varidt bv_varid;
722722
bv_varid.id=lhs.get(ID_identifier);
723-
723+
724724
for(bv_varid.bit_nr=lhs_from;
725725
bv_varid.bit_nr!=(lhs_to+1);
726726
bv_varid.bit_nr++)
@@ -767,9 +767,12 @@ void convert_trans_to_netlistt::add_equality_rec(
767767

768768
boolbv_widtht boolbv_width(ns);
769769

770+
const auto width = boolbv_width(lhs.type());
771+
772+
DATA_INVARIANT(width != 0, "add_equality_rec got zero-width bit-vector");
773+
770774
std::size_t new_lhs_from = lhs_from + index.to_ulong();
771-
std::size_t new_lhs_to =
772-
lhs_from + index.to_ulong() + boolbv_width(lhs.type());
775+
std::size_t new_lhs_to = lhs_from + index.to_ulong() + width - 1;
773776

774777
add_equality_rec(
775778
src, to_extractbits_expr(lhs).src(), new_lhs_from, new_lhs_to, rhs_entry);

0 commit comments

Comments
 (0)