| ... | @@ -184,7 +184,7 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc | ... | @@ -184,7 +184,7 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc |
| 184 | ZigType *ptr_type); | 184 | ZigType *ptr_type); |
| 185 | static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, | 185 | static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 186 | ZigType *dest_type); | 186 | ZigType *dest_type); |
| 187 | static IrInstruction *ir_resolve_result_runtime(IrAnalyze *ira, ResultLoc *result_loc, ZigType *elem_type); | 187 | static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, ZigType *value_type, IrInstruction *value); |
| 188 | | 188 | |
| 189 | static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) { | 189 | static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) { |
| 190 | assert(get_src_ptr_type(const_val->type) != nullptr); | 190 | assert(get_src_ptr_type(const_val->type) != nullptr); |
| ... | @@ -1392,7 +1392,7 @@ static IrInstruction *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_in | ... | @@ -1392,7 +1392,7 @@ static IrInstruction *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_in |
| 1392 | call_instruction->is_async = is_async; | 1392 | call_instruction->is_async = is_async; |
| 1393 | call_instruction->async_allocator = async_allocator; | 1393 | call_instruction->async_allocator = async_allocator; |
| 1394 | call_instruction->new_stack = new_stack; | 1394 | call_instruction->new_stack = new_stack; |
| 1395 | call_instruction->result_loc = ir_resolve_result_runtime(ira, result_loc, return_type); | 1395 | call_instruction->result_loc = ir_resolve_result(ira, result_loc, return_type, nullptr); |
| 1396 | | 1396 | |
| 1397 | if (fn_ref != nullptr) ir_ref_instruction(fn_ref, ira->new_irb.current_basic_block); | 1397 | if (fn_ref != nullptr) ir_ref_instruction(fn_ref, ira->new_irb.current_basic_block); |
| 1398 | for (size_t i = 0; i < arg_count; i += 1) | 1398 | for (size_t i = 0; i < arg_count; i += 1) |
| ... | @@ -14340,8 +14340,15 @@ static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, ResultLoc *result_lo | ... | @@ -14340,8 +14340,15 @@ static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, ResultLoc *result_lo |
| 14340 | zig_unreachable(); | 14340 | zig_unreachable(); |
| 14341 | } | 14341 | } |
| 14342 | | 14342 | |
| 14343 | static IrInstruction *ir_resolve_result_runtime(IrAnalyze *ira, ResultLoc *result_loc, ZigType *elem_type) { | 14343 | // give nullptr for value to resolve it at runtime |
| 14344 | result_loc->implicit_elem_type = elem_type; | 14344 | // returns a result location, or nullptr if the result location was already taken care of by this function |
| | 14345 | static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, ZigType *value_type, |
| | 14346 | IrInstruction *value) |
| | 14347 | { |
| | 14348 | bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime; |
| | 14349 | |
| | 14350 | result_loc->gen_instruction = value; |
| | 14351 | result_loc->implicit_elem_type = value_type; |
| 14345 | switch (result_loc->id) { | 14352 | switch (result_loc->id) { |
| 14346 | case ResultLocIdInvalid: | 14353 | case ResultLocIdInvalid: |
| 14347 | case ResultLocIdPeerParent: | 14354 | case ResultLocIdPeerParent: |
| ... | @@ -14357,11 +14364,16 @@ static IrInstruction *ir_resolve_result_runtime(IrAnalyze *ira, ResultLoc *resul | ... | @@ -14357,11 +14364,16 @@ static IrInstruction *ir_resolve_result_runtime(IrAnalyze *ira, ResultLoc *resul |
| 14357 | if (alloca_src->base.child == nullptr) { | 14364 | if (alloca_src->base.child == nullptr) { |
| 14358 | uint32_t align = 0; // TODO | 14365 | uint32_t align = 0; // TODO |
| 14359 | bool force_comptime = false; // TODO | 14366 | bool force_comptime = false; // TODO |
| 14360 | IrInstruction *alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, elem_type, align, | 14367 | IrInstruction *alloca_gen; |
| 14361 | alloca_src->name_hint, force_comptime); | 14368 | if (is_comptime) { |
| | 14369 | alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false); |
| | 14370 | } else { |
| | 14371 | alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align, |
| | 14372 | alloca_src->name_hint, force_comptime); |
| | 14373 | } |
| 14362 | alloca_src->base.child = alloca_gen; | 14374 | alloca_src->base.child = alloca_gen; |
| 14363 | } | 14375 | } |
| 14364 | return alloca_src->base.child; | 14376 | return is_comptime ? nullptr : alloca_src->base.child; |
| 14365 | } | 14377 | } |
| 14366 | case ResultLocIdReturn: { | 14378 | case ResultLocIdReturn: { |
| 14367 | ZigType *ptr_return_type = get_pointer_to_type(ira->codegen, ira->explicit_return_type, false); | 14379 | ZigType *ptr_return_type = get_pointer_to_type(ira->codegen, ira->explicit_return_type, false); |
| ... | @@ -14373,12 +14385,6 @@ static IrInstruction *ir_resolve_result_runtime(IrAnalyze *ira, ResultLoc *resul | ... | @@ -14373,12 +14385,6 @@ static IrInstruction *ir_resolve_result_runtime(IrAnalyze *ira, ResultLoc *resul |
| 14373 | zig_unreachable(); | 14385 | zig_unreachable(); |
| 14374 | } | 14386 | } |
| 14375 | | 14387 | |
| 14376 | static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, IrInstruction *value) { | | |
| 14377 | IrInstruction *result_inst = ir_resolve_result_runtime(ira, result_loc, value->value.type); | | |
| 14378 | result_loc->gen_instruction = value; | | |
| 14379 | return result_inst; | | |
| 14380 | } | | |
| 14381 | | | |
| 14382 | static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, ZigFn *fn_entry, | 14388 | static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, ZigFn *fn_entry, |
| 14383 | ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, | 14389 | ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, |
| 14384 | IrInstruction *async_allocator_inst) | 14390 | IrInstruction *async_allocator_inst) |
| ... | @@ -23609,7 +23615,7 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct | ... | @@ -23609,7 +23615,7 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct |
| 23609 | return ira_resume(ira); | 23615 | return ira_resume(ira); |
| 23610 | } | 23616 | } |
| 23611 | } | 23617 | } |
| 23612 | IrInstruction *result_loc = ir_resolve_result(ira, instruction->result_loc, value); | 23618 | IrInstruction *result_loc = ir_resolve_result(ira, instruction->result_loc, value->value.type, value); |
| 23613 | if (result_loc != nullptr) { | 23619 | if (result_loc != nullptr) { |
| 23614 | ir_analyze_store_ptr(ira, &instruction->base, result_loc, value); | 23620 | ir_analyze_store_ptr(ira, &instruction->base, result_loc, value); |
| 23615 | } | 23621 | } |