| ... | ... | @@ -540,7 +540,7 @@ static IrInstruction *ir_build_const_c_str_lit(IrBuilder *irb, Scope *scope, Ast |
| 540 | 540 | ptr_val->special = ConstValSpecialStatic; |
| 541 | 541 | ptr_val->data.x_ptr.base_ptr = array_val; |
| 542 | 542 | ptr_val->data.x_ptr.index = 0; |
| 543 | | ptr_val->data.x_ptr.is_c_str = true; |
| 543 | ptr_val->data.x_ptr.special = ConstPtrSpecialCStr; |
| 544 | 544 | |
| 545 | 545 | return &const_instruction->base; |
| 546 | 546 | } |
| ... | ... | @@ -3352,13 +3352,15 @@ static TypeTableEntry *ir_analyze_void(IrAnalyze *ira, IrInstruction *instructio |
| 3352 | 3352 | } |
| 3353 | 3353 | |
| 3354 | 3354 | static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 3355 | | ConstExprValue *pointee, TypeTableEntry *pointee_type, bool depends_on_compile_var) |
| 3355 | ConstExprValue *pointee, TypeTableEntry *pointee_type, bool depends_on_compile_var, |
| 3356 | ConstPtrSpecial special) |
| 3356 | 3357 | { |
| 3357 | 3358 | TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, pointee_type, true); |
| 3358 | 3359 | ConstExprValue *const_val = ir_build_const_from(ira, instruction, |
| 3359 | 3360 | depends_on_compile_var || pointee->depends_on_compile_var); |
| 3360 | 3361 | const_val->data.x_ptr.base_ptr = pointee; |
| 3361 | 3362 | const_val->data.x_ptr.index = SIZE_MAX; |
| 3363 | const_val->data.x_ptr.special = special; |
| 3362 | 3364 | return ptr_type; |
| 3363 | 3365 | } |
| 3364 | 3366 | |
| ... | ... | @@ -3791,7 +3793,7 @@ static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_inst |
| 3791 | 3793 | ConstExprValue *val = ir_resolve_const(ira, value); |
| 3792 | 3794 | if (!val) |
| 3793 | 3795 | return ira->codegen->builtin_types.entry_invalid; |
| 3794 | | return ir_analyze_const_ptr(ira, source_instruction, val, value->type_entry, false); |
| 3796 | return ir_analyze_const_ptr(ira, source_instruction, val, value->type_entry, false, ConstPtrSpecialNone); |
| 3795 | 3797 | } |
| 3796 | 3798 | |
| 3797 | 3799 | TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, value->type_entry, true); |
| ... | ... | @@ -4338,10 +4340,17 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 4338 | 4340 | var->type = result_type; |
| 4339 | 4341 | assert(var->type); |
| 4340 | 4342 | |
| 4341 | | if (var->mem_slot_index != SIZE_MAX) { |
| 4342 | | assert(var->mem_slot_index < ira->exec_context.mem_slot_count); |
| 4343 | | ConstExprValue *mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index]; |
| 4344 | | *mem_slot = casted_init_value->static_value; |
| 4343 | if (casted_init_value->static_value.special == ConstValSpecialStatic) { |
| 4344 | if (var->mem_slot_index != SIZE_MAX) { |
| 4345 | assert(var->mem_slot_index < ira->exec_context.mem_slot_count); |
| 4346 | ConstExprValue *mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index]; |
| 4347 | *mem_slot = casted_init_value->static_value; |
| 4348 | } |
| 4349 | } else if (var->is_inline) { |
| 4350 | ir_add_error(ira, &decl_var_instruction->base, |
| 4351 | buf_sprintf("cannot store runtime value in compile time variable")); |
| 4352 | var->type = ira->codegen->builtin_types.entry_invalid; |
| 4353 | return ira->codegen->builtin_types.entry_invalid; |
| 4345 | 4354 | } |
| 4346 | 4355 | |
| 4347 | 4356 | ir_build_var_decl_from(&ira->new_irb, &decl_var_instruction->base, var, var_type, casted_init_value); |
| ... | ... | @@ -5192,7 +5201,8 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc |
| 5192 | 5201 | } |
| 5193 | 5202 | |
| 5194 | 5203 | if (mem_slot && mem_slot->special != ConstValSpecialRuntime) { |
| 5195 | | return ir_analyze_const_ptr(ira, instruction, mem_slot, var->type, false); |
| 5204 | ConstPtrSpecial ptr_special = var->is_inline ? ConstPtrSpecialInline : ConstPtrSpecialNone; |
| 5205 | return ir_analyze_const_ptr(ira, instruction, mem_slot, var->type, false, ptr_special); |
| 5196 | 5206 | } else { |
| 5197 | 5207 | ir_build_var_ptr_from(&ira->new_irb, instruction, var); |
| 5198 | 5208 | return get_pointer_to_type(ira->codegen, var->type, false); |
| ... | ... | @@ -5407,7 +5417,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source |
| 5407 | 5417 | const_val->special = ConstValSpecialStatic; |
| 5408 | 5418 | const_val->data.x_fn = fn_entry; |
| 5409 | 5419 | |
| 5410 | | return ir_analyze_const_ptr(ira, source_instruction, const_val, fn_entry->type_entry, depends_on_compile_var); |
| 5420 | return ir_analyze_const_ptr(ira, source_instruction, const_val, fn_entry->type_entry, depends_on_compile_var, ConstPtrSpecialNone); |
| 5411 | 5421 | } |
| 5412 | 5422 | case TldIdContainer: |
| 5413 | 5423 | { |
| ... | ... | @@ -5420,7 +5430,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source |
| 5420 | 5430 | const_val->special = ConstValSpecialStatic; |
| 5421 | 5431 | const_val->data.x_type = tld_container->type_entry; |
| 5422 | 5432 | |
| 5423 | | return ir_analyze_const_ptr(ira, source_instruction, const_val, tld_container->type_entry, depends_on_compile_var); |
| 5433 | return ir_analyze_const_ptr(ira, source_instruction, const_val, tld_container->type_entry, depends_on_compile_var, ConstPtrSpecialNone); |
| 5424 | 5434 | } |
| 5425 | 5435 | case TldIdTypeDef: |
| 5426 | 5436 | { |
| ... | ... | @@ -5433,7 +5443,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source |
| 5433 | 5443 | const_val->special = ConstValSpecialStatic; |
| 5434 | 5444 | const_val->data.x_type = tld_typedef->type_entry; |
| 5435 | 5445 | |
| 5436 | | return ir_analyze_const_ptr(ira, source_instruction, const_val, tld_typedef->type_entry, depends_on_compile_var); |
| 5446 | return ir_analyze_const_ptr(ira, source_instruction, const_val, tld_typedef->type_entry, depends_on_compile_var, ConstPtrSpecialNone); |
| 5437 | 5447 | } |
| 5438 | 5448 | } |
| 5439 | 5449 | zig_unreachable(); |
| ... | ... | @@ -5461,7 +5471,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 5461 | 5471 | bignum_init_unsigned(&len_val->data.x_bignum, container_type->data.array.len); |
| 5462 | 5472 | |
| 5463 | 5473 | TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; |
| 5464 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val, usize, false); |
| 5474 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val, usize, false, ConstPtrSpecialNone); |
| 5465 | 5475 | } else { |
| 5466 | 5476 | add_node_error(ira->codegen, source_node, |
| 5467 | 5477 | buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name), |
| ... | ... | @@ -5570,13 +5580,19 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 5570 | 5580 | if (casted_value == ira->codegen->invalid_instruction) |
| 5571 | 5581 | return ira->codegen->builtin_types.entry_invalid; |
| 5572 | 5582 | |
| 5573 | | if (ptr->static_value.special != ConstValSpecialRuntime && |
| 5574 | | casted_value->static_value.special != ConstValSpecialRuntime) |
| 5575 | | { |
| 5576 | | ConstExprValue *dest_val = const_ptr_pointee(&ptr->static_value); |
| 5577 | | if (dest_val->special != ConstValSpecialRuntime) { |
| 5578 | | *dest_val = casted_value->static_value; |
| 5579 | | return ir_analyze_void(ira, &store_ptr_instruction->base); |
| 5583 | if (ptr->static_value.special != ConstValSpecialRuntime) { |
| 5584 | bool is_inline = (ptr->static_value.data.x_ptr.special == ConstPtrSpecialInline); |
| 5585 | if (casted_value->static_value.special != ConstValSpecialRuntime) { |
| 5586 | ConstExprValue *dest_val = const_ptr_pointee(&ptr->static_value); |
| 5587 | if (dest_val->special != ConstValSpecialRuntime) { |
| 5588 | *dest_val = casted_value->static_value; |
| 5589 | return ir_analyze_void(ira, &store_ptr_instruction->base); |
| 5590 | } |
| 5591 | } |
| 5592 | if (is_inline) { |
| 5593 | ir_add_error(ira, &store_ptr_instruction->base, |
| 5594 | buf_sprintf("cannot store runtime value in compile time variable")); |
| 5595 | return ira->codegen->builtin_types.entry_invalid; |
| 5580 | 5596 | } |
| 5581 | 5597 | } |
| 5582 | 5598 | |