Skip to content

Commit 9e2e50e

Browse files
authored
Merge pull request #373 from diffblue/verilog-enum-decay
Verilog: enums decay when used in relational/arithmetic operators
2 parents bb75939 + 18203f5 commit 9e2e50e

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
KNOWNBUG
1+
CORE
22
enum_initializers1.sv
3-
4-
^EXIT=10$
3+
--bound 0
4+
^\[main\.property\.pA\] always 1 == 1: PROVED up to bound 0$
5+
^\[main\.property\.pB\] always 1 \+ 10 == 11: PROVED up to bound 0$
6+
^EXIT=0$
57
^SIGNAL=0$
68
--
79
--
8-
Crashes with missing identifier
9-

src/verilog/verilog_typecheck_expr.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -1665,8 +1665,23 @@ void verilog_typecheck_exprt::tc_binary_expr(
16651665
const exprt &expr,
16661666
exprt &op0, exprt &op1)
16671667
{
1668-
const typet new_type=max_type(op0.type(), op1.type());
1669-
1668+
// Verilog enum types decay to their base type when used in relational
1669+
// or arithmetic expressions.
1670+
auto enum_decay = [](const typet &type) {
1671+
if(type.get(ID_C_verilog_type) == ID_verilog_enum)
1672+
{
1673+
typet result = type;
1674+
result.remove(ID_C_verilog_type);
1675+
result.remove(ID_C_identifier);
1676+
return result;
1677+
}
1678+
else
1679+
return type;
1680+
};
1681+
1682+
const typet new_type =
1683+
max_type(enum_decay(op0.type()), enum_decay(op1.type()));
1684+
16701685
if(new_type.is_nil())
16711686
{
16721687
throw errort().with_location(expr.source_location())

0 commit comments

Comments
 (0)