[dart2wasm] Fix reversal of break labels crossing finally.

The block starts and ends for the entry points to the finally block
instances corresponding to break paths were emitted in the same order,
causing the jump targets to be reversed.

Change-Id: Ifc8a6b6320ba7341140606c98333f5825d2228ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/283042
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
This commit is contained in:
Aske Simon Christensen 2023-02-15 10:24:08 +00:00 committed by Commit Queue
parent 51a29c1218
commit 7a63ff2604
3 changed files with 67 additions and 1 deletions

View file

@ -1044,7 +1044,7 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
w.Label tryFinallyBlock = b.block();
// Create one block for each wrapping label
for (final labelBlocks in breakFinalizers.values) {
for (final labelBlocks in breakFinalizers.values.toList().reversed) {
labelBlocks.add(b.block());
}

View file

@ -0,0 +1,33 @@
// Copyright (c) 2023, 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.
import "package:expect/expect.dart";
String test(int n) {
String s = "$n";
a:
{
b:
{
try {
if (n == 1) {
break a;
} else {
break b;
}
s += "/";
} finally {
s += "-";
}
s += "*";
}
return s + "b";
}
return s + "a";
}
main() {
Expect.equals("1-a", test(1));
Expect.equals("2-b", test(2));
}

View file

@ -0,0 +1,33 @@
// Copyright (c) 2023, 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.
import "package:expect/expect.dart";
String test(int n) {
String s = "$n";
a:
{
b:
{
try {
if (n == 1) {
break a;
} else {
break b;
}
s += "/";
} finally {
s += "-";
}
s += "*";
}
return s + "b";
}
return s + "a";
}
main() {
Expect.equals("1-a", test(1));
Expect.equals("2-b", test(2));
}