From 3fcf660ed159584fe64b17c1212a3de7eb975ce5 Mon Sep 17 00:00:00 2001 From: Tess Strickland Date: Thu, 13 Jul 2023 09:19:57 +0000 Subject: [PATCH] [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 Commit-Queue: Tess Strickland --- runtime/vm/object.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc index 42c1a65e385..33da0ec9400 100644 --- a/runtime/vm/object.cc +++ b/runtime/vm/object.cc @@ -566,7 +566,20 @@ void Object::InitNullAndBool(IsolateGroup* isolate_group) { heap->Allocate(thread, Instance::InstanceSize(), Heap::kOld); null_ = static_cast(address + kHeapObjectTag); // The call below is using 'null_' to initialize itself. - InitializeObjectVariant(address, kNullCid); + // + // TODO(52910): Change the below to + // InitializeObjectVariant(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(); }