Skip to content

Commit

Permalink
Check that a genvar is not shadowed when used in a generate loop cons…
Browse files Browse the repository at this point in the history
…truct.

This also ensures the same genvar cannot be used in two nested loops
(issue steveicarus#533), because the implicit localparam with the same name
shadows the genvar declaration.
  • Loading branch information
martinwhitaker committed Aug 4, 2021
1 parent cefcffe commit 7ee7a48
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion elab_scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 << "'."
Expand Down

0 comments on commit 7ee7a48

Please sign in to comment.