Skip to content

Commit 846a4e0

Browse files
committed
Verilog: reject use of SVA sequences and properties as Boolean expression
SVA named sequences and named properties cannot be used as Booleans. This adds a check.
1 parent 1c7277f commit 846a4e0

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
KNOWNBUG
1+
CORE
22
named_property5.sv
33

4+
^file .* line 8: cannot use SVA property as an expression$
45
^EXIT=2$
56
^SIGNAL=0$
67
--
78
^warning: ignoring
89
--
9-
This should be rejected.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
KNOWNBUG
1+
CORE
22
named_property6.sv
33

44
^EXIT=2$
55
^SIGNAL=0$
66
--
77
^warning: ignoring
88
--
9-
This should be rejected.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
named_property7.sv
3+
4+
^EXIT=2$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module main;
2+
3+
property P;
4+
1
5+
endproperty
6+
7+
// This should be rejected
8+
wire x = P + P;
9+
10+
endmodule

src/verilog/verilog_typecheck_expr.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ void verilog_typecheck_exprt::propagate_type(
121121
if(expr.type()==type)
122122
return;
123123

124+
if(expr.type().id() == ID_verilog_sva_sequence)
125+
{
126+
throw errort{}.with_location(expr.source_location())
127+
<< "cannot use SVA sequence as an expression";
128+
}
129+
else if(expr.type().id() == ID_verilog_sva_property)
130+
{
131+
throw errort{}.with_location(expr.source_location())
132+
<< "cannot use SVA property as an expression";
133+
}
134+
124135
vtypet vt_from=vtypet(expr.type());
125136
vtypet vt_to =vtypet(type);
126137

@@ -2174,8 +2185,19 @@ Function: verilog_typecheck_exprt::make_boolean
21742185

21752186
void verilog_typecheck_exprt::make_boolean(exprt &expr)
21762187
{
2177-
if(expr.type().id()!=ID_bool)
2188+
if(expr.type().id() == ID_verilog_sva_sequence)
2189+
{
2190+
throw errort{}.with_location(expr.source_location())
2191+
<< "cannot use SVA sequence as an expression";
2192+
}
2193+
else if(expr.type().id() == ID_verilog_sva_property)
2194+
{
2195+
throw errort{}.with_location(expr.source_location())
2196+
<< "cannot use SVA property as an expression";
2197+
}
2198+
else if(expr.type().id() != ID_bool)
21782199
{
2200+
// everything else can be converted to Boolean
21792201
mp_integer value;
21802202
if(!to_integer_non_constant(expr, value))
21812203
expr = make_boolean_expr(value != 0);

0 commit comments

Comments
 (0)