mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 18:01:07 +01:00
Destroy locals at the end of blocks, not only on return (#7448)
Destroy local variables and temporaries at each `}`, and when branching with `break` and `continue`. In `for` statements, destroy loop variables along with anything created within the loop at the end of each loop iteration, and destroy the cursor and range object when the loop terminates. Assisted-by: Gemini via Antigravity --------- Co-authored-by: Geoff Romer <gromer@google.com>
This commit is contained in:
co-authored by
Geoff Romer
parent
8bae79f44a
commit
6e62a7d4a2
@@ -469,6 +469,9 @@ auto StartFunctionDefinition(Context& context, SemIR::InstId decl_id,
|
||||
auto FinishFunctionDefinition(Context& context, SemIR::FunctionId function_id)
|
||||
-> void {
|
||||
context.inst_block_stack().Pop();
|
||||
// Any cleanups for a function will have been handled when emitting `return`s.
|
||||
context.scope_stack().DiscardCleanupsSince(
|
||||
context.scope_stack().function_cleanup_scope_depth());
|
||||
context.scope_stack().Pop(/*check_unused=*/true);
|
||||
|
||||
auto observe_block_id =
|
||||
|
||||
Reference in New Issue
Block a user