YosysHQ / yosys

Yosys Open SYnthesis Suite
https://yosyshq.net/yosys/
ISC License
3.49k stars 890 forks source link

Recursive module instantations cause stack overflow #1689

Open daveshah1 opened 4 years ago

daveshah1 commented 4 years ago

MCVE:

module top(input x, output y);
top top_i(.x(x), .y(y));
endmodule
yosys -p hierarchy recurse.v

Produces

-- Parsing `recurse.v' using frontend `verilog' --

1. Executing Verilog-2005 frontend: recurse.v
Parsing Verilog input from `recurse.v' to AST representation.
Generating RTLIL representation for module `\top'.
Successfully finished Verilog frontend.

-- Running command `hierarchy' --

2. Executing HIERARCHY pass (managing design hierarchy).
[1]    5707 segmentation fault (core dumped)  yosys -p hierarchy recurse.v

Backtrace:

0x00005555556ec6e1 in Yosys::RTLIL::Design::module (this=<optimized out>, name=...) at kernel/rtlil.cc:423
423     return modules_.count(name) ? modules_.at(name) : NULL;
(gdb) bt
#0  0x00005555556ec6e1 in Yosys::RTLIL::Design::module (this=<optimized out>, name=...) at kernel/rtlil.cc:423
#1  0x0000555555c643d0 in (anonymous namespace)::set_keep_assert (cache=std::map with 0 elements, mod=<optimized out>)
    at passes/hierarchy/hierarchy.cc:508
#2  0x0000555555c643eb in (anonymous namespace)::set_keep_assert (cache=std::map with 0 elements, mod=<optimized out>)
    at passes/hierarchy/hierarchy.cc:509
#3  0x0000555555c643eb in (anonymous namespace)::set_keep_assert (cache=std::map with 0 elements, mod=<optimized out>)
    at passes/hierarchy/hierarchy.cc:509
#4  0x0000555555c643eb in (anonymous namespace)::set_keep_assert (cache=std::map with 0 elements, mod=<optimized out>)
    at passes/hierarchy/hierarchy.cc:509
#5  0x0000555555c643eb in (anonymous namespace)::set_keep_assert (cache=std::map with 0 elements, mod=<optimized out>)
    at passes/hierarchy/hierarchy.cc:509
#6  0x0000555555c643eb in (anonymous namespace)::set_keep_assert (cache=std::map with 0 elements, mod=<optimized out>)
    at passes/hierarchy/hierarchy.cc:509
#7  0x0000555555c643eb in (anonymous namespace)::set_keep_assert (cache=std::map with 0 elements, mod=<optimized out>)
    at passes/hierarchy/hierarchy.cc:509
#8  0x0000555555c643eb in (anonymous namespace)::set_keep_assert (cache=std::map with 0 elements, mod=<optimized out>)
    at passes/hierarchy/hierarchy.cc:509
#9  0x0000555555c643eb in (anonymous namespace)::set_keep_assert (cache=std::map with 0 elements, mod=<optimized out>)
    at passes/hierarchy/hierarchy.cc:509

(and so on)

Reduced from a testcase from @cr1901 which involved a missing -lib, it would be nice to error out here more meaningfully.

eddiehung commented 4 years ago

Likely related: #1127