Fix initialization of var parameters. (#7023)

When an initializing expression is used to initialize a var parameter,
we need to create the storage earlier in SemIR than the initializing
expression. To do so, pass a pending block to initialization containing
the var storage.

Also stop using `temporary` for this purpose, since we treat temporaries
as potentially-constant and immutable, but `var` parameters can be
mutated by the callee. We should ideally introduce a new kind of
instruction for this purpose but for now we just use `var_storage`.
This commit is contained in:
Richard Smith
2026-04-28 20:10:13 +00:00
committed by GitHub
parent 51e843d904
commit 23339bc810
16 changed files with 420 additions and 143 deletions
+2 -2
View File
@@ -191,8 +191,8 @@ auto BuildReturnWithExpr(Context& context, SemIR::LocId loc_id,
out_param_id =
call_params[function.call_param_ranges.return_begin().index];
CARBON_CHECK(out_param_id.has_value());
expr_id = Initialize(context, loc_id, out_param_id, expr_id,
/*for_return=*/true);
expr_id = InitializeExisting(context, loc_id, out_param_id, expr_id,
/*for_return=*/true);
if (!SemIR::InitRepr::ForType(context.sem_ir(), return_type_id)
.MightBeInPlace()) {
out_param_id = SemIR::InstId::None;