Skip to content

Commit 70f1837

Browse files
committed
Verilog: fix semantics of relations
This replaces the custom code for type checking the operands of relations by the code used for other binary expressions. This fixes the downwards type/size propagation.
1 parent 16aa773 commit 70f1837

File tree

6 files changed

+10
-43
lines changed

6 files changed

+10
-43
lines changed

regression/verilog/assignments/assignment-with-function-call1.sv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ module top(input [7:0] a, input [7:0] b);
1010
wire [7:0] sum_a_b = fn(a, b),
1111
sum_1_2 = fn(1, 2),
1212
sum_2_3 = fn(2, 3);
13-
14-
assert property (sum_a_b==a[2:0]+b[2:0]);
13+
14+
assert property (sum_a_b[2:0]==a[2:0]+b[2:0]);
1515

1616
assert property (sum_1_2==3);
1717

regression/verilog/expressions/equality1.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ equality1.v
1010
^\[.*\] always 32'b0000000000000000000000000000000x != 10 === 32'b0000000000000000000000000000000x: PROVED .*$
1111
^\[.*\] always 32'b0000000000000000000000000000000z != 20 === 32'b0000000000000000000000000000000x: PROVED .*$
1212
^\[.*\] always 1'sb1 == 2'b11 === 0: PROVED .*$
13-
^\[.*\] always 2'sb11 == 2'sb11 === 1: PROVED .*$
13+
^\[.*\] always 1'sb1 == 2'sb11 === 1: PROVED .*$
1414
^\[.*\] always 1\.1 == 1\.1 == 1: PROVED .*$
1515
^\[.*\] always 1\.1 == 1 == 0: PROVED .*$
1616
^EXIT=0$

regression/verilog/expressions/equality2.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ equality2.v
1212
^\[.*\] always 32'b0000000000000000000000000000000z === 1 == 0: PROVED .*$
1313
^\[.*\] always 1 === 1 == 1: PROVED .*$
1414
^\[.*\] always 3'b011 === 2'sb11 == 1: PROVED .*$
15-
^\[.*\] always 3'sb111 === 3'sb111 == 1: PROVED .*$
15+
^\[.*\] always 3'sb111 === 2'sb11 == 1: PROVED .*$
1616
^EXIT=0$
1717
^SIGNAL=0$
1818
--
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
KNOWNBUG
1+
CORE
22
shl4.sv
33
--bound 0
44
^EXIT=0$
55
^SIGNAL=0$
66
--
77
^warning: ignoring
88
--
9-
This gives the wrong answer.

regression/verilog/expressions/wildcard_equality1.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ wildcard_equality1.sv
1010
^\[main\.property07\] always 2'b00 !=\? 2'b0x === 0: PROVED .*$
1111
^\[main\.property08\] always 2'b10 !=\? 2'b0x === 1: PROVED .*$
1212
^\[main\.property09\] always 1'sb1 ==\? 2'b11 === 0: PROVED .*$
13-
^\[main\.property10\] always 2'sb11 ==\? 2'sb11 === 1: PROVED .*$
13+
^\[main\.property10\] always 1'sb1 ==\? 2'sb11 === 1: PROVED .*$
1414
^EXIT=0$
1515
^SIGNAL=0$
1616
--

src/verilog/verilog_typecheck_expr.cpp

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2554,43 +2554,11 @@ Function: verilog_typecheck_exprt::convert_relation
25542554

25552555
void verilog_typecheck_exprt::convert_relation(binary_exprt &expr)
25562556
{
2557-
auto &lhs = expr.lhs();
2558-
auto &rhs = expr.rhs();
2559-
2560-
convert_expr(lhs);
2561-
convert_expr(rhs);
2562-
2563-
union_decay(lhs);
2564-
union_decay(rhs);
2565-
2566-
// Relations are special-cased in 1800-2017 11.8.2.
2567-
const typet new_type =
2568-
max_type(enum_decay(lhs.type()), enum_decay(rhs.type()));
2569-
2570-
if(new_type.is_nil())
2571-
{
2572-
throw errort().with_location(expr.source_location())
2573-
<< "expected operands of compatible type but got:\n"
2574-
<< " " << to_string(lhs.type()) << '\n'
2575-
<< " " << to_string(rhs.type());
2576-
}
2557+
convert_expr(expr.lhs());
2558+
convert_expr(expr.rhs());
25772559

2578-
// If both operands are signed, both are sign-extended to the max width.
2579-
// Otherwise, both are zero-extended to the max width.
2580-
// In particular, signed operands are then _not_ sign extended,
2581-
// which a typecast would do.
2582-
if(new_type.id() == ID_verilog_unsignedbv || new_type.id() == ID_unsignedbv)
2583-
{
2584-
// zero extend both operands
2585-
lhs = zero_extend(lhs, new_type);
2586-
rhs = zero_extend(rhs, new_type);
2587-
}
2588-
else
2589-
{
2590-
// convert
2591-
implicit_typecast(lhs, new_type);
2592-
implicit_typecast(rhs, new_type);
2593-
}
2560+
// determine the max of the operand types and propagate it downwards
2561+
tc_binary_expr(expr);
25942562
}
25952563

25962564
/*******************************************************************\

0 commit comments

Comments
 (0)