Fix #1112: Report error for invalid $bits argument
When $bits() is called with an undefined identifier, the compiler now properly reports an error instead of silently returning 0. The fix checks if the argument expression has type IVL_VT_NO_TYPE after test_width() processing (indicating the identifier couldn't be resolved), and triggers elaboration to produce a proper error message. Includes regression test: br_gh1112 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
f040d513a5
commit
5b8fac5441
|
|
@ -1983,6 +1983,15 @@ NetExpr* PECallFunction::elaborate_sfunc_(Design*des, NetScope*scope,
|
|||
}
|
||||
|
||||
} else {
|
||||
// Check if the expression could be resolved. If test_width
|
||||
// failed to find the identifier, expr_type will be NO_TYPE.
|
||||
if (expr->expr_type() == IVL_VT_NO_TYPE) {
|
||||
// Try to elaborate the expression to get a proper error
|
||||
// message about the undefined identifier.
|
||||
NetExpr *tmp = expr->elaborate_expr(des, scope, (unsigned)1, flags);
|
||||
if (tmp) delete tmp;
|
||||
return 0;
|
||||
}
|
||||
use_width = expr->expr_width();
|
||||
if (debug_elaborate) {
|
||||
cerr << get_fileline() << ": PECallFunction::elaborate_sfunc_: "
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
./ivltests/br_gh1112.v:4: error: Unable to bind parameter `value' in `top'
|
||||
1 error(s) during elaboration.
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
// Test for GitHub issue #1112
|
||||
// $bits() with non-existent identifier should produce an error
|
||||
module top;
|
||||
localparam width = $bits(value); // 'value' doesn't exist - should error
|
||||
initial $display(width);
|
||||
endmodule
|
||||
|
|
@ -989,3 +989,4 @@ partsel_real_idx CE,-g2012 ivltests gold=partsel_real_idx.gold
|
|||
ipsdownsel_real_idx CE,-g2012 ivltests gold=ipsdownsel_real_idx.gold
|
||||
ipsupsel_real_idx CE,-g2012 ivltests gold=ipsupsel_real_idx.gold
|
||||
real_edges CE,-g2012 ivltests gold=real_edges.gold
|
||||
br_gh1112 CE,-g2009 ivltests gold=br_gh1112.gold
|
||||
|
|
|
|||
Loading…
Reference in New Issue