| ... | ... | @@ -17,8 +17,7 @@ |
| 17 | 17 | #include "util.hpp" |
| 18 | 18 | |
| 19 | 19 | struct IrExecContext { |
| 20 | | ConstExprValue *mem_slot_list; |
| 21 | | size_t mem_slot_count; |
| 20 | ZigList<ConstExprValue *> mem_slot_list; |
| 22 | 21 | }; |
| 23 | 22 | |
| 24 | 23 | struct IrBuilder { |
| ... | ... | @@ -12496,13 +12495,20 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 12496 | 12495 | } |
| 12497 | 12496 | } |
| 12498 | 12497 | |
| 12499 | | if (var->value->type != nullptr && var->value->type != result_type && !is_comptime_var) { |
| 12498 | if (var->value->type != nullptr && !is_comptime_var) { |
| 12500 | 12499 | // This is at least the second time we've seen this variable declaration during analysis. |
| 12501 | 12500 | // This means that this is actually a different variable due to, e.g. an inline while loop. |
| 12502 | 12501 | // We make a new variable so that it can hold a different type, and so the debug info can |
| 12503 | 12502 | // be distinct. |
| 12504 | 12503 | VariableTableEntry *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope, |
| 12505 | 12504 | &var->name, var->src_is_const, var->gen_is_const, var->shadowable, var->is_comptime, true); |
| 12505 | new_var->owner_exec = var->owner_exec; |
| 12506 | if (var->mem_slot_index != SIZE_MAX) { |
| 12507 | ConstExprValue *vals = create_const_vals(1); |
| 12508 | new_var->mem_slot_index = ira->exec_context.mem_slot_list.length; |
| 12509 | ira->exec_context.mem_slot_list.append(vals); |
| 12510 | } |
| 12511 | |
| 12506 | 12512 | var->next_var = new_var; |
| 12507 | 12513 | var = new_var; |
| 12508 | 12514 | } |
| ... | ... | @@ -12525,10 +12531,9 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 12525 | 12531 | |
| 12526 | 12532 | if (casted_init_value->value.special != ConstValSpecialRuntime) { |
| 12527 | 12533 | if (var->mem_slot_index != SIZE_MAX) { |
| 12528 | | assert(var->mem_slot_index < ira->exec_context.mem_slot_count); |
| 12529 | | ConstExprValue *mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index]; |
| 12530 | | copy_const_val(mem_slot, &casted_init_value->value, |
| 12531 | | !is_comptime_var || var->gen_is_const); |
| 12534 | assert(var->mem_slot_index < ira->exec_context.mem_slot_list.length); |
| 12535 | ConstExprValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index); |
| 12536 | copy_const_val(mem_slot, &casted_init_value->value, !is_comptime_var || var->gen_is_const); |
| 12532 | 12537 | |
| 12533 | 12538 | if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) { |
| 12534 | 12539 | ir_build_const_from(ira, &decl_var_instruction->base); |
| ... | ... | @@ -13012,8 +13017,8 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 13012 | 13017 | assert(var->owner_exec != nullptr); |
| 13013 | 13018 | assert(var->owner_exec->analysis != nullptr); |
| 13014 | 13019 | IrExecContext *exec_context = &var->owner_exec->analysis->exec_context; |
| 13015 | | assert(var->mem_slot_index < exec_context->mem_slot_count); |
| 13016 | | mem_slot = &exec_context->mem_slot_list[var->mem_slot_index]; |
| 13020 | assert(var->mem_slot_index < exec_context->mem_slot_list.length); |
| 13021 | mem_slot = exec_context->mem_slot_list.at(var->mem_slot_index); |
| 13017 | 13022 | } |
| 13018 | 13023 | } |
| 13019 | 13024 | |
| ... | ... | @@ -21228,8 +21233,11 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl |
| 21228 | 21233 | ira->new_irb.codegen = codegen; |
| 21229 | 21234 | ira->new_irb.exec = new_exec; |
| 21230 | 21235 | |
| 21231 | | ira->exec_context.mem_slot_count = ira->old_irb.exec->mem_slot_count; |
| 21232 | | ira->exec_context.mem_slot_list = create_const_vals(ira->exec_context.mem_slot_count); |
| 21236 | ConstExprValue *vals = create_const_vals(ira->old_irb.exec->mem_slot_count); |
| 21237 | ira->exec_context.mem_slot_list.resize(ira->old_irb.exec->mem_slot_count); |
| 21238 | for (size_t i = 0; i < ira->exec_context.mem_slot_list.length; i += 1) { |
| 21239 | ira->exec_context.mem_slot_list.items[i] = &vals[i]; |
| 21240 | } |
| 21233 | 21241 | |
| 21234 | 21242 | IrBasicBlock *old_entry_bb = ira->old_irb.exec->basic_block_list.at(0); |
| 21235 | 21243 | IrBasicBlock *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr); |