ast: delete wires and localparams after finishing const evaluation
authorXiretza <xiretza@xiretza.xyz>
Tue, 16 Mar 2021 23:14:27 +0000 (00:14 +0100)
committerZachary Snow <zachary.j.snow@gmail.com>
Mon, 14 Jun 2021 17:56:51 +0000 (13:56 -0400)
frontends/ast/simplify.cc

index 8ef681069bf97525113afaed4c6aec494a4b8532..f853064234185ea2d2d11a17e1282ccd6fdf32d5 100644 (file)
@@ -4774,6 +4774,7 @@ AstNode *AstNode::eval_const_function(AstNode *fcall, bool must_succeed)
 {
        std::map<std::string, AstNode*> backup_scope = current_scope;
        std::map<std::string, AstNode::varinfo_t> variables;
+       std::vector<AstNode*> to_delete;
        AstNode *block = new AstNode(AST_BLOCK);
        AstNode *result = nullptr;
 
@@ -4831,6 +4832,7 @@ AstNode *AstNode::eval_const_function(AstNode *fcall, bool must_succeed)
                        current_scope[stmt->str] = stmt;
 
                        block->children.erase(block->children.begin());
+                       to_delete.push_back(stmt);
                        continue;
                }
 
@@ -4843,6 +4845,7 @@ AstNode *AstNode::eval_const_function(AstNode *fcall, bool must_succeed)
                        current_scope[stmt->str] = stmt;
 
                        block->children.erase(block->children.begin());
+                       to_delete.push_back(stmt);
                        continue;
                }
 
@@ -5038,6 +5041,11 @@ finished:
        delete block;
        current_scope = backup_scope;
 
+       for (auto it : to_delete) {
+               delete it;
+       }
+       to_delete.clear();
+
        return result;
 }