mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
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:
@@ -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});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user