Skip to content

Commit

Permalink
Force local context allocation in finally clauses (fixes #26948).
Browse files Browse the repository at this point in the history
Add regression test.

R=fschneider@google.com, hausner@google.com

Review URL: https://codereview.chromium.org/2188863002 .
  • Loading branch information
crelier committed Jul 27, 2016
1 parent 8e787a7 commit 11d340c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
11 changes: 10 additions & 1 deletion runtime/vm/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9293,7 +9293,16 @@ SequenceNode* Parser::EnsureFinallyClause(
LocalVariable* rethrow_stack_trace_var) {
TRACE_PARSER("EnsureFinallyClause");
ASSERT(parse || (is_async && (try_stack_ != NULL)));
OpenBlock();
// Increasing the loop level prevents the reuse of a parent context and forces
// the allocation of a local context to hold captured variables declared
// inside the finally clause. Otherwise, a captured variable gets allocated at
// different slots in the parent context each time the finally clause is
// reparsed, which is done to duplicate the ast. Since only one closure is
// kept due to canonicalization, it will access the correct slot in only one
// copy of the finally clause and the wrong slot in all others. By allocating
// a local context, all copies use the same slot in different local contexts.
// See issue #26948. This is a temporary fix until we eliminate reparsing.
OpenLoopBlock();
if (parse) {
ExpectToken(Token::kLBRACE);
}
Expand Down
26 changes: 26 additions & 0 deletions tests/language/regress_26948_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization-counter-threshold=10 --no-background-compilation

import 'dart:async';
import "package:expect/expect.dart";

void check(Function f) {
Expect.isTrue(f());
}

Future doSync() async {
try {
await 123;
} finally {
var next = 5.0;
check(() => next == 5.0);
}
}

main() async {
for (int i = 0; i < 20; i++) {
await doSync();
}
}

0 comments on commit 11d340c

Please sign in to comment.