authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-01 01:56:06-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-30 17:11:14-04:00
log5e1003bc81466b8ca0e3a3adb613bac8f34f2712
treeef7de5e4cb6dfeaad96fee7b935e1459a6dce063
parent0ccd91faea5ec27a1dce9d3bae84e1feca7fc0ea
signaturelock-open Commit is signed but in an unrecognized format.

no-copy semantics for basic runtime function call variable init

```zig export fn entry() void { var x: Foo = foo(); } ``` ```llvm define void @entry() #2 !dbg !37 { Entry: %x = alloca %Foo, align 4 call fastcc void @foo(%Foo* sret %x), !dbg !48 call void @llvm.dbg.declare(metadata %Foo* %x, metadata !41, metadata !DIExpression()), !dbg !49 ret void, !dbg !50 } ```

6 files changed, 521 insertions(+), 151 deletions(-)

BRANCH_TODO created+10
...@@ -0,0 +1,10 @@
1Scratch pad for stuff to do before merging master
2=================================================
3
4look at all the ir_gen_node ir_gen_node_extra calls and make sure result locations are properly propagated
5
6migrate all the alloca_list to alloca_gen_list
7
8migrate ir_build_var_decl_src to use ir_build_alloca_src and explicitly initialize
9
10inferred comptime
CMakeLists.txt+1
...@@ -6728,6 +6728,7 @@ add_custom_command(...@@ -6728,6 +6728,7 @@ add_custom_command(
6728 "-Doutput-dir=${CMAKE_BINARY_DIR}"6728 "-Doutput-dir=${CMAKE_BINARY_DIR}"
6729 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"6729 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
6730 DEPENDS6730 DEPENDS
6731 zig0
6731 "${CMAKE_SOURCE_DIR}/src-self-hosted/dep_tokenizer.zig"6732 "${CMAKE_SOURCE_DIR}/src-self-hosted/dep_tokenizer.zig"
6732 "${CMAKE_SOURCE_DIR}/src-self-hosted/stage1.zig"6733 "${CMAKE_SOURCE_DIR}/src-self-hosted/stage1.zig"
6733 "${CMAKE_SOURCE_DIR}/src-self-hosted/translate_c.zig"6734 "${CMAKE_SOURCE_DIR}/src-self-hosted/translate_c.zig"
src/all_types.hpp+76-6
...@@ -34,12 +34,14 @@ struct CodeGen;...@@ -34,12 +34,14 @@ struct CodeGen;
34struct ConstExprValue;34struct ConstExprValue;
35struct IrInstruction;35struct IrInstruction;
36struct IrInstructionCast;36struct IrInstructionCast;
37struct IrInstructionAllocaGen;
37struct IrBasicBlock;38struct IrBasicBlock;
38struct ScopeDecls;39struct ScopeDecls;
39struct ZigWindowsSDK;40struct ZigWindowsSDK;
40struct Tld;41struct Tld;
41struct TldExport;42struct TldExport;
42struct IrAnalyze;43struct IrAnalyze;
44struct ResultLoc;
4345
44enum X64CABIClass {46enum X64CABIClass {
45 X64CABIClass_Unknown,47 X64CABIClass_Unknown,
...@@ -1359,6 +1361,7 @@ struct ZigFn {...@@ -1359,6 +1361,7 @@ struct ZigFn {
1359 AstNode *fn_static_eval_set_node;1361 AstNode *fn_static_eval_set_node;
13601362
1361 ZigList<IrInstruction *> alloca_list;1363 ZigList<IrInstruction *> alloca_list;
1364 ZigList<IrInstructionAllocaGen *> alloca_gen_list;
1362 ZigList<ZigVar *> variable_list;1365 ZigList<ZigVar *> variable_list;
13631366
1364 Buf *section_name;1367 Buf *section_name;
...@@ -2171,7 +2174,9 @@ enum IrInstructionId {...@@ -2171,7 +2174,9 @@ enum IrInstructionId {
2171 IrInstructionIdUnionFieldPtr,2174 IrInstructionIdUnionFieldPtr,
2172 IrInstructionIdElemPtr,2175 IrInstructionIdElemPtr,
2173 IrInstructionIdVarPtr,2176 IrInstructionIdVarPtr,
2174 IrInstructionIdCall,2177 IrInstructionIdReturnPtr,
2178 IrInstructionIdCallSrc,
2179 IrInstructionIdCallGen,
2175 IrInstructionIdConst,2180 IrInstructionIdConst,
2176 IrInstructionIdReturn,2181 IrInstructionIdReturn,
2177 IrInstructionIdCast,2182 IrInstructionIdCast,
...@@ -2308,6 +2313,8 @@ enum IrInstructionId {...@@ -2308,6 +2313,8 @@ enum IrInstructionId {
2308 IrInstructionIdAssertNonNull,2313 IrInstructionIdAssertNonNull,
2309 IrInstructionIdHasDecl,2314 IrInstructionIdHasDecl,
2310 IrInstructionIdUndeclaredIdent,2315 IrInstructionIdUndeclaredIdent,
2316 IrInstructionIdAllocaSrc,
2317 IrInstructionIdAllocaGen,
2311};2318};
23122319
2313struct IrInstruction {2320struct IrInstruction {
...@@ -2335,14 +2342,14 @@ struct IrInstructionDeclVarSrc {...@@ -2335,14 +2342,14 @@ struct IrInstructionDeclVarSrc {
2335 ZigVar *var;2342 ZigVar *var;
2336 IrInstruction *var_type;2343 IrInstruction *var_type;
2337 IrInstruction *align_value;2344 IrInstruction *align_value;
2338 IrInstruction *init_value;2345 IrInstruction *ptr;
2339};2346};
23402347
2341struct IrInstructionDeclVarGen {2348struct IrInstructionDeclVarGen {
2342 IrInstruction base;2349 IrInstruction base;
23432350
2344 ZigVar *var;2351 ZigVar *var;
2345 IrInstruction *init_value;2352 IrInstruction *var_ptr;
2346};2353};
23472354
2348struct IrInstructionCondBr {2355struct IrInstructionCondBr {
...@@ -2528,14 +2535,21 @@ struct IrInstructionVarPtr {...@@ -2528,14 +2535,21 @@ struct IrInstructionVarPtr {
2528 ScopeFnDef *crossed_fndef_scope;2535 ScopeFnDef *crossed_fndef_scope;
2529};2536};
25302537
2531struct IrInstructionCall {2538// For functions that have a return type for which handle_is_ptr is true, a
2539// result location pointer is the secret first parameter ("sret"). This
2540// instruction returns that pointer.
2541struct IrInstructionReturnPtr {
2542 IrInstruction base;
2543};
2544
2545struct IrInstructionCallSrc {
2532 IrInstruction base;2546 IrInstruction base;
25332547
2534 IrInstruction *fn_ref;2548 IrInstruction *fn_ref;
2535 ZigFn *fn_entry;2549 ZigFn *fn_entry;
2536 size_t arg_count;2550 size_t arg_count;
2537 IrInstruction **args;2551 IrInstruction **args;
2538 LLVMValueRef tmp_ptr;2552 ResultLoc *result_loc;
25392553
2540 IrInstruction *async_allocator;2554 IrInstruction *async_allocator;
2541 IrInstruction *new_stack;2555 IrInstruction *new_stack;
...@@ -2544,6 +2558,21 @@ struct IrInstructionCall {...@@ -2544,6 +2558,21 @@ struct IrInstructionCall {
2544 bool is_comptime;2558 bool is_comptime;
2545};2559};
25462560
2561struct IrInstructionCallGen {
2562 IrInstruction base;
2563
2564 IrInstruction *fn_ref;
2565 ZigFn *fn_entry;
2566 size_t arg_count;
2567 IrInstruction **args;
2568 IrInstruction *result_loc;
2569
2570 IrInstruction *async_allocator;
2571 IrInstruction *new_stack;
2572 FnInline fn_inline;
2573 bool is_async;
2574};
2575
2547struct IrInstructionConst {2576struct IrInstructionConst {
2548 IrInstruction base;2577 IrInstruction base;
2549};2578};
...@@ -3527,6 +3556,47 @@ struct IrInstructionUndeclaredIdent {...@@ -3527,6 +3556,47 @@ struct IrInstructionUndeclaredIdent {
3527 Buf *name;3556 Buf *name;
3528};3557};
35293558
3559struct IrInstructionAllocaSrc {
3560 IrInstruction base;
3561
3562 IrInstruction *align;
3563 IrInstruction *is_comptime;
3564 const char *name_hint;
3565};
3566
3567struct IrInstructionAllocaGen {
3568 IrInstruction base;
3569
3570 uint32_t align;
3571 const char *name_hint;
3572};
3573
3574enum ResultLocId {
3575 ResultLocIdInvalid,
3576 ResultLocIdNone,
3577 ResultLocIdVar,
3578 ResultLocIdReturn,
3579};
3580
3581struct ResultLoc {
3582 ResultLocId id;
3583 IrInstruction *source_instruction;
3584};
3585
3586struct ResultLocNone {
3587 ResultLoc base;
3588};
3589
3590struct ResultLocVar {
3591 ResultLoc base;
3592
3593 ZigVar *var;
3594};
3595
3596struct ResultLocReturn {
3597 ResultLoc base;
3598};
3599
3530static const size_t slice_ptr_index = 0;3600static const size_t slice_ptr_index = 0;
3531static const size_t slice_len_index = 1;3601static const size_t slice_len_index = 1;
35323602
...@@ -3574,7 +3644,7 @@ struct FnWalkAttrs {...@@ -3574,7 +3644,7 @@ struct FnWalkAttrs {
35743644
3575struct FnWalkCall {3645struct FnWalkCall {
3576 ZigList<LLVMValueRef> *gen_param_values;3646 ZigList<LLVMValueRef> *gen_param_values;
3577 IrInstructionCall *inst;3647 IrInstructionCallGen *inst;
3578 bool is_var_args;3648 bool is_var_args;
3579};3649};
35803650
src/codegen.cpp+54-36
...@@ -1982,6 +1982,7 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_ty...@@ -1982,6 +1982,7 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_ty
1982}1982}
19831983
1984static void gen_var_debug_decl(CodeGen *g, ZigVar *var) {1984static void gen_var_debug_decl(CodeGen *g, ZigVar *var) {
1985 if (g->strip_debug_symbols) return;
1985 assert(var->di_loc_var != nullptr);1986 assert(var->di_loc_var != nullptr);
1986 AstNode *source_node = var->decl_node;1987 AstNode *source_node = var->decl_node;
1987 ZigLLVMDILocation *debug_loc = ZigLLVMGetDebugLoc((unsigned)source_node->line + 1,1988 ZigLLVMDILocation *debug_loc = ZigLLVMGetDebugLoc((unsigned)source_node->line + 1,
...@@ -2288,7 +2289,7 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {...@@ -2288,7 +2289,7 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {
2288 return;2289 return;
2289 }2290 }
2290 if (fn_walk->id == FnWalkIdCall) {2291 if (fn_walk->id == FnWalkIdCall) {
2291 IrInstructionCall *instruction = fn_walk->data.call.inst;2292 IrInstructionCallGen *instruction = fn_walk->data.call.inst;
2292 bool is_var_args = fn_walk->data.call.is_var_args;2293 bool is_var_args = fn_walk->data.call.is_var_args;
2293 for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) {2294 for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) {
2294 IrInstruction *param_instruction = instruction->args[call_i];2295 IrInstruction *param_instruction = instruction->args[call_i];
...@@ -3328,10 +3329,8 @@ static LLVMValueRef ir_render_bool_not(CodeGen *g, IrExecutable *executable, IrI...@@ -3328,10 +3329,8 @@ static LLVMValueRef ir_render_bool_not(CodeGen *g, IrExecutable *executable, IrI
3328 return LLVMBuildICmp(g->builder, LLVMIntEQ, value, zero, "");3329 return LLVMBuildICmp(g->builder, LLVMIntEQ, value, zero, "");
3329}3330}
33303331
3331static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,3332static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable, IrInstructionDeclVarGen *instruction) {
3332 IrInstructionDeclVarGen *decl_var_instruction)3333 ZigVar *var = instruction->var;
3333{
3334 ZigVar *var = decl_var_instruction->var;
33353334
3336 if (!type_has_bits(var->var_type))3335 if (!type_has_bits(var->var_type))
3337 return nullptr;3336 return nullptr;
...@@ -3339,20 +3338,7 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,...@@ -3339,20 +3338,7 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
3339 if (var->ref_count == 0 && g->build_mode != BuildModeDebug)3338 if (var->ref_count == 0 && g->build_mode != BuildModeDebug)
3340 return nullptr;3339 return nullptr;
33413340
3342 IrInstruction *init_value = decl_var_instruction->init_value;3341 var->value_ref = ir_llvm_value(g, instruction->var_ptr);
3343
3344 bool have_init_expr = !value_is_all_undef(&init_value->value);
3345
3346 if (have_init_expr) {
3347 ZigType *var_ptr_type = get_pointer_to_type_extra(g, var->var_type, false, false,
3348 PtrLenSingle, var->align_bytes, 0, 0, false);
3349 LLVMValueRef llvm_init_val = ir_llvm_value(g, init_value);
3350 gen_assign_raw(g, var->value_ref, var_ptr_type, llvm_init_val);
3351 } else if (ir_want_runtime_safety(g, &decl_var_instruction->base)) {
3352 uint32_t align_bytes = (var->align_bytes == 0) ? get_abi_alignment(g, var->var_type) : var->align_bytes;
3353 gen_undef_init(g, align_bytes, var->var_type, var->value_ref);
3354 }
3355
3356 gen_var_debug_decl(g, var);3342 gen_var_debug_decl(g, var);
3357 return nullptr;3343 return nullptr;
3358}3344}
...@@ -3568,6 +3554,13 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn...@@ -3568,6 +3554,13 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn
3568 }3554 }
3569}3555}
35703556
3557static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable,
3558 IrInstructionReturnPtr *instruction)
3559{
3560 assert(g->cur_ret_ptr != nullptr || !type_has_bits(instruction->base.value.type));
3561 return g->cur_ret_ptr;
3562}
3563
3571static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrInstructionElemPtr *instruction) {3564static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrInstructionElemPtr *instruction) {
3572 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr);3565 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr);
3573 ZigType *array_ptr_type = instruction->array_ptr->value.type;3566 ZigType *array_ptr_type = instruction->array_ptr->value.type;
...@@ -3719,7 +3712,7 @@ static void set_call_instr_sret(CodeGen *g, LLVMValueRef call_instr) {...@@ -3719,7 +3712,7 @@ static void set_call_instr_sret(CodeGen *g, LLVMValueRef call_instr) {
3719 LLVMAddCallSiteAttribute(call_instr, 1, sret_attr);3712 LLVMAddCallSiteAttribute(call_instr, 1, sret_attr);
3720}3713}
37213714
3722static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstructionCall *instruction) {3715static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstructionCallGen *instruction) {
3723 LLVMValueRef fn_val;3716 LLVMValueRef fn_val;
3724 ZigType *fn_type;3717 ZigType *fn_type;
3725 if (instruction->fn_entry) {3718 if (instruction->fn_entry) {
...@@ -3742,8 +3735,9 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -3742,8 +3735,9 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
3742 bool prefix_arg_err_ret_stack = get_prefix_arg_err_ret_stack(g, fn_type_id);3735 bool prefix_arg_err_ret_stack = get_prefix_arg_err_ret_stack(g, fn_type_id);
3743 bool is_var_args = fn_type_id->is_var_args;3736 bool is_var_args = fn_type_id->is_var_args;
3744 ZigList<LLVMValueRef> gen_param_values = {};3737 ZigList<LLVMValueRef> gen_param_values = {};
3738 LLVMValueRef result_loc = first_arg_ret ? ir_llvm_value(g, instruction->result_loc) : nullptr;
3745 if (first_arg_ret) {3739 if (first_arg_ret) {
3746 gen_param_values.append(instruction->tmp_ptr);3740 gen_param_values.append(result_loc);
3747 }3741 }
3748 if (prefix_arg_err_ret_stack) {3742 if (prefix_arg_err_ret_stack) {
3749 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.scope));3743 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.scope));
...@@ -3751,7 +3745,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -3751,7 +3745,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
3751 if (instruction->is_async) {3745 if (instruction->is_async) {
3752 gen_param_values.append(ir_llvm_value(g, instruction->async_allocator));3746 gen_param_values.append(ir_llvm_value(g, instruction->async_allocator));
37533747
3754 LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr, err_union_err_index, "");3748 LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, result_loc, err_union_err_index, "");
3755 gen_param_values.append(err_val_ptr);3749 gen_param_values.append(err_val_ptr);
3756 }3750 }
3757 FnWalk fn_walk = {};3751 FnWalk fn_walk = {};
...@@ -3794,9 +3788,9 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -3794,9 +3788,9 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
37943788
37953789
3796 if (instruction->is_async) {3790 if (instruction->is_async) {
3797 LLVMValueRef payload_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr, err_union_payload_index, "");3791 LLVMValueRef payload_ptr = LLVMBuildStructGEP(g->builder, result_loc, err_union_payload_index, "");
3798 LLVMBuildStore(g->builder, result, payload_ptr);3792 LLVMBuildStore(g->builder, result, payload_ptr);
3799 return instruction->tmp_ptr;3793 return result_loc;
3800 }3794 }
38013795
3802 if (src_return_type->id == ZigTypeIdUnreachable) {3796 if (src_return_type->id == ZigTypeIdUnreachable) {
...@@ -3805,11 +3799,11 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -3805,11 +3799,11 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
3805 return nullptr;3799 return nullptr;
3806 } else if (first_arg_ret) {3800 } else if (first_arg_ret) {
3807 set_call_instr_sret(g, result);3801 set_call_instr_sret(g, result);
3808 return instruction->tmp_ptr;3802 return result_loc;
3809 } else if (handle_is_ptr(src_return_type)) {3803 } else if (handle_is_ptr(src_return_type)) {
3810 auto store_instr = LLVMBuildStore(g->builder, result, instruction->tmp_ptr);3804 LLVMValueRef store_instr = LLVMBuildStore(g->builder, result, result_loc);
3811 LLVMSetAlignment(store_instr, LLVMGetAlignment(instruction->tmp_ptr));3805 LLVMSetAlignment(store_instr, LLVMGetAlignment(result_loc));
3812 return instruction->tmp_ptr;3806 return result_loc;
3813 } else {3807 } else {
3814 return result;3808 return result;
3815 }3809 }
...@@ -5535,7 +5529,9 @@ static void set_debug_location(CodeGen *g, IrInstruction *instruction) {...@@ -5535,7 +5529,9 @@ static void set_debug_location(CodeGen *g, IrInstruction *instruction) {
5535}5529}
55365530
5537static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, IrInstruction *instruction) {5531static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, IrInstruction *instruction) {
5538 set_debug_location(g, instruction);5532 if (!g->strip_debug_symbols) {
5533 set_debug_location(g, instruction);
5534 }
55395535
5540 switch (instruction->id) {5536 switch (instruction->id) {
5541 case IrInstructionIdInvalid:5537 case IrInstructionIdInvalid:
...@@ -5608,8 +5604,13 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -5608,8 +5604,13 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
5608 case IrInstructionIdGlobalAsm:5604 case IrInstructionIdGlobalAsm:
5609 case IrInstructionIdHasDecl:5605 case IrInstructionIdHasDecl:
5610 case IrInstructionIdUndeclaredIdent:5606 case IrInstructionIdUndeclaredIdent:
5607 case IrInstructionIdCallSrc:
5608 case IrInstructionIdAllocaSrc:
5611 zig_unreachable();5609 zig_unreachable();
56125610
5611 case IrInstructionIdAllocaGen:
5612 return nullptr;
5613
5613 case IrInstructionIdDeclVarGen:5614 case IrInstructionIdDeclVarGen:
5614 return ir_render_decl_var(g, executable, (IrInstructionDeclVarGen *)instruction);5615 return ir_render_decl_var(g, executable, (IrInstructionDeclVarGen *)instruction);
5615 case IrInstructionIdReturn:5616 case IrInstructionIdReturn:
...@@ -5632,10 +5633,12 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -5632,10 +5633,12 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
5632 return ir_render_store_ptr(g, executable, (IrInstructionStorePtr *)instruction);5633 return ir_render_store_ptr(g, executable, (IrInstructionStorePtr *)instruction);
5633 case IrInstructionIdVarPtr:5634 case IrInstructionIdVarPtr:
5634 return ir_render_var_ptr(g, executable, (IrInstructionVarPtr *)instruction);5635 return ir_render_var_ptr(g, executable, (IrInstructionVarPtr *)instruction);
5636 case IrInstructionIdReturnPtr:
5637 return ir_render_return_ptr(g, executable, (IrInstructionReturnPtr *)instruction);
5635 case IrInstructionIdElemPtr:5638 case IrInstructionIdElemPtr:
5636 return ir_render_elem_ptr(g, executable, (IrInstructionElemPtr *)instruction);5639 return ir_render_elem_ptr(g, executable, (IrInstructionElemPtr *)instruction);
5637 case IrInstructionIdCall:5640 case IrInstructionIdCallGen:
5638 return ir_render_call(g, executable, (IrInstructionCall *)instruction);5641 return ir_render_call(g, executable, (IrInstructionCallGen *)instruction);
5639 case IrInstructionIdStructFieldPtr:5642 case IrInstructionIdStructFieldPtr:
5640 return ir_render_struct_field_ptr(g, executable, (IrInstructionStructFieldPtr *)instruction);5643 return ir_render_struct_field_ptr(g, executable, (IrInstructionStructFieldPtr *)instruction);
5641 case IrInstructionIdUnionFieldPtr:5644 case IrInstructionIdUnionFieldPtr:
...@@ -6851,6 +6854,26 @@ static void do_code_gen(CodeGen *g) {...@@ -6851,6 +6854,26 @@ static void do_code_gen(CodeGen *g) {
6851 }6854 }
68526855
6853 // allocate temporary stack data6856 // allocate temporary stack data
6857 for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_gen_list.length; alloca_i += 1) {
6858 IrInstructionAllocaGen *instruction = fn_table_entry->alloca_gen_list.at(alloca_i);
6859 ZigType *ptr_type = instruction->base.value.type;
6860 assert(ptr_type->id == ZigTypeIdPointer);
6861 ZigType *child_type = ptr_type->data.pointer.child_type;
6862 if (!type_has_bits(child_type))
6863 continue;
6864 if (instruction->base.ref_count == 0)
6865 continue;
6866 if (instruction->base.value.special != ConstValSpecialRuntime) {
6867 if (const_ptr_pointee(nullptr, g, &instruction->base.value, nullptr)->special !=
6868 ConstValSpecialRuntime)
6869 {
6870 continue;
6871 }
6872 }
6873 instruction->base.llvm_value = build_alloca(g, child_type, instruction->name_hint,
6874 get_ptr_align(g, ptr_type));
6875 }
6876
6854 for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_list.length; alloca_i += 1) {6877 for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_list.length; alloca_i += 1) {
6855 IrInstruction *instruction = fn_table_entry->alloca_list.at(alloca_i);6878 IrInstruction *instruction = fn_table_entry->alloca_list.at(alloca_i);
6856 LLVMValueRef *slot;6879 LLVMValueRef *slot;
...@@ -6873,9 +6896,6 @@ static void do_code_gen(CodeGen *g) {...@@ -6873,9 +6896,6 @@ static void do_code_gen(CodeGen *g) {
6873 } else if (instruction->id == IrInstructionIdUnionInit) {6896 } else if (instruction->id == IrInstructionIdUnionInit) {
6874 IrInstructionUnionInit *union_init_instruction = (IrInstructionUnionInit *)instruction;6897 IrInstructionUnionInit *union_init_instruction = (IrInstructionUnionInit *)instruction;
6875 slot = &union_init_instruction->tmp_ptr;6898 slot = &union_init_instruction->tmp_ptr;
6876 } else if (instruction->id == IrInstructionIdCall) {
6877 IrInstructionCall *call_instruction = (IrInstructionCall *)instruction;
6878 slot = &call_instruction->tmp_ptr;
6879 } else if (instruction->id == IrInstructionIdSlice) {6899 } else if (instruction->id == IrInstructionIdSlice) {
6880 IrInstructionSlice *slice_instruction = (IrInstructionSlice *)instruction;6900 IrInstructionSlice *slice_instruction = (IrInstructionSlice *)instruction;
6881 slot = &slice_instruction->tmp_ptr;6901 slot = &slice_instruction->tmp_ptr;
...@@ -6939,8 +6959,6 @@ static void do_code_gen(CodeGen *g) {...@@ -6939,8 +6959,6 @@ static void do_code_gen(CodeGen *g) {
6939 }6959 }
69406960
6941 if (var->src_arg_index == SIZE_MAX) {6961 if (var->src_arg_index == SIZE_MAX) {
6942 var->value_ref = build_alloca(g, var->var_type, buf_ptr(&var->name), var->align_bytes);
6943
6944 var->di_loc_var = ZigLLVMCreateAutoVariable(g->dbuilder, get_di_scope(g, var->parent_scope),6962 var->di_loc_var = ZigLLVMCreateAutoVariable(g->dbuilder, get_di_scope(g, var->parent_scope),
6945 buf_ptr(&var->name), import->data.structure.root_struct->di_file, (unsigned)(var->decl_node->line + 1),6963 buf_ptr(&var->name), import->data.structure.root_struct->di_file, (unsigned)(var->decl_node->line + 1),
6946 get_llvm_di_type(g, var->var_type), !g->strip_debug_symbols, 0);6964 get_llvm_di_type(g, var->var_type), !g->strip_debug_symbols, 0);
src/ir.cpp+298-103
...@@ -157,7 +157,8 @@ enum UndefAllowed {...@@ -157,7 +157,8 @@ enum UndefAllowed {
157};157};
158158
159static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);159static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);
160static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval);160static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval,
161 ResultLoc *result_loc);
161static IrInstruction *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction);162static IrInstruction *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction);
162static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type);163static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type);
163static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr);164static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr);
...@@ -475,8 +476,16 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionVarPtr *) {...@@ -475,8 +476,16 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionVarPtr *) {
475 return IrInstructionIdVarPtr;476 return IrInstructionIdVarPtr;
476}477}
477478
478static constexpr IrInstructionId ir_instruction_id(IrInstructionCall *) {479static constexpr IrInstructionId ir_instruction_id(IrInstructionReturnPtr *) {
479 return IrInstructionIdCall;480 return IrInstructionIdReturnPtr;
481}
482
483static constexpr IrInstructionId ir_instruction_id(IrInstructionCallSrc *) {
484 return IrInstructionIdCallSrc;
485}
486
487static constexpr IrInstructionId ir_instruction_id(IrInstructionCallGen *) {
488 return IrInstructionIdCallGen;
480}489}
481490
482static constexpr IrInstructionId ir_instruction_id(IrInstructionConst *) {491static constexpr IrInstructionId ir_instruction_id(IrInstructionConst *) {
...@@ -1019,6 +1028,14 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionUndeclaredIdent...@@ -1019,6 +1028,14 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionUndeclaredIdent
1019 return IrInstructionIdUndeclaredIdent;1028 return IrInstructionIdUndeclaredIdent;
1020}1029}
10211030
1031static constexpr IrInstructionId ir_instruction_id(IrInstructionAllocaSrc *) {
1032 return IrInstructionIdAllocaSrc;
1033}
1034
1035static constexpr IrInstructionId ir_instruction_id(IrInstructionAllocaGen *) {
1036 return IrInstructionIdAllocaGen;
1037}
1038
1022template<typename T>1039template<typename T>
1023static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) {1040static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1024 T *special_instruction = allocate<T>(1);1041 T *special_instruction = allocate<T>(1);
...@@ -1254,6 +1271,13 @@ static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *so...@@ -1254,6 +1271,13 @@ static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *so
1254 return ir_build_var_ptr_x(irb, scope, source_node, var, nullptr);1271 return ir_build_var_ptr_x(irb, scope, source_node, var, nullptr);
1255}1272}
12561273
1274static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {
1275 IrInstructionReturnPtr *instruction = ir_build_instruction<IrInstructionReturnPtr>(&ira->new_irb,
1276 source_instruction->scope, source_instruction->source_node);
1277 instruction->base.value.type = ty;
1278 return &instruction->base;
1279}
1280
1257static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *array_ptr,1281static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *array_ptr,
1258 IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len)1282 IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len)
1259{1283{
...@@ -1320,12 +1344,12 @@ static IrInstruction *ir_build_union_field_ptr(IrBuilder *irb, Scope *scope, Ast...@@ -1320,12 +1344,12 @@ static IrInstruction *ir_build_union_field_ptr(IrBuilder *irb, Scope *scope, Ast
1320 return &instruction->base;1344 return &instruction->base;
1321}1345}
13221346
1323static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *source_node,1347static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
1324 ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,1348 ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
1325 bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator,1349 bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator,
1326 IrInstruction *new_stack)1350 IrInstruction *new_stack, ResultLoc *result_loc)
1327{1351{
1328 IrInstructionCall *call_instruction = ir_build_instruction<IrInstructionCall>(irb, scope, source_node);1352 IrInstructionCallSrc *call_instruction = ir_build_instruction<IrInstructionCallSrc>(irb, scope, source_node);
1329 call_instruction->fn_entry = fn_entry;1353 call_instruction->fn_entry = fn_entry;
1330 call_instruction->fn_ref = fn_ref;1354 call_instruction->fn_ref = fn_ref;
1331 call_instruction->is_comptime = is_comptime;1355 call_instruction->is_comptime = is_comptime;
...@@ -1335,6 +1359,7 @@ static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *sourc...@@ -1335,6 +1359,7 @@ static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *sourc
1335 call_instruction->is_async = is_async;1359 call_instruction->is_async = is_async;
1336 call_instruction->async_allocator = async_allocator;1360 call_instruction->async_allocator = async_allocator;
1337 call_instruction->new_stack = new_stack;1361 call_instruction->new_stack = new_stack;
1362 call_instruction->result_loc = result_loc;
13381363
1339 if (fn_ref != nullptr) ir_ref_instruction(fn_ref, irb->current_basic_block);1364 if (fn_ref != nullptr) ir_ref_instruction(fn_ref, irb->current_basic_block);
1340 for (size_t i = 0; i < arg_count; i += 1)1365 for (size_t i = 0; i < arg_count; i += 1)
...@@ -1345,6 +1370,33 @@ static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *sourc...@@ -1345,6 +1370,33 @@ static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *sourc
1345 return &call_instruction->base;1370 return &call_instruction->base;
1346}1371}
13471372
1373static IrInstruction *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_instruction,
1374 ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
1375 FnInline fn_inline, bool is_async, IrInstruction *async_allocator, IrInstruction *new_stack,
1376 IrInstruction *result_loc)
1377{
1378 IrInstructionCallGen *call_instruction = ir_build_instruction<IrInstructionCallGen>(&ira->new_irb,
1379 source_instruction->scope, source_instruction->source_node);
1380 call_instruction->fn_entry = fn_entry;
1381 call_instruction->fn_ref = fn_ref;
1382 call_instruction->fn_inline = fn_inline;
1383 call_instruction->args = args;
1384 call_instruction->arg_count = arg_count;
1385 call_instruction->is_async = is_async;
1386 call_instruction->async_allocator = async_allocator;
1387 call_instruction->new_stack = new_stack;
1388 call_instruction->result_loc = result_loc;
1389
1390 if (fn_ref != nullptr) ir_ref_instruction(fn_ref, ira->new_irb.current_basic_block);
1391 for (size_t i = 0; i < arg_count; i += 1)
1392 ir_ref_instruction(args[i], ira->new_irb.current_basic_block);
1393 if (async_allocator != nullptr) ir_ref_instruction(async_allocator, ira->new_irb.current_basic_block);
1394 if (new_stack != nullptr) ir_ref_instruction(new_stack, ira->new_irb.current_basic_block);
1395 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
1396
1397 return &call_instruction->base;
1398}
1399
1348static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source_node,1400static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source_node,
1349 size_t incoming_count, IrBasicBlock **incoming_blocks, IrInstruction **incoming_values)1401 size_t incoming_count, IrBasicBlock **incoming_blocks, IrInstruction **incoming_values)
1350{1402{
...@@ -1511,7 +1563,7 @@ static IrInstruction *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode *...@@ -1511,7 +1563,7 @@ static IrInstruction *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode *
1511}1563}
15121564
1513static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNode *source_node,1565static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
1514 ZigVar *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value)1566 ZigVar *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *ptr)
1515{1567{
1516 IrInstructionDeclVarSrc *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarSrc>(irb, scope, source_node);1568 IrInstructionDeclVarSrc *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarSrc>(irb, scope, source_node);
1517 decl_var_instruction->base.value.special = ConstValSpecialStatic;1569 decl_var_instruction->base.value.special = ConstValSpecialStatic;
...@@ -1519,26 +1571,26 @@ static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNod...@@ -1519,26 +1571,26 @@ static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNod
1519 decl_var_instruction->var = var;1571 decl_var_instruction->var = var;
1520 decl_var_instruction->var_type = var_type;1572 decl_var_instruction->var_type = var_type;
1521 decl_var_instruction->align_value = align_value;1573 decl_var_instruction->align_value = align_value;
1522 decl_var_instruction->init_value = init_value;1574 decl_var_instruction->ptr = ptr;
15231575
1524 if (var_type != nullptr) ir_ref_instruction(var_type, irb->current_basic_block);1576 if (var_type != nullptr) ir_ref_instruction(var_type, irb->current_basic_block);
1525 if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block);1577 if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block);
1526 ir_ref_instruction(init_value, irb->current_basic_block);1578 ir_ref_instruction(ptr, irb->current_basic_block);
15271579
1528 return &decl_var_instruction->base;1580 return &decl_var_instruction->base;
1529}1581}
15301582
1531static IrInstruction *ir_build_var_decl_gen(IrAnalyze *ira, IrInstruction *source_instruction,1583static IrInstruction *ir_build_var_decl_gen(IrAnalyze *ira, IrInstruction *source_instruction,
1532 ZigVar *var, IrInstruction *init_value)1584 ZigVar *var, IrInstruction *var_ptr)
1533{1585{
1534 IrInstructionDeclVarGen *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarGen>(&ira->new_irb,1586 IrInstructionDeclVarGen *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarGen>(&ira->new_irb,
1535 source_instruction->scope, source_instruction->source_node);1587 source_instruction->scope, source_instruction->source_node);
1536 decl_var_instruction->base.value.special = ConstValSpecialStatic;1588 decl_var_instruction->base.value.special = ConstValSpecialStatic;
1537 decl_var_instruction->base.value.type = ira->codegen->builtin_types.entry_void;1589 decl_var_instruction->base.value.type = ira->codegen->builtin_types.entry_void;
1538 decl_var_instruction->var = var;1590 decl_var_instruction->var = var;
1539 decl_var_instruction->init_value = init_value;1591 decl_var_instruction->var_ptr = var_ptr;
15401592
1541 ir_ref_instruction(init_value, ira->new_irb.current_basic_block);1593 ir_ref_instruction(var_ptr, ira->new_irb.current_basic_block);
15421594
1543 return &decl_var_instruction->base;1595 return &decl_var_instruction->base;
1544}1596}
...@@ -3109,6 +3161,32 @@ static IrInstruction *ir_build_assert_non_null(IrAnalyze *ira, IrInstruction *so...@@ -3109,6 +3161,32 @@ static IrInstruction *ir_build_assert_non_null(IrAnalyze *ira, IrInstruction *so
3109 return &instruction->base;3161 return &instruction->base;
3110}3162}
31113163
3164static IrInstruction *ir_build_alloca_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
3165 IrInstruction *align, const char *name_hint, IrInstruction *is_comptime)
3166{
3167 IrInstructionAllocaSrc *instruction = ir_build_instruction<IrInstructionAllocaSrc>(irb, scope, source_node);
3168 instruction->base.is_gen = true;
3169 instruction->align = align;
3170 instruction->name_hint = name_hint;
3171 instruction->is_comptime = is_comptime;
3172
3173 if (align != nullptr) ir_ref_instruction(align, irb->current_basic_block);
3174 if (is_comptime != nullptr) ir_ref_instruction(is_comptime, irb->current_basic_block);
3175
3176 return &instruction->base;
3177}
3178
3179static IrInstructionAllocaGen *ir_create_alloca_gen(IrAnalyze *ira, IrInstruction *source_instruction,
3180 uint32_t align, const char *name_hint)
3181{
3182 IrInstructionAllocaGen *instruction = ir_create_instruction<IrInstructionAllocaGen>(&ira->new_irb,
3183 source_instruction->scope, source_instruction->source_node);
3184 instruction->align = align;
3185 instruction->name_hint = name_hint;
3186
3187 return instruction;
3188}
3189
3112static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) {3190static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) {
3113 results[ReturnKindUnconditional] = 0;3191 results[ReturnKindUnconditional] = 0;
3114 results[ReturnKindError] = 0;3192 results[ReturnKindError] = 0;
...@@ -3321,12 +3399,15 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3321,12 +3399,15 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
3321 switch (node->data.return_expr.kind) {3399 switch (node->data.return_expr.kind) {
3322 case ReturnKindUnconditional:3400 case ReturnKindUnconditional:
3323 {3401 {
3402 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1);
3403 result_loc_ret->base.id = ResultLocIdReturn;
3404
3324 IrInstruction *return_value;3405 IrInstruction *return_value;
3325 if (expr_node) {3406 if (expr_node) {
3326 // Temporarily set this so that if we return a type it gets the name of the function3407 // Temporarily set this so that if we return a type it gets the name of the function
3327 ZigFn *prev_name_fn = irb->exec->name_fn;3408 ZigFn *prev_name_fn = irb->exec->name_fn;
3328 irb->exec->name_fn = exec_fn_entry(irb->exec);3409 irb->exec->name_fn = exec_fn_entry(irb->exec);
3329 return_value = ir_gen_node(irb, expr_node, scope);3410 return_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, &result_loc_ret->base);
3330 irb->exec->name_fn = prev_name_fn;3411 irb->exec->name_fn = prev_name_fn;
3331 if (return_value == irb->codegen->invalid_instruction)3412 if (return_value == irb->codegen->invalid_instruction)
3332 return irb->codegen->invalid_instruction;3413 return irb->codegen->invalid_instruction;
...@@ -3373,17 +3454,21 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3373,17 +3454,21 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
3373 ir_build_br(irb, scope, node, ret_stmt_block, is_comptime);3454 ir_build_br(irb, scope, node, ret_stmt_block, is_comptime);
33743455
3375 ir_set_cursor_at_end_and_append_block(irb, ret_stmt_block);3456 ir_set_cursor_at_end_and_append_block(irb, ret_stmt_block);
3376 return ir_gen_async_return(irb, scope, node, return_value, false);3457 IrInstruction *result = ir_gen_async_return(irb, scope, node, return_value, false);
3458 result_loc_ret->base.source_instruction = result;
3459 return result;
3377 } else {3460 } else {
3378 // generate unconditional defers3461 // generate unconditional defers
3379 ir_gen_defers_for_block(irb, scope, outer_scope, false);3462 ir_gen_defers_for_block(irb, scope, outer_scope, false);
3380 return ir_gen_async_return(irb, scope, node, return_value, false);3463 IrInstruction *result = ir_gen_async_return(irb, scope, node, return_value, false);
3464 result_loc_ret->base.source_instruction = result;
3465 return result;
3381 }3466 }
3382 }3467 }
3383 case ReturnKindError:3468 case ReturnKindError:
3384 {3469 {
3385 assert(expr_node);3470 assert(expr_node);
3386 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr);3471 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
3387 if (err_union_ptr == irb->codegen->invalid_instruction)3472 if (err_union_ptr == irb->codegen->invalid_instruction)
3388 return irb->codegen->invalid_instruction;3473 return irb->codegen->invalid_instruction;
3389 IrInstruction *err_union_val = ir_build_load_ptr(irb, scope, node, err_union_ptr);3474 IrInstruction *err_union_val = ir_build_load_ptr(irb, scope, node, err_union_ptr);
...@@ -3592,7 +3677,7 @@ static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *no...@@ -3592,7 +3677,7 @@ static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *no
3592}3677}
35933678
3594static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) {3679static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) {
3595 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr);3680 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
3596 IrInstruction *rvalue = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);3681 IrInstruction *rvalue = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
35973682
3598 if (lvalue == irb->codegen->invalid_instruction || rvalue == irb->codegen->invalid_instruction)3683 if (lvalue == irb->codegen->invalid_instruction || rvalue == irb->codegen->invalid_instruction)
...@@ -3603,7 +3688,7 @@ static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node)...@@ -3603,7 +3688,7 @@ static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node)
3603}3688}
36043689
3605static IrInstruction *ir_gen_assign_op(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) {3690static IrInstruction *ir_gen_assign_op(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) {
3606 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr);3691 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
3607 if (lvalue == irb->codegen->invalid_instruction)3692 if (lvalue == irb->codegen->invalid_instruction)
3608 return lvalue;3693 return lvalue;
3609 IrInstruction *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);3694 IrInstruction *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);
...@@ -3705,7 +3790,7 @@ static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -3705,7 +3790,7 @@ static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode
3705 AstNode *op1_node = node->data.bin_op_expr.op1;3790 AstNode *op1_node = node->data.bin_op_expr.op1;
3706 AstNode *op2_node = node->data.bin_op_expr.op2;3791 AstNode *op2_node = node->data.bin_op_expr.op2;
37073792
3708 IrInstruction *maybe_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr);3793 IrInstruction *maybe_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr);
3709 if (maybe_ptr == irb->codegen->invalid_instruction)3794 if (maybe_ptr == irb->codegen->invalid_instruction)
3710 return irb->codegen->invalid_instruction;3795 return irb->codegen->invalid_instruction;
37113796
...@@ -3968,7 +4053,7 @@ static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode...@@ -3968,7 +4053,7 @@ static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode
3968 assert(node->type == NodeTypeArrayAccessExpr);4053 assert(node->type == NodeTypeArrayAccessExpr);
39694054
3970 AstNode *array_ref_node = node->data.array_access_expr.array_ref_expr;4055 AstNode *array_ref_node = node->data.array_access_expr.array_ref_expr;
3971 IrInstruction *array_ref_instruction = ir_gen_node_extra(irb, array_ref_node, scope, LValPtr);4056 IrInstruction *array_ref_instruction = ir_gen_node_extra(irb, array_ref_node, scope, LValPtr, nullptr);
3972 if (array_ref_instruction == irb->codegen->invalid_instruction)4057 if (array_ref_instruction == irb->codegen->invalid_instruction)
3973 return array_ref_instruction;4058 return array_ref_instruction;
39744059
...@@ -3991,7 +4076,7 @@ static IrInstruction *ir_gen_field_access(IrBuilder *irb, Scope *scope, AstNode...@@ -3991,7 +4076,7 @@ static IrInstruction *ir_gen_field_access(IrBuilder *irb, Scope *scope, AstNode
3991 AstNode *container_ref_node = node->data.field_access_expr.struct_expr;4076 AstNode *container_ref_node = node->data.field_access_expr.struct_expr;
3992 Buf *field_name = node->data.field_access_expr.field_name;4077 Buf *field_name = node->data.field_access_expr.field_name;
39934078
3994 IrInstruction *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, scope, LValPtr);4079 IrInstruction *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, scope, LValPtr, nullptr);
3995 if (container_ref_instruction == irb->codegen->invalid_instruction)4080 if (container_ref_instruction == irb->codegen->invalid_instruction)
3996 return container_ref_instruction;4081 return container_ref_instruction;
39974082
...@@ -4041,7 +4126,9 @@ static IrInstruction *ir_gen_this(IrBuilder *irb, Scope *orig_scope, AstNode *no...@@ -4041,7 +4126,9 @@ static IrInstruction *ir_gen_this(IrBuilder *irb, Scope *orig_scope, AstNode *no
4041 zig_unreachable();4126 zig_unreachable();
4042}4127}
40434128
4044static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) {4129static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
4130 ResultLoc *result_loc)
4131{
4045 assert(node->type == NodeTypeFnCallExpr);4132 assert(node->type == NodeTypeFnCallExpr);
40464133
4047 AstNode *fn_ref_expr = node->data.fn_call_expr.fn_ref_expr;4134 AstNode *fn_ref_expr = node->data.fn_call_expr.fn_ref_expr;
...@@ -4625,7 +4712,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -4625,7 +4712,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
4625 case BuiltinFnIdField:4712 case BuiltinFnIdField:
4626 {4713 {
4627 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);4714 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4628 IrInstruction *arg0_value = ir_gen_node_extra(irb, arg0_node, scope, LValPtr);4715 IrInstruction *arg0_value = ir_gen_node_extra(irb, arg0_node, scope, LValPtr, nullptr);
4629 if (arg0_value == irb->codegen->invalid_instruction)4716 if (arg0_value == irb->codegen->invalid_instruction)
4630 return arg0_value;4717 return arg0_value;
46314718
...@@ -4855,7 +4942,8 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -4855,7 +4942,8 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
4855 }4942 }
4856 FnInline fn_inline = (builtin_fn->id == BuiltinFnIdInlineCall) ? FnInlineAlways : FnInlineNever;4943 FnInline fn_inline = (builtin_fn->id == BuiltinFnIdInlineCall) ? FnInlineAlways : FnInlineNever;
48574944
4858 IrInstruction *call = ir_build_call(irb, scope, node, nullptr, fn_ref, arg_count, args, false, fn_inline, false, nullptr, nullptr);4945 IrInstruction *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, false,
4946 fn_inline, false, nullptr, nullptr, result_loc);
4859 return ir_lval_wrap(irb, scope, call, lval);4947 return ir_lval_wrap(irb, scope, call, lval);
4860 }4948 }
4861 case BuiltinFnIdNewStackCall:4949 case BuiltinFnIdNewStackCall:
...@@ -4885,7 +4973,8 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -4885,7 +4973,8 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
4885 return args[i];4973 return args[i];
4886 }4974 }
48874975
4888 IrInstruction *call = ir_build_call(irb, scope, node, nullptr, fn_ref, arg_count, args, false, FnInlineAuto, false, nullptr, new_stack);4976 IrInstruction *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, false,
4977 FnInlineAuto, false, nullptr, new_stack, result_loc);
4889 return ir_lval_wrap(irb, scope, call, lval);4978 return ir_lval_wrap(irb, scope, call, lval);
4890 }4979 }
4891 case BuiltinFnIdTypeId:4980 case BuiltinFnIdTypeId:
...@@ -5148,11 +5237,13 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -5148,11 +5237,13 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
5148 zig_unreachable();5237 zig_unreachable();
5149}5238}
51505239
5151static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) {5240static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,
5241 ResultLoc *result_loc)
5242{
5152 assert(node->type == NodeTypeFnCallExpr);5243 assert(node->type == NodeTypeFnCallExpr);
51535244
5154 if (node->data.fn_call_expr.is_builtin)5245 if (node->data.fn_call_expr.is_builtin)
5155 return ir_gen_builtin_fn_call(irb, scope, node, lval);5246 return ir_gen_builtin_fn_call(irb, scope, node, lval, result_loc);
51565247
5157 AstNode *fn_ref_node = node->data.fn_call_expr.fn_ref_expr;5248 AstNode *fn_ref_node = node->data.fn_call_expr.fn_ref_expr;
5158 IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope);5249 IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
...@@ -5178,8 +5269,8 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node...@@ -5178,8 +5269,8 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node
5178 }5269 }
5179 }5270 }
51805271
5181 IrInstruction *fn_call = ir_build_call(irb, scope, node, nullptr, fn_ref, arg_count, args, false, FnInlineAuto,5272 IrInstruction *fn_call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, false, FnInlineAuto,
5182 is_async, async_allocator, nullptr);5273 is_async, async_allocator, nullptr, result_loc);
5183 return ir_lval_wrap(irb, scope, fn_call, lval);5274 return ir_lval_wrap(irb, scope, fn_call, lval);
5184}5275}
51855276
...@@ -5244,7 +5335,7 @@ static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, Scope *scope, Ast...@@ -5244,7 +5335,7 @@ static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, Scope *scope, Ast
5244 assert(node->type == NodeTypePrefixOpExpr);5335 assert(node->type == NodeTypePrefixOpExpr);
5245 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;5336 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
52465337
5247 IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval);5338 IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr);
5248 if (value == irb->codegen->invalid_instruction)5339 if (value == irb->codegen->invalid_instruction)
5249 return value;5340 return value;
52505341
...@@ -5339,7 +5430,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode...@@ -5339,7 +5430,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
5339static IrInstruction *ir_gen_catch_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node, AstNode *expr_node,5430static IrInstruction *ir_gen_catch_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node, AstNode *expr_node,
5340 LVal lval)5431 LVal lval)
5341{5432{
5342 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr);5433 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
5343 if (err_union_ptr == irb->codegen->invalid_instruction)5434 if (err_union_ptr == irb->codegen->invalid_instruction)
5344 return irb->codegen->invalid_instruction;5435 return irb->codegen->invalid_instruction;
53455436
...@@ -5384,7 +5475,7 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod...@@ -5384,7 +5475,7 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod
5384 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpOptional), lval);5475 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpOptional), lval);
5385 case PrefixOpAddrOf: {5476 case PrefixOpAddrOf: {
5386 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;5477 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
5387 return ir_lval_wrap(irb, scope, ir_gen_node_extra(irb, expr_node, scope, LValPtr), lval);5478 return ir_lval_wrap(irb, scope, ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr), lval);
5388 }5479 }
5389 }5480 }
5390 zig_unreachable();5481 zig_unreachable();
...@@ -5486,17 +5577,27 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -5486,17 +5577,27 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
5486 // Parser should ensure that this never happens5577 // Parser should ensure that this never happens
5487 assert(variable_declaration->threadlocal_tok == nullptr);5578 assert(variable_declaration->threadlocal_tok == nullptr);
54885579
5580 IrInstruction *alloca = ir_build_alloca_src(irb, scope, node, align_value,
5581 buf_ptr(variable_declaration->symbol), is_comptime);
5582
5583 // Create a result location for the initialization expression.
5584 ResultLocVar *result_loc_var = allocate<ResultLocVar>(1);
5585 result_loc_var->base.id = ResultLocIdVar;
5586 result_loc_var->base.source_instruction = alloca;
5587 result_loc_var->var = var;
5588
5489 // Temporarily set the name of the IrExecutable to the VariableDeclaration5589 // Temporarily set the name of the IrExecutable to the VariableDeclaration
5490 // so that the struct or enum from the init expression inherits the name.5590 // so that the struct or enum from the init expression inherits the name.
5491 Buf *old_exec_name = irb->exec->name;5591 Buf *old_exec_name = irb->exec->name;
5492 irb->exec->name = variable_declaration->symbol;5592 irb->exec->name = variable_declaration->symbol;
5493 IrInstruction *init_value = ir_gen_node(irb, variable_declaration->expr, scope);5593 IrInstruction *init_value = ir_gen_node_extra(irb, variable_declaration->expr, scope, LValNone,
5594 &result_loc_var->base);
5494 irb->exec->name = old_exec_name;5595 irb->exec->name = old_exec_name;
54955596
5496 if (init_value == irb->codegen->invalid_instruction)5597 if (init_value == irb->codegen->invalid_instruction)
5497 return init_value;5598 return init_value;
54985599
5499 return ir_build_var_decl_src(irb, scope, node, var, type_instruction, align_value, init_value);5600 return ir_build_var_decl_src(irb, scope, node, var, type_instruction, align_value, alloca);
5500}5601}
55015602
5502static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *node) {5603static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *node) {
...@@ -5534,7 +5635,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -5534,7 +5635,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
5534 } else {5635 } else {
5535 payload_scope = subexpr_scope;5636 payload_scope = subexpr_scope;
5536 }5637 }
5537 IrInstruction *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, LValPtr);5638 IrInstruction *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope,
5639 LValPtr, nullptr);
5538 if (err_val_ptr == irb->codegen->invalid_instruction)5640 if (err_val_ptr == irb->codegen->invalid_instruction)
5539 return err_val_ptr;5641 return err_val_ptr;
5540 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, err_val_ptr);5642 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, err_val_ptr);
...@@ -5621,7 +5723,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -5621,7 +5723,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
5621 ZigVar *payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol,5723 ZigVar *payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol,
5622 true, false, false, is_comptime);5724 true, false, false, is_comptime);
5623 Scope *child_scope = payload_var->child_scope;5725 Scope *child_scope = payload_var->child_scope;
5624 IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, LValPtr);5726 IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope,
5727 LValPtr, nullptr);
5625 if (maybe_val_ptr == irb->codegen->invalid_instruction)5728 if (maybe_val_ptr == irb->codegen->invalid_instruction)
5626 return maybe_val_ptr;5729 return maybe_val_ptr;
5627 IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr);5730 IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr);
...@@ -5775,7 +5878,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -5775,7 +5878,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
5775 }5878 }
5776 assert(elem_node->type == NodeTypeSymbol);5879 assert(elem_node->type == NodeTypeSymbol);
57775880
5778 IrInstruction *array_val_ptr = ir_gen_node_extra(irb, array_node, parent_scope, LValPtr);5881 IrInstruction *array_val_ptr = ir_gen_node_extra(irb, array_node, parent_scope, LValPtr, nullptr);
5779 if (array_val_ptr == irb->codegen->invalid_instruction)5882 if (array_val_ptr == irb->codegen->invalid_instruction)
5780 return array_val_ptr;5883 return array_val_ptr;
57815884
...@@ -6182,7 +6285,7 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN...@@ -6182,7 +6285,7 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN
6182 AstNode *else_node = node->data.test_expr.else_node;6285 AstNode *else_node = node->data.test_expr.else_node;
6183 bool var_is_ptr = node->data.test_expr.var_is_ptr;6286 bool var_is_ptr = node->data.test_expr.var_is_ptr;
61846287
6185 IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr);6288 IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
6186 if (maybe_val_ptr == irb->codegen->invalid_instruction)6289 if (maybe_val_ptr == irb->codegen->invalid_instruction)
6187 return maybe_val_ptr;6290 return maybe_val_ptr;
61886291
...@@ -6261,7 +6364,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -6261,7 +6364,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
6261 Buf *var_symbol = node->data.if_err_expr.var_symbol;6364 Buf *var_symbol = node->data.if_err_expr.var_symbol;
6262 Buf *err_symbol = node->data.if_err_expr.err_symbol;6365 Buf *err_symbol = node->data.if_err_expr.err_symbol;
62636366
6264 IrInstruction *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr);6367 IrInstruction *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr);
6265 if (err_val_ptr == irb->codegen->invalid_instruction)6368 if (err_val_ptr == irb->codegen->invalid_instruction)
6266 return err_val_ptr;6369 return err_val_ptr;
62676370
...@@ -6397,7 +6500,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -6397,7 +6500,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
6397 assert(node->type == NodeTypeSwitchExpr);6500 assert(node->type == NodeTypeSwitchExpr);
63986501
6399 AstNode *target_node = node->data.switch_expr.expr;6502 AstNode *target_node = node->data.switch_expr.expr;
6400 IrInstruction *target_value_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr);6503 IrInstruction *target_value_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr);
6401 if (target_value_ptr == irb->codegen->invalid_instruction)6504 if (target_value_ptr == irb->codegen->invalid_instruction)
6402 return target_value_ptr;6505 return target_value_ptr;
6403 IrInstruction *target_value = ir_build_switch_target(irb, scope, node, target_value_ptr);6506 IrInstruction *target_value = ir_build_switch_target(irb, scope, node, target_value_ptr);
...@@ -6597,7 +6700,7 @@ static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -6597,7 +6700,7 @@ static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNo
6597 assert(node->type == NodeTypeCompTime);6700 assert(node->type == NodeTypeCompTime);
65986701
6599 Scope *child_scope = create_comptime_scope(irb->codegen, node, parent_scope);6702 Scope *child_scope = create_comptime_scope(irb->codegen, node, parent_scope);
6600 return ir_gen_node_extra(irb, node->data.comptime_expr.expr, child_scope, lval);6703 return ir_gen_node_extra(irb, node->data.comptime_expr.expr, child_scope, lval, nullptr);
6601}6704}
66026705
6603static IrInstruction *ir_gen_return_from_block(IrBuilder *irb, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) {6706static IrInstruction *ir_gen_return_from_block(IrBuilder *irb, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) {
...@@ -6776,7 +6879,7 @@ static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node)...@@ -6776,7 +6879,7 @@ static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node)
6776 AstNode *start_node = slice_expr->start;6879 AstNode *start_node = slice_expr->start;
6777 AstNode *end_node = slice_expr->end;6880 AstNode *end_node = slice_expr->end;
67786881
6779 IrInstruction *ptr_value = ir_gen_node_extra(irb, array_node, scope, LValPtr);6882 IrInstruction *ptr_value = ir_gen_node_extra(irb, array_node, scope, LValPtr, nullptr);
6780 if (ptr_value == irb->codegen->invalid_instruction)6883 if (ptr_value == irb->codegen->invalid_instruction)
6781 return irb->codegen->invalid_instruction;6884 return irb->codegen->invalid_instruction;
67826885
...@@ -6814,7 +6917,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -6814,7 +6917,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode
6814 }6917 }
68156918
68166919
6817 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr);6920 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr);
6818 if (err_union_ptr == irb->codegen->invalid_instruction)6921 if (err_union_ptr == irb->codegen->invalid_instruction)
6819 return irb->codegen->invalid_instruction;6922 return irb->codegen->invalid_instruction;
68206923
...@@ -7560,7 +7663,7 @@ static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNod...@@ -7560,7 +7663,7 @@ static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNod
7560}7663}
75617664
7562static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scope,7665static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scope,
7563 LVal lval)7666 LVal lval, ResultLoc *result_loc)
7564{7667{
7565 assert(scope);7668 assert(scope);
7566 switch (node->type) {7669 switch (node->type) {
...@@ -7576,7 +7679,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop...@@ -7576,7 +7679,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
7576 case NodeTypeBlock:7679 case NodeTypeBlock:
7577 return ir_lval_wrap(irb, scope, ir_gen_block(irb, scope, node), lval);7680 return ir_lval_wrap(irb, scope, ir_gen_block(irb, scope, node), lval);
7578 case NodeTypeGroupedExpr:7681 case NodeTypeGroupedExpr:
7579 return ir_gen_node_raw(irb, node->data.grouped_expr, scope, lval);7682 return ir_gen_node_raw(irb, node->data.grouped_expr, scope, lval, result_loc);
7580 case NodeTypeBinOpExpr:7683 case NodeTypeBinOpExpr:
7581 return ir_lval_wrap(irb, scope, ir_gen_bin_op(irb, scope, node), lval);7684 return ir_lval_wrap(irb, scope, ir_gen_bin_op(irb, scope, node), lval);
7582 case NodeTypeIntLiteral:7685 case NodeTypeIntLiteral:
...@@ -7588,7 +7691,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop...@@ -7588,7 +7691,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
7588 case NodeTypeSymbol:7691 case NodeTypeSymbol:
7589 return ir_gen_symbol(irb, scope, node, lval);7692 return ir_gen_symbol(irb, scope, node, lval);
7590 case NodeTypeFnCallExpr:7693 case NodeTypeFnCallExpr:
7591 return ir_gen_fn_call(irb, scope, node, lval);7694 return ir_gen_fn_call(irb, scope, node, lval, result_loc);
7592 case NodeTypeIfBoolExpr:7695 case NodeTypeIfBoolExpr:
7593 return ir_lval_wrap(irb, scope, ir_gen_if_bool_expr(irb, scope, node), lval);7696 return ir_lval_wrap(irb, scope, ir_gen_if_bool_expr(irb, scope, node), lval);
7594 case NodeTypePrefixOpExpr:7697 case NodeTypePrefixOpExpr:
...@@ -7617,7 +7720,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop...@@ -7617,7 +7720,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
7617 }7720 }
7618 case NodeTypePtrDeref: {7721 case NodeTypePtrDeref: {
7619 AstNode *expr_node = node->data.ptr_deref_expr.target;7722 AstNode *expr_node = node->data.ptr_deref_expr.target;
7620 IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval);7723 IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr);
7621 if (value == irb->codegen->invalid_instruction)7724 if (value == irb->codegen->invalid_instruction)
7622 return value;7725 return value;
76237726
...@@ -7629,7 +7732,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop...@@ -7629,7 +7732,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
7629 case NodeTypeUnwrapOptional: {7732 case NodeTypeUnwrapOptional: {
7630 AstNode *expr_node = node->data.unwrap_optional.expr;7733 AstNode *expr_node = node->data.unwrap_optional.expr;
76317734
7632 IrInstruction *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr);7735 IrInstruction *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
7633 if (maybe_ptr == irb->codegen->invalid_instruction)7736 if (maybe_ptr == irb->codegen->invalid_instruction)
7634 return irb->codegen->invalid_instruction;7737 return irb->codegen->invalid_instruction;
76357738
...@@ -7697,14 +7800,23 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop...@@ -7697,14 +7800,23 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
7697 zig_unreachable();7800 zig_unreachable();
7698}7801}
76997802
7700static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval) {7803static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval,
7701 IrInstruction *result = ir_gen_node_raw(irb, node, scope, lval);7804 ResultLoc *result_loc)
7805{
7806 if (result_loc == nullptr) {
7807 // Create a result location indicating there is none - but if one gets created
7808 // it will be properly distributed.
7809 ResultLocNone *result_loc_none = allocate<ResultLocNone>(1);
7810 result_loc_none->base.id = ResultLocIdNone;
7811 result_loc = &result_loc_none->base;
7812 }
7813 IrInstruction *result = ir_gen_node_raw(irb, node, scope, lval, result_loc);
7702 irb->exec->invalid = irb->exec->invalid || (result == irb->codegen->invalid_instruction);7814 irb->exec->invalid = irb->exec->invalid || (result == irb->codegen->invalid_instruction);
7703 return result;7815 return result;
7704}7816}
77057817
7706static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope) {7818static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope) {
7707 return ir_gen_node_extra(irb, node, scope, LValNone);7819 return ir_gen_node_extra(irb, node, scope, LValNone, nullptr);
7708}7820}
77097821
7710static void invalidate_exec(IrExecutable *exec) {7822static void invalidate_exec(IrExecutable *exec) {
...@@ -7837,7 +7949,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -7837,7 +7949,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
7837 irb->exec->coro_final_cleanup_block = ir_create_basic_block(irb, scope, "FinalCleanup");7949 irb->exec->coro_final_cleanup_block = ir_create_basic_block(irb, scope, "FinalCleanup");
7838 }7950 }
78397951
7840 IrInstruction *result = ir_gen_node_extra(irb, node, scope, LValNone);7952 IrInstruction *result = ir_gen_node_extra(irb, node, scope, LValNone, nullptr);
7841 assert(result);7953 assert(result);
7842 if (irb->exec->invalid)7954 if (irb->exec->invalid)
7843 return false;7955 return false;
...@@ -7946,7 +8058,10 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -7946,7 +8058,10 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
7946 // non-allocating. Basically coroutines are not supported right now until they are reworked.8058 // non-allocating. Basically coroutines are not supported right now until they are reworked.
7947 args[3] = ir_build_const_usize(irb, scope, node, 1); // new_size8059 args[3] = ir_build_const_usize(irb, scope, node, 1); // new_size
7948 args[4] = ir_build_const_usize(irb, scope, node, 1); // new_align8060 args[4] = ir_build_const_usize(irb, scope, node, 1); // new_align
7949 ir_build_call(irb, scope, node, nullptr, shrink_fn, arg_count, args, false, FnInlineAuto, false, nullptr, nullptr);8061 ResultLocNone *result_loc_none = allocate<ResultLocNone>(1);
8062 result_loc_none->base.id = ResultLocIdNone;
8063 ir_build_call_src(irb, scope, node, nullptr, shrink_fn, arg_count, args, false, FnInlineAuto, false, nullptr,
8064 nullptr, &result_loc_none->base);
79508065
7951 IrBasicBlock *resume_block = ir_create_basic_block(irb, scope, "Resume");8066 IrBasicBlock *resume_block = ir_create_basic_block(irb, scope, "Resume");
7952 ir_build_cond_br(irb, scope, node, resume_awaiter, resume_block, irb->exec->coro_suspend_block, const_bool_false);8067 ir_build_cond_br(irb, scope, node, resume_awaiter, resume_block, irb->exec->coro_suspend_block, const_bool_false);
...@@ -13641,12 +13756,6 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -13641,12 +13756,6 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
13641 Error err;13756 Error err;
13642 ZigVar *var = decl_var_instruction->var;13757 ZigVar *var = decl_var_instruction->var;
1364313758
13644 IrInstruction *init_value = decl_var_instruction->init_value->child;
13645 if (type_is_invalid(init_value->value.type)) {
13646 var->var_type = ira->codegen->builtin_types.entry_invalid;
13647 return ira->codegen->invalid_instruction;
13648 }
13649
13650 ZigType *explicit_type = nullptr;13759 ZigType *explicit_type = nullptr;
13651 IrInstruction *var_type = nullptr;13760 IrInstruction *var_type = nullptr;
13652 if (decl_var_instruction->var_type != nullptr) {13761 if (decl_var_instruction->var_type != nullptr) {
...@@ -13661,12 +13770,19 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -13661,12 +13770,19 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1366113770
13662 AstNode *source_node = decl_var_instruction->base.source_node;13771 AstNode *source_node = decl_var_instruction->base.source_node;
1366313772
13664 IrInstruction *casted_init_value = ir_implicit_cast(ira, init_value, explicit_type);
13665 bool is_comptime_var = ir_get_var_is_comptime(var);13773 bool is_comptime_var = ir_get_var_is_comptime(var);
1366613774
13667 bool var_class_requires_const = false;13775 bool var_class_requires_const = false;
1366813776
13669 ZigType *result_type = casted_init_value->value.type;13777 IrInstruction *var_ptr = decl_var_instruction->ptr->child;
13778 if (type_is_invalid(var_ptr->value.type)) {
13779 var->var_type = ira->codegen->builtin_types.entry_invalid;
13780 return ira->codegen->invalid_instruction;
13781 }
13782
13783 assert(var_ptr->value.type->id == ZigTypeIdPointer);
13784
13785 ZigType *result_type = var_ptr->value.type->data.pointer.child_type;
13670 if (type_is_invalid(result_type)) {13786 if (type_is_invalid(result_type)) {
13671 result_type = ira->codegen->builtin_types.entry_invalid;13787 result_type = ira->codegen->builtin_types.entry_invalid;
13672 } else if (result_type->id == ZigTypeIdUnreachable || result_type->id == ZigTypeIdOpaque) {13788 } else if (result_type->id == ZigTypeIdUnreachable || result_type->id == ZigTypeIdOpaque) {
...@@ -13675,6 +13791,14 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -13675,6 +13791,14 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
13675 result_type = ira->codegen->builtin_types.entry_invalid;13791 result_type = ira->codegen->builtin_types.entry_invalid;
13676 }13792 }
1367713793
13794 ConstExprValue *init_val = nullptr;
13795 if (instr_is_comptime(var_ptr) && var_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) {
13796 init_val = const_ptr_pointee(ira, ira->codegen, &var_ptr->value, decl_var_instruction->base.source_node);
13797 if (is_comptime_var) {
13798 var->const_value = init_val;
13799 }
13800 }
13801
13678 switch (type_requires_comptime(ira->codegen, result_type)) {13802 switch (type_requires_comptime(ira->codegen, result_type)) {
13679 case ReqCompTimeInvalid:13803 case ReqCompTimeInvalid:
13680 result_type = ira->codegen->builtin_types.entry_invalid;13804 result_type = ira->codegen->builtin_types.entry_invalid;
...@@ -13689,18 +13813,20 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -13689,18 +13813,20 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
13689 }13813 }
13690 break;13814 break;
13691 case ReqCompTimeNo:13815 case ReqCompTimeNo:
13692 if (casted_init_value->value.special == ConstValSpecialStatic &&13816 if (init_val != nullptr) {
13693 casted_init_value->value.type->id == ZigTypeIdFn &&13817 if (init_val->special == ConstValSpecialStatic &&
13694 casted_init_value->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&13818 init_val->type->id == ZigTypeIdFn &&
13695 casted_init_value->value.data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways)13819 init_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&
13696 {13820 init_val->data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways)
13697 var_class_requires_const = true;13821 {
13698 if (!var->src_is_const && !is_comptime_var) {13822 var_class_requires_const = true;
13699 ErrorMsg *msg = ir_add_error_node(ira, source_node,13823 if (!var->src_is_const && !is_comptime_var) {
13700 buf_sprintf("functions marked inline must be stored in const or comptime var"));13824 ErrorMsg *msg = ir_add_error_node(ira, source_node,
13701 AstNode *proto_node = casted_init_value->value.data.x_ptr.data.fn.fn_entry->proto_node;13825 buf_sprintf("functions marked inline must be stored in const or comptime var"));
13702 add_error_note(ira->codegen, msg, proto_node, buf_sprintf("declared here"));13826 AstNode *proto_node = init_val->data.x_ptr.data.fn.fn_entry->proto_node;
13703 result_type = ira->codegen->builtin_types.entry_invalid;13827 add_error_note(ira->codegen, msg, proto_node, buf_sprintf("declared here"));
13828 result_type = ira->codegen->builtin_types.entry_invalid;
13829 }
13704 }13830 }
13705 }13831 }
13706 break;13832 break;
...@@ -13747,11 +13873,11 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -13747,11 +13873,11 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
13747 }13873 }
13748 }13874 }
1374913875
13750 if (casted_init_value->value.special != ConstValSpecialRuntime) {13876 if (init_val != nullptr && init_val->special != ConstValSpecialRuntime) {
13751 if (var->mem_slot_index != SIZE_MAX) {13877 if (var->mem_slot_index != SIZE_MAX) {
13752 assert(var->mem_slot_index < ira->exec_context.mem_slot_list.length);13878 assert(var->mem_slot_index < ira->exec_context.mem_slot_list.length);
13753 ConstExprValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index);13879 ConstExprValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index);
13754 copy_const_val(mem_slot, &casted_init_value->value, !is_comptime_var || var->gen_is_const);13880 copy_const_val(mem_slot, init_val, !is_comptime_var || var->gen_is_const);
1375513881
13756 if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) {13882 if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) {
13757 return ir_const_void(ira, &decl_var_instruction->base);13883 return ir_const_void(ira, &decl_var_instruction->base);
...@@ -13768,7 +13894,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -13768,7 +13894,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
13768 if (fn_entry)13894 if (fn_entry)
13769 fn_entry->variable_list.append(var);13895 fn_entry->variable_list.append(var);
1377013896
13771 return ir_build_var_decl_gen(ira, &decl_var_instruction->base, var, casted_init_value);13897 return ir_build_var_decl_gen(ira, &decl_var_instruction->base, var, var_ptr);
13772}13898}
1377313899
13774static VarLinkage global_linkage_to_var_linkage(GlobalLinkageId id) {13900static VarLinkage global_linkage_to_var_linkage(GlobalLinkageId id) {
...@@ -14076,7 +14202,67 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i...@@ -14076,7 +14202,67 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i
14076 zig_unreachable();14202 zig_unreachable();
14077}14203}
1407814204
14079static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *call_instruction, ZigFn *fn_entry,14205static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_inst, ZigType *var_type,
14206 uint32_t align, const char *name_hint, bool force_comptime)
14207{
14208 Error err;
14209
14210 ConstExprValue *pointee = create_const_vals(1);
14211 pointee->special = ConstValSpecialUndef;
14212
14213 IrInstructionAllocaGen *result = ir_create_alloca_gen(ira, source_inst, align, name_hint);
14214 result->base.value.special = force_comptime ? ConstValSpecialStatic : ConstValSpecialRuntime;
14215 result->base.value.data.x_ptr.special = ConstPtrSpecialRef;
14216 result->base.value.data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutRuntimeVar;
14217 result->base.value.data.x_ptr.data.ref.pointee = pointee;
14218
14219 if ((err = type_resolve(ira->codegen, var_type, ResolveStatusZeroBitsKnown)))
14220 return ira->codegen->invalid_instruction;
14221 assert(result->base.value.data.x_ptr.special != ConstPtrSpecialInvalid);
14222
14223 pointee->type = var_type;
14224 result->base.value.type = get_pointer_to_type_extra(ira->codegen, var_type, false, false,
14225 PtrLenSingle, align, 0, 0, false);
14226
14227 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
14228 if (fn_entry != nullptr) {
14229 fn_entry->alloca_gen_list.append(result);
14230 }
14231 result->base.is_gen = true;
14232 return &result->base;
14233}
14234
14235static IrInstruction *ir_resolve_result_loc(IrAnalyze *ira, ResultLoc *result_loc, ZigType *elem_type) {
14236 switch (result_loc->id) {
14237 case ResultLocIdInvalid:
14238 zig_unreachable();
14239 case ResultLocIdNone:
14240 return nullptr;
14241 case ResultLocIdVar: {
14242 // TODO implicit cast?
14243 //ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc);
14244 assert(result_loc->source_instruction->id == IrInstructionIdAllocaSrc);
14245 IrInstructionAllocaSrc *alloca_src =
14246 reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction);
14247 if (alloca_src->base.child == nullptr) {
14248 uint32_t align = 0; // TODO
14249 bool force_comptime = false; // TODO
14250 IrInstruction *alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, elem_type, align,
14251 alloca_src->name_hint, force_comptime);
14252 alloca_src->base.child = alloca_gen;
14253 }
14254 return alloca_src->base.child;
14255 }
14256 case ResultLocIdReturn: {
14257 //ResultLocReturn *result_loc_ret = reinterpret_cast<ResultLocReturn *>(result_loc);
14258 // TODO implicit cast?
14259 return ir_build_return_ptr(ira, result_loc->source_instruction, elem_type);
14260 }
14261 }
14262 zig_unreachable();
14263}
14264
14265static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, ZigFn *fn_entry,
14080 ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count,14266 ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count,
14081 IrInstruction *async_allocator_inst)14267 IrInstruction *async_allocator_inst)
14082{14268{
...@@ -14109,8 +14295,10 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *c...@@ -14109,8 +14295,10 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *c
14109 ZigType *promise_type = get_promise_type(ira->codegen, return_type);14295 ZigType *promise_type = get_promise_type(ira->codegen, return_type);
14110 ZigType *async_return_type = get_error_union_type(ira->codegen, alloc_fn_error_set_type, promise_type);14296 ZigType *async_return_type = get_error_union_type(ira->codegen, alloc_fn_error_set_type, promise_type);
1411114297
14112 IrInstruction *result = ir_build_call(&ira->new_irb, call_instruction->base.scope, call_instruction->base.source_node,14298 IrInstruction *result_loc = ir_resolve_result_loc(ira, call_instruction->result_loc, async_return_type);
14113 fn_entry, fn_ref, arg_count, casted_args, false, FnInlineAuto, true, async_allocator_inst, nullptr);14299
14300 IrInstruction *result = ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref, arg_count,
14301 casted_args, FnInlineAuto, true, async_allocator_inst, nullptr, result_loc);
14114 result->value.type = async_return_type;14302 result->value.type = async_return_type;
14115 return result;14303 return result;
14116}14304}
...@@ -14416,7 +14604,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -14416,7 +14604,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
14416 return result;14604 return result;
14417}14605}
1441814606
14419static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instruction,14607static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction,
14420 ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref,14608 ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref,
14421 IrInstruction *first_arg_ptr, bool comptime_fn_call, FnInline fn_inline)14609 IrInstruction *first_arg_ptr, bool comptime_fn_call, FnInline fn_inline)
14422{14610{
...@@ -14861,19 +15049,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call...@@ -14861,19 +15049,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call
14861 if (call_instruction->is_async) {15049 if (call_instruction->is_async) {
14862 IrInstruction *result = ir_analyze_async_call(ira, call_instruction, impl_fn, impl_fn->type_entry,15050 IrInstruction *result = ir_analyze_async_call(ira, call_instruction, impl_fn, impl_fn->type_entry,
14863 fn_ref, casted_args, impl_param_count, async_allocator_inst);15051 fn_ref, casted_args, impl_param_count, async_allocator_inst);
14864 ir_add_alloca(ira, result, result->value.type);
14865 return ir_finish_anal(ira, result);15052 return ir_finish_anal(ira, result);
14866 }15053 }
1486715054
14868 assert(async_allocator_inst == nullptr);15055 assert(async_allocator_inst == nullptr);
14869 IrInstruction *new_call_instruction = ir_build_call(&ira->new_irb,15056 IrInstruction *result_loc = ir_resolve_result_loc(ira, call_instruction->result_loc,
14870 call_instruction->base.scope, call_instruction->base.source_node,15057 impl_fn_type_id->return_type);
14871 impl_fn, nullptr, impl_param_count, casted_args, false, fn_inline,15058 IrInstruction *new_call_instruction = ir_build_call_gen(ira, &call_instruction->base,
14872 call_instruction->is_async, nullptr, casted_new_stack);15059 impl_fn, nullptr, impl_param_count, casted_args, fn_inline,
15060 call_instruction->is_async, nullptr, casted_new_stack, result_loc);
14873 new_call_instruction->value.type = impl_fn_type_id->return_type;15061 new_call_instruction->value.type = impl_fn_type_id->return_type;
1487415062
14875 ir_add_alloca(ira, new_call_instruction, impl_fn_type_id->return_type);
14876
14877 return ir_finish_anal(ira, new_call_instruction);15063 return ir_finish_anal(ira, new_call_instruction);
14878 }15064 }
1487915065
...@@ -14957,7 +15143,6 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call...@@ -14957,7 +15143,6 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call
1495715143
14958 IrInstruction *result = ir_analyze_async_call(ira, call_instruction, fn_entry, fn_type, fn_ref,15144 IrInstruction *result = ir_analyze_async_call(ira, call_instruction, fn_entry, fn_type, fn_ref,
14959 casted_args, call_param_count, async_allocator_inst);15145 casted_args, call_param_count, async_allocator_inst);
14960 ir_add_alloca(ira, result, result->value.type);
14961 return ir_finish_anal(ira, result);15146 return ir_finish_anal(ira, result);
14962 }15147 }
1496315148
...@@ -14967,15 +15152,14 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call...@@ -14967,15 +15152,14 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call
14967 return ira->codegen->invalid_instruction;15152 return ira->codegen->invalid_instruction;
14968 }15153 }
1496915154
14970 IrInstruction *new_call_instruction = ir_build_call(&ira->new_irb,15155 IrInstruction *result_loc = ir_resolve_result_loc(ira, call_instruction->result_loc, return_type);
14971 call_instruction->base.scope, call_instruction->base.source_node,15156 IrInstruction *new_call_instruction = ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref,
14972 fn_entry, fn_ref, call_param_count, casted_args, false, fn_inline, false, nullptr, casted_new_stack);15157 call_param_count, casted_args, fn_inline, false, nullptr, casted_new_stack, result_loc);
14973 new_call_instruction->value.type = return_type;15158 new_call_instruction->value.type = return_type;
14974 ir_add_alloca(ira, new_call_instruction, return_type);
14975 return ir_finish_anal(ira, new_call_instruction);15159 return ir_finish_anal(ira, new_call_instruction);
14976}15160}
1497715161
14978static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *call_instruction) {15162static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction) {
14979 IrInstruction *fn_ref = call_instruction->fn_ref->child;15163 IrInstruction *fn_ref = call_instruction->fn_ref->child;
14980 if (type_is_invalid(fn_ref->value.type))15164 if (type_is_invalid(fn_ref->value.type))
14981 return ira->codegen->invalid_instruction;15165 return ira->codegen->invalid_instruction;
...@@ -23304,6 +23488,9 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio...@@ -23304,6 +23488,9 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio
23304 case IrInstructionIdResizeSlice:23488 case IrInstructionIdResizeSlice:
23305 case IrInstructionIdLoadPtrGen:23489 case IrInstructionIdLoadPtrGen:
23306 case IrInstructionIdBitCastGen:23490 case IrInstructionIdBitCastGen:
23491 case IrInstructionIdCallGen:
23492 case IrInstructionIdReturnPtr:
23493 case IrInstructionIdAllocaGen:
23307 zig_unreachable();23494 zig_unreachable();
2330823495
23309 case IrInstructionIdReturn:23496 case IrInstructionIdReturn:
...@@ -23326,8 +23513,8 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio...@@ -23326,8 +23513,8 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio
23326 return ir_analyze_instruction_var_ptr(ira, (IrInstructionVarPtr *)instruction);23513 return ir_analyze_instruction_var_ptr(ira, (IrInstructionVarPtr *)instruction);
23327 case IrInstructionIdFieldPtr:23514 case IrInstructionIdFieldPtr:
23328 return ir_analyze_instruction_field_ptr(ira, (IrInstructionFieldPtr *)instruction);23515 return ir_analyze_instruction_field_ptr(ira, (IrInstructionFieldPtr *)instruction);
23329 case IrInstructionIdCall:23516 case IrInstructionIdCallSrc:
23330 return ir_analyze_instruction_call(ira, (IrInstructionCall *)instruction);23517 return ir_analyze_instruction_call(ira, (IrInstructionCallSrc *)instruction);
23331 case IrInstructionIdBr:23518 case IrInstructionIdBr:
23332 return ir_analyze_instruction_br(ira, (IrInstructionBr *)instruction);23519 return ir_analyze_instruction_br(ira, (IrInstructionBr *)instruction);
23333 case IrInstructionIdCondBr:23520 case IrInstructionIdCondBr:
...@@ -23580,13 +23767,15 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio...@@ -23580,13 +23767,15 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio
23580 return ir_analyze_instruction_has_decl(ira, (IrInstructionHasDecl *)instruction);23767 return ir_analyze_instruction_has_decl(ira, (IrInstructionHasDecl *)instruction);
23581 case IrInstructionIdUndeclaredIdent:23768 case IrInstructionIdUndeclaredIdent:
23582 return ir_analyze_instruction_undeclared_ident(ira, (IrInstructionUndeclaredIdent *)instruction);23769 return ir_analyze_instruction_undeclared_ident(ira, (IrInstructionUndeclaredIdent *)instruction);
23770 case IrInstructionIdAllocaSrc:
23771 return nullptr;
23583 }23772 }
23584 zig_unreachable();23773 zig_unreachable();
23585}23774}
2358623775
23587static IrInstruction *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *old_instruction) {23776static IrInstruction *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *old_instruction) {
23588 IrInstruction *new_instruction = ir_analyze_instruction_nocast(ira, old_instruction);23777 IrInstruction *new_instruction = ir_analyze_instruction_nocast(ira, old_instruction);
23589 ir_assert(new_instruction->value.type != nullptr, old_instruction);23778 ir_assert(new_instruction->value.type != nullptr || new_instruction->value.type != nullptr, old_instruction);
23590 old_instruction->child = new_instruction;23779 old_instruction->child = new_instruction;
23591 return new_instruction;23780 return new_instruction;
23592}23781}
...@@ -23637,13 +23826,15 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -23637,13 +23826,15 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
23637 }23826 }
2363823827
23639 IrInstruction *new_instruction = ir_analyze_instruction(ira, old_instruction);23828 IrInstruction *new_instruction = ir_analyze_instruction(ira, old_instruction);
23640 if (type_is_invalid(new_instruction->value.type) && ir_should_inline(new_exec, old_instruction->scope)) {23829 if (new_instruction != nullptr) {
23641 return ira->codegen->builtin_types.entry_invalid;23830 if (type_is_invalid(new_instruction->value.type) && ir_should_inline(new_exec, old_instruction->scope)) {
23642 }23831 return ira->codegen->builtin_types.entry_invalid;
23832 }
2364323833
23644 // unreachable instructions do their own control flow.23834 // unreachable instructions do their own control flow.
23645 if (new_instruction->value.type->id == ZigTypeIdUnreachable)23835 if (new_instruction->value.type->id == ZigTypeIdUnreachable)
23646 continue;23836 continue;
23837 }
2364723838
23648 ira->instruction_index += 1;23839 ira->instruction_index += 1;
23649 }23840 }
...@@ -23668,7 +23859,8 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -23668,7 +23859,8 @@ bool ir_has_side_effects(IrInstruction *instruction) {
23668 case IrInstructionIdDeclVarSrc:23859 case IrInstructionIdDeclVarSrc:
23669 case IrInstructionIdDeclVarGen:23860 case IrInstructionIdDeclVarGen:
23670 case IrInstructionIdStorePtr:23861 case IrInstructionIdStorePtr:
23671 case IrInstructionIdCall:23862 case IrInstructionIdCallSrc:
23863 case IrInstructionIdCallGen:
23672 case IrInstructionIdReturn:23864 case IrInstructionIdReturn:
23673 case IrInstructionIdUnreachable:23865 case IrInstructionIdUnreachable:
23674 case IrInstructionIdSetCold:23866 case IrInstructionIdSetCold:
...@@ -23731,6 +23923,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -23731,6 +23923,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
23731 case IrInstructionIdFieldPtr:23923 case IrInstructionIdFieldPtr:
23732 case IrInstructionIdElemPtr:23924 case IrInstructionIdElemPtr:
23733 case IrInstructionIdVarPtr:23925 case IrInstructionIdVarPtr:
23926 case IrInstructionIdReturnPtr:
23734 case IrInstructionIdTypeOf:23927 case IrInstructionIdTypeOf:
23735 case IrInstructionIdToPtrType:23928 case IrInstructionIdToPtrType:
23736 case IrInstructionIdPtrTypeChild:23929 case IrInstructionIdPtrTypeChild:
...@@ -23818,6 +24011,8 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -23818,6 +24011,8 @@ bool ir_has_side_effects(IrInstruction *instruction) {
23818 case IrInstructionIdVectorToArray:24011 case IrInstructionIdVectorToArray:
23819 case IrInstructionIdArrayToVector:24012 case IrInstructionIdArrayToVector:
23820 case IrInstructionIdHasDecl:24013 case IrInstructionIdHasDecl:
24014 case IrInstructionIdAllocaSrc:
24015 case IrInstructionIdAllocaGen:
23821 return false;24016 return false;
2382224017
23823 case IrInstructionIdAsm:24018 case IrInstructionIdAsm:
src/ir_print.cpp+82-6
...@@ -188,7 +188,7 @@ static void ir_print_decl_var_src(IrPrint *irp, IrInstructionDeclVarSrc *decl_va...@@ -188,7 +188,7 @@ static void ir_print_decl_var_src(IrPrint *irp, IrInstructionDeclVarSrc *decl_va
188 fprintf(irp->f, " ");188 fprintf(irp->f, " ");
189 }189 }
190 fprintf(irp->f, "= ");190 fprintf(irp->f, "= ");
191 ir_print_other_instruction(irp, decl_var_instruction->init_value);191 ir_print_other_instruction(irp, decl_var_instruction->ptr);
192 if (decl_var_instruction->var->is_comptime != nullptr) {192 if (decl_var_instruction->var->is_comptime != nullptr) {
193 fprintf(irp->f, " // comptime = ");193 fprintf(irp->f, " // comptime = ");
194 ir_print_other_instruction(irp, decl_var_instruction->var->is_comptime);194 ir_print_other_instruction(irp, decl_var_instruction->var->is_comptime);
...@@ -201,7 +201,29 @@ static void ir_print_cast(IrPrint *irp, IrInstructionCast *cast_instruction) {...@@ -201,7 +201,29 @@ static void ir_print_cast(IrPrint *irp, IrInstructionCast *cast_instruction) {
201 fprintf(irp->f, " to %s", buf_ptr(&cast_instruction->dest_type->name));201 fprintf(irp->f, " to %s", buf_ptr(&cast_instruction->dest_type->name));
202}202}
203203
204static void ir_print_call(IrPrint *irp, IrInstructionCall *call_instruction) {204static void ir_print_result_loc_var(IrPrint *irp, ResultLocVar *result_loc_var) {
205 fprintf(irp->f, "var(");
206 ir_print_other_instruction(irp, result_loc_var->base.source_instruction);
207 fprintf(irp->f, ")");
208}
209
210static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {
211 switch (result_loc->id) {
212 case ResultLocIdInvalid:
213 zig_unreachable();
214 case ResultLocIdNone:
215 fprintf(irp->f, "none");
216 return;
217 case ResultLocIdReturn:
218 fprintf(irp->f, "return");
219 return;
220 case ResultLocIdVar:
221 return ir_print_result_loc_var(irp, (ResultLocVar *)result_loc);
222 }
223 zig_unreachable();
224}
225
226static void ir_print_call_src(IrPrint *irp, IrInstructionCallSrc *call_instruction) {
205 if (call_instruction->is_async) {227 if (call_instruction->is_async) {
206 fprintf(irp->f, "async");228 fprintf(irp->f, "async");
207 if (call_instruction->async_allocator != nullptr) {229 if (call_instruction->async_allocator != nullptr) {
...@@ -224,7 +246,35 @@ static void ir_print_call(IrPrint *irp, IrInstructionCall *call_instruction) {...@@ -224,7 +246,35 @@ static void ir_print_call(IrPrint *irp, IrInstructionCall *call_instruction) {
224 fprintf(irp->f, ", ");246 fprintf(irp->f, ", ");
225 ir_print_other_instruction(irp, arg);247 ir_print_other_instruction(irp, arg);
226 }248 }
227 fprintf(irp->f, ")");249 fprintf(irp->f, ")result=");
250 ir_print_result_loc(irp, call_instruction->result_loc);
251}
252
253static void ir_print_call_gen(IrPrint *irp, IrInstructionCallGen *call_instruction) {
254 if (call_instruction->is_async) {
255 fprintf(irp->f, "async");
256 if (call_instruction->async_allocator != nullptr) {
257 fprintf(irp->f, "<");
258 ir_print_other_instruction(irp, call_instruction->async_allocator);
259 fprintf(irp->f, ">");
260 }
261 fprintf(irp->f, " ");
262 }
263 if (call_instruction->fn_entry) {
264 fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));
265 } else {
266 assert(call_instruction->fn_ref);
267 ir_print_other_instruction(irp, call_instruction->fn_ref);
268 }
269 fprintf(irp->f, "(");
270 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
271 IrInstruction *arg = call_instruction->args[i];
272 if (i != 0)
273 fprintf(irp->f, ", ");
274 ir_print_other_instruction(irp, arg);
275 }
276 fprintf(irp->f, ")result=");
277 ir_print_other_instruction(irp, call_instruction->result_loc);
228}278}
229279
230static void ir_print_cond_br(IrPrint *irp, IrInstructionCondBr *cond_br_instruction) {280static void ir_print_cond_br(IrPrint *irp, IrInstructionCondBr *cond_br_instruction) {
...@@ -331,6 +381,10 @@ static void ir_print_var_ptr(IrPrint *irp, IrInstructionVarPtr *instruction) {...@@ -331,6 +381,10 @@ static void ir_print_var_ptr(IrPrint *irp, IrInstructionVarPtr *instruction) {
331 fprintf(irp->f, "&%s", buf_ptr(&instruction->var->name));381 fprintf(irp->f, "&%s", buf_ptr(&instruction->var->name));
332}382}
333383
384static void ir_print_return_ptr(IrPrint *irp, IrInstructionReturnPtr *instruction) {
385 fprintf(irp->f, "@ReturnPtr");
386}
387
334static void ir_print_load_ptr(IrPrint *irp, IrInstructionLoadPtr *instruction) {388static void ir_print_load_ptr(IrPrint *irp, IrInstructionLoadPtr *instruction) {
335 ir_print_other_instruction(irp, instruction->ptr);389 ir_print_other_instruction(irp, instruction->ptr);
336 fprintf(irp->f, ".*");390 fprintf(irp->f, ".*");
...@@ -1064,6 +1118,16 @@ static void ir_print_resize_slice(IrPrint *irp, IrInstructionResizeSlice *instru...@@ -1064,6 +1118,16 @@ static void ir_print_resize_slice(IrPrint *irp, IrInstructionResizeSlice *instru
1064 fprintf(irp->f, ")");1118 fprintf(irp->f, ")");
1065}1119}
10661120
1121static void ir_print_alloca_src(IrPrint *irp, IrInstructionAllocaSrc *instruction) {
1122 fprintf(irp->f, "Alloca(align=");
1123 ir_print_other_instruction(irp, instruction->align);
1124 fprintf(irp->f, ",name=%s)", instruction->name_hint);
1125}
1126
1127static void ir_print_alloca_gen(IrPrint *irp, IrInstructionAllocaGen *instruction) {
1128 fprintf(irp->f, "Alloca(align=%" PRIu32 ",name=%s)", instruction->align, instruction->name_hint);
1129}
1130
1067static void ir_print_int_to_err(IrPrint *irp, IrInstructionIntToErr *instruction) {1131static void ir_print_int_to_err(IrPrint *irp, IrInstructionIntToErr *instruction) {
1068 fprintf(irp->f, "inttoerr ");1132 fprintf(irp->f, "inttoerr ");
1069 ir_print_other_instruction(irp, instruction->target);1133 ir_print_other_instruction(irp, instruction->target);
...@@ -1446,7 +1510,7 @@ static void ir_print_decl_var_gen(IrPrint *irp, IrInstructionDeclVarGen *decl_va...@@ -1446,7 +1510,7 @@ static void ir_print_decl_var_gen(IrPrint *irp, IrInstructionDeclVarGen *decl_va
1446 fprintf(irp->f, "%s %s: %s align(%u) = ", var_or_const, name, buf_ptr(&var->var_type->name),1510 fprintf(irp->f, "%s %s: %s align(%u) = ", var_or_const, name, buf_ptr(&var->var_type->name),
1447 var->align_bytes);1511 var->align_bytes);
14481512
1449 ir_print_other_instruction(irp, decl_var_instruction->init_value);1513 ir_print_other_instruction(irp, decl_var_instruction->var_ptr);
1450 if (decl_var_instruction->var->is_comptime != nullptr) {1514 if (decl_var_instruction->var->is_comptime != nullptr) {
1451 fprintf(irp->f, " // comptime = ");1515 fprintf(irp->f, " // comptime = ");
1452 ir_print_other_instruction(irp, decl_var_instruction->var->is_comptime);1516 ir_print_other_instruction(irp, decl_var_instruction->var->is_comptime);
...@@ -1485,8 +1549,11 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -1485,8 +1549,11 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
1485 case IrInstructionIdCast:1549 case IrInstructionIdCast:
1486 ir_print_cast(irp, (IrInstructionCast *)instruction);1550 ir_print_cast(irp, (IrInstructionCast *)instruction);
1487 break;1551 break;
1488 case IrInstructionIdCall:1552 case IrInstructionIdCallSrc:
1489 ir_print_call(irp, (IrInstructionCall *)instruction);1553 ir_print_call_src(irp, (IrInstructionCallSrc *)instruction);
1554 break;
1555 case IrInstructionIdCallGen:
1556 ir_print_call_gen(irp, (IrInstructionCallGen *)instruction);
1490 break;1557 break;
1491 case IrInstructionIdUnOp:1558 case IrInstructionIdUnOp:
1492 ir_print_un_op(irp, (IrInstructionUnOp *)instruction);1559 ir_print_un_op(irp, (IrInstructionUnOp *)instruction);
...@@ -1521,6 +1588,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -1521,6 +1588,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
1521 case IrInstructionIdVarPtr:1588 case IrInstructionIdVarPtr:
1522 ir_print_var_ptr(irp, (IrInstructionVarPtr *)instruction);1589 ir_print_var_ptr(irp, (IrInstructionVarPtr *)instruction);
1523 break;1590 break;
1591 case IrInstructionIdReturnPtr:
1592 ir_print_return_ptr(irp, (IrInstructionReturnPtr *)instruction);
1593 break;
1524 case IrInstructionIdLoadPtr:1594 case IrInstructionIdLoadPtr:
1525 ir_print_load_ptr(irp, (IrInstructionLoadPtr *)instruction);1595 ir_print_load_ptr(irp, (IrInstructionLoadPtr *)instruction);
1526 break;1596 break;
...@@ -1938,6 +2008,12 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -1938,6 +2008,12 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
1938 case IrInstructionIdUndeclaredIdent:2008 case IrInstructionIdUndeclaredIdent:
1939 ir_print_undeclared_ident(irp, (IrInstructionUndeclaredIdent *)instruction);2009 ir_print_undeclared_ident(irp, (IrInstructionUndeclaredIdent *)instruction);
1940 break;2010 break;
2011 case IrInstructionIdAllocaSrc:
2012 ir_print_alloca_src(irp, (IrInstructionAllocaSrc *)instruction);
2013 break;
2014 case IrInstructionIdAllocaGen:
2015 ir_print_alloca_gen(irp, (IrInstructionAllocaGen *)instruction);
2016 break;
1941 }2017 }
1942 fprintf(irp->f, "\n");2018 fprintf(irp->f, "\n");
1943}2019}