Skip to content

Commit cb63685

Browse files
dcharkescommit-bot@chromium.org
authored andcommitted
[vm] Exclude current_context_var from ValidatePhis
current_context_var is special cased in the liveness analysis and never pruned even though it does not have uses by instructions. The lack of pruning caused the assert to fire. This CL adds the special casing to this assert as well. Closes: dart-lang/sdk#45855 TEST=tests/language/vm/regress_45855_test.dart Change-Id: Ica74a43bd2449dd994639c686253449146216458 Fixed: 45855 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/197541 Commit-Queue: Daco Harkes <dacoharkes@google.com> Reviewed-by: Alexander Markov <alexmarkov@google.com>
1 parent ee27684 commit cb63685

File tree

4 files changed

+75
-3
lines changed

4 files changed

+75
-3
lines changed

runtime/vm/compiler/backend/flow_graph.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,10 @@ void FlowGraph::ValidatePhis() {
16131613
return;
16141614
}
16151615

1616+
// Current_context_var is never pruned, it is artificially kept alive, so
1617+
// it should not be checked here.
1618+
const intptr_t current_context_var_index = CurrentContextEnvIndex();
1619+
16161620
for (intptr_t i = 0, n = preorder().length(); i < n; ++i) {
16171621
BlockEntryInstr* block_entry = preorder()[i];
16181622
Instruction* last_instruction = block_entry->last_instruction();
@@ -1624,7 +1628,7 @@ void FlowGraph::ValidatePhis() {
16241628
if (successor->phis() != NULL) {
16251629
for (intptr_t j = 0; j < successor->phis()->length(); ++j) {
16261630
PhiInstr* phi = (*successor->phis())[j];
1627-
if (phi == nullptr) {
1631+
if (phi == nullptr && j != current_context_var_index) {
16281632
// We have no phi node for the this variable.
16291633
// Double check we do not have a different value in our env.
16301634
// If we do, we would have needed a phi-node in the successsor.

runtime/vm/compiler/backend/flow_graph.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,8 @@ class LivenessAnalysis : public ValueObject {
651651
const GrowableArray<BlockEntryInstr*>& postorder_;
652652

653653
// Live-out sets for each block. They contain indices of variables
654-
// that are live out from this block: that is values that were either
655-
// defined in this block or live into it and that are used in some
654+
// that are live out from this block. That is values that were (1) either
655+
// defined in this block or live into it, and (2) that are used in some
656656
// successor block.
657657
GrowableArray<BitVector*> live_out_;
658658

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2021, 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+
// VMOptions=--optimization-counter-threshold=100 --deterministic
6+
//
7+
// The Dart Project Fuzz Tester (1.89).
8+
// Program generated as:
9+
// dart dartfuzz.dart --seed 928581289 --no-fp --ffi --no-flat
10+
//
11+
// Minimized.
12+
13+
@pragma('vm:never-inline')
14+
void main2(bool? boolParam) {
15+
for (int i = 0; i < 200; i++) {
16+
final bool1 = boolParam ?? false;
17+
if (bool1) {
18+
() {
19+
// Force creating a new current context.
20+
i.toString();
21+
};
22+
// Force having multiple paths to the exit, popping the current context.
23+
break;
24+
}
25+
}
26+
}
27+
28+
void main() {
29+
// Test OSR.
30+
main2(null);
31+
32+
// Test non-OSR.
33+
main2(null);
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2021, 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+
// VMOptions=--optimization-counter-threshold=100 --deterministic
6+
//
7+
// The Dart Project Fuzz Tester (1.89).
8+
// Program generated as:
9+
// dart dartfuzz.dart --seed 928581289 --no-fp --ffi --no-flat
10+
//
11+
// Minimized.
12+
13+
@pragma('vm:never-inline')
14+
void main2(bool boolParam) {
15+
for (int i = 0; i < 200; i++) {
16+
final bool1 = boolParam ?? false;
17+
if (bool1) {
18+
() {
19+
// Force creating a new current context.
20+
i.toString();
21+
};
22+
// Force having multiple paths to the exit, popping the current context.
23+
break;
24+
}
25+
}
26+
}
27+
28+
void main() {
29+
// Test OSR.
30+
main2(null);
31+
32+
// Test non-OSR.
33+
main2(null);
34+
}

0 commit comments

Comments
 (0)