mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 18:01:07 +01: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:
@@ -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