diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc index 749767743..3d33f9de0 100644 --- a/frontends/ast/simplify.cc +++ b/frontends/ast/simplify.cc @@ -4100,16 +4100,24 @@ skip_dynamic_range_lvalue_expansion:; delete arg; continue; } + AstNode *wire_id = new AstNode(AST_IDENTIFIER); wire_id->str = wire->str; - AstNode *assign = child->is_input ? - new AstNode(AST_ASSIGN_EQ, wire_id, arg) : - new AstNode(AST_ASSIGN_EQ, arg, wire_id); - assign->children[0]->was_checked = true; - if (child->is_input) + + if (child->is_input) { + AstNode *assign = new AstNode(AST_ASSIGN_EQ, wire_id->clone(), arg->clone()); + assign->children[0]->was_checked = true; new_stmts.push_back(assign); - else + } + + if (child->is_output) { + AstNode *assign = new AstNode(AST_ASSIGN_EQ, arg->clone(), wire_id->clone()); + assign->children[0]->was_checked = true; output_assignments.push_back(assign); + } + + delete arg; + delete wire_id; } } diff --git a/tests/verilog/func_task_arg_copying.ys b/tests/verilog/func_task_arg_copying.ys new file mode 100644 index 000000000..e87c2781b --- /dev/null +++ b/tests/verilog/func_task_arg_copying.ys @@ -0,0 +1,132 @@ +# https://github.com/YosysHQ/yosys/issues/5157 +read_verilog -sv <