Segfault if a for loop (with variable declaration) or a foreach loop is used inside a named block or a block that declares variables.
Root cause seems to be parser forgetting to pop the current_block_stack after processing one of these two statements, which ends up creating a loop in the Statement tree. The segfault happens later during PBlock::elaborate_scope when it hits infinite recursion.
Some test cases: The first three will trigger the bug, but the last doesn't.
1: Inside a block that declares a variable (reg a)
2: Inside a named block
3: The same thing with foreach
4: This passes because the
initialblock isn't named, and no variables are declared.I tested with
iverilog -g2012to enable SystemVerilog features.Applied to git mater.