Skip to content

Commit d46b79b

Browse files
committed
Verilog: size casts are assignments
Size casts act like assignments, and hence, use the assignment conversion.
1 parent b0f4fe4 commit d46b79b

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# EBMC 5.8
22

3+
* SystemVerilog: semantics fix for size casts
4+
35
# EBMC 5.7
46

57
* Verilog: --initial-zero changes the default value from nondet to zero
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
KNOWNBUG
1+
CORE
22
size_cast3.sv
33
--module main
44
^EXIT=0$
55
^SIGNAL=0$
66
--
77
^warning: ignoring
88
--
9-
This is not yet implemented.

src/verilog/verilog_expr.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2554,12 +2554,6 @@ class verilog_explicit_size_cast_exprt : public binary_exprt
25542554
{
25552555
return op1();
25562556
}
2557-
2558-
// lower to typecast
2559-
exprt lower() const
2560-
{
2561-
return typecast_exprt{op(), type()};
2562-
}
25632557
};
25642558

25652559
inline const verilog_explicit_size_cast_exprt &

src/verilog/verilog_lowering.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,12 @@ exprt verilog_lowering(exprt expr)
480480
}
481481
else if(expr.id() == ID_verilog_explicit_size_cast)
482482
{
483-
return to_verilog_explicit_size_cast_expr(expr).lower();
483+
// These act like an assignment, and hence, the type checker
484+
// has already converted the argument to the target type.
485+
auto &size_cast = to_verilog_explicit_size_cast_expr(expr);
486+
DATA_INVARIANT(
487+
size_cast.op().type() == size_cast.type(), "size cast type consistency");
488+
return size_cast.op();
484489
}
485490
else if(
486491
expr.id() == ID_verilog_streaming_concatenation_left_to_right ||

src/verilog/verilog_typecheck_expr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3319,6 +3319,11 @@ exprt verilog_typecheck_exprt::convert_binary_expr(binary_exprt expr)
33193319
<< "cannot perform size cast on " << to_string(op_type);
33203320
}
33213321

3322+
// These act like an assignment (1800-2017 6.24.1)
3323+
assignment_conversion(expr.rhs(), expr.type());
3324+
3325+
CHECK_RETURN(expr.rhs().type() == expr.type());
3326+
33223327
return std::move(expr);
33233328
}
33243329
else if(

0 commit comments

Comments
 (0)