Fix double-destruction of temporaries. (#6010)

Attach the cleanup to the `Temporary` instruction instead of to the
`TemporaryStorage` instruction. We create `TemporaryStorage`
instructions speculatively when creating an initializing expression, and
may overwrite those instructions with other instructions if it turns out
that a temporary is not required. Instead, wait until we finalize the
temporary and create a `Temporary` instruction to register the cleanup.
This commit is contained in:
Richard Smith
2025-09-04 19:19:59 +00:00
committed by GitHub
parent f943f31e41
commit db0a00d713
102 changed files with 1139 additions and 1659 deletions
+1 -1
View File
@@ -600,7 +600,7 @@ auto PerformCppThunkCall(Context& context, SemIR::LocId loc_id,
if (thunk_takes_return_address) {
// Create a temporary if the caller didn't provide a return slot.
if (!return_slot_id.has_value()) {
return_slot_id = AddInstWithCleanup<SemIR::TemporaryStorage>(
return_slot_id = AddInst<SemIR::TemporaryStorage>(
context, loc_id, {.type_id = return_type_id});
}