Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Unified Diff: pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart

Issue 970853006: Fix reference counting bug in StatementRewriter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Consistent use of pre-decrement Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart
diff --git a/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart b/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart
index 61f0a3121de4010b2290fd73e3800ca95af61d52..9293c8ff50438e5b41af458344c22eeac5ac2e27 100644
--- a/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart
+++ b/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart
@@ -169,7 +169,10 @@ class StatementRewriter extends Visitor<Statement, Expression> with PassMixin {
Expression visitVariableUse(VariableUse node) {
// Propagate constant to use site.
Expression constant = constantEnvironment[node.variable];
- if (constant != null) return constant;
+ if (constant != null) {
+ --node.variable.readCount;
+ return constant;
+ }
// Propagate a variable's definition to its use site if:
// 1. It has a single use, to avoid code growth and potential duplication
@@ -178,7 +181,8 @@ class StatementRewriter extends Visitor<Statement, Expression> with PassMixin {
// reorder expressions with side effects.
if (!environment.isEmpty &&
environment.last.variable == node.variable &&
- environment.last.hasExactlyOneUse) {
+ node.variable.readCount == 1) {
+ --node.variable.readCount;
return visitExpression(environment.removeLast().definition);
}
@@ -207,6 +211,7 @@ class StatementRewriter extends Visitor<Statement, Expression> with PassMixin {
if (node.variable.readCount <= 1) {
// A single-use constant should always be propagted to its use site.
constantEnvironment[node.variable] = visitExpression(node.definition);
+ --node.variable.writeCount;
return visitStatement(node.next);
} else {
// With more than one use, we cannot propagate the constant.
@@ -229,6 +234,7 @@ class StatementRewriter extends Visitor<Statement, Expression> with PassMixin {
return node;
}
assert(!environment.contains(node));
+ --node.variable.writeCount; // This assignment was removed.
return next;
}
}
@@ -517,7 +523,10 @@ class StatementRewriter extends Visitor<Statement, Expression> with PassMixin {
if (s is Assign && t is Assign && s.variable == t.variable) {
Statement next = combineStatements(s.next, t.next);
if (next != null) {
- --t.variable.writeCount; // Two assignments become one.
+ // Destroy both original assignments to the variable.
+ --s.variable.writeCount;
+ --t.variable.writeCount;
+ // The Assign constructor will increment the reference count again.
return new Assign(s.variable,
combine(s.definition, t.definition),
next);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698