[vm] For now, initialize the contents of null with its address.

When running with `--no-sound-null-safety` turned on, it turns out null
is unboxed as an Mint in some cases without checking for null first.
Before, tests would fail because unboxing it would give a really
large int that was unlikely to be acceptable to subsequent range
checks and the like.

However, since 2f63ace, that memory is now zero-initialized, and zero is
more likely to be an acceptable value, so tests either fail for
unexpected reasons or, worse, unexpectedly succeed.

As a stopgap until the appropriate checks are emitted, we initialize
the contents of null with its address as an ObjectPtr like we used to.

TEST=corelib{,_2}/list_removeat_test on dartkp-* configurations.

Issue: https://github.com/dart-lang/sdk/issues/52910
Change-Id: If456d503c86202616f4f566a402118e9c41194ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313500
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
This commit is contained in:
Tess Strickland 2023-07-13 09:19:57 +00:00 committed by Commit Queue
parent db2e318b5d
commit 3fcf660ed1

View file

@ -566,7 +566,20 @@ void Object::InitNullAndBool(IsolateGroup* isolate_group) {
heap->Allocate(thread, Instance::InstanceSize(), Heap::kOld);
null_ = static_cast<InstancePtr>(address + kHeapObjectTag);
// The call below is using 'null_' to initialize itself.
InitializeObjectVariant<Instance>(address, kNullCid);
//
// TODO(52910): Change the below to
// InitializeObjectVariant<Instance>(address, kNullCid);
// after we've fixed the unboxing of the null object without checking for
// null first when --no-sound-null-safety is on. (This is a stopgap so that
// those bad unboxings pull out really large values that almost certainly
// will fail, which was the old status quo.)
const intptr_t ptr_field_end_offset =
Instance::InstanceSize() - (Instance::ContainsCompressedPointers()
? kCompressedWordSize
: kWordSize);
InitializeObject(address, kNullCid, Instance::InstanceSize(),
Instance::ContainsCompressedPointers(),
sizeof(UntaggedObject), ptr_field_end_offset);
null_->untag()->SetCanonical();
}