diff --git a/Makefile b/Makefile index 4443718c8..968e62fac 100644 --- a/Makefile +++ b/Makefile @@ -176,7 +176,7 @@ ifeq ($(OS), Haiku) CXXFLAGS += -D_DEFAULT_SOURCE endif -YOSYS_VER := 0.54+15 +YOSYS_VER := 0.54+17 YOSYS_MAJOR := $(shell echo $(YOSYS_VER) | cut -d'.' -f1) YOSYS_MINOR := $(shell echo $(YOSYS_VER) | cut -d'.' -f2) YOSYS_COMMIT := $(shell echo $(YOSYS_VER) | cut -d'.' -f3) diff --git a/frontends/verilog/verilog_lexer.l b/frontends/verilog/verilog_lexer.l index 8148748d8..40162b8d3 100644 --- a/frontends/verilog/verilog_lexer.l +++ b/frontends/verilog/verilog_lexer.l @@ -336,7 +336,7 @@ TIME_SCALE_SUFFIX [munpf]?s } \" { BEGIN(STRING); } -([^\"]|\\.)+ { yymore(); real_location = old_location; } +([^\\"]|\\.)+ { yymore(); real_location = old_location; } \" { BEGIN(0); char *yystr = strdup(yytext); diff --git a/frontends/verilog/verilog_parser.y b/frontends/verilog/verilog_parser.y index 7e53005f3..17edc357d 100644 --- a/frontends/verilog/verilog_parser.y +++ b/frontends/verilog/verilog_parser.y @@ -2874,6 +2874,7 @@ behavioral_stmt: } | if_attr TOK_IF '(' expr ')' { AstNode *node = 0; + AstNode *block = new AstNode(AST_BLOCK); AstNode *context = ast_stack.back(); if (context && context->type == AST_BLOCK && context->get_bool_attribute(ID::promoted_if)) { AstNode *outer = ast_stack[ast_stack.size() - 2]; @@ -2882,8 +2883,10 @@ behavioral_stmt: // parallel "else if": append condition to outer "if" node = outer; log_assert (node->children.size()); + ast_stack.pop_back(); delete node->children.back(); node->children.pop_back(); + ast_stack.push_back(block); } else if (outer->get_bool_attribute(ID::full_case)) (*$1)[ID::full_case] = AstNode::mkconst_int(1, false); } @@ -2894,8 +2897,8 @@ behavioral_stmt: append_attr(node, $1); ast_stack.back()->children.push_back(node); node->children.push_back(node->get_bool_attribute(ID::parallel_case) ? AstNode::mkconst_int(1, false, 1) : expr); - } - AstNode *block = new AstNode(AST_BLOCK); + } else + free_attr($1); AstNode *cond = new AstNode(AST_COND, node->get_bool_attribute(ID::parallel_case) ? expr : AstNode::mkconst_int(1, false, 1), block); SET_AST_NODE_LOC(cond, @4, @4); node->children.push_back(cond); diff --git a/passes/opt/opt_dff.cc b/passes/opt/opt_dff.cc index c4c01ea66..07d5bc289 100644 --- a/passes/opt/opt_dff.cc +++ b/passes/opt/opt_dff.cc @@ -760,7 +760,11 @@ struct OptDffWorker ModWalker modwalker(module->design, module); QuickConeSat qcsat(modwalker); - // Run as a separate sub-pass, so that we don't mutate (non-FF) cells under ModWalker. + // Defer mutating cells by removing them/emiting new flip flops so that + // cell references in modwalker are not invalidated + std::vector cells_to_remove; + std::vector ffs_to_emit; + bool did_something = false; for (auto cell : module->selected_cells()) { if (!RTLIL::builtin_ff_cell_types().count(cell->type)) @@ -852,16 +856,20 @@ struct OptDffWorker if (!removed_sigbits.count(i)) keep_bits.push_back(i); if (keep_bits.empty()) { - module->remove(cell); + cells_to_remove.emplace_back(cell); did_something = true; continue; } ff = ff.slice(keep_bits); ff.cell = cell; - ff.emit(); + ffs_to_emit.emplace_back(ff); did_something = true; } } + for (auto* cell : cells_to_remove) + module->remove(cell); + for (auto& ff : ffs_to_emit) + ff.emit(); return did_something; } }; diff --git a/tests/opt/bug5164.ys b/tests/opt/bug5164.ys new file mode 100644 index 000000000..4ee71fe45 --- /dev/null +++ b/tests/opt/bug5164.ys @@ -0,0 +1,60 @@ +read_rtlil <