diff --git a/src/V3Randomize.cpp b/src/V3Randomize.cpp index 25f13a704..d7333a1f1 100644 --- a/src/V3Randomize.cpp +++ b/src/V3Randomize.cpp @@ -3631,6 +3631,14 @@ class RandomizeVisitor final : public VNVisitor { constrExprp->replaceWith(chainp); VL_DO_DANGLING(constrExprp->deleteTree(), constrExprp); } + + // Clean up nodes used only as clone templates (never inserted into tree) + for (auto& bucket : buckets) { + VL_DO_DANGLING(bucket.weightExprp->deleteTree(), bucket.weightExprp); + } + VL_DO_DANGLING(runningSump->deleteTree(), runningSump); + // Last cumSum is unused (last bucket is unconditional default) + VL_DO_DANGLING(cumSums.back()->deleteTree(), cumSums.back()); } }