mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 10:54:49 +01:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user