From 96472e5537effda855505d000ea2be1ee8a3217e Mon Sep 17 00:00:00 2001 From: Cary R Date: Wed, 10 Dec 2014 14:38:12 -0800 Subject: [PATCH] For a signed R-value we can use the full width when converting to long When trying to get the value we can use the full width of a long if the expression is signed. --- elab_expr.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/elab_expr.cc b/elab_expr.cc index c467671f7..1a2aebe80 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -785,8 +785,11 @@ unsigned PEBLeftWidth::test_width(Design*des, NetScope*scope, width_mode_t&mode) right_ = tmp; } NetEConst*rc = dynamic_cast (rp); - if (rc && (r_width < sizeof(long)*8)) - r_val = rc->value().as_long(); + // Adjust the expression width that can be converter depending + // on if the R-value is signed or not. + unsigned c_width = sizeof(long)*8; + if (! right_->has_sign()) c_width -= 1; + if (rc && (r_width <= c_width)) r_val = rc->value().as_long(); if (debug_elaborate && rc) { cerr << get_fileline() << ": PEBLeftWidth::test_width: "