Fix GitHub issue #219 and #220 - incorrect results from SV size cast.

(cherry picked from commit 230f0bc13c)
This commit is contained in:
Martin Whitaker
2018-12-15 12:49:12 +00:00
parent edfe398e26
commit bd4d73d9ae
+7 -1
View File
@@ -2535,7 +2535,13 @@ NetExpr* PECastSize::elaborate_expr(Design*des, NetScope*scope,
ivl_assert(*this, size_);
ivl_assert(*this, base_);
NetExpr*sub = base_->elaborate_expr(des, scope, base_->expr_width(), flags);
// When changing size, a cast behaves exactly like an assignment,
// so the result size affects the final expression width.
unsigned cast_width = base_->expr_width();
if (cast_width < expr_width_)
cast_width = expr_width_;
NetExpr*sub = base_->elaborate_expr(des, scope, cast_width, flags);
// Perform the cast. The extension method (zero/sign), if needed,
// depends on the type of the base expression.