diff options
author | Daniel Wirtz <dcode@dcode.io> | 2020-09-02 15:57:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-02 15:57:43 +0200 |
commit | ef7ab77b598885a88ca8eb5cc3b8485c3da84db9 (patch) | |
tree | 437ba26f72d92d54b8237b8024602fe1983c3527 /src/passes/DataFlowOpts.cpp | |
parent | 949bf4916c6dcd9409888a677739c4c844bb9eda (diff) | |
download | binaryen-ef7ab77b598885a88ca8eb5cc3b8485c3da84db9.tar.gz binaryen-ef7ab77b598885a88ca8eb5cc3b8485c3da84db9.tar.bz2 binaryen-ef7ab77b598885a88ca8eb5cc3b8485c3da84db9.zip |
Fix DataFlowOpts leaking temporary Functions (#3093)
Fixes `DataFlowOpts` leaking allocated temporary functions created to precompute an expression as their body. Reusing the `body` afterwards is fine since expressions are arena allocated separately.
Diffstat (limited to 'src/passes/DataFlowOpts.cpp')
-rw-r--r-- | src/passes/DataFlowOpts.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/passes/DataFlowOpts.cpp b/src/passes/DataFlowOpts.cpp index cf0092d37..40e0c3c48 100644 --- a/src/passes/DataFlowOpts.cpp +++ b/src/passes/DataFlowOpts.cpp @@ -137,14 +137,14 @@ struct DataFlowOpts : public WalkerPass<PostWalker<DataFlowOpts>> { Module temp; // XXX we should copy expr here, in principle, and definitely will need to // when we do arbitrarily regenerated expressions - auto* func = Builder(temp).makeFunction( - "temp", Signature(Type::none, Type::none), {}, expr); + std::unique_ptr<Function> tempFunc(Builder(temp).makeFunction( + "temp", Signature(Type::none, Type::none), {}, expr)); PassRunner runner(&temp); runner.setIsNested(true); runner.add("precompute"); - runner.runOnFunction(func); + runner.runOnFunction(tempFunc.get()); // Get the optimized thing - auto* result = func->body; + auto* result = tempFunc->body; // It may not be a constant, e.g. 0 / 0 does not optimize to 0 if (!result->is<Const>()) { return; |