| ... | ... | @@ -15259,23 +15259,25 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 15259 | 15259 | |
| 15260 | 15260 | bool comptime_var_mem = ir_get_var_is_comptime(var); |
| 15261 | 15261 | bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern; |
| 15262 | | bool is_const = var->src_is_const; |
| 15263 | 15262 | bool is_volatile = false; |
| 15264 | 15263 | |
| 15264 | IrInstruction *result = ir_build_var_ptr(&ira->new_irb, |
| 15265 | instruction->scope, instruction->source_node, var); |
| 15266 | result->value.type = get_pointer_to_type_extra(ira->codegen, var->var_type, |
| 15267 | var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false); |
| 15268 | |
| 15265 | 15269 | if (linkage_makes_it_runtime) |
| 15266 | 15270 | goto no_mem_slot; |
| 15267 | 15271 | |
| 15268 | 15272 | if (value_is_comptime(var->const_value)) { |
| 15269 | 15273 | mem_slot = var->const_value; |
| 15270 | | } else { |
| 15271 | | if (var->mem_slot_index != SIZE_MAX && (comptime_var_mem || var->gen_is_const)) { |
| 15272 | | // find the relevant exec_context |
| 15273 | | assert(var->owner_exec != nullptr); |
| 15274 | | assert(var->owner_exec->analysis != nullptr); |
| 15275 | | IrExecContext *exec_context = &var->owner_exec->analysis->exec_context; |
| 15276 | | assert(var->mem_slot_index < exec_context->mem_slot_list.length); |
| 15277 | | mem_slot = exec_context->mem_slot_list.at(var->mem_slot_index); |
| 15278 | | } |
| 15274 | } else if (var->mem_slot_index != SIZE_MAX && (comptime_var_mem || var->gen_is_const)) { |
| 15275 | // find the relevant exec_context |
| 15276 | assert(var->owner_exec != nullptr); |
| 15277 | assert(var->owner_exec->analysis != nullptr); |
| 15278 | IrExecContext *exec_context = &var->owner_exec->analysis->exec_context; |
| 15279 | assert(var->mem_slot_index < exec_context->mem_slot_list.length); |
| 15280 | mem_slot = exec_context->mem_slot_list.at(var->mem_slot_index); |
| 15279 | 15281 | } |
| 15280 | 15282 | |
| 15281 | 15283 | if (mem_slot != nullptr) { |
| ... | ... | @@ -15294,8 +15296,11 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 15294 | 15296 | assert(!comptime_var_mem); |
| 15295 | 15297 | ptr_mut = ConstPtrMutRuntimeVar; |
| 15296 | 15298 | } |
| 15297 | | return ir_get_const_ptr(ira, instruction, mem_slot, var->var_type, |
| 15298 | | ptr_mut, is_const, is_volatile, var->align_bytes); |
| 15299 | result->value.special = ConstValSpecialStatic; |
| 15300 | result->value.data.x_ptr.mut = ptr_mut; |
| 15301 | result->value.data.x_ptr.special = ConstPtrSpecialRef; |
| 15302 | result->value.data.x_ptr.data.ref.pointee = mem_slot; |
| 15303 | return result; |
| 15299 | 15304 | } |
| 15300 | 15305 | } |
| 15301 | 15306 | zig_unreachable(); |
| ... | ... | @@ -15303,15 +15308,10 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 15303 | 15308 | |
| 15304 | 15309 | no_mem_slot: |
| 15305 | 15310 | |
| 15306 | | IrInstruction *var_ptr_instruction = ir_build_var_ptr(&ira->new_irb, |
| 15307 | | instruction->scope, instruction->source_node, var); |
| 15308 | | var_ptr_instruction->value.type = get_pointer_to_type_extra(ira->codegen, var->var_type, |
| 15309 | | var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false); |
| 15310 | | |
| 15311 | 15311 | bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr); |
| 15312 | | var_ptr_instruction->value.data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack; |
| 15312 | result->value.data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack; |
| 15313 | 15313 | |
| 15314 | | return var_ptr_instruction; |
| 15314 | return result; |
| 15315 | 15315 | } |
| 15316 | 15316 | |
| 15317 | 15317 | // This function is called when a comptime value becomes accessible at runtime. |
| ... | ... | @@ -17317,8 +17317,7 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_ |
| 17317 | 17317 | case TldIdCompTime: |
| 17318 | 17318 | case TldIdUsingNamespace: |
| 17319 | 17319 | zig_unreachable(); |
| 17320 | | case TldIdVar: |
| 17321 | | { |
| 17320 | case TldIdVar: { |
| 17322 | 17321 | TldVar *tld_var = (TldVar *)tld; |
| 17323 | 17322 | ZigVar *var = tld_var->var; |
| 17324 | 17323 | if (var == nullptr) { |
| ... | ... | @@ -17330,8 +17329,7 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_ |
| 17330 | 17329 | |
| 17331 | 17330 | return ir_get_var_ptr(ira, source_instruction, var); |
| 17332 | 17331 | } |
| 17333 | | case TldIdFn: |
| 17334 | | { |
| 17332 | case TldIdFn: { |
| 17335 | 17333 | TldFn *tld_fn = (TldFn *)tld; |
| 17336 | 17334 | ZigFn *fn_entry = tld_fn->fn_entry; |
| 17337 | 17335 | assert(fn_entry->type_entry); |