From 75b12151a437e16e3cf913846c30cdce01ecf9a1 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Mon, 30 Apr 2012 23:05:42 +0100 Subject: [PATCH] Disable width minimisation of literal numbers passed to system tasks. The final step of expression elaboration is to reduce the width of lossless/unsized constant expressions to the minimum needed to hold the resulting constant value. This leads to unexpected results if the user supplies a literal number with redundant digits that gets passed to a system task that is sensitive to the width (e.g. $display). This patch prevents width reduction occurring in this case. --- netmisc.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/netmisc.cc b/netmisc.cc index 504b58dcb..d6b5e6b98 100644 --- a/netmisc.cc +++ b/netmisc.cc @@ -602,7 +602,11 @@ NetExpr* elab_sys_task_arg(Design*des, NetScope*scope, perm_string name, eval_expr(tmp, -1); if (NetEConst*ce = dynamic_cast(tmp)) { - if (mode != PExpr::SIZED) + // For lossless/unsized constant expressions, we can now + // determine the exact width required to hold the result. + // But leave literal numbers exactly as the user supplied + // them. + if ((mode != PExpr::SIZED) && !dynamic_cast(pe)) ce->trim(); }