Skip to content

Commit 2d5c46c

Browse files
alexmarkovCommit Queue
authored and
Commit Queue
committed
[vm/compiler] Do not assume that LoadField is performed from a record of a compatible shape
Compiler can see an unreachable code like this: v1 <- Constant(Record (C, C)) if v1 is (C, C, C) { v2 <- LoadField (v1.$3) } So it should check that record type of the receiver has enough fields before querying field type in LoadField. TEST=co19/LanguageFeatures/Patterns/matching_record_* Fixes #51767 Issue #49755 Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-nnbd-linux-release-x64-try Change-Id: Iac42c8edf3d22dce0061b6d75e8bdf51b7bf88e6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289540 Auto-Submit: Alexander Markov <[email protected]> Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Martin Kustermann <[email protected]>
1 parent 10f53cb commit 2d5c46c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

runtime/vm/compiler/backend/type_propagator.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,10 +1688,14 @@ CompileType LoadFieldInstr::ComputeType() const {
16881688
}
16891689
const AbstractType* instance_type = instance()->Type()->ToAbstractType();
16901690
if (instance_type->IsRecordType()) {
1691-
const auto& field_type = AbstractType::ZoneHandle(
1692-
RecordType::Cast(*instance_type).FieldTypeAt(index));
1693-
return CompileType::FromAbstractType(field_type, CompileType::kCanBeNull,
1694-
CompileType::kCannotBeSentinel);
1691+
const auto& record_type = RecordType::Cast(*instance_type);
1692+
if (index < record_type.NumFields()) {
1693+
const auto& field_type =
1694+
AbstractType::ZoneHandle(record_type.FieldTypeAt(index));
1695+
return CompileType::FromAbstractType(field_type,
1696+
CompileType::kCanBeNull,
1697+
CompileType::kCannotBeSentinel);
1698+
}
16951699
}
16961700
}
16971701
CompileType type = slot().ComputeCompileType();

0 commit comments

Comments
 (0)