Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit bd39cca

Browse files
mralephcommit-bot@chromium.org
authored andcommitted
[compiler] Mark each variable stored on entry to catch block.
We do not generate explicit control flow and phis for exceptional edges. Instead CatchBlockEntry has a Parameter instruction for each local variable. These Parameter-s represent that state of local variables on entry into the catch block. This means that we should mark all variables assigned on entry to the catch block. Previous version of the code was incorrectly marking only direct parameters as stored. Fixes dart-lang/sdk#36953 Bug: 36953 Change-Id: I2e8040d75ba23d2483e451300f44bbdcef458655 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103802 Reviewed-by: Daco Harkes <[email protected]> Commit-Queue: Vyacheslav Egorov <[email protected]>
1 parent 0e5ebca commit bd39cca

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// Regression test for dartbug.com/36953: check that phi is inserted correctly
6+
// when try block has no normal exit.
7+
8+
// VMOptions=--optimization_counter_threshold=10 --deterministic
9+
10+
import "package:expect/expect.dart";
11+
12+
void testBody() {
13+
var v;
14+
do {
15+
try {} catch (e, st) {
16+
continue;
17+
}
18+
19+
try {
20+
v = 10;
21+
throw "";
22+
} catch (e, st) {}
23+
} while (v++ < 10);
24+
Expect.equals(11, v);
25+
}
26+
27+
void main() {
28+
testBody();
29+
testBody();
30+
}

runtime/vm/compiler/backend/flow_graph.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -756,10 +756,12 @@ void VariableLivenessAnalysis::ComputeInitialSets() {
756756
// to the kill set.
757757
const bool is_function_entry = block->IsFunctionEntry();
758758
const bool is_osr_entry = block->IsOsrEntry();
759-
if (is_function_entry || is_osr_entry || block->IsCatchBlockEntry()) {
759+
const bool is_catch_block_entry = block->IsCatchBlockEntry();
760+
if (is_function_entry || is_osr_entry || is_catch_block_entry) {
760761
const intptr_t parameter_count =
761-
is_osr_entry ? flow_graph_->variable_count()
762-
: flow_graph_->num_direct_parameters();
762+
(is_osr_entry || is_catch_block_entry)
763+
? flow_graph_->variable_count()
764+
: flow_graph_->num_direct_parameters();
763765
for (intptr_t i = 0; i < parameter_count; ++i) {
764766
live_in->Remove(i);
765767
kill->Add(i);

0 commit comments

Comments
 (0)