Check that a genvar is not shadowed when used in a generate loop construct.

This also ensures the same genvar cannot be used in two nested loops
(issue #533), because the implicit localparam with the same name
shadows the genvar declaration.
This commit is contained in:
Martin Whitaker 2021-08-04 14:35:38 +01:00
parent cefcffecda
commit 7ee7a48310
1 changed files with 9 additions and 1 deletions

View File

@ -950,8 +950,16 @@ bool PGenerate::generate_scope_loop_(Design*des, NetScope*container)
// Check that the loop_index variable was declared in a
// genvar statement.
NetScope*cscope = container;
while (cscope && !cscope->find_genvar(loop_index))
while (cscope && !cscope->find_genvar(loop_index)) {
if (cscope->symbol_exists(loop_index)) {
cerr << get_fileline() << ": error: "
<< "generate loop variable '" << loop_index
<< "' is not a genvar in this scope." << endl;
des->errors += 1;
return false;
}
cscope = cscope->parent();
}
if (!cscope) {
cerr << get_fileline() << ": error: genvar is missing for "
"generate \"loop\" variable '" << loop_index << "'."