Skip to content

Commit 4749930

Browse files
committed
Verilog: KNOWNBUG for primitive gates with more than two inputs
This replicates issue #880.
1 parent b6deb2e commit 4749930

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
KNOWNBUG
2+
or1.sv
3+
--bound 0
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
This is a small version of a misencoding of the Verilog primitive gates
10+
reported as https://github.com/diffblue/hw-cbmc/issues/880
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module main(input or_in1, or_in2, or_in3);
2+
3+
wire or_out;
4+
5+
or o1(or_out, or_in1, or_in2, or_in3);
6+
7+
// should pass
8+
or_ok: assert final ((or_in1 || or_in2 || or_in3)==or_out);
9+
10+
// should fail
11+
or_not_ok: assert final (or_out == (or_in1 || or_in2));
12+
13+
endmodule

src/verilog/verilog_synthesis.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,17 +1586,21 @@ void verilog_synthesist::synth_module_instance_builtin(
15861586
{
15871587
assert(instance.connections().size() >= 2);
15881588

1589-
for(unsigned i = 0; i < instance.connections().size() - 1; i++)
1590-
{
1591-
exprt op(ID_not, instance.type());
1592-
op.add_to_operands(instance.connections()[i]);
1589+
// May have multiple outputs. The input is the last connection.
1590+
auto &input = instance.connections().back();
1591+
exprt rhs;
15931592

1594-
if(instance.type().id()!=ID_bool)
1595-
op.id("bit"+op.id_string());
1596-
1597-
equal_exprt constraint{op, instance.connections().back()};
1593+
if(input.type().id() == ID_bool)
1594+
rhs = not_exprt{input};
1595+
else
1596+
rhs = bitnot_exprt{input};
15981597

1599-
assert(trans.operands().size()==3);
1598+
rhs.add_source_location() = module_item.source_location();
1599+
1600+
for(std::size_t i = 0; i < instance.connections().size() - 1; i++)
1601+
{
1602+
auto &lhs = instance.connections()[i];
1603+
auto constraint = equal_exprt{lhs, rhs};
16001604
trans.invar().add_to_operands(std::move(constraint));
16011605
}
16021606
}

0 commit comments

Comments
 (0)