Skip to content

Commit cbaec11

Browse files
alexmarkovCommit Queue
authored and
Commit Queue
committed
[beta] [vm] Fix compiler crash when returning a value of uninitialized late variable from async function
This change fixes CompileType::CanBeFuture() which previously attempted to use Class objects by class id without first checking if cid is internal. Cid can be internal (SentinelCid) when CompileType::CanBeFuture() is called for a return value of an async function when it is returning a value of an uninitialized late local variable (such Return instruction is unreachable). TEST=runtime/tests/vm/dart/regress_flutter117892_test.dart Bug: flutter/flutter#117892 Bug: #50894 Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/278094 Change-Id: I51653bdea62eebe2b73bdf98397112f011a0d112 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278362 Reviewed-by: Slava Egorov <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent 7c564e5 commit cbaec11

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2023, 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+
// Verifies that compiler doesn't crash when uninitialized late variable
6+
// (sentinel) is returned from an async function.
7+
// Regression test for https://github.com/flutter/flutter/issues/117892.
8+
9+
import 'package:expect/expect.dart';
10+
11+
foo() async {
12+
late int x;
13+
if (3 != 3) {
14+
x = 42;
15+
}
16+
return x;
17+
}
18+
19+
main() {
20+
foo().then((_) {
21+
Expect.fail("Exception should be thrown.");
22+
}, onError: (_) {});
23+
}

runtime/vm/compiler/backend/type_propagator.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,8 @@ bool CompileType::CanBeFuture() {
947947
ObjectStore* object_store = isolate_group->object_store();
948948

949949
if (cid_ != kIllegalCid && cid_ != kDynamicCid) {
950-
if ((cid_ == kNullCid) || (cid_ == kNeverCid)) {
950+
if ((cid_ == kNullCid) || (cid_ == kNeverCid) ||
951+
IsInternalOnlyClassId(cid_) || cid_ == kTypeArgumentsCid) {
951952
return false;
952953
}
953954
const Class& cls = Class::Handle(isolate_group->class_table()->At(cid_));

0 commit comments

Comments
 (0)