mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-20 21:16:43 +00:00
Explorer: fix class destructor not called with heap.Delete (#2546)
This change ensures that DestroyAction is executed for the value being deallocated when calling heap.Delete. Relates to #2521
This commit is contained in:
1 parent
82f7d06855
commit
b4e3a3e6cc
3 files changed
+92
-2
No files matched your search
@@ -1454,8 +1454,18 @@ auto Interpreter::StepExp() -> ErrorOr<Success> {
|
||||
}
|
||||
case IntrinsicExpression::Intrinsic::Dealloc: {
|
||||
CARBON_CHECK(args.size() == 1);
|
||||
heap_.Deallocate(cast<PointerValue>(args[0])->address());
|
||||
return todo_.FinishAction(TupleValue::Empty());
|
||||
CARBON_CHECK(act.pos() > 0);
|
||||
const auto* ptr = cast<PointerValue>(args[0]);
|
||||
if (act.pos() == 1) {
|
||||
CARBON_ASSIGN_OR_RETURN(
|
||||
const auto* pointee,
|
||||
this->heap_.Read(ptr->address(), exp.source_loc()));
|
||||
return todo_.Spawn(std::make_unique<DestroyAction>(
|
||||
arena_->New<LValue>(ptr->address()), pointee));
|
||||
} else {
|
||||
heap_.Deallocate(ptr->address());
|
||||
return todo_.FinishAction(TupleValue::Empty());
|
||||
}
|
||||
}
|
||||
case IntrinsicExpression::Intrinsic::Rand: {
|
||||
CARBON_CHECK(args.size() == 2);
|
||||
|
||||
Reference in new issue
Block a user