Skip to content

Commit ef7ab77

Browse files
authored
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.
1 parent 949bf49 commit ef7ab77

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/passes/DataFlowOpts.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ struct DataFlowOpts : public WalkerPass<PostWalker<DataFlowOpts>> {
137137
Module temp;
138138
// XXX we should copy expr here, in principle, and definitely will need to
139139
// when we do arbitrarily regenerated expressions
140-
auto* func = Builder(temp).makeFunction(
141-
"temp", Signature(Type::none, Type::none), {}, expr);
140+
std::unique_ptr<Function> tempFunc(Builder(temp).makeFunction(
141+
"temp", Signature(Type::none, Type::none), {}, expr));
142142
PassRunner runner(&temp);
143143
runner.setIsNested(true);
144144
runner.add("precompute");
145-
runner.runOnFunction(func);
145+
runner.runOnFunction(tempFunc.get());
146146
// Get the optimized thing
147-
auto* result = func->body;
147+
auto* result = tempFunc->body;
148148
// It may not be a constant, e.g. 0 / 0 does not optimize to 0
149149
if (!result->is<Const>()) {
150150
return;

0 commit comments

Comments
 (0)