[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
Fixes https://github.com/flutter/flutter/issues/117892

Change-Id: I63f0ca32d6246487f5c33d983cef9bd22aaa2fb8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278094
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
Alexander Markov
2023-01-04 15:26:34 +00:00
committed by Commit Queue
parent ade4e52fa5
commit b205ea18cb
2 changed files with 25 additions and 1 deletions
@@ -0,0 +1,23 @@
// 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.
// Verifies that compiler doesn't crash when uninitialized late variable
// (sentinel) is returned from an async function.
// Regression test for https://github.com/flutter/flutter/issues/117892.
import 'package:expect/expect.dart';
foo() async {
late int x;
if (3 != 3) {
x = 42;
}
return x;
}
main() {
foo().then((_) {
Expect.fail("Exception should be thrown.");
}, onError: (_) {});
}
@@ -947,7 +947,8 @@ bool CompileType::CanBeFuture() {
ObjectStore* object_store = isolate_group->object_store();
if (cid_ != kIllegalCid && cid_ != kDynamicCid) {
if ((cid_ == kNullCid) || (cid_ == kNeverCid)) {
if ((cid_ == kNullCid) || (cid_ == kNeverCid) ||
IsInternalOnlyClassId(cid_) || cid_ == kTypeArgumentsCid) {
return false;
}
const Class& cls = Class::Handle(isolate_group->class_table()->At(cid_));