diff --git a/passes/hierarchy/hierarchy.cc b/passes/hierarchy/hierarchy.cc index 08b14dca0..74edbabf4 100644 --- a/passes/hierarchy/hierarchy.cc +++ b/passes/hierarchy/hierarchy.cc @@ -684,23 +684,31 @@ void hierarchy_clean(RTLIL::Design *design, RTLIL::Module *top, bool purge_lib) bool set_keep_print(std::map &cache, RTLIL::Module *mod) { - if (cache.count(mod) == 0) + if (cache.count(mod) == 0) { + cache[mod] = false; for (auto c : mod->cells()) { RTLIL::Module *m = mod->design->module(c->type); - if ((m != nullptr && set_keep_print(cache, m)) || c->type == ID($print)) - return cache[mod] = true; + if ((m != nullptr && set_keep_print(cache, m)) || c->type == ID($print)) { + cache[mod] = true; + break; + } } + } return cache[mod]; } bool set_keep_assert(std::map &cache, RTLIL::Module *mod) { - if (cache.count(mod) == 0) + if (cache.count(mod) == 0) { + cache[mod] = false; for (auto c : mod->cells()) { RTLIL::Module *m = mod->design->module(c->type); - if ((m != nullptr && set_keep_assert(cache, m)) || c->type.in(ID($check), ID($assert), ID($assume), ID($live), ID($fair), ID($cover))) - return cache[mod] = true; + if ((m != nullptr && set_keep_assert(cache, m)) || c->type.in(ID($check), ID($assert), ID($assume), ID($live), ID($fair), ID($cover))) { + cache[mod] = true; + break; + } } + } return cache[mod]; } diff --git a/tests/various/hierarchy_keep.ys b/tests/various/hierarchy_keep.ys new file mode 100644 index 000000000..3e3f1b4a1 --- /dev/null +++ b/tests/various/hierarchy_keep.ys @@ -0,0 +1,48 @@ +read_verilog -noblackbox <