authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-02 19:46:12-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-03 03:14:54-04:00
logaf20fdbce71d6799ab8fdca4374ade80755b04a3
treee1d2c8779dde26ea40a01a658c04c8a8249e487d
parentbb98620c10992884d58ae97a3a30dd9e26735fea

stage1: eliminate the IrInst base struct

This commit intentions to have no functional changes. The only purpose is to delete the struct IrInst, which is the common base struct that both IrInstSrc (ZIR) and IrInstGen (AIR) instructions embed. This untangles stage1 ZIR and AIR memory layout, paving the way for a following commit to reduce memory usage.

6 files changed, 2011 insertions(+), 1945 deletions(-)

src/stage1/all_types.hpp+13-20
...@@ -31,7 +31,6 @@ struct BuiltinFnEntry;...@@ -31,7 +31,6 @@ struct BuiltinFnEntry;
31struct TypeStructField;31struct TypeStructField;
32struct CodeGen;32struct CodeGen;
33struct ZigValue;33struct ZigValue;
34struct IrInst;
35struct IrInstSrc;34struct IrInstSrc;
36struct IrInstGen;35struct IrInstGen;
37struct IrInstGenCast;36struct IrInstGenCast;
...@@ -313,7 +312,7 @@ struct ConstErrValue {...@@ -313,7 +312,7 @@ struct ConstErrValue {
313struct ConstBoundFnValue {312struct ConstBoundFnValue {
314 ZigFn *fn;313 ZigFn *fn;
315 IrInstGen *first_arg;314 IrInstGen *first_arg;
316 IrInst *first_arg_src;315 AstNode *first_arg_src;
317};316};
318317
319struct ConstArgTuple {318struct ConstArgTuple {
...@@ -394,7 +393,7 @@ struct LazyValueTypeInfoDecls {...@@ -394,7 +393,7 @@ struct LazyValueTypeInfoDecls {
394 IrAnalyze *ira;393 IrAnalyze *ira;
395394
396 ScopeDecls *decls_scope;395 ScopeDecls *decls_scope;
397 IrInst *source_instr;396 AstNode *source_node;
398};397};
399398
400struct LazyValueAlignOf {399struct LazyValueAlignOf {
...@@ -2444,7 +2443,7 @@ struct Stage1ZirBasicBlock {...@@ -2444,7 +2443,7 @@ struct Stage1ZirBasicBlock {
2444 IrBasicBlockGen *child;2443 IrBasicBlockGen *child;
2445 Scope *scope;2444 Scope *scope;
2446 const char *name_hint;2445 const char *name_hint;
2447 IrInst *suspend_instruction_ref;2446 IrInstSrc *suspend_instruction_ref;
24482447
2449 uint32_t ref_count;2448 uint32_t ref_count;
2450 uint32_t index; // index into the basic block list2449 uint32_t index; // index into the basic block list
...@@ -2463,11 +2462,11 @@ struct IrBasicBlockGen {...@@ -2463,11 +2462,11 @@ struct IrBasicBlockGen {
2463 // The instruction that referenced this basic block and caused us to2462 // The instruction that referenced this basic block and caused us to
2464 // analyze the basic block. If the same instruction wants us to emit2463 // analyze the basic block. If the same instruction wants us to emit
2465 // the same basic block, then we re-generate it instead of saving it.2464 // the same basic block, then we re-generate it instead of saving it.
2466 IrInst *ref_instruction;2465 IrInstSrc *ref_instruction;
2467 // When this is non-null, a branch to this basic block is only allowed2466 // When this is non-null, a branch to this basic block is only allowed
2468 // if the branch is comptime. The instruction points to the reason2467 // if the branch is comptime. The instruction points to the reason
2469 // the basic block must be comptime.2468 // the basic block must be comptime.
2470 IrInst *must_be_comptime_source_instr;2469 AstNode *must_be_comptime_source_node;
24712470
2472 uint32_t debug_id;2471 uint32_t debug_id;
2473 bool already_appended;2472 bool already_appended;
...@@ -2714,24 +2713,13 @@ enum IrInstGenId {...@@ -2714,24 +2713,13 @@ enum IrInstGenId {
2714 IrInstGenIdExtern,2713 IrInstGenIdExtern,
2715};2714};
27162715
2717// Common fields between IrInstSrc and IrInstGen.2716struct IrInstSrc {
2718struct IrInst {
2719 // if ref_count is zero and the instruction has no side effects,
2720 // the instruction can be omitted in codegen
2721 uint32_t ref_count;2717 uint32_t ref_count;
2722 uint32_t debug_id;2718 uint32_t debug_id;
27232719
2724 Scope *scope;2720 Scope *scope;
2725 AstNode *source_node;2721 AstNode *source_node;
27262722
2727 // for debugging purposes, these are useful to call to inspect the instruction
2728 void dump();
2729 void src();
2730};
2731
2732struct IrInstSrc {
2733 IrInst base;
2734
2735 IrInstSrcId id;2723 IrInstSrcId id;
27362724
2737 // When analyzing IR, instructions that point to this instruction in the "old ir"2725 // When analyzing IR, instructions that point to this instruction in the "old ir"
...@@ -2746,9 +2734,14 @@ struct IrInstSrc {...@@ -2746,9 +2734,14 @@ struct IrInstSrc {
2746};2734};
27472735
2748struct IrInstGen {2736struct IrInstGen {
2749 IrInst base;
2750
2751 IrInstGenId id;2737 IrInstGenId id;
2738 // if ref_count is zero and the instruction has no side effects,
2739 // the instruction can be omitted in codegen
2740 uint32_t ref_count;
2741 uint32_t debug_id;
2742
2743 Scope *scope;
2744 AstNode *source_node;
27522745
2753 LLVMValueRef llvm_value;2746 LLVMValueRef llvm_value;
2754 ZigValue *value;2747 ZigValue *value;
src/stage1/analyze.cpp+18-18
...@@ -5076,7 +5076,7 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {...@@ -5076,7 +5076,7 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {
5076 // TODO function pointer call here, could be anything5076 // TODO function pointer call here, could be anything
5077 continue;5077 continue;
5078 }5078 }
5079 switch (analyze_callee_async(g, fn, call->fn_entry, call->base.base.source_node, must_not_be_async,5079 switch (analyze_callee_async(g, fn, call->fn_entry, call->base.source_node, must_not_be_async,
5080 call->modifier))5080 call->modifier))
5081 {5081 {
5082 case ErrorSemanticAnalyzeFail:5082 case ErrorSemanticAnalyzeFail:
...@@ -5096,7 +5096,7 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {...@@ -5096,7 +5096,7 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {
5096 for (size_t i = 0; i < fn->await_list.length; i += 1) {5096 for (size_t i = 0; i < fn->await_list.length; i += 1) {
5097 IrInstGenAwait *await = fn->await_list.at(i);5097 IrInstGenAwait *await = fn->await_list.at(i);
5098 if (await->is_nosuspend) continue;5098 if (await->is_nosuspend) continue;
5099 switch (analyze_callee_async(g, fn, await->target_fn, await->base.base.source_node, must_not_be_async,5099 switch (analyze_callee_async(g, fn, await->target_fn, await->base.source_node, must_not_be_async,
5100 CallModifierNone))5100 CallModifierNone))
5101 {5101 {
5102 case ErrorSemanticAnalyzeFail:5102 case ErrorSemanticAnalyzeFail:
...@@ -6736,11 +6736,11 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6736,11 +6736,11 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6736 if (fn->analyzed_executable.need_err_code_spill) {6736 if (fn->analyzed_executable.need_err_code_spill) {
6737 IrInstGenAlloca *alloca_gen = heap::c_allocator.create<IrInstGenAlloca>();6737 IrInstGenAlloca *alloca_gen = heap::c_allocator.create<IrInstGenAlloca>();
6738 alloca_gen->base.id = IrInstGenIdAlloca;6738 alloca_gen->base.id = IrInstGenIdAlloca;
6739 alloca_gen->base.base.source_node = fn->proto_node;6739 alloca_gen->base.source_node = fn->proto_node;
6740 alloca_gen->base.base.scope = fn->child_scope;6740 alloca_gen->base.scope = fn->child_scope;
6741 alloca_gen->base.value = g->pass1_arena->create<ZigValue>();6741 alloca_gen->base.value = g->pass1_arena->create<ZigValue>();
6742 alloca_gen->base.value->type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);6742 alloca_gen->base.value->type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
6743 alloca_gen->base.base.ref_count = 1;6743 alloca_gen->base.ref_count = 1;
6744 alloca_gen->name_hint = "";6744 alloca_gen->name_hint = "";
6745 fn->alloca_gen_list.append(alloca_gen);6745 fn->alloca_gen_list.append(alloca_gen);
6746 fn->err_code_spill = &alloca_gen->base;6746 fn->err_code_spill = &alloca_gen->base;
...@@ -6762,7 +6762,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6762,7 +6762,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6762 if (call->fn_ref->value->type->data.fn.fn_type_id.cc != CallingConventionAsync) {6762 if (call->fn_ref->value->type->data.fn.fn_type_id.cc != CallingConventionAsync) {
6763 continue;6763 continue;
6764 }6764 }
6765 add_node_error(g, call->base.base.source_node,6765 add_node_error(g, call->base.source_node,
6766 buf_sprintf("function is not comptime-known; @asyncCall required"));6766 buf_sprintf("function is not comptime-known; @asyncCall required"));
6767 return ErrorSemanticAnalyzeFail;6767 return ErrorSemanticAnalyzeFail;
6768 }6768 }
...@@ -6772,14 +6772,14 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6772,14 +6772,14 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6772 if (callee->anal_state == FnAnalStateProbing) {6772 if (callee->anal_state == FnAnalStateProbing) {
6773 ErrorMsg *msg = add_node_error(g, fn->proto_node,6773 ErrorMsg *msg = add_node_error(g, fn->proto_node,
6774 buf_sprintf("unable to determine async function frame of '%s'", buf_ptr(&fn->symbol_name)));6774 buf_sprintf("unable to determine async function frame of '%s'", buf_ptr(&fn->symbol_name)));
6775 g->trace_err = add_error_note(g, msg, call->base.base.source_node,6775 g->trace_err = add_error_note(g, msg, call->base.source_node,
6776 buf_sprintf("analysis of function '%s' depends on the frame", buf_ptr(&callee->symbol_name)));6776 buf_sprintf("analysis of function '%s' depends on the frame", buf_ptr(&callee->symbol_name)));
6777 return ErrorSemanticAnalyzeFail;6777 return ErrorSemanticAnalyzeFail;
6778 }6778 }
67796779
6780 ZigType *callee_frame_type = get_fn_frame_type(g, callee);6780 ZigType *callee_frame_type = get_fn_frame_type(g, callee);
6781 frame_type->data.frame.resolve_loop_type = callee_frame_type;6781 frame_type->data.frame.resolve_loop_type = callee_frame_type;
6782 frame_type->data.frame.resolve_loop_src_node = call->base.base.source_node;6782 frame_type->data.frame.resolve_loop_src_node = call->base.source_node;
67836783
6784 analyze_fn_body(g, callee);6784 analyze_fn_body(g, callee);
6785 if (callee->anal_state == FnAnalStateInvalid) {6785 if (callee->anal_state == FnAnalStateInvalid) {
...@@ -6795,7 +6795,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6795,7 +6795,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6795 if (!fn_is_async(callee))6795 if (!fn_is_async(callee))
6796 continue;6796 continue;
67976797
6798 mark_suspension_point(call->base.base.scope);6798 mark_suspension_point(call->base.scope);
67996799
6800 if ((err = type_resolve(g, callee_frame_type, ResolveStatusSizeKnown))) {6800 if ((err = type_resolve(g, callee_frame_type, ResolveStatusSizeKnown))) {
6801 return err;6801 return err;
...@@ -6840,17 +6840,17 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6840,17 +6840,17 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6840 }6840 }
6841 // This await is a suspend point, but it might not need a spill.6841 // This await is a suspend point, but it might not need a spill.
6842 // We do need to mark the ExprScope as having a suspend point in it.6842 // We do need to mark the ExprScope as having a suspend point in it.
6843 mark_suspension_point(await->base.base.scope);6843 mark_suspension_point(await->base.scope);
68446844
6845 if (await->result_loc != nullptr) {6845 if (await->result_loc != nullptr) {
6846 // If there's a result location, that is the spill6846 // If there's a result location, that is the spill
6847 continue;6847 continue;
6848 }6848 }
6849 if (await->base.base.ref_count == 0)6849 if (await->base.ref_count == 0)
6850 continue;6850 continue;
6851 if (!type_has_bits(g, await->base.value->type))6851 if (!type_has_bits(g, await->base.value->type))
6852 continue;6852 continue;
6853 await->result_loc = ir_create_alloca(g, await->base.base.scope, await->base.base.source_node, fn,6853 await->result_loc = ir_create_alloca(g, await->base.scope, await->base.source_node, fn,
6854 await->base.value->type, "");6854 await->base.value->type, "");
6855 }6855 }
6856 for (size_t block_i = 0; block_i < fn->analyzed_executable.basic_block_list.length; block_i += 1) {6856 for (size_t block_i = 0; block_i < fn->analyzed_executable.basic_block_list.length; block_i += 1) {
...@@ -6858,7 +6858,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6858,7 +6858,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6858 for (size_t instr_i = 0; instr_i < block->instruction_list.length; instr_i += 1) {6858 for (size_t instr_i = 0; instr_i < block->instruction_list.length; instr_i += 1) {
6859 IrInstGen *instruction = block->instruction_list.at(instr_i);6859 IrInstGen *instruction = block->instruction_list.at(instr_i);
6860 if (instruction->id == IrInstGenIdSuspendFinish) {6860 if (instruction->id == IrInstGenIdSuspendFinish) {
6861 mark_suspension_point(instruction->base.scope);6861 mark_suspension_point(instruction->scope);
6862 }6862 }
6863 }6863 }
6864 }6864 }
...@@ -6885,14 +6885,14 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6885,14 +6885,14 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6885 }6885 }
6886 if (instruction->value->special != ConstValSpecialRuntime)6886 if (instruction->value->special != ConstValSpecialRuntime)
6887 continue;6887 continue;
6888 if (instruction->base.ref_count == 0)6888 if (instruction->ref_count == 0)
6889 continue;6889 continue;
6890 if ((err = type_resolve(g, instruction->value->type, ResolveStatusZeroBitsKnown)))6890 if ((err = type_resolve(g, instruction->value->type, ResolveStatusZeroBitsKnown)))
6891 return ErrorSemanticAnalyzeFail;6891 return ErrorSemanticAnalyzeFail;
6892 if (!type_has_bits(g, instruction->value->type))6892 if (!type_has_bits(g, instruction->value->type))
6893 continue;6893 continue;
6894 if (scope_needs_spill(instruction->base.scope)) {6894 if (scope_needs_spill(instruction->scope)) {
6895 instruction->spill = ir_create_alloca(g, instruction->base.scope, instruction->base.source_node,6895 instruction->spill = ir_create_alloca(g, instruction->scope, instruction->source_node,
6896 fn, instruction->value->type, "");6896 fn, instruction->value->type, "");
6897 }6897 }
6898 }6898 }
...@@ -6950,7 +6950,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6950,7 +6950,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6950 ZigType *child_type = resolve_type_isf(ptr_type->data.pointer.child_type);6950 ZigType *child_type = resolve_type_isf(ptr_type->data.pointer.child_type);
6951 if (!type_has_bits(g, child_type))6951 if (!type_has_bits(g, child_type))
6952 continue;6952 continue;
6953 if (instruction->base.base.ref_count == 0)6953 if (instruction->base.ref_count == 0)
6954 continue;6954 continue;
6955 if (instruction->base.value->special != ConstValSpecialRuntime) {6955 if (instruction->base.value->special != ConstValSpecialRuntime) {
6956 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=6956 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=
...@@ -6961,7 +6961,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6961,7 +6961,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6961 }6961 }
69626962
6963 frame_type->data.frame.resolve_loop_type = child_type;6963 frame_type->data.frame.resolve_loop_type = child_type;
6964 frame_type->data.frame.resolve_loop_src_node = instruction->base.base.source_node;6964 frame_type->data.frame.resolve_loop_src_node = instruction->base.source_node;
6965 if ((err = type_resolve(g, child_type, ResolveStatusSizeKnown))) {6965 if ((err = type_resolve(g, child_type, ResolveStatusSizeKnown))) {
6966 return err;6966 return err;
6967 }6967 }
src/stage1/astgen.cpp+37-28
...@@ -39,7 +39,7 @@ static ZigVar *ir_create_var(Stage1AstGen *ag, AstNode *node, Scope *scope, Buf...@@ -39,7 +39,7 @@ static ZigVar *ir_create_var(Stage1AstGen *ag, AstNode *node, Scope *scope, Buf
39static void build_decl_var_and_init(Stage1AstGen *ag, Scope *scope, AstNode *source_node,39static void build_decl_var_and_init(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
40 ZigVar *var, IrInstSrc *init, const char *name_hint, IrInstSrc *is_comptime);40 ZigVar *var, IrInstSrc *init, const char *name_hint, IrInstSrc *is_comptime);
4141
42static void ir_assert_impl(bool ok, IrInst *source_instruction, char const *file, unsigned int line) {42static void ir_assert_impl(bool ok, IrInstSrc *source_instruction, char const *file, unsigned int line) {
43 if (ok) return;43 if (ok) return;
44 src_assert_impl(ok, source_instruction->source_node, file, line);44 src_assert_impl(ok, source_instruction->source_node, file, line);
45}45}
...@@ -386,7 +386,7 @@ static void ir_ref_bb(Stage1ZirBasicBlock *bb) {...@@ -386,7 +386,7 @@ static void ir_ref_bb(Stage1ZirBasicBlock *bb) {
386386
387static void ir_ref_instruction(IrInstSrc *instruction, Stage1ZirBasicBlock *cur_bb) {387static void ir_ref_instruction(IrInstSrc *instruction, Stage1ZirBasicBlock *cur_bb) {
388 assert(instruction->id != IrInstSrcIdInvalid);388 assert(instruction->id != IrInstSrcIdInvalid);
389 instruction->base.ref_count += 1;389 instruction->ref_count += 1;
390 if (instruction->owner_bb != cur_bb && !instr_is_unreachable(instruction)390 if (instruction->owner_bb != cur_bb && !instr_is_unreachable(instruction)
391 && instruction->id != IrInstSrcIdConst)391 && instruction->id != IrInstSrcIdConst)
392 {392 {
...@@ -939,9 +939,9 @@ template<typename T>...@@ -939,9 +939,9 @@ template<typename T>
939static T *ir_create_instruction(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {939static T *ir_create_instruction(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {
940 T *special_instruction = heap::c_allocator.create<T>();940 T *special_instruction = heap::c_allocator.create<T>();
941 special_instruction->base.id = ir_inst_id(special_instruction);941 special_instruction->base.id = ir_inst_id(special_instruction);
942 special_instruction->base.base.scope = scope;942 special_instruction->base.scope = scope;
943 special_instruction->base.base.source_node = source_node;943 special_instruction->base.source_node = source_node;
944 special_instruction->base.base.debug_id = irb_next_debug_id(ag);944 special_instruction->base.debug_id = irb_next_debug_id(ag);
945 special_instruction->base.owner_bb = ag->current_basic_block;945 special_instruction->base.owner_bb = ag->current_basic_block;
946 return special_instruction;946 return special_instruction;
947}947}
...@@ -1325,9 +1325,9 @@ static IrInstSrc *ir_build_ptr_type_simple(Stage1AstGen *ag, Scope *scope, AstNo...@@ -1325,9 +1325,9 @@ static IrInstSrc *ir_build_ptr_type_simple(Stage1AstGen *ag, Scope *scope, AstNo
1325{1325{
1326 IrInstSrcPtrTypeSimple *inst = heap::c_allocator.create<IrInstSrcPtrTypeSimple>();1326 IrInstSrcPtrTypeSimple *inst = heap::c_allocator.create<IrInstSrcPtrTypeSimple>();
1327 inst->base.id = is_const ? IrInstSrcIdPtrTypeSimpleConst : IrInstSrcIdPtrTypeSimple;1327 inst->base.id = is_const ? IrInstSrcIdPtrTypeSimpleConst : IrInstSrcIdPtrTypeSimple;
1328 inst->base.base.scope = scope;1328 inst->base.scope = scope;
1329 inst->base.base.source_node = source_node;1329 inst->base.source_node = source_node;
1330 inst->base.base.debug_id = irb_next_debug_id(ag);1330 inst->base.debug_id = irb_next_debug_id(ag);
1331 inst->base.owner_bb = ag->current_basic_block;1331 inst->base.owner_bb = ag->current_basic_block;
1332 ir_instruction_append(ag->current_basic_block, &inst->base);1332 ir_instruction_append(ag->current_basic_block, &inst->base);
13331333
...@@ -2391,9 +2391,9 @@ static IrInstSrc *ir_build_check_switch_prongs(Stage1AstGen *ag, Scope *scope, A...@@ -2391,9 +2391,9 @@ static IrInstSrc *ir_build_check_switch_prongs(Stage1AstGen *ag, Scope *scope, A
2391 IrInstSrcCheckSwitchProngs *instruction = heap::c_allocator.create<IrInstSrcCheckSwitchProngs>();2391 IrInstSrcCheckSwitchProngs *instruction = heap::c_allocator.create<IrInstSrcCheckSwitchProngs>();
2392 instruction->base.id = have_underscore_prong ?2392 instruction->base.id = have_underscore_prong ?
2393 IrInstSrcIdCheckSwitchProngsUnderYes : IrInstSrcIdCheckSwitchProngsUnderNo;2393 IrInstSrcIdCheckSwitchProngsUnderYes : IrInstSrcIdCheckSwitchProngsUnderNo;
2394 instruction->base.base.scope = scope;2394 instruction->base.scope = scope;
2395 instruction->base.base.source_node = source_node;2395 instruction->base.source_node = source_node;
2396 instruction->base.base.debug_id = irb_next_debug_id(ag);2396 instruction->base.debug_id = irb_next_debug_id(ag);
2397 instruction->base.owner_bb = ag->current_basic_block;2397 instruction->base.owner_bb = ag->current_basic_block;
2398 ir_instruction_append(ag->current_basic_block, &instruction->base);2398 ir_instruction_append(ag->current_basic_block, &instruction->base);
23992399
...@@ -2582,9 +2582,9 @@ static IrInstSrc *ir_build_arg_type(Stage1AstGen *ag, Scope *scope, AstNode *sou...@@ -2582,9 +2582,9 @@ static IrInstSrc *ir_build_arg_type(Stage1AstGen *ag, Scope *scope, AstNode *sou
2582 IrInstSrcArgType *instruction = heap::c_allocator.create<IrInstSrcArgType>();2582 IrInstSrcArgType *instruction = heap::c_allocator.create<IrInstSrcArgType>();
2583 instruction->base.id = allow_var ?2583 instruction->base.id = allow_var ?
2584 IrInstSrcIdArgTypeAllowVarTrue : IrInstSrcIdArgTypeAllowVarFalse;2584 IrInstSrcIdArgTypeAllowVarTrue : IrInstSrcIdArgTypeAllowVarFalse;
2585 instruction->base.base.scope = scope;2585 instruction->base.scope = scope;
2586 instruction->base.base.source_node = source_node;2586 instruction->base.source_node = source_node;
2587 instruction->base.base.debug_id = irb_next_debug_id(ag);2587 instruction->base.debug_id = irb_next_debug_id(ag);
2588 instruction->base.owner_bb = ag->current_basic_block;2588 instruction->base.owner_bb = ag->current_basic_block;
2589 ir_instruction_append(ag->current_basic_block, &instruction->base);2589 ir_instruction_append(ag->current_basic_block, &instruction->base);
25902590
...@@ -3157,7 +3157,7 @@ ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope,...@@ -3157,7 +3157,7 @@ ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope,
3157 variable_entry->const_value = codegen->pass1_arena->create<ZigValue>();3157 variable_entry->const_value = codegen->pass1_arena->create<ZigValue>();
31583158
3159 if (is_comptime != nullptr) {3159 if (is_comptime != nullptr) {
3160 is_comptime->base.ref_count += 1;3160 is_comptime->ref_count += 1;
3161 }3161 }
31623162
3163 if (name) {3163 if (name) {
...@@ -3405,7 +3405,7 @@ static IrInstSrc *astgen_block(Stage1AstGen *ag, Scope *parent_scope, AstNode *b...@@ -3405,7 +3405,7 @@ static IrInstSrc *astgen_block(Stage1AstGen *ag, Scope *parent_scope, AstNode *b
3405 ir_build_end_expr(ag, parent_scope, block_node, result, &result_loc_ret->base);3405 ir_build_end_expr(ag, parent_scope, block_node, result, &result_loc_ret->base);
3406 if (!astgen_defers_for_block(ag, child_scope, outer_block_scope, nullptr, nullptr))3406 if (!astgen_defers_for_block(ag, child_scope, outer_block_scope, nullptr, nullptr))
3407 return ag->codegen->invalid_inst_src;3407 return ag->codegen->invalid_inst_src;
3408 return ir_build_return_src(ag, child_scope, result->base.source_node, result);3408 return ir_build_return_src(ag, child_scope, result->source_node, result);
3409}3409}
34103410
3411static IrInstSrc *astgen_bin_op_id(Stage1AstGen *ag, Scope *scope, AstNode *node, IrBinOp op_id) {3411static IrInstSrc *astgen_bin_op_id(Stage1AstGen *ag, Scope *scope, AstNode *node, IrBinOp op_id) {
...@@ -3565,9 +3565,9 @@ static ResultLocPeerParent *ir_build_result_peers(Stage1AstGen *ag, IrInstSrc *c...@@ -3565,9 +3565,9 @@ static ResultLocPeerParent *ir_build_result_peers(Stage1AstGen *ag, IrInstSrc *c
3565 peer_parent->parent = parent;3565 peer_parent->parent = parent;
35663566
3567 IrInstSrc *popped_inst = ag->current_basic_block->instruction_list.pop();3567 IrInstSrc *popped_inst = ag->current_basic_block->instruction_list.pop();
3568 ir_assert(popped_inst == cond_br_inst, &cond_br_inst->base);3568 ir_assert(popped_inst == cond_br_inst, cond_br_inst);
35693569
3570 ir_build_reset_result(ag, cond_br_inst->base.scope, cond_br_inst->base.source_node, &peer_parent->base);3570 ir_build_reset_result(ag, cond_br_inst->scope, cond_br_inst->source_node, &peer_parent->base);
3571 ag->current_basic_block->instruction_list.append(popped_inst);3571 ag->current_basic_block->instruction_list.append(popped_inst);
35723572
3573 return peer_parent;3573 return peer_parent;
...@@ -5436,7 +5436,7 @@ static IrInstSrc *astgen_prefix_op_id(Stage1AstGen *ag, Scope *scope, AstNode *n...@@ -5436,7 +5436,7 @@ static IrInstSrc *astgen_prefix_op_id(Stage1AstGen *ag, Scope *scope, AstNode *n
54365436
5437static IrInstSrc *ir_expr_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc) {5437static IrInstSrc *ir_expr_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc) {
5438 if (inst == ag->codegen->invalid_inst_src) return inst;5438 if (inst == ag->codegen->invalid_inst_src) return inst;
5439 ir_build_end_expr(ag, scope, inst->base.source_node, inst, result_loc);5439 ir_build_end_expr(ag, scope, inst->source_node, inst, result_loc);
5440 return inst;5440 return inst;
5441}5441}
54425442
...@@ -5447,7 +5447,7 @@ static IrInstSrc *ir_lval_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *value,...@@ -5447,7 +5447,7 @@ static IrInstSrc *ir_lval_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *value,
5447 // [STMT_EXPR_TEST_THING] <--- (search this token)5447 // [STMT_EXPR_TEST_THING] <--- (search this token)
5448 if (value == ag->codegen->invalid_inst_src ||5448 if (value == ag->codegen->invalid_inst_src ||
5449 instr_is_unreachable(value) ||5449 instr_is_unreachable(value) ||
5450 value->base.source_node->type == NodeTypeDefer ||5450 value->source_node->type == NodeTypeDefer ||
5451 value->id == IrInstSrcIdDeclVar)5451 value->id == IrInstSrcIdDeclVar)
5452 {5452 {
5453 return value;5453 return value;
...@@ -5457,7 +5457,7 @@ static IrInstSrc *ir_lval_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *value,...@@ -5457,7 +5457,7 @@ static IrInstSrc *ir_lval_wrap(Stage1AstGen *ag, Scope *scope, IrInstSrc *value,
5457 if (lval == LValPtr) {5457 if (lval == LValPtr) {
5458 // We needed a pointer to a value, but we got a value. So we create5458 // We needed a pointer to a value, but we got a value. So we create
5459 // an instruction which just makes a pointer of it.5459 // an instruction which just makes a pointer of it.
5460 return ir_build_ref_src(ag, scope, value->base.source_node, value);5460 return ir_build_ref_src(ag, scope, value->source_node, value);
5461 } else if (result_loc != nullptr) {5461 } else if (result_loc != nullptr) {
5462 return ir_expr_wrap(ag, scope, value, result_loc);5462 return ir_expr_wrap(ag, scope, value, result_loc);
5463 } else {5463 } else {
...@@ -5690,11 +5690,11 @@ static IrInstSrc *astgen_container_init_expr(Stage1AstGen *ag, Scope *scope, Ast...@@ -5690,11 +5690,11 @@ static IrInstSrc *astgen_container_init_expr(Stage1AstGen *ag, Scope *scope, Ast
56905690
5691 result_loc_cast = ir_build_cast_result_loc(ag, container_type, parent_result_loc);5691 result_loc_cast = ir_build_cast_result_loc(ag, container_type, parent_result_loc);
5692 child_result_loc = &result_loc_cast->base;5692 child_result_loc = &result_loc_cast->base;
5693 init_array_type_source_node = container_type->base.source_node;5693 init_array_type_source_node = container_type->source_node;
5694 } else {5694 } else {
5695 child_result_loc = parent_result_loc;5695 child_result_loc = parent_result_loc;
5696 if (parent_result_loc->source_instruction != nullptr) {5696 if (parent_result_loc->source_instruction != nullptr) {
5697 init_array_type_source_node = parent_result_loc->source_instruction->base.source_node;5697 init_array_type_source_node = parent_result_loc->source_instruction->source_node;
5698 } else {5698 } else {
5699 init_array_type_source_node = node;5699 init_array_type_source_node = node;
5700 }5700 }
...@@ -5784,7 +5784,7 @@ static ResultLocVar *ir_build_var_result_loc(Stage1AstGen *ag, IrInstSrc *alloca...@@ -5784,7 +5784,7 @@ static ResultLocVar *ir_build_var_result_loc(Stage1AstGen *ag, IrInstSrc *alloca
5784 result_loc_var->base.allow_write_through_const = true;5784 result_loc_var->base.allow_write_through_const = true;
5785 result_loc_var->var = var;5785 result_loc_var->var = var;
57865786
5787 ir_build_reset_result(ag, alloca->base.scope, alloca->base.source_node, &result_loc_var->base);5787 ir_build_reset_result(ag, alloca->scope, alloca->source_node, &result_loc_var->base);
57885788
5789 return result_loc_var;5789 return result_loc_var;
5790}5790}
...@@ -5799,7 +5799,7 @@ static ResultLocCast *ir_build_cast_result_loc(Stage1AstGen *ag, IrInstSrc *dest...@@ -5799,7 +5799,7 @@ static ResultLocCast *ir_build_cast_result_loc(Stage1AstGen *ag, IrInstSrc *dest
5799 ir_ref_instruction(dest_type, ag->current_basic_block);5799 ir_ref_instruction(dest_type, ag->current_basic_block);
5800 result_loc_cast->parent = parent_result_loc;5800 result_loc_cast->parent = parent_result_loc;
58015801
5802 ir_build_reset_result(ag, dest_type->base.scope, dest_type->base.source_node, &result_loc_cast->base);5802 ir_build_reset_result(ag, dest_type->scope, dest_type->source_node, &result_loc_cast->base);
58035803
5804 return result_loc_cast;5804 return result_loc_cast;
5805}5805}
...@@ -5897,7 +5897,7 @@ static IrInstSrc *astgen_var_decl(Stage1AstGen *ag, Scope *scope, AstNode *node)...@@ -5897,7 +5897,7 @@ static IrInstSrc *astgen_var_decl(Stage1AstGen *ag, Scope *scope, AstNode *node)
5897 return ag->codegen->invalid_inst_src;5897 return ag->codegen->invalid_inst_src;
58985898
5899 if (result_loc_cast != nullptr) {5899 if (result_loc_cast != nullptr) {
5900 IrInstSrc *implicit_cast = ir_build_implicit_cast(ag, scope, init_value->base.source_node,5900 IrInstSrc *implicit_cast = ir_build_implicit_cast(ag, scope, init_value->source_node,
5901 init_value, result_loc_cast);5901 init_value, result_loc_cast);
5902 ir_build_end_expr(ag, scope, node, implicit_cast, &result_loc_var->base);5902 ir_build_end_expr(ag, scope, node, implicit_cast, &result_loc_var->base);
5903 }5903 }
...@@ -8066,13 +8066,13 @@ bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *sta...@@ -8066,13 +8066,13 @@ bool stage1_astgen(CodeGen *codegen, AstNode *node, Scope *scope, Stage1Zir *sta
8066 }8066 }
80678067
8068 if (!instr_is_unreachable(result)) {8068 if (!instr_is_unreachable(result)) {
8069 ir_build_add_implicit_return_type(ag, scope, result->base.source_node, result, nullptr);8069 ir_build_add_implicit_return_type(ag, scope, result->source_node, result, nullptr);
8070 // no need for save_err_ret_addr because this cannot return error8070 // no need for save_err_ret_addr because this cannot return error
8071 ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>();8071 ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>();
8072 result_loc_ret->base.id = ResultLocIdReturn;8072 result_loc_ret->base.id = ResultLocIdReturn;
8073 ir_build_reset_result(ag, scope, node, &result_loc_ret->base);8073 ir_build_reset_result(ag, scope, node, &result_loc_ret->base);
8074 ir_build_end_expr(ag, scope, node, result, &result_loc_ret->base);8074 ir_build_end_expr(ag, scope, node, result, &result_loc_ret->base);
8075 ir_build_return_src(ag, scope, result->base.source_node, result);8075 ir_build_return_src(ag, scope, result->source_node, result);
8076 }8076 }
80778077
8078 return true;8078 return true;
...@@ -8113,3 +8113,12 @@ void ir_add_call_stack_errors_gen(CodeGen *codegen, Stage1Air *exec, ErrorMsg *e...@@ -8113,3 +8113,12 @@ void ir_add_call_stack_errors_gen(CodeGen *codegen, Stage1Air *exec, ErrorMsg *e
8113 ir_add_call_stack_errors_gen(codegen, exec->parent_exec, err_msg, limit - 1);8113 ir_add_call_stack_errors_gen(codegen, exec->parent_exec, err_msg, limit - 1);
8114}8114}
81158115
8116void IrInstSrc::src() {
8117 IrInstSrc *inst = this;
8118 if (inst->source_node != nullptr) {
8119 inst->source_node->src();
8120 } else {
8121 fprintf(stderr, "(null source node)\n");
8122 }
8123}
8124
src/stage1/codegen.cpp+26-26
...@@ -908,14 +908,14 @@ static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, ZigType *type...@@ -908,14 +908,14 @@ static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, ZigType *type
908908
909static void ir_assert_impl(bool ok, IrInstGen *source_instruction, const char *file, unsigned int line) {909static void ir_assert_impl(bool ok, IrInstGen *source_instruction, const char *file, unsigned int line) {
910 if (ok) return;910 if (ok) return;
911 src_assert_impl(ok, source_instruction->base.source_node, file, line);911 src_assert_impl(ok, source_instruction->source_node, file, line);
912}912}
913913
914#define ir_assert(OK, SOURCE_INSTRUCTION) ir_assert_impl((OK), (SOURCE_INSTRUCTION), __FILE__, __LINE__)914#define ir_assert(OK, SOURCE_INSTRUCTION) ir_assert_impl((OK), (SOURCE_INSTRUCTION), __FILE__, __LINE__)
915915
916static bool ir_want_fast_math(CodeGen *g, IrInstGen *instruction) {916static bool ir_want_fast_math(CodeGen *g, IrInstGen *instruction) {
917 // TODO memoize917 // TODO memoize
918 Scope *scope = instruction->base.scope;918 Scope *scope = instruction->scope;
919 while (scope) {919 while (scope) {
920 if (scope->id == ScopeIdBlock) {920 if (scope->id == ScopeIdBlock) {
921 ScopeBlock *block_scope = (ScopeBlock *)scope;921 ScopeBlock *block_scope = (ScopeBlock *)scope;
...@@ -951,7 +951,7 @@ static bool ir_want_runtime_safety_scope(CodeGen *g, Scope *scope) {...@@ -951,7 +951,7 @@ static bool ir_want_runtime_safety_scope(CodeGen *g, Scope *scope) {
951}951}
952952
953static bool ir_want_runtime_safety(CodeGen *g, IrInstGen *instruction) {953static bool ir_want_runtime_safety(CodeGen *g, IrInstGen *instruction) {
954 return ir_want_runtime_safety_scope(g, instruction->base.scope);954 return ir_want_runtime_safety_scope(g, instruction->scope);
955}955}
956956
957static Buf *panic_msg_buf(PanicMsgId msg_id) {957static Buf *panic_msg_buf(PanicMsgId msg_id) {
...@@ -1078,7 +1078,7 @@ static void gen_assertion_scope(CodeGen *g, PanicMsgId msg_id, Scope *source_sco...@@ -1078,7 +1078,7 @@ static void gen_assertion_scope(CodeGen *g, PanicMsgId msg_id, Scope *source_sco
1078}1078}
10791079
1080static void gen_assertion(CodeGen *g, PanicMsgId msg_id, IrInstGen *source_instruction) {1080static void gen_assertion(CodeGen *g, PanicMsgId msg_id, IrInstGen *source_instruction) {
1081 return gen_assertion_scope(g, msg_id, source_instruction->base.scope);1081 return gen_assertion_scope(g, msg_id, source_instruction->scope);
1082}1082}
10831083
1084static LLVMValueRef gen_wasm_memory_size(CodeGen *g) {1084static LLVMValueRef gen_wasm_memory_size(CodeGen *g) {
...@@ -1923,7 +1923,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_...@@ -1923,7 +1923,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
1923 return false;1923 return false;
1924 IrInstGen *arg = fn_walk->data.call.inst->args[src_i];1924 IrInstGen *arg = fn_walk->data.call.inst->args[src_i];
1925 ty = arg->value->type;1925 ty = arg->value->type;
1926 source_node = arg->base.source_node;1926 source_node = arg->source_node;
1927 val = ir_llvm_value(g, arg);1927 val = ir_llvm_value(g, arg);
1928 break;1928 break;
1929 }1929 }
...@@ -2451,7 +2451,7 @@ static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, Stage1Air *executabl...@@ -2451,7 +2451,7 @@ static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, Stage1Air *executabl
24512451
2452 LLVMValueRef return_err_fn = get_return_err_fn(g);2452 LLVMValueRef return_err_fn = get_return_err_fn(g);
2453 bool is_llvm_alloca;2453 bool is_llvm_alloca;
2454 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, save_err_ret_addr_instruction->base.base.scope,2454 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, save_err_ret_addr_instruction->base.scope,
2455 &is_llvm_alloca);2455 &is_llvm_alloca);
2456 ZigLLVMBuildCall(g->builder, return_err_fn, &my_err_trace_val, 1,2456 ZigLLVMBuildCall(g->builder, return_err_fn, &my_err_trace_val, 1,
2457 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");2457 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
...@@ -2622,7 +2622,7 @@ static void gen_async_return(CodeGen *g, IrInstGenReturn *instruction) {...@@ -2622,7 +2622,7 @@ static void gen_async_return(CodeGen *g, IrInstGenReturn *instruction) {
2622 frame_index_trace_arg(g, ret_type) + 1, "");2622 frame_index_trace_arg(g, ret_type) + 1, "");
2623 LLVMValueRef dest_trace_ptr = LLVMBuildLoad(g->builder, awaiter_trace_ptr_ptr, "");2623 LLVMValueRef dest_trace_ptr = LLVMBuildLoad(g->builder, awaiter_trace_ptr_ptr, "");
2624 bool is_llvm_alloca;2624 bool is_llvm_alloca;
2625 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);2625 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);
2626 LLVMValueRef args[] = { dest_trace_ptr, my_err_trace_val };2626 LLVMValueRef args[] = { dest_trace_ptr, my_err_trace_val };
2627 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,2627 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,
2628 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");2628 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
...@@ -3900,7 +3900,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, Stage1Air *executable, IrIns...@@ -3900,7 +3900,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, Stage1Air *executable, IrIns
3900 codegen_report_errors_and_exit(g);3900 codegen_report_errors_and_exit(g);
3901 if (!ptr_type_has_bits)3901 if (!ptr_type_has_bits)
3902 return nullptr;3902 return nullptr;
3903 if (instruction->ptr->base.ref_count == 0) {3903 if (instruction->ptr->ref_count == 0) {
3904 // In this case, this StorePtr instruction should be elided. Something happened like this:3904 // In this case, this StorePtr instruction should be elided. Something happened like this:
3905 // var t = true;3905 // var t = true;
3906 // const x = if (t) Num.Two else unreachable;3906 // const x = if (t) Num.Two else unreachable;
...@@ -4365,7 +4365,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, IrInstGenC...@@ -4365,7 +4365,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, IrInstGenC
4365 LLVMValueRef err_ret_trace_ptr_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc,4365 LLVMValueRef err_ret_trace_ptr_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc,
4366 frame_index_trace_arg(g, src_return_type) + 1, "");4366 frame_index_trace_arg(g, src_return_type) + 1, "");
4367 bool is_llvm_alloca;4367 bool is_llvm_alloca;
4368 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope,4368 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope,
4369 &is_llvm_alloca);4369 &is_llvm_alloca);
4370 LLVMBuildStore(g->builder, my_err_ret_trace_val, err_ret_trace_ptr_ptr);4370 LLVMBuildStore(g->builder, my_err_ret_trace_val, err_ret_trace_ptr_ptr);
4371 }4371 }
...@@ -4424,7 +4424,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, IrInstGenC...@@ -4424,7 +4424,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, IrInstGenC
4424 gen_init_stack_trace(g, trace_field_ptr, addrs_field_ptr);4424 gen_init_stack_trace(g, trace_field_ptr, addrs_field_ptr);
44254425
4426 bool is_llvm_alloca;4426 bool is_llvm_alloca;
4427 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca));4427 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca));
4428 }4428 }
4429 }4429 }
4430 } else {4430 } else {
...@@ -4433,7 +4433,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, IrInstGenC...@@ -4433,7 +4433,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, IrInstGenC
4433 }4433 }
4434 if (prefix_arg_err_ret_stack) {4434 if (prefix_arg_err_ret_stack) {
4435 bool is_llvm_alloca;4435 bool is_llvm_alloca;
4436 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca));4436 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca));
4437 }4437 }
4438 }4438 }
4439 FnWalk fn_walk = {};4439 FnWalk fn_walk = {};
...@@ -4567,7 +4567,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, IrInstGenC...@@ -4567,7 +4567,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, IrInstGenC
45674567
4568 LLVMPositionBuilderAtEnd(g->builder, call_bb);4568 LLVMPositionBuilderAtEnd(g->builder, call_bb);
4569 gen_assert_resume_id(g, &instruction->base, ResumeIdReturn, PanicMsgIdResumedAnAwaitingFn, nullptr);4569 gen_assert_resume_id(g, &instruction->base, ResumeIdReturn, PanicMsgIdResumedAnAwaitingFn, nullptr);
4570 render_async_var_decls(g, instruction->base.base.scope);4570 render_async_var_decls(g, instruction->base.scope);
45714571
4572 if (!type_has_bits(g, src_return_type))4572 if (!type_has_bits(g, src_return_type))
4573 return nullptr;4573 return nullptr;
...@@ -4795,7 +4795,7 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_...@@ -4795,7 +4795,7 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_
4795}4795}
47964796
4797static LLVMValueRef ir_render_asm_gen(CodeGen *g, Stage1Air *executable, IrInstGenAsm *instruction) {4797static LLVMValueRef ir_render_asm_gen(CodeGen *g, Stage1Air *executable, IrInstGenAsm *instruction) {
4798 AstNode *asm_node = instruction->base.base.source_node;4798 AstNode *asm_node = instruction->base.source_node;
4799 assert(asm_node->type == NodeTypeAsmExpr);4799 assert(asm_node->type == NodeTypeAsmExpr);
4800 AstNodeAsmExpr *asm_expr = &asm_node->data.asm_expr;4800 AstNodeAsmExpr *asm_expr = &asm_node->data.asm_expr;
48014801
...@@ -5463,7 +5463,7 @@ static LLVMValueRef ir_render_error_return_trace(CodeGen *g, Stage1Air *executab...@@ -5463,7 +5463,7 @@ static LLVMValueRef ir_render_error_return_trace(CodeGen *g, Stage1Air *executab
5463 IrInstGenErrorReturnTrace *instruction)5463 IrInstGenErrorReturnTrace *instruction)
5464{5464{
5465 bool is_llvm_alloca;5465 bool is_llvm_alloca;
5466 LLVMValueRef cur_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);5466 LLVMValueRef cur_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);
5467 if (cur_err_ret_trace_val == nullptr) {5467 if (cur_err_ret_trace_val == nullptr) {
5468 return LLVMConstNull(get_llvm_type(g, ptr_to_stack_trace_type(g)));5468 return LLVMConstNull(get_llvm_type(g, ptr_to_stack_trace_type(g)));
5469 }5469 }
...@@ -5692,7 +5692,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, Stage1Air *executable, IrInstGe...@@ -5692,7 +5692,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, Stage1Air *executable, IrInstGe
5692 bool val_is_undef = value_is_all_undef(g, instruction->byte->value);5692 bool val_is_undef = value_is_all_undef(g, instruction->byte->value);
5693 LLVMValueRef fill_char;5693 LLVMValueRef fill_char;
5694 if (val_is_undef) {5694 if (val_is_undef) {
5695 if (ir_want_runtime_safety_scope(g, instruction->base.base.scope)) {5695 if (ir_want_runtime_safety_scope(g, instruction->base.scope)) {
5696 fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false);5696 fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false);
5697 } else {5697 } else {
5698 return nullptr;5698 return nullptr;
...@@ -6179,7 +6179,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, Stage1Air *executab...@@ -6179,7 +6179,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, Stage1Air *executab
6179 LLVMBuildCondBr(g->builder, cond_val, ok_block, err_block);6179 LLVMBuildCondBr(g->builder, cond_val, ok_block, err_block);
61806180
6181 LLVMPositionBuilderAtEnd(g->builder, err_block);6181 LLVMPositionBuilderAtEnd(g->builder, err_block);
6182 gen_safety_crash_for_err(g, err_val, instruction->base.base.scope);6182 gen_safety_crash_for_err(g, err_val, instruction->base.scope);
61836183
6184 LLVMPositionBuilderAtEnd(g->builder, ok_block);6184 LLVMPositionBuilderAtEnd(g->builder, ok_block);
6185 }6185 }
...@@ -6306,7 +6306,7 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, Stage1Air *executable, IrIns...@@ -6306,7 +6306,7 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, Stage1Air *executable, IrIns
63066306
6307static LLVMValueRef ir_render_panic(CodeGen *g, Stage1Air *executable, IrInstGenPanic *instruction) {6307static LLVMValueRef ir_render_panic(CodeGen *g, Stage1Air *executable, IrInstGenPanic *instruction) {
6308 bool is_llvm_alloca;6308 bool is_llvm_alloca;
6309 LLVMValueRef err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);6309 LLVMValueRef err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);
6310 gen_panic(g, ir_llvm_value(g, instruction->msg), err_ret_trace_val, is_llvm_alloca);6310 gen_panic(g, ir_llvm_value(g, instruction->msg), err_ret_trace_val, is_llvm_alloca);
6311 return nullptr;6311 return nullptr;
6312}6312}
...@@ -6619,7 +6619,7 @@ static LLVMValueRef ir_render_suspend_finish(CodeGen *g, Stage1Air *executable,...@@ -6619,7 +6619,7 @@ static LLVMValueRef ir_render_suspend_finish(CodeGen *g, Stage1Air *executable,
6619 if (ir_want_runtime_safety(g, &instruction->base)) {6619 if (ir_want_runtime_safety(g, &instruction->base)) {
6620 LLVMBuildStore(g->builder, g->cur_bad_not_suspended_index, g->cur_async_resume_index_ptr);6620 LLVMBuildStore(g->builder, g->cur_bad_not_suspended_index, g->cur_async_resume_index_ptr);
6621 }6621 }
6622 render_async_var_decls(g, instruction->base.base.scope);6622 render_async_var_decls(g, instruction->base.scope);
6623 return nullptr;6623 return nullptr;
6624}6624}
66256625
...@@ -6649,7 +6649,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstGen *source_instr,...@@ -6649,7 +6649,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstGen *source_instr,
6649 frame_index_trace_arg(g, result_type), "");6649 frame_index_trace_arg(g, result_type), "");
6650 LLVMValueRef src_trace_ptr = LLVMBuildLoad(g->builder, their_trace_ptr_ptr, "");6650 LLVMValueRef src_trace_ptr = LLVMBuildLoad(g->builder, their_trace_ptr_ptr, "");
6651 bool is_llvm_alloca;6651 bool is_llvm_alloca;
6652 LLVMValueRef dest_trace_ptr = get_cur_err_ret_trace_val(g, source_instr->base.scope, &is_llvm_alloca);6652 LLVMValueRef dest_trace_ptr = get_cur_err_ret_trace_val(g, source_instr->scope, &is_llvm_alloca);
6653 LLVMValueRef args[] = { dest_trace_ptr, src_trace_ptr };6653 LLVMValueRef args[] = { dest_trace_ptr, src_trace_ptr };
6654 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,6654 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,
6655 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");6655 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
...@@ -6701,7 +6701,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, Stage1Air *executable, IrInstGen...@@ -6701,7 +6701,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, Stage1Air *executable, IrInstGen
6701 // supply the error return trace pointer6701 // supply the error return trace pointer
6702 if (codegen_fn_has_err_ret_tracing_arg(g, result_type)) {6702 if (codegen_fn_has_err_ret_tracing_arg(g, result_type)) {
6703 bool is_llvm_alloca;6703 bool is_llvm_alloca;
6704 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);6704 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);
6705 assert(my_err_ret_trace_val != nullptr);6705 assert(my_err_ret_trace_val != nullptr);
6706 LLVMValueRef err_ret_trace_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr,6706 LLVMValueRef err_ret_trace_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr,
6707 frame_index_trace_arg(g, result_type) + 1, "");6707 frame_index_trace_arg(g, result_type) + 1, "");
...@@ -6810,8 +6810,8 @@ static LLVMValueRef ir_render_vector_extract_elem(CodeGen *g, Stage1Air *executa...@@ -6810,8 +6810,8 @@ static LLVMValueRef ir_render_vector_extract_elem(CodeGen *g, Stage1Air *executa
6810}6810}
68116811
6812static void set_debug_location(CodeGen *g, IrInstGen *instruction) {6812static void set_debug_location(CodeGen *g, IrInstGen *instruction) {
6813 AstNode *source_node = instruction->base.source_node;6813 AstNode *source_node = instruction->source_node;
6814 Scope *scope = instruction->base.scope;6814 Scope *scope = instruction->scope;
68156815
6816 assert(source_node);6816 assert(source_node);
6817 assert(scope);6817 assert(scope);
...@@ -7020,9 +7020,9 @@ static void ir_render(CodeGen *g, ZigFn *fn_entry) {...@@ -7020,9 +7020,9 @@ static void ir_render(CodeGen *g, ZigFn *fn_entry) {
7020 LLVMPositionBuilderAtEnd(g->builder, current_block->llvm_block);7020 LLVMPositionBuilderAtEnd(g->builder, current_block->llvm_block);
7021 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {7021 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {
7022 IrInstGen *instruction = current_block->instruction_list.at(instr_i);7022 IrInstGen *instruction = current_block->instruction_list.at(instr_i);
7023 if (instruction->base.ref_count == 0 && !ir_inst_gen_has_side_effects(instruction))7023 if (instruction->ref_count == 0 && !ir_inst_gen_has_side_effects(instruction))
7024 continue;7024 continue;
7025 if (get_scope_typeof(instruction->base.scope) != nullptr)7025 if (get_scope_typeof(instruction->scope) != nullptr)
7026 continue;7026 continue;
70277027
7028 if (!g->strip_debug_symbols) {7028 if (!g->strip_debug_symbols) {
...@@ -8270,7 +8270,7 @@ static void do_code_gen(CodeGen *g) {...@@ -8270,7 +8270,7 @@ static void do_code_gen(CodeGen *g) {
8270 zig_unreachable();8270 zig_unreachable();
8271 if (!type_has_bits(g, child_type))8271 if (!type_has_bits(g, child_type))
8272 continue;8272 continue;
8273 if (instruction->base.base.ref_count == 0)8273 if (instruction->base.ref_count == 0)
8274 continue;8274 continue;
8275 if (instruction->base.value->special != ConstValSpecialRuntime) {8275 if (instruction->base.value->special != ConstValSpecialRuntime) {
8276 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=8276 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=
...@@ -8448,7 +8448,7 @@ static void do_code_gen(CodeGen *g) {...@@ -8448,7 +8448,7 @@ static void do_code_gen(CodeGen *g) {
84488448
8449 gen_init_stack_trace(g, trace_field_ptr, addrs_field_ptr);8449 gen_init_stack_trace(g, trace_field_ptr, addrs_field_ptr);
8450 }8450 }
8451 render_async_var_decls(g, entry_block->instruction_list.at(0)->base.scope);8451 render_async_var_decls(g, entry_block->instruction_list.at(0)->scope);
8452 } else {8452 } else {
8453 // create debug variable declarations for parameters8453 // create debug variable declarations for parameters
8454 // rely on the first variables in the variable_list being parameters.8454 // rely on the first variables in the variable_list being parameters.
src/stage1/ir.cpp+1893-1841
...@@ -50,6 +50,7 @@ struct IrAnalyze {...@@ -50,6 +50,7 @@ struct IrAnalyze {
50 size_t *backward_branch_count;50 size_t *backward_branch_count;
51 size_t *backward_branch_quota;51 size_t *backward_branch_quota;
52 ZigFn *fn;52 ZigFn *fn;
53 IrInstSrc *suspend_source_instr;
5354
54 // For the purpose of using in a debugger55 // For the purpose of using in a debugger
55 void dump();56 void dump();
...@@ -216,15 +217,14 @@ struct DbgIrBreakPoint {...@@ -216,15 +217,14 @@ struct DbgIrBreakPoint {
216};217};
217218
218static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type);219static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type);
219static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr,220static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, Scope *scope, AstNode *source_node,
220 IrInstGen *value, ZigType *expected_type);221 IrInstGen *value, ZigType *expected_type);
221static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst *source_instr, IrInstGen *ptr,222static IrInstGen *ir_get_deref(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *ptr,
222 ResultLoc *result_loc);223 ResultLoc *result_loc);
223static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,224static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
224 IrInst* source_instr, IrInstGen *container_ptr, IrInst *container_ptr_src,225 Scope *scope, AstNode *source_node, IrInstGen *container_ptr, AstNode *container_ptr_src,
225 ZigType *container_type, bool initializing);226 ZigType *container_type, bool initializing);
226static void ir_assert_gen_impl(bool ok, IrInstGen *source_instruction, const char *file, unsigned int line);227static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigVar *var);
227static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var);
228static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op);228static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op);
229static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);229static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);
230static ZigType *adjust_ptr_const(CodeGen *g, ZigType *ptr_type, bool is_const);230static ZigType *adjust_ptr_const(CodeGen *g, ZigType *ptr_type, bool is_const);
...@@ -233,53 +233,51 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou...@@ -233,53 +233,51 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
233static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val);233static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val);
234static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,234static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
235 ZigValue *out_val, ZigValue *ptr_val);235 ZigValue *out_val, ZigValue *ptr_val);
236static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr,236static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node,
237 IrInst *ptr_src, ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on,237 IrInstGen *ptr, AstNode *ptr_src, ZigType *dest_type, AstNode *dest_type_src,
238 bool keep_bigger_alignment);238 bool safety_check_on, bool keep_bigger_alignment);
239static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed);239static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed);
240static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);240static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);
241static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,241static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
242 ZigType *ptr_type);242 ZigType *ptr_type);
243static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,243static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
244 ZigType *dest_type);244 ZigType *dest_type);
245static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr,245static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInstSrc *suspend_source_instr,
246 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, bool allow_discard);246 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, bool allow_discard);
247static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr,247static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInstSrc *suspend_source_instr,
248 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, bool allow_discard);248 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, bool allow_discard);
249static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr,249static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, Scope *scope, AstNode *source_node,
250 IrInstGen *base_ptr, bool safety_check_on, bool initializing);250 IrInstGen *base_ptr, bool safety_check_on, bool initializing);
251static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr,251static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, Scope *scope, AstNode *source_node,
252 IrInstGen *base_ptr, bool safety_check_on, bool initializing);252 IrInstGen *base_ptr, bool safety_check_on, bool initializing);
253static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_instr,253static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, Scope *scope, AstNode *source_node,
254 IrInstGen *base_ptr, bool initializing);254 IrInstGen *base_ptr, bool initializing);
255static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,255static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node,
256 IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const);256 IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const);
257static void ir_reset_result(ResultLoc *result_loc);257static void ir_reset_result(ResultLoc *result_loc);
258static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_instr,258static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node,
259 TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing);259 TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing);
260static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,260static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
261 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type);261 Scope *scope, AstNode *source_node, IrInstGen *container_ptr, ZigType *container_type);
262static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value);262static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value);
263static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst *source_instr);263static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, AstNode *source_node);
264static IrInstGen *ir_const_undef(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty);264static IrInstGen *ir_const_undef(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ty);
265static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, IrInst* source_instruction,265static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, Scope *scope, AstNode *source_node,
266 AstNode *field_source_node, ZigType *union_type, Buf *field_name, IrInstGen *field_result_loc,266 AstNode *field_source_node, ZigType *union_type, Buf *field_name, IrInstGen *field_result_loc,
267 IrInstGen *result_loc);267 IrInstGen *result_loc);
268static IrInstGen *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInst* source_instr,268static IrInstGen *ir_analyze_struct_value_field_value(IrAnalyze *ira, Scope *scope, AstNode *source_node,
269 IrInstGen *struct_operand, TypeStructField *field);269 IrInstGen *struct_operand, TypeStructField *field);
270static bool value_cmp_numeric_val_any(ZigValue *left, Cmp predicate, ZigValue *right);270static bool value_cmp_numeric_val_any(ZigValue *left, Cmp predicate, ZigValue *right);
271static bool value_cmp_numeric_val_all(ZigValue *left, Cmp predicate, ZigValue *right);271static bool value_cmp_numeric_val_all(ZigValue *left, Cmp predicate, ZigValue *right);
272static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, TypeStructField *field);272static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, TypeStructField *field);
273static void value_to_bigfloat(BigFloat *out, ZigValue *val);273static void value_to_bigfloat(BigFloat *out, ZigValue *val);
274274
275static void ir_assert_impl(bool ok, IrInst *source_instruction, char const *file, unsigned int line) {275static void ir_assert_impl(bool ok, IrInstGen *source_instruction, char const *file, unsigned int line) {
276 if (ok) return;276 if (ok) return;
277 src_assert_impl(ok, source_instruction->source_node, file, line);277 src_assert_impl(ok, source_instruction->source_node, file, line);
278}278}
279279
280
281#define ir_assert(OK, SOURCE_INSTRUCTION) ir_assert_impl((OK), (SOURCE_INSTRUCTION), __FILE__, __LINE__)280#define ir_assert(OK, SOURCE_INSTRUCTION) ir_assert_impl((OK), (SOURCE_INSTRUCTION), __FILE__, __LINE__)
282#define ir_assert_gen(OK, SOURCE_INSTRUCTION) ir_assert_gen_impl((OK), (SOURCE_INSTRUCTION), __FILE__, __LINE__)
283281
284void destroy_instruction_gen(IrInstGen *inst) {282void destroy_instruction_gen(IrInstGen *inst) {
285 switch (inst->id) {283 switch (inst->id) {
...@@ -498,7 +496,7 @@ static void ira_deref(IrAnalyze *ira) {...@@ -498,7 +496,7 @@ static void ira_deref(IrAnalyze *ira) {
498 // destroy dangling IrInstGenConst496 // destroy dangling IrInstGenConst
499 for (size_t i = 0; i < ira->new_irb.constants.length; i += 1) {497 for (size_t i = 0; i < ira->new_irb.constants.length; i += 1) {
500 auto constant = ira->new_irb.constants.items[i];498 auto constant = ira->new_irb.constants.items[i];
501 if (constant->base.base.ref_count == 0 && !ir_inst_gen_has_side_effects(&constant->base))499 if (constant->base.ref_count == 0 && !ir_inst_gen_has_side_effects(&constant->base))
502 destroy_instruction_gen(&constant->base);500 destroy_instruction_gen(&constant->base);
503 }501 }
504 ira->new_irb.constants.deinit(&heap::c_allocator);502 ira->new_irb.constants.deinit(&heap::c_allocator);
...@@ -692,7 +690,7 @@ static bool instr_is_comptime(IrInstGen *instruction) {...@@ -692,7 +690,7 @@ static bool instr_is_comptime(IrInstGen *instruction) {
692690
693static void ir_ref_inst_gen(IrInstGen *instruction) {691static void ir_ref_inst_gen(IrInstGen *instruction) {
694 assert(instruction->id != IrInstGenIdInvalid);692 assert(instruction->id != IrInstGenIdInvalid);
695 instruction->base.ref_count += 1;693 instruction->ref_count += 1;
696}694}
697695
698static void create_result_ptr(CodeGen *codegen, ZigType *expected_type,696static void create_result_ptr(CodeGen *codegen, ZigType *expected_type,
...@@ -1108,9 +1106,9 @@ template<typename T>...@@ -1108,9 +1106,9 @@ template<typename T>
1108static T *ir_create_inst_gen(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {1106static T *ir_create_inst_gen(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
1109 T *special_instruction = heap::c_allocator.create<T>();1107 T *special_instruction = heap::c_allocator.create<T>();
1110 special_instruction->base.id = ir_inst_id(special_instruction);1108 special_instruction->base.id = ir_inst_id(special_instruction);
1111 special_instruction->base.base.scope = scope;1109 special_instruction->base.scope = scope;
1112 special_instruction->base.base.source_node = source_node;1110 special_instruction->base.source_node = source_node;
1113 special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec);1111 special_instruction->base.debug_id = exec_next_debug_id_gen(irb->exec);
1114 special_instruction->base.owner_bb = irb->current_basic_block;1112 special_instruction->base.owner_bb = irb->current_basic_block;
1115 special_instruction->base.value = irb->codegen->pass1_arena->create<ZigValue>();1113 special_instruction->base.value = irb->codegen->pass1_arena->create<ZigValue>();
1116 return special_instruction;1114 return special_instruction;
...@@ -1120,9 +1118,9 @@ template<typename T>...@@ -1120,9 +1118,9 @@ template<typename T>
1120static T *ir_create_inst_noval(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {1118static T *ir_create_inst_noval(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
1121 T *special_instruction = heap::c_allocator.create<T>();1119 T *special_instruction = heap::c_allocator.create<T>();
1122 special_instruction->base.id = ir_inst_id(special_instruction);1120 special_instruction->base.id = ir_inst_id(special_instruction);
1123 special_instruction->base.base.scope = scope;1121 special_instruction->base.scope = scope;
1124 special_instruction->base.base.source_node = source_node;1122 special_instruction->base.source_node = source_node;
1125 special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec);1123 special_instruction->base.debug_id = exec_next_debug_id_gen(irb->exec);
1126 special_instruction->base.owner_bb = irb->current_basic_block;1124 special_instruction->base.owner_bb = irb->current_basic_block;
1127 return special_instruction;1125 return special_instruction;
1128}1126}
...@@ -1155,20 +1153,20 @@ IrInstGen *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigF...@@ -1155,20 +1153,20 @@ IrInstGen *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigF
1155{1153{
1156 IrInstGenAlloca *alloca_gen = heap::c_allocator.create<IrInstGenAlloca>();1154 IrInstGenAlloca *alloca_gen = heap::c_allocator.create<IrInstGenAlloca>();
1157 alloca_gen->base.id = IrInstGenIdAlloca;1155 alloca_gen->base.id = IrInstGenIdAlloca;
1158 alloca_gen->base.base.source_node = source_node;1156 alloca_gen->base.source_node = source_node;
1159 alloca_gen->base.base.scope = scope;1157 alloca_gen->base.scope = scope;
1160 alloca_gen->base.value = g->pass1_arena->create<ZigValue>();1158 alloca_gen->base.value = g->pass1_arena->create<ZigValue>();
1161 alloca_gen->base.value->type = get_pointer_to_type(g, var_type, false);1159 alloca_gen->base.value->type = get_pointer_to_type(g, var_type, false);
1162 alloca_gen->base.base.ref_count = 1;1160 alloca_gen->base.ref_count = 1;
1163 alloca_gen->name_hint = name_hint;1161 alloca_gen->name_hint = name_hint;
1164 fn->alloca_gen_list.append(alloca_gen);1162 fn->alloca_gen_list.append(alloca_gen);
1165 return &alloca_gen->base;1163 return &alloca_gen->base;
1166}1164}
11671165
1168static IrInstGen *ir_build_cast(IrAnalyze *ira, IrInst *source_instr,ZigType *dest_type,1166static IrInstGen *ir_build_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1169 IrInstGen *value, CastOp cast_op)1167 ZigType *dest_type, IrInstGen *value, CastOp cast_op)
1170{1168{
1171 IrInstGenCast *inst = ir_build_inst_gen<IrInstGenCast>(&ira->new_irb, source_instr->scope, source_instr->source_node);1169 IrInstGenCast *inst = ir_build_inst_gen<IrInstGenCast>(&ira->new_irb, scope, source_node);
1172 inst->base.value->type = dest_type;1170 inst->base.value->type = dest_type;
1173 inst->value = value;1171 inst->value = value;
1174 inst->cast_op = cast_op;1172 inst->cast_op = cast_op;
...@@ -1178,10 +1176,10 @@ static IrInstGen *ir_build_cast(IrAnalyze *ira, IrInst *source_instr,ZigType *de...@@ -1178,10 +1176,10 @@ static IrInstGen *ir_build_cast(IrAnalyze *ira, IrInst *source_instr,ZigType *de
1178 return &inst->base;1176 return &inst->base;
1179}1177}
11801178
1181static IrInstGen *ir_build_cond_br_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *condition,1179static IrInstGen *ir_build_cond_br_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *condition,
1182 IrBasicBlockGen *then_block, IrBasicBlockGen *else_block)1180 IrBasicBlockGen *then_block, IrBasicBlockGen *else_block)
1183{1181{
1184 IrInstGenCondBr *inst = ir_build_inst_noreturn<IrInstGenCondBr>(&ira->new_irb, source_instr->scope, source_instr->source_node);1182 IrInstGenCondBr *inst = ir_build_inst_noreturn<IrInstGenCondBr>(&ira->new_irb, scope, source_node);
1185 inst->condition = condition;1183 inst->condition = condition;
1186 inst->then_block = then_block;1184 inst->then_block = then_block;
1187 inst->else_block = else_block;1185 inst->else_block = else_block;
...@@ -1191,9 +1189,8 @@ static IrInstGen *ir_build_cond_br_gen(IrAnalyze *ira, IrInst *source_instr, IrI...@@ -1191,9 +1189,8 @@ static IrInstGen *ir_build_cond_br_gen(IrAnalyze *ira, IrInst *source_instr, IrI
1191 return &inst->base;1189 return &inst->base;
1192}1190}
11931191
1194static IrInstGen *ir_build_return_gen(IrAnalyze *ira, IrInst *source_inst, IrInstGen *operand) {1192static IrInstGen *ir_build_return_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *operand) {
1195 IrInstGenReturn *inst = ir_build_inst_noreturn<IrInstGenReturn>(&ira->new_irb,1193 IrInstGenReturn *inst = ir_build_inst_noreturn<IrInstGenReturn>(&ira->new_irb, scope, source_node);
1196 source_inst->scope, source_inst->source_node);
1197 inst->operand = operand;1194 inst->operand = operand;
11981195
1199 if (operand != nullptr) ir_ref_inst_gen(operand);1196 if (operand != nullptr) ir_ref_inst_gen(operand);
...@@ -1201,11 +1198,11 @@ static IrInstGen *ir_build_return_gen(IrAnalyze *ira, IrInst *source_inst, IrIns...@@ -1201,11 +1198,11 @@ static IrInstGen *ir_build_return_gen(IrAnalyze *ira, IrInst *source_inst, IrIns
1201 return &inst->base;1198 return &inst->base;
1202}1199}
12031200
1204static IrInstGen *ir_build_bin_op_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *res_type,1201static IrInstGen *ir_build_bin_op_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *res_type,
1205 IrBinOp op_id, IrInstGen *op1, IrInstGen *op2, bool safety_check_on)1202 IrBinOp op_id, IrInstGen *op1, IrInstGen *op2, bool safety_check_on)
1206{1203{
1207 IrInstGenBinOp *inst = ir_build_inst_gen<IrInstGenBinOp>(&ira->new_irb,1204 IrInstGenBinOp *inst = ir_build_inst_gen<IrInstGenBinOp>(&ira->new_irb,
1208 source_instr->scope, source_instr->source_node);1205 scope, source_node);
1209 inst->base.value->type = res_type;1206 inst->base.value->type = res_type;
1210 inst->op_id = op_id;1207 inst->op_id = op_id;
1211 inst->op1 = op1;1208 inst->op1 = op1;
...@@ -1219,8 +1216,8 @@ static IrInstGen *ir_build_bin_op_gen(IrAnalyze *ira, IrInst *source_instr, ZigT...@@ -1219,8 +1216,8 @@ static IrInstGen *ir_build_bin_op_gen(IrAnalyze *ira, IrInst *source_instr, ZigT
1219}1216}
12201217
12211218
1222static IrInstGen *ir_build_var_ptr_gen(IrAnalyze *ira, IrInst *source_instr, ZigVar *var) {1219static IrInstGen *ir_build_var_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigVar *var) {
1223 IrInstGenVarPtr *instruction = ir_build_inst_gen<IrInstGenVarPtr>(&ira->new_irb, source_instr->scope, source_instr->source_node);1220 IrInstGenVarPtr *instruction = ir_build_inst_gen<IrInstGenVarPtr>(&ira->new_irb, scope, source_node);
1224 instruction->var = var;1221 instruction->var = var;
12251222
1226 var->ref_count += 1;1223 var->ref_count += 1;
...@@ -1249,10 +1246,10 @@ static IrInstGen *ir_build_elem_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *s...@@ -1249,10 +1246,10 @@ static IrInstGen *ir_build_elem_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *s
1249 return &instruction->base;1246 return &instruction->base;
1250}1247}
12511248
1252static IrInstGen *ir_build_struct_field_ptr(IrAnalyze *ira, IrInst *source_instr,1249static IrInstGen *ir_build_struct_field_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1253 IrInstGen *struct_ptr, TypeStructField *field, ZigType *ptr_type)1250 IrInstGen *struct_ptr, TypeStructField *field, ZigType *ptr_type)
1254{1251{
1255 IrInstGenStructFieldPtr *inst = ir_build_inst_gen<IrInstGenStructFieldPtr>(&ira->new_irb, source_instr->scope, source_instr->source_node);1252 IrInstGenStructFieldPtr *inst = ir_build_inst_gen<IrInstGenStructFieldPtr>(&ira->new_irb, scope, source_node);
1256 inst->base.value->type = ptr_type;1253 inst->base.value->type = ptr_type;
1257 inst->struct_ptr = struct_ptr;1254 inst->struct_ptr = struct_ptr;
1258 inst->field = field;1255 inst->field = field;
...@@ -1262,11 +1259,11 @@ static IrInstGen *ir_build_struct_field_ptr(IrAnalyze *ira, IrInst *source_instr...@@ -1262,11 +1259,11 @@ static IrInstGen *ir_build_struct_field_ptr(IrAnalyze *ira, IrInst *source_instr
1262 return &inst->base;1259 return &inst->base;
1263}1260}
12641261
1265static IrInstGen *ir_build_union_field_ptr(IrAnalyze *ira, IrInst *source_instr,1262static IrInstGen *ir_build_union_field_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1266 IrInstGen *union_ptr, TypeUnionField *field, bool safety_check_on, bool initializing, ZigType *ptr_type)1263 IrInstGen *union_ptr, TypeUnionField *field, bool safety_check_on, bool initializing, ZigType *ptr_type)
1267{1264{
1268 IrInstGenUnionFieldPtr *inst = ir_build_inst_gen<IrInstGenUnionFieldPtr>(&ira->new_irb,1265 IrInstGenUnionFieldPtr *inst = ir_build_inst_gen<IrInstGenUnionFieldPtr>(&ira->new_irb,
1269 source_instr->scope, source_instr->source_node);1266 scope, source_node);
1270 inst->base.value->type = ptr_type;1267 inst->base.value->type = ptr_type;
1271 inst->initializing = initializing;1268 inst->initializing = initializing;
1272 inst->safety_check_on = safety_check_on;1269 inst->safety_check_on = safety_check_on;
...@@ -1278,13 +1275,13 @@ static IrInstGen *ir_build_union_field_ptr(IrAnalyze *ira, IrInst *source_instr,...@@ -1278,13 +1275,13 @@ static IrInstGen *ir_build_union_field_ptr(IrAnalyze *ira, IrInst *source_instr,
1278 return &inst->base;1275 return &inst->base;
1279}1276}
12801277
1281static IrInstGenCall *ir_build_call_gen(IrAnalyze *ira, IrInst *source_instruction,1278static IrInstGenCall *ir_build_call_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1282 ZigFn *fn_entry, IrInstGen *fn_ref, size_t arg_count, IrInstGen **args,1279 ZigFn *fn_entry, IrInstGen *fn_ref, size_t arg_count, IrInstGen **args,
1283 CallModifier modifier, IrInstGen *new_stack, bool is_async_call_builtin,1280 CallModifier modifier, IrInstGen *new_stack, bool is_async_call_builtin,
1284 IrInstGen *result_loc, ZigType *return_type)1281 IrInstGen *result_loc, ZigType *return_type)
1285{1282{
1286 IrInstGenCall *call_instruction = ir_build_inst_gen<IrInstGenCall>(&ira->new_irb,1283 IrInstGenCall *call_instruction = ir_build_inst_gen<IrInstGenCall>(&ira->new_irb,
1287 source_instruction->scope, source_instruction->source_node);1284 scope, source_node);
1288 call_instruction->base.value->type = return_type;1285 call_instruction->base.value->type = return_type;
1289 call_instruction->fn_entry = fn_entry;1286 call_instruction->fn_entry = fn_entry;
1290 call_instruction->fn_ref = fn_ref;1287 call_instruction->fn_ref = fn_ref;
...@@ -1304,14 +1301,14 @@ static IrInstGenCall *ir_build_call_gen(IrAnalyze *ira, IrInst *source_instructi...@@ -1304,14 +1301,14 @@ static IrInstGenCall *ir_build_call_gen(IrAnalyze *ira, IrInst *source_instructi
1304 return call_instruction;1301 return call_instruction;
1305}1302}
13061303
1307static IrInstGen *ir_build_phi_gen(IrAnalyze *ira, IrInst *source_instr, size_t incoming_count,1304static IrInstGen *ir_build_phi_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, size_t incoming_count,
1308 IrBasicBlockGen **incoming_blocks, IrInstGen **incoming_values, ZigType *result_type)1305 IrBasicBlockGen **incoming_blocks, IrInstGen **incoming_values, ZigType *result_type)
1309{1306{
1310 assert(incoming_count != 0);1307 assert(incoming_count != 0);
1311 assert(incoming_count != SIZE_MAX);1308 assert(incoming_count != SIZE_MAX);
13121309
1313 IrInstGenPhi *phi_instruction = ir_build_inst_gen<IrInstGenPhi>(&ira->new_irb,1310 IrInstGenPhi *phi_instruction = ir_build_inst_gen<IrInstGenPhi>(&ira->new_irb,
1314 source_instr->scope, source_instr->source_node);1311 scope, source_node);
1315 phi_instruction->base.value->type = result_type;1312 phi_instruction->base.value->type = result_type;
1316 phi_instruction->incoming_count = incoming_count;1313 phi_instruction->incoming_count = incoming_count;
1317 phi_instruction->incoming_blocks = incoming_blocks;1314 phi_instruction->incoming_blocks = incoming_blocks;
...@@ -1324,16 +1321,16 @@ static IrInstGen *ir_build_phi_gen(IrAnalyze *ira, IrInst *source_instr, size_t...@@ -1324,16 +1321,16 @@ static IrInstGen *ir_build_phi_gen(IrAnalyze *ira, IrInst *source_instr, size_t
1324 return &phi_instruction->base;1321 return &phi_instruction->base;
1325}1322}
13261323
1327static IrInstGen *ir_build_br_gen(IrAnalyze *ira, IrInst *source_instr, IrBasicBlockGen *dest_block) {1324static IrInstGen *ir_build_br_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrBasicBlockGen *dest_block) {
1328 IrInstGenBr *inst = ir_build_inst_noreturn<IrInstGenBr>(&ira->new_irb, source_instr->scope, source_instr->source_node);1325 IrInstGenBr *inst = ir_build_inst_noreturn<IrInstGenBr>(&ira->new_irb, scope, source_node);
1329 inst->dest_block = dest_block;1326 inst->dest_block = dest_block;
13301327
1331 return &inst->base;1328 return &inst->base;
1332}1329}
13331330
1334static IrInstGen *ir_build_negation(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, ZigType *expr_type, bool wrapping) {1331static IrInstGen *ir_build_negation(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *operand, ZigType *expr_type, bool wrapping) {
1335 IrInstGenNegation *instruction = ir_build_inst_gen<IrInstGenNegation>(&ira->new_irb,1332 IrInstGenNegation *instruction = ir_build_inst_gen<IrInstGenNegation>(&ira->new_irb,
1336 source_instr->scope, source_instr->source_node);1333 scope, source_node);
1337 instruction->base.value->type = expr_type;1334 instruction->base.value->type = expr_type;
1338 instruction->operand = operand;1335 instruction->operand = operand;
1339 instruction->wrapping = wrapping;1336 instruction->wrapping = wrapping;
...@@ -1343,11 +1340,11 @@ static IrInstGen *ir_build_negation(IrAnalyze *ira, IrInst *source_instr, IrInst...@@ -1343,11 +1340,11 @@ static IrInstGen *ir_build_negation(IrAnalyze *ira, IrInst *source_instr, IrInst
1343 return &instruction->base;1340 return &instruction->base;
1344}1341}
13451342
1346static IrInstGen *ir_build_binary_not(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,1343static IrInstGen *ir_build_binary_not(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *operand,
1347 ZigType *expr_type)1344 ZigType *expr_type)
1348{1345{
1349 IrInstGenBinaryNot *instruction = ir_build_inst_gen<IrInstGenBinaryNot>(&ira->new_irb,1346 IrInstGenBinaryNot *instruction = ir_build_inst_gen<IrInstGenBinaryNot>(&ira->new_irb,
1350 source_instr->scope, source_instr->source_node);1347 scope, source_node);
1351 instruction->base.value->type = expr_type;1348 instruction->base.value->type = expr_type;
1352 instruction->operand = operand;1349 instruction->operand = operand;
13531350
...@@ -1356,14 +1353,14 @@ static IrInstGen *ir_build_binary_not(IrAnalyze *ira, IrInst *source_instr, IrIn...@@ -1356,14 +1353,14 @@ static IrInstGen *ir_build_binary_not(IrAnalyze *ira, IrInst *source_instr, IrIn
1356 return &instruction->base;1353 return &instruction->base;
1357}1354}
13581355
1359static IrInstGen *ir_build_unreachable_gen(IrAnalyze *ira, IrInst *source_instr) {1356static IrInstGen *ir_build_unreachable_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node) {
1360 IrInstGenUnreachable *inst = ir_build_inst_noreturn<IrInstGenUnreachable>(&ira->new_irb, source_instr->scope, source_instr->source_node);1357 IrInstGenUnreachable *inst = ir_build_inst_noreturn<IrInstGenUnreachable>(&ira->new_irb, scope, source_node);
1361 return &inst->base;1358 return &inst->base;
1362}1359}
13631360
1364static IrInstGen *ir_build_store_ptr_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *ptr, IrInstGen *value) {1361static IrInstGen *ir_build_store_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *ptr, IrInstGen *value) {
1365 IrInstGenStorePtr *instruction = ir_build_inst_void<IrInstGenStorePtr>(&ira->new_irb,1362 IrInstGenStorePtr *instruction = ir_build_inst_void<IrInstGenStorePtr>(&ira->new_irb,
1366 source_instr->scope, source_instr->source_node);1363 scope, source_node);
1367 instruction->ptr = ptr;1364 instruction->ptr = ptr;
1368 instruction->value = value;1365 instruction->value = value;
13691366
...@@ -1373,11 +1370,11 @@ static IrInstGen *ir_build_store_ptr_gen(IrAnalyze *ira, IrInst *source_instr, I...@@ -1373,11 +1370,11 @@ static IrInstGen *ir_build_store_ptr_gen(IrAnalyze *ira, IrInst *source_instr, I
1373 return &instruction->base;1370 return &instruction->base;
1374}1371}
13751372
1376static IrInstGen *ir_build_vector_store_elem(IrAnalyze *ira, IrInst *src_inst,1373static IrInstGen *ir_build_vector_store_elem(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1377 IrInstGen *vector_ptr, IrInstGen *index, IrInstGen *value)1374 IrInstGen *vector_ptr, IrInstGen *index, IrInstGen *value)
1378{1375{
1379 IrInstGenVectorStoreElem *inst = ir_build_inst_void<IrInstGenVectorStoreElem>(1376 IrInstGenVectorStoreElem *inst = ir_build_inst_void<IrInstGenVectorStoreElem>(
1380 &ira->new_irb, src_inst->scope, src_inst->source_node);1377 &ira->new_irb, scope, source_node);
1381 inst->vector_ptr = vector_ptr;1378 inst->vector_ptr = vector_ptr;
1382 inst->index = index;1379 inst->index = index;
1383 inst->value = value;1380 inst->value = value;
...@@ -1389,11 +1386,11 @@ static IrInstGen *ir_build_vector_store_elem(IrAnalyze *ira, IrInst *src_inst,...@@ -1389,11 +1386,11 @@ static IrInstGen *ir_build_vector_store_elem(IrAnalyze *ira, IrInst *src_inst,
1389 return &inst->base;1386 return &inst->base;
1390}1387}
13911388
1392static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, IrInst *source_instruction,1389static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1393 ZigVar *var, IrInstGen *var_ptr)1390 ZigVar *var, IrInstGen *var_ptr)
1394{1391{
1395 IrInstGenDeclVar *inst = ir_build_inst_gen<IrInstGenDeclVar>(&ira->new_irb,1392 IrInstGenDeclVar *inst = ir_build_inst_gen<IrInstGenDeclVar>(&ira->new_irb,
1396 source_instruction->scope, source_instruction->source_node);1393 scope, source_node);
1397 inst->base.value->special = ConstValSpecialStatic;1394 inst->base.value->special = ConstValSpecialStatic;
1398 inst->base.value->type = ira->codegen->builtin_types.entry_void;1395 inst->base.value->type = ira->codegen->builtin_types.entry_void;
1399 inst->var = var;1396 inst->var = var;
...@@ -1404,11 +1401,11 @@ static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, IrInst *source_instructi...@@ -1404,11 +1401,11 @@ static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, IrInst *source_instructi
1404 return &inst->base;1401 return &inst->base;
1405}1402}
14061403
1407static IrInstGen *ir_build_extern_gen(IrAnalyze *ira, IrInst *source_instr, Buf *name,1404static IrInstGen *ir_build_extern_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, Buf *name,
1408 GlobalLinkageId linkage, bool is_thread_local, ZigType *expr_type)1405 GlobalLinkageId linkage, bool is_thread_local, ZigType *expr_type)
1409{1406{
1410 IrInstGenExtern *instruction = ir_build_inst_gen<IrInstGenExtern>(&ira->new_irb,1407 IrInstGenExtern *instruction = ir_build_inst_gen<IrInstGenExtern>(&ira->new_irb,
1411 source_instr->scope, source_instr->source_node);1408 scope, source_node);
1412 instruction->base.value->type = expr_type;1409 instruction->base.value->type = expr_type;
1413 instruction->name = name;1410 instruction->name = name;
1414 instruction->linkage = linkage;1411 instruction->linkage = linkage;
...@@ -1417,11 +1414,11 @@ static IrInstGen *ir_build_extern_gen(IrAnalyze *ira, IrInst *source_instr, Buf...@@ -1417,11 +1414,11 @@ static IrInstGen *ir_build_extern_gen(IrAnalyze *ira, IrInst *source_instr, Buf
1417 return &instruction->base;1414 return &instruction->base;
1418}1415}
14191416
1420static IrInstGen *ir_build_load_ptr_gen(IrAnalyze *ira, IrInst *source_instruction,1417static IrInstGen *ir_build_load_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1421 IrInstGen *ptr, ZigType *ty, IrInstGen *result_loc)1418 IrInstGen *ptr, ZigType *ty, IrInstGen *result_loc)
1422{1419{
1423 IrInstGenLoadPtr *instruction = ir_build_inst_gen<IrInstGenLoadPtr>(1420 IrInstGenLoadPtr *instruction = ir_build_inst_gen<IrInstGenLoadPtr>(
1424 &ira->new_irb, source_instruction->scope, source_instruction->source_node);1421 &ira->new_irb, scope, source_node);
1425 instruction->base.value->type = ty;1422 instruction->base.value->type = ty;
1426 instruction->ptr = ptr;1423 instruction->ptr = ptr;
1427 instruction->result_loc = result_loc;1424 instruction->result_loc = result_loc;
...@@ -1432,12 +1429,12 @@ static IrInstGen *ir_build_load_ptr_gen(IrAnalyze *ira, IrInst *source_instructi...@@ -1432,12 +1429,12 @@ static IrInstGen *ir_build_load_ptr_gen(IrAnalyze *ira, IrInst *source_instructi
1432 return &instruction->base;1429 return &instruction->base;
1433}1430}
14341431
1435static IrInstGen *ir_build_asm_gen(IrAnalyze *ira, IrInst *source_instr,1432static IrInstGen *ir_build_asm_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1436 Buf *asm_template, AsmToken *token_list, size_t token_list_len,1433 Buf *asm_template, AsmToken *token_list, size_t token_list_len,
1437 IrInstGen **input_list, IrInstGen **output_types, ZigVar **output_vars, size_t return_count,1434 IrInstGen **input_list, IrInstGen **output_types, ZigVar **output_vars, size_t return_count,
1438 bool has_side_effects, ZigType *return_type)1435 bool has_side_effects, ZigType *return_type)
1439{1436{
1440 IrInstGenAsm *instruction = ir_build_inst_gen<IrInstGenAsm>(&ira->new_irb, source_instr->scope, source_instr->source_node);1437 IrInstGenAsm *instruction = ir_build_inst_gen<IrInstGenAsm>(&ira->new_irb, scope, source_node);
1441 instruction->base.value->type = return_type;1438 instruction->base.value->type = return_type;
1442 instruction->asm_template = asm_template;1439 instruction->asm_template = asm_template;
1443 instruction->token_list = token_list;1440 instruction->token_list = token_list;
...@@ -1448,13 +1445,13 @@ static IrInstGen *ir_build_asm_gen(IrAnalyze *ira, IrInst *source_instr,...@@ -1448,13 +1445,13 @@ static IrInstGen *ir_build_asm_gen(IrAnalyze *ira, IrInst *source_instr,
1448 instruction->return_count = return_count;1445 instruction->return_count = return_count;
1449 instruction->has_side_effects = has_side_effects;1446 instruction->has_side_effects = has_side_effects;
14501447
1451 assert(source_instr->source_node->type == NodeTypeAsmExpr);1448 assert(source_node->type == NodeTypeAsmExpr);
1452 for (size_t i = 0; i < source_instr->source_node->data.asm_expr.output_list.length; i += 1) {1449 for (size_t i = 0; i < source_node->data.asm_expr.output_list.length; i += 1) {
1453 IrInstGen *output_type = output_types[i];1450 IrInstGen *output_type = output_types[i];
1454 if (output_type) ir_ref_inst_gen(output_type);1451 if (output_type) ir_ref_inst_gen(output_type);
1455 }1452 }
14561453
1457 for (size_t i = 0; i < source_instr->source_node->data.asm_expr.input_list.length; i += 1) {1454 for (size_t i = 0; i < source_node->data.asm_expr.input_list.length; i += 1) {
1458 IrInstGen *input_value = input_list[i];1455 IrInstGen *input_value = input_list[i];
1459 ir_ref_inst_gen(input_value);1456 ir_ref_inst_gen(input_value);
1460 }1457 }
...@@ -1462,9 +1459,9 @@ static IrInstGen *ir_build_asm_gen(IrAnalyze *ira, IrInst *source_instr,...@@ -1462,9 +1459,9 @@ static IrInstGen *ir_build_asm_gen(IrAnalyze *ira, IrInst *source_instr,
1462 return &instruction->base;1459 return &instruction->base;
1463}1460}
14641461
1465static IrInstGen *ir_build_test_non_null_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value) {1462static IrInstGen *ir_build_test_non_null_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value) {
1466 IrInstGenTestNonNull *inst = ir_build_inst_gen<IrInstGenTestNonNull>(&ira->new_irb,1463 IrInstGenTestNonNull *inst = ir_build_inst_gen<IrInstGenTestNonNull>(&ira->new_irb,
1467 source_instr->scope, source_instr->source_node);1464 scope, source_node);
1468 inst->base.value->type = ira->codegen->builtin_types.entry_bool;1465 inst->base.value->type = ira->codegen->builtin_types.entry_bool;
1469 inst->value = value;1466 inst->value = value;
14701467
...@@ -1473,11 +1470,11 @@ static IrInstGen *ir_build_test_non_null_gen(IrAnalyze *ira, IrInst *source_inst...@@ -1473,11 +1470,11 @@ static IrInstGen *ir_build_test_non_null_gen(IrAnalyze *ira, IrInst *source_inst
1473 return &inst->base;1470 return &inst->base;
1474}1471}
14751472
1476static IrInstGen *ir_build_optional_unwrap_ptr_gen(IrAnalyze *ira, IrInst *source_instr,1473static IrInstGen *ir_build_optional_unwrap_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1477 IrInstGen *base_ptr, bool safety_check_on, bool initializing, ZigType *result_type)1474 IrInstGen *base_ptr, bool safety_check_on, bool initializing, ZigType *result_type)
1478{1475{
1479 IrInstGenOptionalUnwrapPtr *inst = ir_build_inst_gen<IrInstGenOptionalUnwrapPtr>(&ira->new_irb,1476 IrInstGenOptionalUnwrapPtr *inst = ir_build_inst_gen<IrInstGenOptionalUnwrapPtr>(&ira->new_irb,
1480 source_instr->scope, source_instr->source_node);1477 scope, source_node);
1481 inst->base.value->type = result_type;1478 inst->base.value->type = result_type;
1482 inst->base_ptr = base_ptr;1479 inst->base_ptr = base_ptr;
1483 inst->safety_check_on = safety_check_on;1480 inst->safety_check_on = safety_check_on;
...@@ -1488,11 +1485,11 @@ static IrInstGen *ir_build_optional_unwrap_ptr_gen(IrAnalyze *ira, IrInst *sourc...@@ -1488,11 +1485,11 @@ static IrInstGen *ir_build_optional_unwrap_ptr_gen(IrAnalyze *ira, IrInst *sourc
1488 return &inst->base;1485 return &inst->base;
1489}1486}
14901487
1491static IrInstGen *ir_build_optional_wrap(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_ty,1488static IrInstGen *ir_build_optional_wrap(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_ty,
1492 IrInstGen *operand, IrInstGen *result_loc)1489 IrInstGen *operand, IrInstGen *result_loc)
1493{1490{
1494 IrInstGenOptionalWrap *instruction = ir_build_inst_gen<IrInstGenOptionalWrap>(1491 IrInstGenOptionalWrap *instruction = ir_build_inst_gen<IrInstGenOptionalWrap>(
1495 &ira->new_irb, source_instruction->scope, source_instruction->source_node);1492 &ira->new_irb, scope, source_node);
1496 instruction->base.value->type = result_ty;1493 instruction->base.value->type = result_ty;
1497 instruction->operand = operand;1494 instruction->operand = operand;
1498 instruction->result_loc = result_loc;1495 instruction->result_loc = result_loc;
...@@ -1503,11 +1500,11 @@ static IrInstGen *ir_build_optional_wrap(IrAnalyze *ira, IrInst *source_instruct...@@ -1503,11 +1500,11 @@ static IrInstGen *ir_build_optional_wrap(IrAnalyze *ira, IrInst *source_instruct
1503 return &instruction->base;1500 return &instruction->base;
1504}1501}
15051502
1506static IrInstGen *ir_build_err_wrap_payload(IrAnalyze *ira, IrInst *source_instruction,1503static IrInstGen *ir_build_err_wrap_payload(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1507 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)1504 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)
1508{1505{
1509 IrInstGenErrWrapPayload *instruction = ir_build_inst_gen<IrInstGenErrWrapPayload>(1506 IrInstGenErrWrapPayload *instruction = ir_build_inst_gen<IrInstGenErrWrapPayload>(
1510 &ira->new_irb, source_instruction->scope, source_instruction->source_node);1507 &ira->new_irb, scope, source_node);
1511 instruction->base.value->type = result_type;1508 instruction->base.value->type = result_type;
1512 instruction->operand = operand;1509 instruction->operand = operand;
1513 instruction->result_loc = result_loc;1510 instruction->result_loc = result_loc;
...@@ -1518,11 +1515,11 @@ static IrInstGen *ir_build_err_wrap_payload(IrAnalyze *ira, IrInst *source_instr...@@ -1518,11 +1515,11 @@ static IrInstGen *ir_build_err_wrap_payload(IrAnalyze *ira, IrInst *source_instr
1518 return &instruction->base;1515 return &instruction->base;
1519}1516}
15201517
1521static IrInstGen *ir_build_err_wrap_code(IrAnalyze *ira, IrInst *source_instruction,1518static IrInstGen *ir_build_err_wrap_code(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1522 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)1519 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)
1523{1520{
1524 IrInstGenErrWrapCode *instruction = ir_build_inst_gen<IrInstGenErrWrapCode>(1521 IrInstGenErrWrapCode *instruction = ir_build_inst_gen<IrInstGenErrWrapCode>(
1525 &ira->new_irb, source_instruction->scope, source_instruction->source_node);1522 &ira->new_irb, scope, source_node);
1526 instruction->base.value->type = result_type;1523 instruction->base.value->type = result_type;
1527 instruction->operand = operand;1524 instruction->operand = operand;
1528 instruction->result_loc = result_loc;1525 instruction->result_loc = result_loc;
...@@ -1533,9 +1530,9 @@ static IrInstGen *ir_build_err_wrap_code(IrAnalyze *ira, IrInst *source_instruct...@@ -1533,9 +1530,9 @@ static IrInstGen *ir_build_err_wrap_code(IrAnalyze *ira, IrInst *source_instruct
1533 return &instruction->base;1530 return &instruction->base;
1534}1531}
15351532
1536static IrInstGen *ir_build_clz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, IrInstGen *op) {1533static IrInstGen *ir_build_clz_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_type, IrInstGen *op) {
1537 IrInstGenClz *instruction = ir_build_inst_gen<IrInstGenClz>(&ira->new_irb,1534 IrInstGenClz *instruction = ir_build_inst_gen<IrInstGenClz>(&ira->new_irb,
1538 source_instr->scope, source_instr->source_node);1535 scope, source_node);
1539 instruction->base.value->type = result_type;1536 instruction->base.value->type = result_type;
1540 instruction->op = op;1537 instruction->op = op;
15411538
...@@ -1544,9 +1541,9 @@ static IrInstGen *ir_build_clz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType...@@ -1544,9 +1541,9 @@ static IrInstGen *ir_build_clz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType
1544 return &instruction->base;1541 return &instruction->base;
1545}1542}
15461543
1547static IrInstGen *ir_build_ctz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, IrInstGen *op) {1544static IrInstGen *ir_build_ctz_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_type, IrInstGen *op) {
1548 IrInstGenCtz *instruction = ir_build_inst_gen<IrInstGenCtz>(&ira->new_irb,1545 IrInstGenCtz *instruction = ir_build_inst_gen<IrInstGenCtz>(&ira->new_irb,
1549 source_instr->scope, source_instr->source_node);1546 scope, source_node);
1550 instruction->base.value->type = result_type;1547 instruction->base.value->type = result_type;
1551 instruction->op = op;1548 instruction->op = op;
15521549
...@@ -1555,11 +1552,11 @@ static IrInstGen *ir_build_ctz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType...@@ -1555,11 +1552,11 @@ static IrInstGen *ir_build_ctz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType
1555 return &instruction->base;1552 return &instruction->base;
1556}1553}
15571554
1558static IrInstGen *ir_build_pop_count_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type,1555static IrInstGen *ir_build_pop_count_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_type,
1559 IrInstGen *op)1556 IrInstGen *op)
1560{1557{
1561 IrInstGenPopCount *instruction = ir_build_inst_gen<IrInstGenPopCount>(&ira->new_irb,1558 IrInstGenPopCount *instruction = ir_build_inst_gen<IrInstGenPopCount>(&ira->new_irb,
1562 source_instr->scope, source_instr->source_node);1559 scope, source_node);
1563 instruction->base.value->type = result_type;1560 instruction->base.value->type = result_type;
1564 instruction->op = op;1561 instruction->op = op;
15651562
...@@ -1568,11 +1565,11 @@ static IrInstGen *ir_build_pop_count_gen(IrAnalyze *ira, IrInst *source_instr, Z...@@ -1568,11 +1565,11 @@ static IrInstGen *ir_build_pop_count_gen(IrAnalyze *ira, IrInst *source_instr, Z
1568 return &instruction->base;1565 return &instruction->base;
1569}1566}
15701567
1571static IrInstGen *ir_build_bswap_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *op_type,1568static IrInstGen *ir_build_bswap_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *op_type,
1572 IrInstGen *op)1569 IrInstGen *op)
1573{1570{
1574 IrInstGenBswap *instruction = ir_build_inst_gen<IrInstGenBswap>(&ira->new_irb,1571 IrInstGenBswap *instruction = ir_build_inst_gen<IrInstGenBswap>(&ira->new_irb,
1575 source_instr->scope, source_instr->source_node);1572 scope, source_node);
1576 instruction->base.value->type = op_type;1573 instruction->base.value->type = op_type;
1577 instruction->op = op;1574 instruction->op = op;
15781575
...@@ -1581,11 +1578,11 @@ static IrInstGen *ir_build_bswap_gen(IrAnalyze *ira, IrInst *source_instr, ZigTy...@@ -1581,11 +1578,11 @@ static IrInstGen *ir_build_bswap_gen(IrAnalyze *ira, IrInst *source_instr, ZigTy
1581 return &instruction->base;1578 return &instruction->base;
1582}1579}
15831580
1584static IrInstGen *ir_build_bit_reverse_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *int_type,1581static IrInstGen *ir_build_bit_reverse_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *int_type,
1585 IrInstGen *op)1582 IrInstGen *op)
1586{1583{
1587 IrInstGenBitReverse *instruction = ir_build_inst_gen<IrInstGenBitReverse>(&ira->new_irb,1584 IrInstGenBitReverse *instruction = ir_build_inst_gen<IrInstGenBitReverse>(&ira->new_irb,
1588 source_instr->scope, source_instr->source_node);1585 scope, source_node);
1589 instruction->base.value->type = int_type;1586 instruction->base.value->type = int_type;
1590 instruction->op = op;1587 instruction->op = op;
15911588
...@@ -1594,11 +1591,11 @@ static IrInstGen *ir_build_bit_reverse_gen(IrAnalyze *ira, IrInst *source_instr,...@@ -1594,11 +1591,11 @@ static IrInstGen *ir_build_bit_reverse_gen(IrAnalyze *ira, IrInst *source_instr,
1594 return &instruction->base;1591 return &instruction->base;
1595}1592}
15961593
1597static IrInstGenSwitchBr *ir_build_switch_br_gen(IrAnalyze *ira, IrInst *source_instr,1594static IrInstGenSwitchBr *ir_build_switch_br_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1598 IrInstGen *target_value, IrBasicBlockGen *else_block, size_t case_count, IrInstGenSwitchBrCase *cases)1595 IrInstGen *target_value, IrBasicBlockGen *else_block, size_t case_count, IrInstGenSwitchBrCase *cases)
1599{1596{
1600 IrInstGenSwitchBr *instruction = ir_build_inst_noreturn<IrInstGenSwitchBr>(&ira->new_irb,1597 IrInstGenSwitchBr *instruction = ir_build_inst_noreturn<IrInstGenSwitchBr>(&ira->new_irb,
1601 source_instr->scope, source_instr->source_node);1598 scope, source_node);
1602 instruction->target_value = target_value;1599 instruction->target_value = target_value;
1603 instruction->else_block = else_block;1600 instruction->else_block = else_block;
1604 instruction->case_count = case_count;1601 instruction->case_count = case_count;
...@@ -1613,11 +1610,11 @@ static IrInstGenSwitchBr *ir_build_switch_br_gen(IrAnalyze *ira, IrInst *source_...@@ -1613,11 +1610,11 @@ static IrInstGenSwitchBr *ir_build_switch_br_gen(IrAnalyze *ira, IrInst *source_
1613 return instruction;1610 return instruction;
1614}1611}
16151612
1616static IrInstGen *ir_build_union_tag(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,1613static IrInstGen *ir_build_union_tag(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
1617 ZigType *tag_type)1614 ZigType *tag_type)
1618{1615{
1619 IrInstGenUnionTag *instruction = ir_build_inst_gen<IrInstGenUnionTag>(&ira->new_irb,1616 IrInstGenUnionTag *instruction = ir_build_inst_gen<IrInstGenUnionTag>(&ira->new_irb,
1620 source_instr->scope, source_instr->source_node);1617 scope, source_node);
1621 instruction->value = value;1618 instruction->value = value;
1622 instruction->base.value->type = tag_type;1619 instruction->base.value->type = tag_type;
16231620
...@@ -1626,11 +1623,11 @@ static IrInstGen *ir_build_union_tag(IrAnalyze *ira, IrInst *source_instr, IrIns...@@ -1626,11 +1623,11 @@ static IrInstGen *ir_build_union_tag(IrAnalyze *ira, IrInst *source_instr, IrIns
1626 return &instruction->base;1623 return &instruction->base;
1627}1624}
16281625
1629static IrInstGen *ir_build_ref_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type,1626static IrInstGen *ir_build_ref_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_type,
1630 IrInstGen *operand, IrInstGen *result_loc)1627 IrInstGen *operand, IrInstGen *result_loc)
1631{1628{
1632 IrInstGenRef *instruction = ir_build_inst_gen<IrInstGenRef>(&ira->new_irb,1629 IrInstGenRef *instruction = ir_build_inst_gen<IrInstGenRef>(&ira->new_irb,
1633 source_instruction->scope, source_instruction->source_node);1630 scope, source_node);
1634 instruction->base.value->type = result_type;1631 instruction->base.value->type = result_type;
1635 instruction->operand = operand;1632 instruction->operand = operand;
1636 instruction->result_loc = result_loc;1633 instruction->result_loc = result_loc;
...@@ -1641,11 +1638,11 @@ static IrInstGen *ir_build_ref_gen(IrAnalyze *ira, IrInst *source_instruction, Z...@@ -1641,11 +1638,11 @@ static IrInstGen *ir_build_ref_gen(IrAnalyze *ira, IrInst *source_instruction, Z
1641 return &instruction->base;1638 return &instruction->base;
1642}1639}
16431640
1644static IrInstGen *ir_build_err_name_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,1641static IrInstGen *ir_build_err_name_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
1645 ZigType *str_type)1642 ZigType *str_type)
1646{1643{
1647 IrInstGenErrName *instruction = ir_build_inst_gen<IrInstGenErrName>(&ira->new_irb,1644 IrInstGenErrName *instruction = ir_build_inst_gen<IrInstGenErrName>(&ira->new_irb,
1648 source_instr->scope, source_instr->source_node);1645 scope, source_node);
1649 instruction->base.value->type = str_type;1646 instruction->base.value->type = str_type;
1650 instruction->value = value;1647 instruction->value = value;
16511648
...@@ -1654,12 +1651,12 @@ static IrInstGen *ir_build_err_name_gen(IrAnalyze *ira, IrInst *source_instr, Ir...@@ -1654,12 +1651,12 @@ static IrInstGen *ir_build_err_name_gen(IrAnalyze *ira, IrInst *source_instr, Ir
1654 return &instruction->base;1651 return &instruction->base;
1655}1652}
16561653
1657static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type,1654static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_type,
1658 IrInstGen *ptr, IrInstGen *cmp_value, IrInstGen *new_value,1655 IrInstGen *ptr, IrInstGen *cmp_value, IrInstGen *new_value,
1659 AtomicOrder success_order, AtomicOrder failure_order, bool is_weak, IrInstGen *result_loc)1656 AtomicOrder success_order, AtomicOrder failure_order, bool is_weak, IrInstGen *result_loc)
1660{1657{
1661 IrInstGenCmpxchg *instruction = ir_build_inst_gen<IrInstGenCmpxchg>(&ira->new_irb,1658 IrInstGenCmpxchg *instruction = ir_build_inst_gen<IrInstGenCmpxchg>(&ira->new_irb,
1662 source_instruction->scope, source_instruction->source_node);1659 scope, source_node);
1663 instruction->base.value->type = result_type;1660 instruction->base.value->type = result_type;
1664 instruction->ptr = ptr;1661 instruction->ptr = ptr;
1665 instruction->cmp_value = cmp_value;1662 instruction->cmp_value = cmp_value;
...@@ -1677,17 +1674,17 @@ static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInst *source_instructio...@@ -1677,17 +1674,17 @@ static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInst *source_instructio
1677 return &instruction->base;1674 return &instruction->base;
1678}1675}
16791676
1680static IrInstGen *ir_build_fence_gen(IrAnalyze *ira, IrInst *source_instr, AtomicOrder order) {1677static IrInstGen *ir_build_fence_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, AtomicOrder order) {
1681 IrInstGenFence *instruction = ir_build_inst_void<IrInstGenFence>(&ira->new_irb,1678 IrInstGenFence *instruction = ir_build_inst_void<IrInstGenFence>(&ira->new_irb,
1682 source_instr->scope, source_instr->source_node);1679 scope, source_node);
1683 instruction->order = order;1680 instruction->order = order;
16841681
1685 return &instruction->base;1682 return &instruction->base;
1686}1683}
16871684
1688static IrInstGen *ir_build_reduce_gen(IrAnalyze *ira, IrInst *source_instruction, ReduceOp op, IrInstGen *value, ZigType *result_type) {1685static IrInstGen *ir_build_reduce_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ReduceOp op, IrInstGen *value, ZigType *result_type) {
1689 IrInstGenReduce *instruction = ir_build_inst_gen<IrInstGenReduce>(&ira->new_irb,1686 IrInstGenReduce *instruction = ir_build_inst_gen<IrInstGenReduce>(&ira->new_irb,
1690 source_instruction->scope, source_instruction->source_node);1687 scope, source_node);
1691 instruction->base.value->type = result_type;1688 instruction->base.value->type = result_type;
1692 instruction->op = op;1689 instruction->op = op;
1693 instruction->value = value;1690 instruction->value = value;
...@@ -1713,23 +1710,23 @@ static void ir_set_cursor_at_end_and_append_block_gen(IrBuilderGen *irb, IrBasic...@@ -1713,23 +1710,23 @@ static void ir_set_cursor_at_end_and_append_block_gen(IrBuilderGen *irb, IrBasic
1713 ir_set_cursor_at_end_gen(irb, basic_block);1710 ir_set_cursor_at_end_gen(irb, basic_block);
1714}1711}
17151712
1716static IrInstGen *ir_build_suspend_begin_gen(IrAnalyze *ira, IrInst *source_instr) {1713static IrInstGen *ir_build_suspend_begin_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node) {
1717 IrInstGenSuspendBegin *inst = ir_build_inst_void<IrInstGenSuspendBegin>(&ira->new_irb,1714 IrInstGenSuspendBegin *inst = ir_build_inst_void<IrInstGenSuspendBegin>(&ira->new_irb,
1718 source_instr->scope, source_instr->source_node);1715 scope, source_node);
1719 return &inst->base;1716 return &inst->base;
1720}1717}
17211718
1722static IrInstGen *ir_build_save_err_ret_addr_gen(IrAnalyze *ira, IrInst *source_instr) {1719static IrInstGen *ir_build_save_err_ret_addr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node) {
1723 IrInstGenSaveErrRetAddr *inst = ir_build_inst_void<IrInstGenSaveErrRetAddr>(&ira->new_irb,1720 IrInstGenSaveErrRetAddr *inst = ir_build_inst_void<IrInstGenSaveErrRetAddr>(&ira->new_irb,
1724 source_instr->scope, source_instr->source_node);1721 scope, source_node);
1725 return &inst->base;1722 return &inst->base;
1726}1723}
17271724
1728static IrInstGen *ir_build_truncate_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *dest_type,1725static IrInstGen *ir_build_truncate_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *dest_type,
1729 IrInstGen *target)1726 IrInstGen *target)
1730{1727{
1731 IrInstGenTruncate *instruction = ir_build_inst_gen<IrInstGenTruncate>(&ira->new_irb,1728 IrInstGenTruncate *instruction = ir_build_inst_gen<IrInstGenTruncate>(&ira->new_irb,
1732 source_instr->scope, source_instr->source_node);1729 scope, source_node);
1733 instruction->base.value->type = dest_type;1730 instruction->base.value->type = dest_type;
1734 instruction->target = target;1731 instruction->target = target;
17351732
...@@ -1754,11 +1751,11 @@ static IrInstGen *ir_build_shuffle_vector_gen(IrAnalyze *ira, Scope *scope, AstN...@@ -1754,11 +1751,11 @@ static IrInstGen *ir_build_shuffle_vector_gen(IrAnalyze *ira, Scope *scope, AstN
1754 return &inst->base;1751 return &inst->base;
1755}1752}
17561753
1757static IrInstGen *ir_build_splat_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type,1754static IrInstGen *ir_build_splat_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_type,
1758 IrInstGen *scalar)1755 IrInstGen *scalar)
1759{1756{
1760 IrInstGenSplat *instruction = ir_build_inst_gen<IrInstGenSplat>(1757 IrInstGenSplat *instruction = ir_build_inst_gen<IrInstGenSplat>(
1761 &ira->new_irb, source_instruction->scope, source_instruction->source_node);1758 &ira->new_irb, scope, source_node);
1762 instruction->base.value->type = result_type;1759 instruction->base.value->type = result_type;
1763 instruction->scalar = scalar;1760 instruction->scalar = scalar;
17641761
...@@ -1767,9 +1764,9 @@ static IrInstGen *ir_build_splat_gen(IrAnalyze *ira, IrInst *source_instruction,...@@ -1767,9 +1764,9 @@ static IrInstGen *ir_build_splat_gen(IrAnalyze *ira, IrInst *source_instruction,
1767 return &instruction->base;1764 return &instruction->base;
1768}1765}
17691766
1770static IrInstGen *ir_build_bool_not_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value) {1767static IrInstGen *ir_build_bool_not_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value) {
1771 IrInstGenBoolNot *instruction = ir_build_inst_gen<IrInstGenBoolNot>(&ira->new_irb,1768 IrInstGenBoolNot *instruction = ir_build_inst_gen<IrInstGenBoolNot>(&ira->new_irb,
1772 source_instr->scope, source_instr->source_node);1769 scope, source_node);
1773 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;1770 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;
1774 instruction->value = value;1771 instruction->value = value;
17751772
...@@ -1778,11 +1775,11 @@ static IrInstGen *ir_build_bool_not_gen(IrAnalyze *ira, IrInst *source_instr, Ir...@@ -1778,11 +1775,11 @@ static IrInstGen *ir_build_bool_not_gen(IrAnalyze *ira, IrInst *source_instr, Ir
1778 return &instruction->base;1775 return &instruction->base;
1779}1776}
17801777
1781static IrInstGen *ir_build_memset_gen(IrAnalyze *ira, IrInst *source_instr,1778static IrInstGen *ir_build_memset_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1782 IrInstGen *dest_ptr, IrInstGen *byte, IrInstGen *count)1779 IrInstGen *dest_ptr, IrInstGen *byte, IrInstGen *count)
1783{1780{
1784 IrInstGenMemset *instruction = ir_build_inst_void<IrInstGenMemset>(&ira->new_irb,1781 IrInstGenMemset *instruction = ir_build_inst_void<IrInstGenMemset>(&ira->new_irb,
1785 source_instr->scope, source_instr->source_node);1782 scope, source_node);
1786 instruction->dest_ptr = dest_ptr;1783 instruction->dest_ptr = dest_ptr;
1787 instruction->byte = byte;1784 instruction->byte = byte;
1788 instruction->count = count;1785 instruction->count = count;
...@@ -1794,11 +1791,11 @@ static IrInstGen *ir_build_memset_gen(IrAnalyze *ira, IrInst *source_instr,...@@ -1794,11 +1791,11 @@ static IrInstGen *ir_build_memset_gen(IrAnalyze *ira, IrInst *source_instr,
1794 return &instruction->base;1791 return &instruction->base;
1795}1792}
17961793
1797static IrInstGen *ir_build_memcpy_gen(IrAnalyze *ira, IrInst *source_instr,1794static IrInstGen *ir_build_memcpy_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1798 IrInstGen *dest_ptr, IrInstGen *src_ptr, IrInstGen *count)1795 IrInstGen *dest_ptr, IrInstGen *src_ptr, IrInstGen *count)
1799{1796{
1800 IrInstGenMemcpy *instruction = ir_build_inst_void<IrInstGenMemcpy>(&ira->new_irb,1797 IrInstGenMemcpy *instruction = ir_build_inst_void<IrInstGenMemcpy>(&ira->new_irb,
1801 source_instr->scope, source_instr->source_node);1798 scope, source_node);
1802 instruction->dest_ptr = dest_ptr;1799 instruction->dest_ptr = dest_ptr;
1803 instruction->src_ptr = src_ptr;1800 instruction->src_ptr = src_ptr;
1804 instruction->count = count;1801 instruction->count = count;
...@@ -1810,12 +1807,12 @@ static IrInstGen *ir_build_memcpy_gen(IrAnalyze *ira, IrInst *source_instr,...@@ -1810,12 +1807,12 @@ static IrInstGen *ir_build_memcpy_gen(IrAnalyze *ira, IrInst *source_instr,
1810 return &instruction->base;1807 return &instruction->base;
1811}1808}
18121809
1813static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *slice_type,1810static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *slice_type,
1814 IrInstGen *ptr, IrInstGen *start, IrInstGen *end, bool safety_check_on, IrInstGen *result_loc,1811 IrInstGen *ptr, IrInstGen *start, IrInstGen *end, bool safety_check_on, IrInstGen *result_loc,
1815 ZigValue *sentinel)1812 ZigValue *sentinel)
1816{1813{
1817 IrInstGenSlice *instruction = ir_build_inst_gen<IrInstGenSlice>(1814 IrInstGenSlice *instruction = ir_build_inst_gen<IrInstGenSlice>(
1818 &ira->new_irb, source_instruction->scope, source_instruction->source_node);1815 &ira->new_irb, scope, source_node);
1819 instruction->base.value->type = slice_type;1816 instruction->base.value->type = slice_type;
1820 instruction->ptr = ptr;1817 instruction->ptr = ptr;
1821 instruction->start = start;1818 instruction->start = start;
...@@ -1832,33 +1829,33 @@ static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction,...@@ -1832,33 +1829,33 @@ static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction,
1832 return &instruction->base;1829 return &instruction->base;
1833}1830}
18341831
1835static IrInstGen *ir_build_breakpoint_gen(IrAnalyze *ira, IrInst *source_instr) {1832static IrInstGen *ir_build_breakpoint_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node) {
1836 IrInstGenBreakpoint *instruction = ir_build_inst_void<IrInstGenBreakpoint>(&ira->new_irb,1833 IrInstGenBreakpoint *instruction = ir_build_inst_void<IrInstGenBreakpoint>(&ira->new_irb,
1837 source_instr->scope, source_instr->source_node);1834 scope, source_node);
1838 return &instruction->base;1835 return &instruction->base;
1839}1836}
18401837
1841static IrInstGen *ir_build_return_address_gen(IrAnalyze *ira, IrInst *source_instr) {1838static IrInstGen *ir_build_return_address_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node) {
1842 IrInstGenReturnAddress *inst = ir_build_inst_gen<IrInstGenReturnAddress>(&ira->new_irb, source_instr->scope, source_instr->source_node);1839 IrInstGenReturnAddress *inst = ir_build_inst_gen<IrInstGenReturnAddress>(&ira->new_irb, scope, source_node);
1843 inst->base.value->type = ira->codegen->builtin_types.entry_usize;1840 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
1844 return &inst->base;1841 return &inst->base;
1845}1842}
18461843
1847static IrInstGen *ir_build_frame_address_gen(IrAnalyze *ira, IrInst *source_instr) {1844static IrInstGen *ir_build_frame_address_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node) {
1848 IrInstGenFrameAddress *inst = ir_build_inst_gen<IrInstGenFrameAddress>(&ira->new_irb, source_instr->scope, source_instr->source_node);1845 IrInstGenFrameAddress *inst = ir_build_inst_gen<IrInstGenFrameAddress>(&ira->new_irb, scope, source_node);
1849 inst->base.value->type = ira->codegen->builtin_types.entry_usize;1846 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
1850 return &inst->base;1847 return &inst->base;
1851}1848}
18521849
1853static IrInstGen *ir_build_handle_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *ty) {1850static IrInstGen *ir_build_handle_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ty) {
1854 IrInstGenFrameHandle *inst = ir_build_inst_gen<IrInstGenFrameHandle>(&ira->new_irb, source_instr->scope, source_instr->source_node);1851 IrInstGenFrameHandle *inst = ir_build_inst_gen<IrInstGenFrameHandle>(&ira->new_irb, scope, source_node);
1855 inst->base.value->type = ty;1852 inst->base.value->type = ty;
1856 return &inst->base;1853 return &inst->base;
1857}1854}
18581855
1859static IrInstGen *ir_build_frame_size_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *fn)1856static IrInstGen *ir_build_frame_size_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *fn)
1860{1857{
1861 IrInstGenFrameSize *inst = ir_build_inst_gen<IrInstGenFrameSize>(&ira->new_irb, source_instr->scope, source_instr->source_node);1858 IrInstGenFrameSize *inst = ir_build_inst_gen<IrInstGenFrameSize>(&ira->new_irb, scope, source_node);
1862 inst->base.value->type = ira->codegen->builtin_types.entry_usize;1859 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
1863 inst->fn = fn;1860 inst->fn = fn;
18641861
...@@ -1867,12 +1864,12 @@ static IrInstGen *ir_build_frame_size_gen(IrAnalyze *ira, IrInst *source_instr,...@@ -1867,12 +1864,12 @@ static IrInstGen *ir_build_frame_size_gen(IrAnalyze *ira, IrInst *source_instr,
1867 return &inst->base;1864 return &inst->base;
1868}1865}
18691866
1870static IrInstGen *ir_build_overflow_op_gen(IrAnalyze *ira, IrInst *source_instr,1867static IrInstGen *ir_build_overflow_op_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1871 IrOverflowOp op, IrInstGen *op1, IrInstGen *op2, IrInstGen *result_ptr,1868 IrOverflowOp op, IrInstGen *op1, IrInstGen *op2, IrInstGen *result_ptr,
1872 ZigType *result_ptr_type)1869 ZigType *result_ptr_type)
1873{1870{
1874 IrInstGenOverflowOp *instruction = ir_build_inst_gen<IrInstGenOverflowOp>(&ira->new_irb,1871 IrInstGenOverflowOp *instruction = ir_build_inst_gen<IrInstGenOverflowOp>(&ira->new_irb,
1875 source_instr->scope, source_instr->source_node);1872 scope, source_node);
1876 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;1873 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;
1877 instruction->op = op;1874 instruction->op = op;
1878 instruction->op1 = op1;1875 instruction->op1 = op1;
...@@ -1887,11 +1884,11 @@ static IrInstGen *ir_build_overflow_op_gen(IrAnalyze *ira, IrInst *source_instr,...@@ -1887,11 +1884,11 @@ static IrInstGen *ir_build_overflow_op_gen(IrAnalyze *ira, IrInst *source_instr,
1887 return &instruction->base;1884 return &instruction->base;
1888}1885}
18891886
1890static IrInstGen *ir_build_float_op_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,1887static IrInstGen *ir_build_float_op_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *operand,
1891 BuiltinFnId fn_id, ZigType *operand_type)1888 BuiltinFnId fn_id, ZigType *operand_type)
1892{1889{
1893 IrInstGenFloatOp *instruction = ir_build_inst_gen<IrInstGenFloatOp>(&ira->new_irb,1890 IrInstGenFloatOp *instruction = ir_build_inst_gen<IrInstGenFloatOp>(&ira->new_irb,
1894 source_instr->scope, source_instr->source_node);1891 scope, source_node);
1895 instruction->base.value->type = operand_type;1892 instruction->base.value->type = operand_type;
1896 instruction->operand = operand;1893 instruction->operand = operand;
1897 instruction->fn_id = fn_id;1894 instruction->fn_id = fn_id;
...@@ -1901,11 +1898,11 @@ static IrInstGen *ir_build_float_op_gen(IrAnalyze *ira, IrInst *source_instr, Ir...@@ -1901,11 +1898,11 @@ static IrInstGen *ir_build_float_op_gen(IrAnalyze *ira, IrInst *source_instr, Ir
1901 return &instruction->base;1898 return &instruction->base;
1902}1899}
19031900
1904static IrInstGen *ir_build_mul_add_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *op1, IrInstGen *op2,1901static IrInstGen *ir_build_mul_add_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *op1, IrInstGen *op2,
1905 IrInstGen *op3, ZigType *expr_type)1902 IrInstGen *op3, ZigType *expr_type)
1906{1903{
1907 IrInstGenMulAdd *instruction = ir_build_inst_gen<IrInstGenMulAdd>(&ira->new_irb,1904 IrInstGenMulAdd *instruction = ir_build_inst_gen<IrInstGenMulAdd>(&ira->new_irb,
1908 source_instr->scope, source_instr->source_node);1905 scope, source_node);
1909 instruction->base.value->type = expr_type;1906 instruction->base.value->type = expr_type;
1910 instruction->op1 = op1;1907 instruction->op1 = op1;
1911 instruction->op2 = op2;1908 instruction->op2 = op2;
...@@ -1918,9 +1915,9 @@ static IrInstGen *ir_build_mul_add_gen(IrAnalyze *ira, IrInst *source_instr, IrI...@@ -1918,9 +1915,9 @@ static IrInstGen *ir_build_mul_add_gen(IrAnalyze *ira, IrInst *source_instr, IrI
1918 return &instruction->base;1915 return &instruction->base;
1919}1916}
19201917
1921static IrInstGen *ir_build_test_err_gen(IrAnalyze *ira, IrInst *source_instruction, IrInstGen *err_union) {1918static IrInstGen *ir_build_test_err_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *err_union) {
1922 IrInstGenTestErr *instruction = ir_build_inst_gen<IrInstGenTestErr>(1919 IrInstGenTestErr *instruction = ir_build_inst_gen<IrInstGenTestErr>(
1923 &ira->new_irb, source_instruction->scope, source_instruction->source_node);1920 &ira->new_irb, scope, source_node);
1924 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;1921 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;
1925 instruction->err_union = err_union;1922 instruction->err_union = err_union;
19261923
...@@ -1955,11 +1952,11 @@ static IrInstGen *ir_build_unwrap_err_payload_gen(IrAnalyze *ira, Scope *scope,...@@ -1955,11 +1952,11 @@ static IrInstGen *ir_build_unwrap_err_payload_gen(IrAnalyze *ira, Scope *scope,
1955 return &inst->base;1952 return &inst->base;
1956}1953}
19571954
1958static IrInstGen *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInst *source_instruction,1955static IrInstGen *ir_build_ptr_cast_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1959 ZigType *ptr_type, IrInstGen *ptr, bool safety_check_on)1956 ZigType *ptr_type, IrInstGen *ptr, bool safety_check_on)
1960{1957{
1961 IrInstGenPtrCast *instruction = ir_build_inst_gen<IrInstGenPtrCast>(1958 IrInstGenPtrCast *instruction = ir_build_inst_gen<IrInstGenPtrCast>(
1962 &ira->new_irb, source_instruction->scope, source_instruction->source_node);1959 &ira->new_irb, scope, source_node);
1963 instruction->base.value->type = ptr_type;1960 instruction->base.value->type = ptr_type;
1964 instruction->ptr = ptr;1961 instruction->ptr = ptr;
1965 instruction->safety_check_on = safety_check_on;1962 instruction->safety_check_on = safety_check_on;
...@@ -1969,11 +1966,11 @@ static IrInstGen *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInst *source_instructi...@@ -1969,11 +1966,11 @@ static IrInstGen *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInst *source_instructi
1969 return &instruction->base;1966 return &instruction->base;
1970}1967}
19711968
1972static IrInstGen *ir_build_bit_cast_gen(IrAnalyze *ira, IrInst *source_instruction,1969static IrInstGen *ir_build_bit_cast_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1973 IrInstGen *operand, ZigType *ty)1970 IrInstGen *operand, ZigType *ty)
1974{1971{
1975 IrInstGenBitCast *instruction = ir_build_inst_gen<IrInstGenBitCast>(1972 IrInstGenBitCast *instruction = ir_build_inst_gen<IrInstGenBitCast>(
1976 &ira->new_irb, source_instruction->scope, source_instruction->source_node);1973 &ira->new_irb, scope, source_node);
1977 instruction->base.value->type = ty;1974 instruction->base.value->type = ty;
1978 instruction->operand = operand;1975 instruction->operand = operand;
19791976
...@@ -2006,8 +2003,8 @@ static IrInstGen *ir_build_int_to_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode...@@ -2006,8 +2003,8 @@ static IrInstGen *ir_build_int_to_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode
2006 return &instruction->base;2003 return &instruction->base;
2007}2004}
20082005
2009static IrInstGen *ir_build_ptr_to_int_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target) {2006static IrInstGen *ir_build_ptr_to_int_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target) {
2010 IrInstGenPtrToInt *inst = ir_build_inst_gen<IrInstGenPtrToInt>(&ira->new_irb, source_instr->scope, source_instr->source_node);2007 IrInstGenPtrToInt *inst = ir_build_inst_gen<IrInstGenPtrToInt>(&ira->new_irb, scope, source_node);
2011 inst->base.value->type = ira->codegen->builtin_types.entry_usize;2008 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
2012 inst->target = target;2009 inst->target = target;
20132010
...@@ -2052,9 +2049,9 @@ static IrInstGen *ir_build_err_to_int_gen(IrAnalyze *ira, Scope *scope, AstNode...@@ -2052,9 +2049,9 @@ static IrInstGen *ir_build_err_to_int_gen(IrAnalyze *ira, Scope *scope, AstNode
2052 return &instruction->base;2049 return &instruction->base;
2053}2050}
20542051
2055static IrInstGen *ir_build_panic_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *msg) {2052static IrInstGen *ir_build_panic_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *msg) {
2056 IrInstGenPanic *instruction = ir_build_inst_noreturn<IrInstGenPanic>(&ira->new_irb,2053 IrInstGenPanic *instruction = ir_build_inst_noreturn<IrInstGenPanic>(&ira->new_irb,
2057 source_instr->scope, source_instr->source_node);2054 scope, source_node);
2058 instruction->msg = msg;2055 instruction->msg = msg;
20592056
2060 ir_ref_inst_gen(msg);2057 ir_ref_inst_gen(msg);
...@@ -2062,11 +2059,11 @@ static IrInstGen *ir_build_panic_gen(IrAnalyze *ira, IrInst *source_instr, IrIns...@@ -2062,11 +2059,11 @@ static IrInstGen *ir_build_panic_gen(IrAnalyze *ira, IrInst *source_instr, IrIns
2062 return &instruction->base;2059 return &instruction->base;
2063}2060}
20642061
2065static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target,2062static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
2066 ZigType *result_type)2063 ZigType *result_type)
2067{2064{
2068 IrInstGenTagName *instruction = ir_build_inst_gen<IrInstGenTagName>(&ira->new_irb,2065 IrInstGenTagName *instruction = ir_build_inst_gen<IrInstGenTagName>(&ira->new_irb,
2069 source_instr->scope, source_instr->source_node);2066 scope, source_node);
2070 instruction->base.value->type = result_type;2067 instruction->base.value->type = result_type;
2071 instruction->target = target;2068 instruction->target = target;
20722069
...@@ -2075,11 +2072,11 @@ static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, IrInst *source_instr, Ir...@@ -2075,11 +2072,11 @@ static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, IrInst *source_instr, Ir
2075 return &instruction->base;2072 return &instruction->base;
2076}2073}
20772074
2078static IrInstGen *ir_build_field_parent_ptr_gen(IrAnalyze *ira, IrInst *source_instr,2075static IrInstGen *ir_build_field_parent_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2079 IrInstGen *field_ptr, TypeStructField *field, ZigType *result_type)2076 IrInstGen *field_ptr, TypeStructField *field, ZigType *result_type)
2080{2077{
2081 IrInstGenFieldParentPtr *inst = ir_build_inst_gen<IrInstGenFieldParentPtr>(&ira->new_irb,2078 IrInstGenFieldParentPtr *inst = ir_build_inst_gen<IrInstGenFieldParentPtr>(&ira->new_irb,
2082 source_instr->scope, source_instr->source_node);2079 scope, source_node);
2083 inst->base.value->type = result_type;2080 inst->base.value->type = result_type;
2084 inst->field_ptr = field_ptr;2081 inst->field_ptr = field_ptr;
2085 inst->field = field;2082 inst->field = field;
...@@ -2111,10 +2108,10 @@ static IrInstGen *ir_build_error_return_trace_gen(IrAnalyze *ira, Scope *scope,...@@ -2111,10 +2108,10 @@ static IrInstGen *ir_build_error_return_trace_gen(IrAnalyze *ira, Scope *scope,
2111 return &inst->base;2108 return &inst->base;
2112}2109}
21132110
2114static IrInstGen *ir_build_atomic_rmw_gen(IrAnalyze *ira, IrInst *source_instr,2111static IrInstGen *ir_build_atomic_rmw_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2115 IrInstGen *ptr, IrInstGen *operand, AtomicRmwOp op, AtomicOrder ordering, ZigType *operand_type)2112 IrInstGen *ptr, IrInstGen *operand, AtomicRmwOp op, AtomicOrder ordering, ZigType *operand_type)
2116{2113{
2117 IrInstGenAtomicRmw *instruction = ir_build_inst_gen<IrInstGenAtomicRmw>(&ira->new_irb, source_instr->scope, source_instr->source_node);2114 IrInstGenAtomicRmw *instruction = ir_build_inst_gen<IrInstGenAtomicRmw>(&ira->new_irb, scope, source_node);
2118 instruction->base.value->type = operand_type;2115 instruction->base.value->type = operand_type;
2119 instruction->ptr = ptr;2116 instruction->ptr = ptr;
2120 instruction->op = op;2117 instruction->op = op;
...@@ -2127,11 +2124,11 @@ static IrInstGen *ir_build_atomic_rmw_gen(IrAnalyze *ira, IrInst *source_instr,...@@ -2127,11 +2124,11 @@ static IrInstGen *ir_build_atomic_rmw_gen(IrAnalyze *ira, IrInst *source_instr,
2127 return &instruction->base;2124 return &instruction->base;
2128}2125}
21292126
2130static IrInstGen *ir_build_atomic_load_gen(IrAnalyze *ira, IrInst *source_instr,2127static IrInstGen *ir_build_atomic_load_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2131 IrInstGen *ptr, AtomicOrder ordering, ZigType *operand_type)2128 IrInstGen *ptr, AtomicOrder ordering, ZigType *operand_type)
2132{2129{
2133 IrInstGenAtomicLoad *instruction = ir_build_inst_gen<IrInstGenAtomicLoad>(&ira->new_irb,2130 IrInstGenAtomicLoad *instruction = ir_build_inst_gen<IrInstGenAtomicLoad>(&ira->new_irb,
2134 source_instr->scope, source_instr->source_node);2131 scope, source_node);
2135 instruction->base.value->type = operand_type;2132 instruction->base.value->type = operand_type;
2136 instruction->ptr = ptr;2133 instruction->ptr = ptr;
2137 instruction->ordering = ordering;2134 instruction->ordering = ordering;
...@@ -2141,11 +2138,11 @@ static IrInstGen *ir_build_atomic_load_gen(IrAnalyze *ira, IrInst *source_instr,...@@ -2141,11 +2138,11 @@ static IrInstGen *ir_build_atomic_load_gen(IrAnalyze *ira, IrInst *source_instr,
2141 return &instruction->base;2138 return &instruction->base;
2142}2139}
21432140
2144static IrInstGen *ir_build_atomic_store_gen(IrAnalyze *ira, IrInst *source_instr,2141static IrInstGen *ir_build_atomic_store_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2145 IrInstGen *ptr, IrInstGen *value, AtomicOrder ordering)2142 IrInstGen *ptr, IrInstGen *value, AtomicOrder ordering)
2146{2143{
2147 IrInstGenAtomicStore *instruction = ir_build_inst_void<IrInstGenAtomicStore>(&ira->new_irb,2144 IrInstGenAtomicStore *instruction = ir_build_inst_void<IrInstGenAtomicStore>(&ira->new_irb,
2148 source_instr->scope, source_instr->source_node);2145 scope, source_node);
2149 instruction->ptr = ptr;2146 instruction->ptr = ptr;
2150 instruction->value = value;2147 instruction->value = value;
2151 instruction->ordering = ordering;2148 instruction->ordering = ordering;
...@@ -2157,11 +2154,11 @@ static IrInstGen *ir_build_atomic_store_gen(IrAnalyze *ira, IrInst *source_instr...@@ -2157,11 +2154,11 @@ static IrInstGen *ir_build_atomic_store_gen(IrAnalyze *ira, IrInst *source_instr
2157}2154}
21582155
21592156
2160static IrInstGen *ir_build_vector_to_array(IrAnalyze *ira, IrInst *source_instruction,2157static IrInstGen *ir_build_vector_to_array(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2161 ZigType *result_type, IrInstGen *vector, IrInstGen *result_loc)2158 ZigType *result_type, IrInstGen *vector, IrInstGen *result_loc)
2162{2159{
2163 IrInstGenVectorToArray *instruction = ir_build_inst_gen<IrInstGenVectorToArray>(&ira->new_irb,2160 IrInstGenVectorToArray *instruction = ir_build_inst_gen<IrInstGenVectorToArray>(&ira->new_irb,
2164 source_instruction->scope, source_instruction->source_node);2161 scope, source_node);
2165 instruction->base.value->type = result_type;2162 instruction->base.value->type = result_type;
2166 instruction->vector = vector;2163 instruction->vector = vector;
2167 instruction->result_loc = result_loc;2164 instruction->result_loc = result_loc;
...@@ -2172,11 +2169,11 @@ static IrInstGen *ir_build_vector_to_array(IrAnalyze *ira, IrInst *source_instru...@@ -2172,11 +2169,11 @@ static IrInstGen *ir_build_vector_to_array(IrAnalyze *ira, IrInst *source_instru
2172 return &instruction->base;2169 return &instruction->base;
2173}2170}
21742171
2175static IrInstGen *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInst *source_instruction,2172static IrInstGen *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2176 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)2173 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)
2177{2174{
2178 IrInstGenPtrOfArrayToSlice *instruction = ir_build_inst_gen<IrInstGenPtrOfArrayToSlice>(&ira->new_irb,2175 IrInstGenPtrOfArrayToSlice *instruction = ir_build_inst_gen<IrInstGenPtrOfArrayToSlice>(&ira->new_irb,
2179 source_instruction->scope, source_instruction->source_node);2176 scope, source_node);
2180 instruction->base.value->type = result_type;2177 instruction->base.value->type = result_type;
2181 instruction->operand = operand;2178 instruction->operand = operand;
2182 instruction->result_loc = result_loc;2179 instruction->result_loc = result_loc;
...@@ -2187,11 +2184,11 @@ static IrInstGen *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInst *source_...@@ -2187,11 +2184,11 @@ static IrInstGen *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInst *source_
2187 return &instruction->base;2184 return &instruction->base;
2188}2185}
21892186
2190static IrInstGen *ir_build_array_to_vector(IrAnalyze *ira, IrInst *source_instruction,2187static IrInstGen *ir_build_array_to_vector(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2191 IrInstGen *array, ZigType *result_type)2188 IrInstGen *array, ZigType *result_type)
2192{2189{
2193 IrInstGenArrayToVector *instruction = ir_build_inst_gen<IrInstGenArrayToVector>(&ira->new_irb,2190 IrInstGenArrayToVector *instruction = ir_build_inst_gen<IrInstGenArrayToVector>(&ira->new_irb,
2194 source_instruction->scope, source_instruction->source_node);2191 scope, source_node);
2195 instruction->base.value->type = result_type;2192 instruction->base.value->type = result_type;
2196 instruction->array = array;2193 instruction->array = array;
21972194
...@@ -2200,11 +2197,11 @@ static IrInstGen *ir_build_array_to_vector(IrAnalyze *ira, IrInst *source_instru...@@ -2200,11 +2197,11 @@ static IrInstGen *ir_build_array_to_vector(IrAnalyze *ira, IrInst *source_instru
2200 return &instruction->base;2197 return &instruction->base;
2201}2198}
22022199
2203static IrInstGen *ir_build_assert_zero(IrAnalyze *ira, IrInst *source_instruction,2200static IrInstGen *ir_build_assert_zero(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2204 IrInstGen *target)2201 IrInstGen *target)
2205{2202{
2206 IrInstGenAssertZero *instruction = ir_build_inst_gen<IrInstGenAssertZero>(&ira->new_irb,2203 IrInstGenAssertZero *instruction = ir_build_inst_gen<IrInstGenAssertZero>(&ira->new_irb,
2207 source_instruction->scope, source_instruction->source_node);2204 scope, source_node);
2208 instruction->base.value->type = ira->codegen->builtin_types.entry_void;2205 instruction->base.value->type = ira->codegen->builtin_types.entry_void;
2209 instruction->target = target;2206 instruction->target = target;
22102207
...@@ -2213,11 +2210,11 @@ static IrInstGen *ir_build_assert_zero(IrAnalyze *ira, IrInst *source_instructio...@@ -2213,11 +2210,11 @@ static IrInstGen *ir_build_assert_zero(IrAnalyze *ira, IrInst *source_instructio
2213 return &instruction->base;2210 return &instruction->base;
2214}2211}
22152212
2216static IrInstGen *ir_build_assert_non_null(IrAnalyze *ira, IrInst *source_instruction,2213static IrInstGen *ir_build_assert_non_null(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2217 IrInstGen *target)2214 IrInstGen *target)
2218{2215{
2219 IrInstGenAssertNonNull *instruction = ir_build_inst_gen<IrInstGenAssertNonNull>(&ira->new_irb,2216 IrInstGenAssertNonNull *instruction = ir_build_inst_gen<IrInstGenAssertNonNull>(&ira->new_irb,
2220 source_instruction->scope, source_instruction->source_node);2217 scope, source_node);
2221 instruction->base.value->type = ira->codegen->builtin_types.entry_void;2218 instruction->base.value->type = ira->codegen->builtin_types.entry_void;
2222 instruction->target = target;2219 instruction->target = target;
22232220
...@@ -2226,20 +2223,20 @@ static IrInstGen *ir_build_assert_non_null(IrAnalyze *ira, IrInst *source_instru...@@ -2226,20 +2223,20 @@ static IrInstGen *ir_build_assert_non_null(IrAnalyze *ira, IrInst *source_instru
2226 return &instruction->base;2223 return &instruction->base;
2227}2224}
22282225
2229static IrInstGenAlloca *ir_build_alloca_gen(IrAnalyze *ira, IrInst *source_instruction,2226static IrInstGenAlloca *ir_build_alloca_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2230 uint32_t align, const char *name_hint)2227 uint32_t align, const char *name_hint)
2231{2228{
2232 IrInstGenAlloca *instruction = ir_create_inst_gen<IrInstGenAlloca>(&ira->new_irb,2229 IrInstGenAlloca *instruction = ir_create_inst_gen<IrInstGenAlloca>(&ira->new_irb,
2233 source_instruction->scope, source_instruction->source_node);2230 scope, source_node);
2234 instruction->align = align;2231 instruction->align = align;
2235 instruction->name_hint = name_hint;2232 instruction->name_hint = name_hint;
22362233
2237 return instruction;2234 return instruction;
2238}2235}
22392236
2240static IrInstGen *ir_build_suspend_finish_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGenSuspendBegin *begin) {2237static IrInstGen *ir_build_suspend_finish_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGenSuspendBegin *begin) {
2241 IrInstGenSuspendFinish *inst = ir_build_inst_void<IrInstGenSuspendFinish>(&ira->new_irb,2238 IrInstGenSuspendFinish *inst = ir_build_inst_void<IrInstGenSuspendFinish>(&ira->new_irb,
2242 source_instr->scope, source_instr->source_node);2239 scope, source_node);
2243 inst->begin = begin;2240 inst->begin = begin;
22442241
2245 ir_ref_inst_gen(&begin->base);2242 ir_ref_inst_gen(&begin->base);
...@@ -2247,11 +2244,11 @@ static IrInstGen *ir_build_suspend_finish_gen(IrAnalyze *ira, IrInst *source_ins...@@ -2247,11 +2244,11 @@ static IrInstGen *ir_build_suspend_finish_gen(IrAnalyze *ira, IrInst *source_ins
2247 return &inst->base;2244 return &inst->base;
2248}2245}
22492246
2250static IrInstGenAwait *ir_build_await_gen(IrAnalyze *ira, IrInst *source_instruction,2247static IrInstGenAwait *ir_build_await_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2251 IrInstGen *frame, ZigType *result_type, IrInstGen *result_loc, bool is_nosuspend)2248 IrInstGen *frame, ZigType *result_type, IrInstGen *result_loc, bool is_nosuspend)
2252{2249{
2253 IrInstGenAwait *instruction = ir_build_inst_gen<IrInstGenAwait>(&ira->new_irb,2250 IrInstGenAwait *instruction = ir_build_inst_gen<IrInstGenAwait>(&ira->new_irb,
2254 source_instruction->scope, source_instruction->source_node);2251 scope, source_node);
2255 instruction->base.value->type = result_type;2252 instruction->base.value->type = result_type;
2256 instruction->frame = frame;2253 instruction->frame = frame;
2257 instruction->result_loc = result_loc;2254 instruction->result_loc = result_loc;
...@@ -2263,9 +2260,9 @@ static IrInstGenAwait *ir_build_await_gen(IrAnalyze *ira, IrInst *source_instruc...@@ -2263,9 +2260,9 @@ static IrInstGenAwait *ir_build_await_gen(IrAnalyze *ira, IrInst *source_instruc
2263 return instruction;2260 return instruction;
2264}2261}
22652262
2266static IrInstGen *ir_build_resume_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *frame) {2263static IrInstGen *ir_build_resume_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *frame) {
2267 IrInstGenResume *instruction = ir_build_inst_void<IrInstGenResume>(&ira->new_irb,2264 IrInstGenResume *instruction = ir_build_inst_void<IrInstGenResume>(&ira->new_irb,
2268 source_instr->scope, source_instr->source_node);2265 scope, source_node);
2269 instruction->frame = frame;2266 instruction->frame = frame;
22702267
2271 ir_ref_inst_gen(frame);2268 ir_ref_inst_gen(frame);
...@@ -2273,11 +2270,11 @@ static IrInstGen *ir_build_resume_gen(IrAnalyze *ira, IrInst *source_instr, IrIn...@@ -2273,11 +2270,11 @@ static IrInstGen *ir_build_resume_gen(IrAnalyze *ira, IrInst *source_instr, IrIn
2273 return &instruction->base;2270 return &instruction->base;
2274}2271}
22752272
2276static IrInstGen *ir_build_spill_begin_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,2273static IrInstGen *ir_build_spill_begin_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *operand,
2277 SpillId spill_id)2274 SpillId spill_id)
2278{2275{
2279 IrInstGenSpillBegin *instruction = ir_build_inst_void<IrInstGenSpillBegin>(&ira->new_irb,2276 IrInstGenSpillBegin *instruction = ir_build_inst_void<IrInstGenSpillBegin>(&ira->new_irb,
2280 source_instr->scope, source_instr->source_node);2277 scope, source_node);
2281 instruction->operand = operand;2278 instruction->operand = operand;
2282 instruction->spill_id = spill_id;2279 instruction->spill_id = spill_id;
22832280
...@@ -2286,11 +2283,11 @@ static IrInstGen *ir_build_spill_begin_gen(IrAnalyze *ira, IrInst *source_instr,...@@ -2286,11 +2283,11 @@ static IrInstGen *ir_build_spill_begin_gen(IrAnalyze *ira, IrInst *source_instr,
2286 return &instruction->base;2283 return &instruction->base;
2287}2284}
22882285
2289static IrInstGen *ir_build_spill_end_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGenSpillBegin *begin,2286static IrInstGen *ir_build_spill_end_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGenSpillBegin *begin,
2290 ZigType *result_type)2287 ZigType *result_type)
2291{2288{
2292 IrInstGenSpillEnd *instruction = ir_build_inst_gen<IrInstGenSpillEnd>(&ira->new_irb,2289 IrInstGenSpillEnd *instruction = ir_build_inst_gen<IrInstGenSpillEnd>(&ira->new_irb,
2293 source_instr->scope, source_instr->source_node);2290 scope, source_node);
2294 instruction->base.value->type = result_type;2291 instruction->base.value->type = result_type;
2295 instruction->begin = begin;2292 instruction->begin = begin;
22962293
...@@ -2299,11 +2296,11 @@ static IrInstGen *ir_build_spill_end_gen(IrAnalyze *ira, IrInst *source_instr, I...@@ -2299,11 +2296,11 @@ static IrInstGen *ir_build_spill_end_gen(IrAnalyze *ira, IrInst *source_instr, I
2299 return &instruction->base;2296 return &instruction->base;
2300}2297}
23012298
2302static IrInstGen *ir_build_vector_extract_elem(IrAnalyze *ira, IrInst *source_instruction,2299static IrInstGen *ir_build_vector_extract_elem(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2303 IrInstGen *vector, IrInstGen *index)2300 IrInstGen *vector, IrInstGen *index)
2304{2301{
2305 IrInstGenVectorExtractElem *instruction = ir_build_inst_gen<IrInstGenVectorExtractElem>(2302 IrInstGenVectorExtractElem *instruction = ir_build_inst_gen<IrInstGenVectorExtractElem>(
2306 &ira->new_irb, source_instruction->scope, source_instruction->source_node);2303 &ira->new_irb, scope, source_node);
2307 instruction->base.value->type = vector->value->type->data.vector.elem_type;2304 instruction->base.value->type = vector->value->type->data.vector.elem_type;
2308 instruction->vector = vector;2305 instruction->vector = vector;
2309 instruction->index = index;2306 instruction->index = index;
...@@ -2314,9 +2311,9 @@ static IrInstGen *ir_build_vector_extract_elem(IrAnalyze *ira, IrInst *source_in...@@ -2314,9 +2311,9 @@ static IrInstGen *ir_build_vector_extract_elem(IrAnalyze *ira, IrInst *source_in
2314 return &instruction->base;2311 return &instruction->base;
2315}2312}
23162313
2317static IrInstGen *ir_build_wasm_memory_size_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *index) {2314static IrInstGen *ir_build_wasm_memory_size_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *index) {
2318 IrInstGenWasmMemorySize *instruction = ir_build_inst_gen<IrInstGenWasmMemorySize>(&ira->new_irb,2315 IrInstGenWasmMemorySize *instruction = ir_build_inst_gen<IrInstGenWasmMemorySize>(&ira->new_irb,
2319 source_instr->scope, source_instr->source_node);2316 scope, source_node);
2320 instruction->base.value->type = ira->codegen->builtin_types.entry_u32;2317 instruction->base.value->type = ira->codegen->builtin_types.entry_u32;
2321 instruction->index = index;2318 instruction->index = index;
23222319
...@@ -2325,9 +2322,9 @@ static IrInstGen *ir_build_wasm_memory_size_gen(IrAnalyze *ira, IrInst *source_i...@@ -2325,9 +2322,9 @@ static IrInstGen *ir_build_wasm_memory_size_gen(IrAnalyze *ira, IrInst *source_i
2325 return &instruction->base;2322 return &instruction->base;
2326}2323}
23272324
2328static IrInstGen *ir_build_wasm_memory_grow_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *index, IrInstGen *delta) {2325static IrInstGen *ir_build_wasm_memory_grow_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *index, IrInstGen *delta) {
2329 IrInstGenWasmMemoryGrow *instruction = ir_build_inst_gen<IrInstGenWasmMemoryGrow>(&ira->new_irb,2326 IrInstGenWasmMemoryGrow *instruction = ir_build_inst_gen<IrInstGenWasmMemoryGrow>(&ira->new_irb,
2330 source_instr->scope, source_instr->source_node);2327 scope, source_node);
2331 instruction->base.value->type = ira->codegen->builtin_types.entry_i32;2328 instruction->base.value->type = ira->codegen->builtin_types.entry_i32;
2332 instruction->index = index;2329 instruction->index = index;
2333 instruction->delta = delta;2330 instruction->delta = delta;
...@@ -2551,15 +2548,10 @@ static ErrorMsg *opt_ir_add_error_node(IrAnalyze *ira, CodeGen *codegen, AstNode...@@ -2551,15 +2548,10 @@ static ErrorMsg *opt_ir_add_error_node(IrAnalyze *ira, CodeGen *codegen, AstNode
2551 return add_node_error(codegen, source_node, msg);2548 return add_node_error(codegen, source_node, msg);
2552}2549}
25532550
2554static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInst *source_instruction, Buf *msg) {2551static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstGen *source_instruction, Buf *msg) {
2555 return ir_add_error_node(ira, source_instruction->source_node, msg);2552 return ir_add_error_node(ira, source_instruction->source_node, msg);
2556}2553}
25572554
2558static void ir_assert_gen_impl(bool ok, IrInstGen *source_instruction, char const *file, unsigned int line) {
2559 if (ok) return;
2560 src_assert_impl(ok, source_instruction->base.source_node, file, line);
2561}
2562
2563// This function takes a comptime ptr and makes the child const value conform to the type2555// This function takes a comptime ptr and makes the child const value conform to the type
2564// described by the pointer.2556// described by the pointer.
2565static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,2557static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
...@@ -2622,11 +2614,11 @@ static Error ir_exec_scan_for_side_effects(CodeGen *codegen, Stage1Air *exec) {...@@ -2622,11 +2614,11 @@ static Error ir_exec_scan_for_side_effects(CodeGen *codegen, Stage1Air *exec) {
2622 break;2614 break;
2623 }2615 }
2624 }2616 }
2625 if (get_scope_typeof(instruction->base.scope) != nullptr) {2617 if (get_scope_typeof(instruction->scope) != nullptr) {
2626 // doesn't count, it's inside a @TypeOf()2618 // doesn't count, it's inside a @TypeOf()
2627 continue;2619 continue;
2628 }2620 }
2629 exec_add_error_node_gen(codegen, exec, instruction->base.source_node,2621 exec_add_error_node_gen(codegen, exec, instruction->source_node,
2630 buf_sprintf("unable to evaluate constant expression"));2622 buf_sprintf("unable to evaluate constant expression"));
2631 return ErrorSemanticAnalyzeFail;2623 return ErrorSemanticAnalyzeFail;
2632 }2624 }
...@@ -2634,9 +2626,9 @@ static Error ir_exec_scan_for_side_effects(CodeGen *codegen, Stage1Air *exec) {...@@ -2634,9 +2626,9 @@ static Error ir_exec_scan_for_side_effects(CodeGen *codegen, Stage1Air *exec) {
2634 zig_unreachable();2626 zig_unreachable();
2635}2627}
26362628
2637static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInst* source_instruction) {2629static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstSrc* source_instruction) {
2638 if (ir_should_inline(ira->zir, source_instruction->scope)) {2630 if (ir_should_inline(ira->zir, source_instruction->scope)) {
2639 ir_add_error(ira, source_instruction, buf_sprintf("unable to evaluate constant expression"));2631 ir_add_error_node(ira, source_instruction->source_node, buf_sprintf("unable to evaluate constant expression"));
2640 return false;2632 return false;
2641 }2633 }
2642 return true;2634 return true;
...@@ -3518,7 +3510,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction...@@ -3518,7 +3510,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction
3518 }3510 }
3519 Buf *val_buf = buf_alloc();3511 Buf *val_buf = buf_alloc();
3520 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);3512 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
3521 ir_add_error_node(ira, instruction->base.source_node,3513 ir_add_error_node(ira, instruction->source_node,
3522 buf_sprintf("type %s cannot represent integer value %s",3514 buf_sprintf("type %s cannot represent integer value %s",
3523 buf_ptr(&other_type->name),3515 buf_ptr(&other_type->name),
3524 buf_ptr(val_buf)));3516 buf_ptr(val_buf)));
...@@ -3613,7 +3605,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction...@@ -3613,7 +3605,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction
3613 }3605 }
3614 Buf *val_buf = buf_alloc();3606 Buf *val_buf = buf_alloc();
3615 float_append_buf(val_buf, const_val);3607 float_append_buf(val_buf, const_val);
3616 ir_add_error_node(ira, instruction->base.source_node,3608 ir_add_error_node(ira, instruction->source_node,
3617 buf_sprintf("cast of value %s to type '%s' loses information",3609 buf_sprintf("cast of value %s to type '%s' loses information",
3618 buf_ptr(val_buf),3610 buf_ptr(val_buf),
3619 buf_ptr(&other_type->name)));3611 buf_ptr(&other_type->name)));
...@@ -3622,7 +3614,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction...@@ -3622,7 +3614,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction
3622 if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {3614 if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
3623 Buf *val_buf = buf_alloc();3615 Buf *val_buf = buf_alloc();
3624 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);3616 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
3625 ir_add_error_node(ira, instruction->base.source_node,3617 ir_add_error_node(ira, instruction->source_node,
3626 buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'",3618 buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'",
3627 buf_ptr(val_buf),3619 buf_ptr(val_buf),
3628 buf_ptr(&other_type->name)));3620 buf_ptr(&other_type->name)));
...@@ -3643,7 +3635,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction...@@ -3643,7 +3635,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction
3643 if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {3635 if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
3644 Buf *val_buf = buf_alloc();3636 Buf *val_buf = buf_alloc();
3645 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);3637 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
3646 ir_add_error_node(ira, instruction->base.source_node,3638 ir_add_error_node(ira, instruction->source_node,
3647 buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'",3639 buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'",
3648 buf_ptr(val_buf),3640 buf_ptr(val_buf),
3649 buf_ptr(&child_type->name)));3641 buf_ptr(&child_type->name)));
...@@ -3666,7 +3658,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction...@@ -3666,7 +3658,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction
3666 Buf *val_buf = buf_alloc();3658 Buf *val_buf = buf_alloc();
3667 float_append_buf(val_buf, const_val);3659 float_append_buf(val_buf, const_val);
36683660
3669 ir_add_error_node(ira, instruction->base.source_node,3661 ir_add_error_node(ira, instruction->source_node,
3670 buf_sprintf("fractional component prevents float value %s from being casted to type '%s'",3662 buf_sprintf("fractional component prevents float value %s from being casted to type '%s'",
3671 buf_ptr(val_buf),3663 buf_ptr(val_buf),
3672 buf_ptr(&other_type->name)));3664 buf_ptr(&other_type->name)));
...@@ -3696,7 +3688,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction...@@ -3696,7 +3688,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction
3696 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);3688 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
3697 }3689 }
36983690
3699 ir_add_error_node(ira, instruction->base.source_node,3691 ir_add_error_node(ira, instruction->source_node,
3700 buf_sprintf("%s value %s cannot be coerced to type '%s'",3692 buf_sprintf("%s value %s cannot be coerced to type '%s'",
3701 num_lit_str,3693 num_lit_str,
3702 buf_ptr(val_buf),3694 buf_ptr(val_buf),
...@@ -4210,7 +4202,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -4210,7 +4202,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
4210 size_t errors_count = 0;4202 size_t errors_count = 0;
4211 ZigType *err_set_type = nullptr;4203 ZigType *err_set_type = nullptr;
4212 if (prev_inst->value->type->id == ZigTypeIdErrorSet) {4204 if (prev_inst->value->type->id == ZigTypeIdErrorSet) {
4213 if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->base.source_node)) {4205 if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->source_node)) {
4214 return ira->codegen->builtin_types.entry_invalid;4206 return ira->codegen->builtin_types.entry_invalid;
4215 }4207 }
4216 if (type_is_global_error_set(prev_inst->value->type)) {4208 if (type_is_global_error_set(prev_inst->value->type)) {
...@@ -4254,14 +4246,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -4254,14 +4246,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
4254 }4246 }
42554247
4256 if (prev_type->id == ZigTypeIdErrorSet) {4248 if (prev_type->id == ZigTypeIdErrorSet) {
4257 ir_assert_gen(err_set_type != nullptr, prev_inst);4249 ir_assert(err_set_type != nullptr, prev_inst);
4258 if (cur_type->id == ZigTypeIdErrorSet) {4250 if (cur_type->id == ZigTypeIdErrorSet) {
4259 if (type_is_global_error_set(err_set_type)) {4251 if (type_is_global_error_set(err_set_type)) {
4260 continue;4252 continue;
4261 }4253 }
4262 bool allow_infer = cur_type->data.error_set.infer_fn != nullptr &&4254 bool allow_infer = cur_type->data.error_set.infer_fn != nullptr &&
4263 cur_type->data.error_set.infer_fn == ira->fn;4255 cur_type->data.error_set.infer_fn == ira->fn;
4264 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->base.source_node)) {4256 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) {
4265 return ira->codegen->builtin_types.entry_invalid;4257 return ira->codegen->builtin_types.entry_invalid;
4266 }4258 }
4267 if (!allow_infer && type_is_global_error_set(cur_type)) {4259 if (!allow_infer && type_is_global_error_set(cur_type)) {
...@@ -4329,7 +4321,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -4329,7 +4321,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
4329 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;4321 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
4330 bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr &&4322 bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr &&
4331 cur_err_set_type->data.error_set.infer_fn == ira->fn;4323 cur_err_set_type->data.error_set.infer_fn == ira->fn;
4332 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) {4324 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
4333 return ira->codegen->builtin_types.entry_invalid;4325 return ira->codegen->builtin_types.entry_invalid;
4334 }4326 }
4335 if (!allow_infer && type_is_global_error_set(cur_err_set_type)) {4327 if (!allow_infer && type_is_global_error_set(cur_err_set_type)) {
...@@ -4384,7 +4376,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -4384,7 +4376,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
4384 if (cur_type->id == ZigTypeIdErrorSet) {4376 if (cur_type->id == ZigTypeIdErrorSet) {
4385 bool allow_infer = cur_type->data.error_set.infer_fn != nullptr &&4377 bool allow_infer = cur_type->data.error_set.infer_fn != nullptr &&
4386 cur_type->data.error_set.infer_fn == ira->fn;4378 cur_type->data.error_set.infer_fn == ira->fn;
4387 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->base.source_node)) {4379 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) {
4388 return ira->codegen->builtin_types.entry_invalid;4380 return ira->codegen->builtin_types.entry_invalid;
4389 }4381 }
4390 if (!allow_infer && type_is_global_error_set(cur_type)) {4382 if (!allow_infer && type_is_global_error_set(cur_type)) {
...@@ -4407,7 +4399,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -4407,7 +4399,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
4407 err_set_type = cur_type;4399 err_set_type = cur_type;
4408 }4400 }
44094401
4410 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, err_set_type, cur_inst->base.source_node)) {4402 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, err_set_type, cur_inst->source_node)) {
4411 return ira->codegen->builtin_types.entry_invalid;4403 return ira->codegen->builtin_types.entry_invalid;
4412 }4404 }
44134405
...@@ -4470,11 +4462,11 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -4470,11 +4462,11 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
4470 bool allow_infer_cur = cur_err_set_type->data.error_set.infer_fn != nullptr &&4462 bool allow_infer_cur = cur_err_set_type->data.error_set.infer_fn != nullptr &&
4471 cur_err_set_type->data.error_set.infer_fn == ira->fn;4463 cur_err_set_type->data.error_set.infer_fn == ira->fn;
44724464
4473 if (!allow_infer_prev && !resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->base.source_node)) {4465 if (!allow_infer_prev && !resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->source_node)) {
4474 return ira->codegen->builtin_types.entry_invalid;4466 return ira->codegen->builtin_types.entry_invalid;
4475 }4467 }
44764468
4477 if (!allow_infer_cur && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) {4469 if (!allow_infer_cur && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
4478 return ira->codegen->builtin_types.entry_invalid;4470 return ira->codegen->builtin_types.entry_invalid;
4479 }4471 }
44804472
...@@ -4653,7 +4645,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -4653,7 +4645,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
4653 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;4645 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
4654 bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr &&4646 bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr &&
4655 cur_err_set_type->data.error_set.infer_fn == ira->fn;4647 cur_err_set_type->data.error_set.infer_fn == ira->fn;
4656 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) {4648 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
4657 return ira->codegen->builtin_types.entry_invalid;4649 return ira->codegen->builtin_types.entry_invalid;
4658 }4650 }
4659 if ((!allow_infer && type_is_global_error_set(cur_err_set_type)) ||4651 if ((!allow_infer && type_is_global_error_set(cur_err_set_type)) ||
...@@ -4890,9 +4882,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -4890,9 +4882,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
4890 ErrorMsg *msg = ir_add_error_node(ira, source_node,4882 ErrorMsg *msg = ir_add_error_node(ira, source_node,
4891 buf_sprintf("incompatible types: '%s' and '%s'",4883 buf_sprintf("incompatible types: '%s' and '%s'",
4892 buf_ptr(&prev_type->name), buf_ptr(&cur_type->name)));4884 buf_ptr(&prev_type->name), buf_ptr(&cur_type->name)));
4893 add_error_note(ira->codegen, msg, prev_inst->base.source_node,4885 add_error_note(ira->codegen, msg, prev_inst->source_node,
4894 buf_sprintf("type '%s' here", buf_ptr(&prev_type->name)));4886 buf_sprintf("type '%s' here", buf_ptr(&prev_type->name)));
4895 add_error_note(ira->codegen, msg, cur_inst->base.source_node,4887 add_error_note(ira->codegen, msg, cur_inst->source_node,
4896 buf_sprintf("type '%s' here", buf_ptr(&cur_type->name)));4888 buf_sprintf("type '%s' here", buf_ptr(&cur_type->name)));
48974889
4898 return ira->codegen->builtin_types.entry_invalid;4890 return ira->codegen->builtin_types.entry_invalid;
...@@ -4984,7 +4976,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -4984,7 +4976,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
4984 }4976 }
4985}4977}
49864978
4987static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr,4979static bool eval_const_expr_implicit_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node,
4988 CastOp cast_op,4980 CastOp cast_op,
4989 ZigValue *other_val, ZigType *other_type,4981 ZigValue *other_val, ZigType *other_type,
4990 ZigValue *const_val, ZigType *new_type)4982 ZigValue *const_val, ZigType *new_type)
...@@ -5069,7 +5061,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -5069,7 +5061,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr,
5069 Buf *int_buf = buf_alloc();5061 Buf *int_buf = buf_alloc();
5070 bigint_append_buf(int_buf, &const_val->data.x_bigint, 10);5062 bigint_append_buf(int_buf, &const_val->data.x_bigint, 10);
50715063
5072 ir_add_error(ira, source_instr,5064 ir_add_error_node(ira, source_node,
5073 buf_sprintf("integer value '%s' cannot be stored in type '%s'",5065 buf_sprintf("integer value '%s' cannot be stored in type '%s'",
5074 buf_ptr(int_buf), buf_ptr(&new_type->name)));5066 buf_ptr(int_buf), buf_ptr(&new_type->name)));
5075 return false;5067 return false;
...@@ -5086,9 +5078,9 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -5086,9 +5078,9 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr,
5086 return true;5078 return true;
5087}5079}
50885080
5089static IrInstGen *ir_const(IrAnalyze *ira, IrInst *inst, ZigType *ty) {5081static IrInstGen *ir_const(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ty) {
5090 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,5082 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
5091 inst->scope, inst->source_node);5083 scope, source_node);
5092 IrInstGen *new_instruction = &const_instruction->base;5084 IrInstGen *new_instruction = &const_instruction->base;
5093 new_instruction->value->type = ty;5085 new_instruction->value->type = ty;
5094 new_instruction->value->special = ConstValSpecialStatic;5086 new_instruction->value->special = ConstValSpecialStatic;
...@@ -5096,45 +5088,46 @@ static IrInstGen *ir_const(IrAnalyze *ira, IrInst *inst, ZigType *ty) {...@@ -5096,45 +5088,46 @@ static IrInstGen *ir_const(IrAnalyze *ira, IrInst *inst, ZigType *ty) {
5096 return new_instruction;5088 return new_instruction;
5097}5089}
50985090
5099static IrInstGen *ir_const_noval(IrAnalyze *ira, IrInst *old_instruction) {5091static IrInstGen *ir_const_noval(IrAnalyze *ira, Scope *scope, AstNode *source_node) {
5100 IrInstGenConst *const_instruction = ir_create_inst_noval<IrInstGenConst>(&ira->new_irb,5092 IrInstGenConst *const_instruction = ir_create_inst_noval<IrInstGenConst>(&ira->new_irb,
5101 old_instruction->scope, old_instruction->source_node);5093 scope, source_node);
5102 ira->new_irb.constants.append(&heap::c_allocator, const_instruction);5094 ira->new_irb.constants.append(&heap::c_allocator, const_instruction);
5103 return &const_instruction->base;5095 return &const_instruction->base;
5104}5096}
51055097
5106// This function initializes the new IrInstGen with the provided ZigValue,5098// This function initializes the new IrInstGen with the provided ZigValue,
5107// rather than creating a new one.5099// rather than creating a new one.
5108static IrInstGen *ir_const_move(IrAnalyze *ira, IrInst *old_instruction, ZigValue *val) {5100static IrInstGen *ir_const_move(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigValue *val) {
5109 IrInstGen *result = ir_const_noval(ira, old_instruction);5101 IrInstGen *result = ir_const_noval(ira, scope, source_node);
5110 result->value = val;5102 result->value = val;
5111 return result;5103 return result;
5112}5104}
51135105
5114static IrInstGen *ir_resolve_cast(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,5106static IrInstGen *ir_resolve_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
5115 ZigType *wanted_type, CastOp cast_op)5107 ZigType *wanted_type, CastOp cast_op)
5116{5108{
5117 if (instr_is_comptime(value) || !type_has_bits(ira->codegen, wanted_type)) {5109 if (instr_is_comptime(value) || !type_has_bits(ira->codegen, wanted_type)) {
5118 IrInstGen *result = ir_const(ira, source_instr, wanted_type);5110 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
5119 ZigValue *val = ir_resolve_const(ira, value, UndefBad);5111 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
5120 if (val == nullptr)5112 if (val == nullptr)
5121 return ira->codegen->invalid_inst_gen;5113 return ira->codegen->invalid_inst_gen;
51225114
5123 if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, val, val->type,5115 if (!eval_const_expr_implicit_cast(ira, scope, source_node, cast_op, val, val->type,
5124 result->value, wanted_type))5116 result->value, wanted_type))
5125 {5117 {
5126 return ira->codegen->invalid_inst_gen;5118 return ira->codegen->invalid_inst_gen;
5127 }5119 }
5128 return result;5120 return result;
5129 } else {5121 } else {
5130 return ir_build_cast(ira, source_instr, wanted_type, value, cast_op);5122 return ir_build_cast(ira, scope, source_node,
5123 wanted_type, value, cast_op);
5131 }5124 }
5132}5125}
51335126
5134static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInst* source_instr,5127static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,
5135 IrInstGen *value, ZigType *wanted_type)5128 Scope *scope, AstNode *source_node, IrInstGen *value, ZigType *wanted_type)
5136{5129{
5137 ir_assert(value->value->type->id == ZigTypeIdPointer, source_instr);5130 src_assert(value->value->type->id == ZigTypeIdPointer, source_node);
51385131
5139 Error err;5132 Error err;
51405133
...@@ -5151,13 +5144,13 @@ static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrI...@@ -5151,13 +5144,13 @@ static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrI
5151 if (val == nullptr)5144 if (val == nullptr)
5152 return ira->codegen->invalid_inst_gen;5145 return ira->codegen->invalid_inst_gen;
5153 if (val->special == ConstValSpecialUndef)5146 if (val->special == ConstValSpecialUndef)
5154 return ir_const_undef(ira, source_instr, wanted_type);5147 return ir_const_undef(ira, scope, source_node, wanted_type);
51555148
5156 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);5149 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_node);
5157 if (pointee == nullptr)5150 if (pointee == nullptr)
5158 return ira->codegen->invalid_inst_gen;5151 return ira->codegen->invalid_inst_gen;
5159 if (pointee->special != ConstValSpecialRuntime) {5152 if (pointee->special != ConstValSpecialRuntime) {
5160 IrInstGen *result = ir_const(ira, source_instr, wanted_type);5153 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
5161 result->value->data.x_ptr.special = ConstPtrSpecialBaseArray;5154 result->value->data.x_ptr.special = ConstPtrSpecialBaseArray;
5162 result->value->data.x_ptr.mut = val->data.x_ptr.mut;5155 result->value->data.x_ptr.mut = val->data.x_ptr.mut;
5163 result->value->data.x_ptr.data.base_array.array_val = pointee;5156 result->value->data.x_ptr.data.base_array.array_val = pointee;
...@@ -5166,10 +5159,11 @@ static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrI...@@ -5166,10 +5159,11 @@ static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrI
5166 }5159 }
5167 }5160 }
51685161
5169 return ir_build_cast(ira, source_instr, wanted_type, value, CastOpBitCast);5162 return ir_build_cast(ira, scope, source_node,
5163 wanted_type, value, CastOpBitCast);
5170}5164}
51715165
5172static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* source_instr,5166static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, Scope *scope, AstNode *source_node,
5173 IrInstGen *array_ptr, ZigType *wanted_type, ResultLoc *result_loc)5167 IrInstGen *array_ptr, ZigType *wanted_type, ResultLoc *result_loc)
5174{5168{
5175 Error err;5169 Error err;
...@@ -5189,7 +5183,7 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc...@@ -5189,7 +5183,7 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc
5189 // undef_array->special = ConstValSpecialUndef;5183 // undef_array->special = ConstValSpecialUndef;
5190 // undef_array->type = array_type;5184 // undef_array->type = array_type;
51915185
5192 // IrInstGen *result = ir_const(ira, source_instr, wanted_type);5186 // IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
5193 // init_const_slice(ira->codegen, result->value, undef_array, 0, 0, false, nullptr);5187 // init_const_slice(ira->codegen, result->value, undef_array, 0, 0, false, nullptr);
5194 // result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = ConstPtrMutComptimeConst;5188 // result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = ConstPtrMutComptimeConst;
5195 // result->value->type = wanted_type;5189 // result->value->type = wanted_type;
...@@ -5210,13 +5204,13 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc...@@ -5210,13 +5204,13 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc
5210 ZigValue *array_ptr_val = ir_resolve_const(ira, array_ptr, undef_allowed);5204 ZigValue *array_ptr_val = ir_resolve_const(ira, array_ptr, undef_allowed);
5211 if (array_ptr_val == nullptr)5205 if (array_ptr_val == nullptr)
5212 return ira->codegen->invalid_inst_gen;5206 return ira->codegen->invalid_inst_gen;
5213 ir_assert(is_slice(wanted_type), source_instr);5207 src_assert(is_slice(wanted_type), source_node);
5214 if (array_ptr_val->special == ConstValSpecialUndef) {5208 if (array_ptr_val->special == ConstValSpecialUndef) {
5215 ZigValue *undef_array = ira->codegen->pass1_arena->create<ZigValue>();5209 ZigValue *undef_array = ira->codegen->pass1_arena->create<ZigValue>();
5216 undef_array->special = ConstValSpecialUndef;5210 undef_array->special = ConstValSpecialUndef;
5217 undef_array->type = array_type;5211 undef_array->type = array_type;
52185212
5219 IrInstGen *result = ir_const(ira, source_instr, wanted_type);5213 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
5220 init_const_slice(ira->codegen, result->value, undef_array, 0, 0, false, nullptr);5214 init_const_slice(ira->codegen, result->value, undef_array, 0, 0, false, nullptr);
5221 result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = ConstPtrMutComptimeConst;5215 result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = ConstPtrMutComptimeConst;
5222 result->value->type = wanted_type;5216 result->value->type = wanted_type;
...@@ -5227,7 +5221,7 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc...@@ -5227,7 +5221,7 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc
5227 if (array_ptr_val->data.x_ptr.special == ConstPtrSpecialSubArray) {5221 if (array_ptr_val->data.x_ptr.special == ConstPtrSpecialSubArray) {
5228 ZigValue *array_val = array_ptr_val->data.x_ptr.data.base_array.array_val;5222 ZigValue *array_val = array_ptr_val->data.x_ptr.data.base_array.array_val;
5229 if (array_val->special != ConstValSpecialRuntime) {5223 if (array_val->special != ConstValSpecialRuntime) {
5230 IrInstGen *result = ir_const(ira, source_instr, wanted_type);5224 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
5231 init_const_slice(ira->codegen, result->value, array_val,5225 init_const_slice(ira->codegen, result->value, array_val,
5232 array_ptr_val->data.x_ptr.data.base_array.elem_index,5226 array_ptr_val->data.x_ptr.data.base_array.elem_index,
5233 array_type->data.array.len, wanted_const, nullptr);5227 array_type->data.array.len, wanted_const, nullptr);
...@@ -5236,13 +5230,13 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc...@@ -5236,13 +5230,13 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc
5236 return result;5230 return result;
5237 }5231 }
5238 } else if (array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {5232 } else if (array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
5239 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr_val, source_instr->source_node);5233 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr_val, source_node);
5240 if (pointee == nullptr)5234 if (pointee == nullptr)
5241 return ira->codegen->invalid_inst_gen;5235 return ira->codegen->invalid_inst_gen;
5242 if (pointee->special != ConstValSpecialRuntime) {5236 if (pointee->special != ConstValSpecialRuntime) {
5243 assert(array_ptr_val->type->id == ZigTypeIdPointer);5237 assert(array_ptr_val->type->id == ZigTypeIdPointer);
52445238
5245 IrInstGen *result = ir_const(ira, source_instr, wanted_type);5239 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
5246 init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, wanted_const, nullptr);5240 init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, wanted_const, nullptr);
5247 result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;5241 result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;
5248 result->value->type = wanted_type;5242 result->value->type = wanted_type;
...@@ -5252,16 +5246,17 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc...@@ -5252,16 +5246,17 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc
5252 }5246 }
52535247
5254 if (result_loc == nullptr) result_loc = no_result_loc();5248 if (result_loc == nullptr) result_loc = no_result_loc();
5255 IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true);5249 IrInstGen *result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr,
5250 result_loc, wanted_type, nullptr, true, true);
5256 if (type_is_invalid(result_loc_inst->value->type) ||5251 if (type_is_invalid(result_loc_inst->value->type) ||
5257 result_loc_inst->value->type->id == ZigTypeIdUnreachable)5252 result_loc_inst->value->type->id == ZigTypeIdUnreachable)
5258 {5253 {
5259 return result_loc_inst;5254 return result_loc_inst;
5260 }5255 }
5261 return ir_build_ptr_of_array_to_slice(ira, source_instr, wanted_type, array_ptr, result_loc_inst);5256 return ir_build_ptr_of_array_to_slice(ira, scope, source_node, wanted_type, array_ptr, result_loc_inst);
5262}5257}
52635258
5264static IrBasicBlockGen *ir_get_new_bb(IrAnalyze *ira, Stage1ZirBasicBlock *old_bb, IrInst *ref_old_instruction) {5259static IrBasicBlockGen *ir_get_new_bb(IrAnalyze *ira, Stage1ZirBasicBlock *old_bb, IrInstSrc *ref_old_instruction) {
5265 assert(old_bb);5260 assert(old_bb);
52665261
5267 if (old_bb->child) {5262 if (old_bb->child) {
...@@ -5276,13 +5271,13 @@ static IrBasicBlockGen *ir_get_new_bb(IrAnalyze *ira, Stage1ZirBasicBlock *old_b...@@ -5276,13 +5271,13 @@ static IrBasicBlockGen *ir_get_new_bb(IrAnalyze *ira, Stage1ZirBasicBlock *old_b
5276 return new_bb;5271 return new_bb;
5277}5272}
52785273
5279static IrBasicBlockGen *ir_get_new_bb_runtime(IrAnalyze *ira, Stage1ZirBasicBlock *old_bb, IrInst *ref_old_instruction) {5274static IrBasicBlockGen *ir_get_new_bb_runtime(IrAnalyze *ira, Stage1ZirBasicBlock *old_bb, IrInstSrc *ref_old_instruction) {
5280 assert(ref_old_instruction != nullptr);5275 assert(ref_old_instruction != nullptr);
5281 IrBasicBlockGen *new_bb = ir_get_new_bb(ira, old_bb, ref_old_instruction);5276 IrBasicBlockGen *new_bb = ir_get_new_bb(ira, old_bb, ref_old_instruction);
5282 if (new_bb->must_be_comptime_source_instr) {5277 if (new_bb->must_be_comptime_source_node != nullptr) {
5283 ErrorMsg *msg = ir_add_error(ira, ref_old_instruction,5278 ErrorMsg *msg = ir_add_error_node(ira, ref_old_instruction->source_node,
5284 buf_sprintf("control flow attempts to use compile-time variable at runtime"));5279 buf_sprintf("control flow attempts to use compile-time variable at runtime"));
5285 add_error_note(ira->codegen, msg, new_bb->must_be_comptime_source_instr->source_node,5280 add_error_note(ira->codegen, msg, new_bb->must_be_comptime_source_node,
5286 buf_sprintf("compile-time variable assigned here"));5281 buf_sprintf("compile-time variable assigned here"));
5287 return nullptr;5282 return nullptr;
5288 }5283 }
...@@ -5290,14 +5285,16 @@ static IrBasicBlockGen *ir_get_new_bb_runtime(IrAnalyze *ira, Stage1ZirBasicBloc...@@ -5290,14 +5285,16 @@ static IrBasicBlockGen *ir_get_new_bb_runtime(IrAnalyze *ira, Stage1ZirBasicBloc
5290}5285}
52915286
5292static void ir_start_bb(IrAnalyze *ira, Stage1ZirBasicBlock *old_bb, Stage1ZirBasicBlock *const_predecessor_bb) {5287static void ir_start_bb(IrAnalyze *ira, Stage1ZirBasicBlock *old_bb, Stage1ZirBasicBlock *const_predecessor_bb) {
5293 ir_assert(!old_bb->suspended, (old_bb->instruction_list.length != 0) ? &old_bb->instruction_list.at(0)->base : nullptr);5288 src_assert(!old_bb->suspended,
5289 (old_bb->instruction_list.length != 0) ?
5290 old_bb->instruction_list.at(0)->source_node : nullptr);
5294 ira->instruction_index = 0;5291 ira->instruction_index = 0;
5295 ira->zir_current_basic_block = old_bb;5292 ira->zir_current_basic_block = old_bb;
5296 ira->const_predecessor_bb = const_predecessor_bb;5293 ira->const_predecessor_bb = const_predecessor_bb;
5297 ira->old_bb_index = old_bb->index;5294 ira->old_bb_index = old_bb->index;
5298}5295}
52995296
5300static IrInstGen *ira_suspend(IrAnalyze *ira, IrInst *old_instruction, Stage1ZirBasicBlock *next_bb,5297static IrInstGen *ira_suspend(IrAnalyze *ira, IrInstSrc *old_instruction, Stage1ZirBasicBlock *next_bb,
5301 IrSuspendPosition *suspend_pos)5298 IrSuspendPosition *suspend_pos)
5302{5299{
5303 if (ira->codegen->verbose_ir) {5300 if (ira->codegen->verbose_ir) {
...@@ -5306,7 +5303,7 @@ static IrInstGen *ira_suspend(IrAnalyze *ira, IrInst *old_instruction, Stage1Zir...@@ -5306,7 +5303,7 @@ static IrInstGen *ira_suspend(IrAnalyze *ira, IrInst *old_instruction, Stage1Zir
5306 ira->zir_current_basic_block->debug_id,5303 ira->zir_current_basic_block->debug_id,
5307 ira->zir->basic_block_list.at(ira->old_bb_index)->name_hint,5304 ira->zir->basic_block_list.at(ira->old_bb_index)->name_hint,
5308 ira->zir->basic_block_list.at(ira->old_bb_index)->debug_id,5305 ira->zir->basic_block_list.at(ira->old_bb_index)->debug_id,
5309 ira->zir_current_basic_block->instruction_list.at(ira->instruction_index)->base.debug_id,5306 ira->zir_current_basic_block->instruction_list.at(ira->instruction_index)->debug_id,
5310 ira->old_bb_index, ira->instruction_index);5307 ira->old_bb_index, ira->instruction_index);
5311 }5308 }
5312 suspend_pos->basic_block_index = ira->old_bb_index;5309 suspend_pos->basic_block_index = ira->old_bb_index;
...@@ -5342,7 +5339,7 @@ static IrInstGen *ira_resume(IrAnalyze *ira) {...@@ -5342,7 +5339,7 @@ static IrInstGen *ira_resume(IrAnalyze *ira) {
5342 if (ira->codegen->verbose_ir) {5339 if (ira->codegen->verbose_ir) {
5343 fprintf(stderr, "%s_%" PRIu32 " #%" PRIu32 "\n", ira->zir_current_basic_block->name_hint,5340 fprintf(stderr, "%s_%" PRIu32 " #%" PRIu32 "\n", ira->zir_current_basic_block->name_hint,
5344 ira->zir_current_basic_block->debug_id,5341 ira->zir_current_basic_block->debug_id,
5345 ira->zir_current_basic_block->instruction_list.at(pos.instruction_index)->base.debug_id);5342 ira->zir_current_basic_block->instruction_list.at(pos.instruction_index)->debug_id);
5346 }5343 }
5347 ira->const_predecessor_bb = nullptr;5344 ira->const_predecessor_bb = nullptr;
5348 ira->new_irb.current_basic_block = ira->zir_current_basic_block->child;5345 ira->new_irb.current_basic_block = ira->zir_current_basic_block->child;
...@@ -5418,7 +5415,7 @@ static IrInstGen *ir_unreach_error(IrAnalyze *ira) {...@@ -5418,7 +5415,7 @@ static IrInstGen *ir_unreach_error(IrAnalyze *ira) {
5418 return ira->codegen->unreach_instruction;5415 return ira->codegen->unreach_instruction;
5419}5416}
54205417
5421static bool ir_emit_backward_branch(IrAnalyze *ira, IrInst* source_instruction) {5418static bool ir_emit_backward_branch(IrAnalyze *ira, AstNode* source_node) {
5422 size_t *bbc = ira->backward_branch_count;5419 size_t *bbc = ira->backward_branch_count;
5423 size_t *quota = ira->backward_branch_quota;5420 size_t *quota = ira->backward_branch_quota;
54245421
...@@ -5430,16 +5427,16 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInst* source_instruction)...@@ -5430,16 +5427,16 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInst* source_instruction)
54305427
5431 *bbc += 1;5428 *bbc += 1;
5432 if (*bbc > *quota) {5429 if (*bbc > *quota) {
5433 ir_add_error(ira, source_instruction,5430 ir_add_error_node(ira, source_node,
5434 buf_sprintf("evaluation exceeded %" ZIG_PRI_usize " backwards branches", *quota));5431 buf_sprintf("evaluation exceeded %" ZIG_PRI_usize " backwards branches", *quota));
5435 return false;5432 return false;
5436 }5433 }
5437 return true;5434 return true;
5438}5435}
54395436
5440static IrInstGen *ir_inline_bb(IrAnalyze *ira, IrInst* source_instruction, Stage1ZirBasicBlock *old_bb) {5437static IrInstGen *ir_inline_bb(IrAnalyze *ira, AstNode* source_node, Stage1ZirBasicBlock *old_bb) {
5441 if (old_bb->debug_id <= ira->zir_current_basic_block->debug_id) {5438 if (old_bb->debug_id <= ira->zir_current_basic_block->debug_id) {
5442 if (!ir_emit_backward_branch(ira, source_instruction))5439 if (!ir_emit_backward_branch(ira, source_node))
5443 return ir_unreach_error(ira);5440 return ir_unreach_error(ira);
5444 }5441 }
54455442
...@@ -5454,8 +5451,8 @@ static IrInstGen *ir_finish_anal(IrAnalyze *ira, IrInstGen *instruction) {...@@ -5454,8 +5451,8 @@ static IrInstGen *ir_finish_anal(IrAnalyze *ira, IrInstGen *instruction) {
5454 return instruction;5451 return instruction;
5455}5452}
54565453
5457static IrInstGen *ir_const_fn(IrAnalyze *ira, IrInst *source_instr, ZigFn *fn_entry) {5454static IrInstGen *ir_const_fn(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigFn *fn_entry) {
5458 IrInstGen *result = ir_const(ira, source_instr, fn_entry->type_entry);5455 IrInstGen *result = ir_const(ira, scope, source_node, fn_entry->type_entry);
5459 result->value->special = ConstValSpecialStatic;5456 result->value->special = ConstValSpecialStatic;
5460 result->value->data.x_ptr.data.fn.fn_entry = fn_entry;5457 result->value->data.x_ptr.data.fn.fn_entry = fn_entry;
5461 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;5458 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;
...@@ -5463,62 +5460,62 @@ static IrInstGen *ir_const_fn(IrAnalyze *ira, IrInst *source_instr, ZigFn *fn_en...@@ -5463,62 +5460,62 @@ static IrInstGen *ir_const_fn(IrAnalyze *ira, IrInst *source_instr, ZigFn *fn_en
5463 return result;5460 return result;
5464}5461}
54655462
5466static IrInstGen *ir_const_bound_fn(IrAnalyze *ira, IrInst *src_inst, ZigFn *fn_entry, IrInstGen *first_arg,5463static IrInstGen *ir_const_bound_fn(IrAnalyze *ira, Scope *scope, AstNode *source_node,
5467 IrInst *first_arg_src)5464 ZigFn *fn_entry, IrInstGen *first_arg, AstNode *first_arg_src)
5468{5465{
5469 // This is unfortunately required to avoid improperly freeing first_arg_src5466 // This is unfortunately required to avoid improperly freeing first_arg_src
5470 ira_ref(ira);5467 ira_ref(ira);
54715468
5472 IrInstGen *result = ir_const(ira, src_inst, get_bound_fn_type(ira->codegen, fn_entry));5469 IrInstGen *result = ir_const(ira, scope, source_node, get_bound_fn_type(ira->codegen, fn_entry));
5473 result->value->data.x_bound_fn.fn = fn_entry;5470 result->value->data.x_bound_fn.fn = fn_entry;
5474 result->value->data.x_bound_fn.first_arg = first_arg;5471 result->value->data.x_bound_fn.first_arg = first_arg;
5475 result->value->data.x_bound_fn.first_arg_src = first_arg_src;5472 result->value->data.x_bound_fn.first_arg_src = first_arg_src;
5476 return result;5473 return result;
5477}5474}
54785475
5479static IrInstGen *ir_const_type(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) {5476static IrInstGen *ir_const_type(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ty) {
5480 IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_type);5477 IrInstGen *result = ir_const(ira, scope, source_node, ira->codegen->builtin_types.entry_type);
5481 result->value->data.x_type = ty;5478 result->value->data.x_type = ty;
5482 return result;5479 return result;
5483}5480}
54845481
5485static IrInstGen *ir_const_bool(IrAnalyze *ira, IrInst *source_instruction, bool value) {5482static IrInstGen *ir_const_bool(IrAnalyze *ira, Scope *scope, AstNode *source_node, bool value) {
5486 IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool);5483 IrInstGen *result = ir_const(ira, scope, source_node, ira->codegen->builtin_types.entry_bool);
5487 result->value->data.x_bool = value;5484 result->value->data.x_bool = value;
5488 return result;5485 return result;
5489}5486}
54905487
5491static IrInstGen *ir_const_undef(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) {5488static IrInstGen *ir_const_undef(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ty) {
5492 IrInstGen *result = ir_const(ira, source_instruction, ty);5489 IrInstGen *result = ir_const(ira, scope, source_node, ty);
5493 result->value->special = ConstValSpecialUndef;5490 result->value->special = ConstValSpecialUndef;
5494 return result;5491 return result;
5495}5492}
54965493
5497static IrInstGen *ir_const_unreachable(IrAnalyze *ira, IrInst *source_instruction) {5494static IrInstGen *ir_const_unreachable(IrAnalyze *ira, Scope *scope, AstNode *source_node) {
5498 IrInstGen *result = ir_const_noval(ira, source_instruction);5495 IrInstGen *result = ir_const_noval(ira, scope, source_node);
5499 result->value = ira->codegen->intern.for_unreachable();5496 result->value = ira->codegen->intern.for_unreachable();
5500 return result;5497 return result;
5501}5498}
55025499
5503static IrInstGen *ir_const_void(IrAnalyze *ira, IrInst *source_instruction) {5500static IrInstGen *ir_const_void(IrAnalyze *ira, Scope *scope, AstNode *source_node) {
5504 IrInstGen *result = ir_const_noval(ira, source_instruction);5501 IrInstGen *result = ir_const_noval(ira, scope, source_node);
5505 result->value = ira->codegen->intern.for_void();5502 result->value = ira->codegen->intern.for_void();
5506 return result;5503 return result;
5507}5504}
55085505
5509static IrInstGen *ir_const_unsigned(IrAnalyze *ira, IrInst *source_instruction, uint64_t value) {5506static IrInstGen *ir_const_unsigned(IrAnalyze *ira, Scope *scope, AstNode *source_node, uint64_t value) {
5510 IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int);5507 IrInstGen *result = ir_const(ira, scope, source_node, ira->codegen->builtin_types.entry_num_lit_int);
5511 bigint_init_unsigned(&result->value->data.x_bigint, value);5508 bigint_init_unsigned(&result->value->data.x_bigint, value);
5512 return result;5509 return result;
5513}5510}
55145511
5515static IrInstGen *ir_get_const_ptr(IrAnalyze *ira, IrInst *instruction,5512static IrInstGen *ir_get_const_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node,
5516 ZigValue *pointee, ZigType *pointee_type,5513 ZigValue *pointee, ZigType *pointee_type,
5517 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)5514 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)
5518{5515{
5519 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,5516 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
5520 ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false);5517 ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false);
5521 IrInstGen *const_instr = ir_const(ira, instruction, ptr_type);5518 IrInstGen *const_instr = ir_const(ira, scope, source_node, ptr_type);
5522 ZigValue *const_val = const_instr->value;5519 ZigValue *const_val = const_instr->value;
5523 const_val->data.x_ptr.special = ConstPtrSpecialRef;5520 const_val->data.x_ptr.special = ConstPtrSpecialRef;
5524 const_val->data.x_ptr.mut = ptr_mut;5521 const_val->data.x_ptr.mut = ptr_mut;
...@@ -5562,7 +5559,7 @@ static Error ir_resolve_const_val(CodeGen *codegen, Stage1Air *exec, AstNode *so...@@ -5562,7 +5559,7 @@ static Error ir_resolve_const_val(CodeGen *codegen, Stage1Air *exec, AstNode *so
55625559
5563static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed) {5560static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed) {
5564 Error err;5561 Error err;
5565 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->base.source_node,5562 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->source_node,
5566 value->value, undef_allowed)))5563 value->value, undef_allowed)))
5567 {5564 {
5568 return nullptr;5565 return nullptr;
...@@ -5641,7 +5638,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstGen *err_value) {...@@ -5641,7 +5638,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstGen *err_value) {
5641 return nullptr;5638 return nullptr;
56425639
5643 if (err_value->value->type->id != ZigTypeIdErrorSet) {5640 if (err_value->value->type->id != ZigTypeIdErrorSet) {
5644 ir_add_error_node(ira, err_value->base.source_node,5641 ir_add_error_node(ira, err_value->source_node,
5645 buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value->type->name)));5642 buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value->type->name)));
5646 return nullptr;5643 return nullptr;
5647 }5644 }
...@@ -5670,13 +5667,13 @@ static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstGen *type_value) {...@@ -5670,13 +5667,13 @@ static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstGen *type_value) {
5670 return nullptr;5667 return nullptr;
56715668
5672 if (type_value->value->type->id != ZigTypeIdMetaType) {5669 if (type_value->value->type->id != ZigTypeIdMetaType) {
5673 ir_add_error_node(ira, type_value->base.source_node,5670 ir_add_error_node(ira, type_value->source_node,
5674 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value->type->name)));5671 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value->type->name)));
5675 return nullptr;5672 return nullptr;
5676 }5673 }
56775674
5678 Error err;5675 Error err;
5679 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->base.source_node,5676 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->source_node,
5680 type_value->value, LazyOkNoUndef)))5677 type_value->value, LazyOkNoUndef)))
5681 {5678 {
5682 return nullptr;5679 return nullptr;
...@@ -5690,7 +5687,7 @@ static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstGen *type_value) {...@@ -5690,7 +5687,7 @@ static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstGen *type_value) {
5690 if (val == nullptr)5687 if (val == nullptr)
5691 return ira->codegen->builtin_types.entry_invalid;5688 return ira->codegen->builtin_types.entry_invalid;
56925689
5693 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, type_value->base.source_node, val);5690 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, type_value->source_node, val);
5694}5691}
56955692
5696static Error ir_validate_vector_elem_type(IrAnalyze *ira, AstNode *source_node, ZigType *elem_type) {5693static Error ir_validate_vector_elem_type(IrAnalyze *ira, AstNode *source_node, ZigType *elem_type) {
...@@ -5712,7 +5709,7 @@ static ZigType *ir_resolve_vector_elem_type(IrAnalyze *ira, IrInstGen *elem_type...@@ -5712,7 +5709,7 @@ static ZigType *ir_resolve_vector_elem_type(IrAnalyze *ira, IrInstGen *elem_type
5712 ZigType *elem_type = ir_resolve_type(ira, elem_type_value);5709 ZigType *elem_type = ir_resolve_type(ira, elem_type_value);
5713 if (type_is_invalid(elem_type))5710 if (type_is_invalid(elem_type))
5714 return ira->codegen->builtin_types.entry_invalid;5711 return ira->codegen->builtin_types.entry_invalid;
5715 if ((err = ir_validate_vector_elem_type(ira, elem_type_value->base.source_node, elem_type)))5712 if ((err = ir_validate_vector_elem_type(ira, elem_type_value->source_node, elem_type)))
5716 return ira->codegen->builtin_types.entry_invalid;5713 return ira->codegen->builtin_types.entry_invalid;
5717 return elem_type;5714 return elem_type;
5718}5715}
...@@ -5723,12 +5720,12 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstGen *type_value) {...@@ -5723,12 +5720,12 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstGen *type_value) {
5723 return ira->codegen->builtin_types.entry_invalid;5720 return ira->codegen->builtin_types.entry_invalid;
57245721
5725 if (ty->id != ZigTypeIdInt) {5722 if (ty->id != ZigTypeIdInt) {
5726 ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node,5723 ErrorMsg *msg = ir_add_error_node(ira, type_value->source_node,
5727 buf_sprintf("expected integer type, found '%s'", buf_ptr(&ty->name)));5724 buf_sprintf("expected integer type, found '%s'", buf_ptr(&ty->name)));
5728 if (ty->id == ZigTypeIdVector &&5725 if (ty->id == ZigTypeIdVector &&
5729 ty->data.vector.elem_type->id == ZigTypeIdInt)5726 ty->data.vector.elem_type->id == ZigTypeIdInt)
5730 {5727 {
5731 add_error_note(ira->codegen, msg, type_value->base.source_node,5728 add_error_note(ira->codegen, msg, type_value->source_node,
5732 buf_sprintf("represent vectors with their element types, i.e. '%s'",5729 buf_sprintf("represent vectors with their element types, i.e. '%s'",
5733 buf_ptr(&ty->data.vector.elem_type->name)));5730 buf_ptr(&ty->data.vector.elem_type->name)));
5734 }5731 }
...@@ -5738,14 +5735,14 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstGen *type_value) {...@@ -5738,14 +5735,14 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstGen *type_value) {
5738 return ty;5735 return ty;
5739}5736}
57405737
5741static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInst *op_source, IrInstGen *type_value) {5738static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, AstNode *op_source, IrInstGen *type_value) {
5742 if (type_is_invalid(type_value->value->type))5739 if (type_is_invalid(type_value->value->type))
5743 return ira->codegen->builtin_types.entry_invalid;5740 return ira->codegen->builtin_types.entry_invalid;
57445741
5745 if (type_value->value->type->id != ZigTypeIdMetaType) {5742 if (type_value->value->type->id != ZigTypeIdMetaType) {
5746 ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node,5743 ErrorMsg *msg = ir_add_error_node(ira, type_value->source_node,
5747 buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value->type->name)));5744 buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value->type->name)));
5748 add_error_note(ira->codegen, msg, op_source->source_node,5745 add_error_note(ira->codegen, msg, op_source,
5749 buf_sprintf("`||` merges error sets; `or` performs boolean OR"));5746 buf_sprintf("`||` merges error sets; `or` performs boolean OR"));
5750 return ira->codegen->builtin_types.entry_invalid;5747 return ira->codegen->builtin_types.entry_invalid;
5751 }5748 }
...@@ -5757,9 +5754,9 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInst *op_source, IrI...@@ -5757,9 +5754,9 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInst *op_source, IrI
5757 assert(const_val->data.x_type != nullptr);5754 assert(const_val->data.x_type != nullptr);
5758 ZigType *result_type = const_val->data.x_type;5755 ZigType *result_type = const_val->data.x_type;
5759 if (result_type->id != ZigTypeIdErrorSet) {5756 if (result_type->id != ZigTypeIdErrorSet) {
5760 ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node,5757 ErrorMsg *msg = ir_add_error_node(ira, type_value->source_node,
5761 buf_sprintf("expected error set type, found type '%s'", buf_ptr(&result_type->name)));5758 buf_sprintf("expected error set type, found type '%s'", buf_ptr(&result_type->name)));
5762 add_error_note(ira->codegen, msg, op_source->source_node,5759 add_error_note(ira->codegen, msg, op_source,
5763 buf_sprintf("`||` merges error sets; `or` performs boolean OR"));5760 buf_sprintf("`||` merges error sets; `or` performs boolean OR"));
5764 return ira->codegen->builtin_types.entry_invalid;5761 return ira->codegen->builtin_types.entry_invalid;
5765 }5762 }
...@@ -5771,7 +5768,7 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstGen *fn_value) {...@@ -5771,7 +5768,7 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstGen *fn_value) {
5771 return nullptr;5768 return nullptr;
57725769
5773 if (fn_value->value->type->id != ZigTypeIdFn) {5770 if (fn_value->value->type->id != ZigTypeIdFn) {
5774 ir_add_error_node(ira, fn_value->base.source_node,5771 ir_add_error_node(ira, fn_value->source_node,
5775 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value->type->name)));5772 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value->type->name)));
5776 return nullptr;5773 return nullptr;
5777 }5774 }
...@@ -5787,7 +5784,7 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstGen *fn_value) {...@@ -5787,7 +5784,7 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstGen *fn_value) {
5787 return const_val->data.x_ptr.data.fn.fn_entry;5784 return const_val->data.x_ptr.data.fn.fn_entry;
5788}5785}
57895786
5790static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr,5787static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, Scope *scope, AstNode *source_node,
5791 IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc)5788 IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc)
5792{5789{
5793 assert(wanted_type->id == ZigTypeIdOptional);5790 assert(wanted_type->id == ZigTypeIdOptional);
...@@ -5803,7 +5800,7 @@ static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr,...@@ -5803,7 +5800,7 @@ static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr,
5803 return ira->codegen->invalid_inst_gen;5800 return ira->codegen->invalid_inst_gen;
58045801
5805 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,5802 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
5806 source_instr->scope, source_instr->source_node);5803 scope, source_node);
5807 const_instruction->base.value->special = ConstValSpecialStatic;5804 const_instruction->base.value->special = ConstValSpecialStatic;
5808 if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) {5805 if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) {
5809 copy_const_val(ira->codegen, const_instruction->base.value, val);5806 copy_const_val(ira->codegen, const_instruction->base.value, val);
...@@ -5819,19 +5816,19 @@ static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr,...@@ -5819,19 +5816,19 @@ static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr,
5819 }5816 }
5820 IrInstGen *result_loc_inst = nullptr;5817 IrInstGen *result_loc_inst = nullptr;
5821 if (result_loc != nullptr) {5818 if (result_loc != nullptr) {
5822 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true);5819 result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, result_loc, wanted_type, nullptr, true, true);
5823 if (type_is_invalid(result_loc_inst->value->type) ||5820 if (type_is_invalid(result_loc_inst->value->type) ||
5824 result_loc_inst->value->type->id == ZigTypeIdUnreachable)5821 result_loc_inst->value->type->id == ZigTypeIdUnreachable)
5825 {5822 {
5826 return result_loc_inst;5823 return result_loc_inst;
5827 }5824 }
5828 }5825 }
5829 IrInstGen *result = ir_build_optional_wrap(ira, source_instr, wanted_type, value, result_loc_inst);5826 IrInstGen *result = ir_build_optional_wrap(ira, scope, source_node, wanted_type, value, result_loc_inst);
5830 result->value->data.rh_maybe = RuntimeHintOptionalNonNull;5827 result->value->data.rh_maybe = RuntimeHintOptionalNonNull;
5831 return result;5828 return result;
5832}5829}
58335830
5834static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_instr,5831static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, Scope *scope, AstNode *source_node,
5835 IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc)5832 IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc)
5836{5833{
5837 assert(wanted_type->id == ZigTypeIdErrorUnion);5834 assert(wanted_type->id == ZigTypeIdErrorUnion);
...@@ -5853,7 +5850,7 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins...@@ -5853,7 +5850,7 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins
5853 err_set_val->data.x_err_set = nullptr;5850 err_set_val->data.x_err_set = nullptr;
58545851
5855 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,5852 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
5856 source_instr->scope, source_instr->source_node);5853 scope, source_node);
5857 const_instruction->base.value->type = wanted_type;5854 const_instruction->base.value->type = wanted_type;
5858 const_instruction->base.value->special = ConstValSpecialStatic;5855 const_instruction->base.value->special = ConstValSpecialStatic;
5859 const_instruction->base.value->data.x_err_union.error_set = err_set_val;5856 const_instruction->base.value->data.x_err_union.error_set = err_set_val;
...@@ -5864,7 +5861,7 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins...@@ -5864,7 +5861,7 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins
5864 IrInstGen *result_loc_inst;5861 IrInstGen *result_loc_inst;
5865 if (handle_is_ptr(ira->codegen, wanted_type)) {5862 if (handle_is_ptr(ira->codegen, wanted_type)) {
5866 if (result_loc == nullptr) result_loc = no_result_loc();5863 if (result_loc == nullptr) result_loc = no_result_loc();
5867 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true);5864 result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, result_loc, wanted_type, nullptr, true, true);
5868 if (type_is_invalid(result_loc_inst->value->type) ||5865 if (type_is_invalid(result_loc_inst->value->type) ||
5869 result_loc_inst->value->type->id == ZigTypeIdUnreachable) {5866 result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
5870 return result_loc_inst;5867 return result_loc_inst;
...@@ -5873,12 +5870,12 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins...@@ -5873,12 +5870,12 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins
5873 result_loc_inst = nullptr;5870 result_loc_inst = nullptr;
5874 }5871 }
58755872
5876 IrInstGen *result = ir_build_err_wrap_payload(ira, source_instr, wanted_type, value, result_loc_inst);5873 IrInstGen *result = ir_build_err_wrap_payload(ira, scope, source_node, wanted_type, value, result_loc_inst);
5877 result->value->data.rh_error_union = RuntimeHintErrorUnionNonError;5874 result->value->data.rh_error_union = RuntimeHintErrorUnionNonError;
5878 return result;5875 return result;
5879}5876}
58805877
5881static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,5878static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
5882 ZigType *wanted_type)5879 ZigType *wanted_type)
5883{5880{
5884 assert(value->value->type->id == ZigTypeIdErrorSet);5881 assert(value->value->type->id == ZigTypeIdErrorSet);
...@@ -5889,7 +5886,7 @@ static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr,...@@ -5889,7 +5886,7 @@ static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr,
5889 if (!val)5886 if (!val)
5890 return ira->codegen->invalid_inst_gen;5887 return ira->codegen->invalid_inst_gen;
58915888
5892 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) {5889 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_node)) {
5893 return ira->codegen->invalid_inst_gen;5890 return ira->codegen->invalid_inst_gen;
5894 }5891 }
5895 if (!type_is_global_error_set(wanted_type)) {5892 if (!type_is_global_error_set(wanted_type)) {
...@@ -5901,7 +5898,7 @@ static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr,...@@ -5901,7 +5898,7 @@ static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr,
5901 }5898 }
5902 }5899 }
5903 if (!subset) {5900 if (!subset) {
5904 ir_add_error(ira, source_instr,5901 ir_add_error_node(ira, source_node,
5905 buf_sprintf("error.%s not a member of error set '%s'",5902 buf_sprintf("error.%s not a member of error set '%s'",
5906 buf_ptr(&val->data.x_err_set->name), buf_ptr(&wanted_type->name)));5903 buf_ptr(&val->data.x_err_set->name), buf_ptr(&wanted_type->name)));
5907 return ira->codegen->invalid_inst_gen;5904 return ira->codegen->invalid_inst_gen;
...@@ -5909,17 +5906,17 @@ static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr,...@@ -5909,17 +5906,17 @@ static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr,
5909 }5906 }
59105907
5911 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,5908 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
5912 source_instr->scope, source_instr->source_node);5909 scope, source_node);
5913 const_instruction->base.value->type = wanted_type;5910 const_instruction->base.value->type = wanted_type;
5914 const_instruction->base.value->special = ConstValSpecialStatic;5911 const_instruction->base.value->special = ConstValSpecialStatic;
5915 const_instruction->base.value->data.x_err_set = val->data.x_err_set;5912 const_instruction->base.value->data.x_err_set = val->data.x_err_set;
5916 return &const_instruction->base;5913 return &const_instruction->base;
5917 }5914 }
59185915
5919 return ir_build_cast(ira, source_instr, wanted_type, value, CastOpErrSet);5916 return ir_build_cast(ira, scope, source_node, wanted_type, value, CastOpErrSet);
5920}5917}
59215918
5922static IrInstGen *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInst* source_instr,5919static IrInstGen *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, Scope *scope, AstNode *source_node,
5923 IrInstGen *frame_ptr, ZigType *wanted_type)5920 IrInstGen *frame_ptr, ZigType *wanted_type)
5924{5921{
5925 if (instr_is_comptime(frame_ptr)) {5922 if (instr_is_comptime(frame_ptr)) {
...@@ -5927,27 +5924,27 @@ static IrInstGen *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInst* sourc...@@ -5927,27 +5924,27 @@ static IrInstGen *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInst* sourc
5927 if (ptr_val == nullptr)5924 if (ptr_val == nullptr)
5928 return ira->codegen->invalid_inst_gen;5925 return ira->codegen->invalid_inst_gen;
59295926
5930 ir_assert(ptr_val->type->id == ZigTypeIdPointer, source_instr);5927 src_assert(ptr_val->type->id == ZigTypeIdPointer, source_node );
5931 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {5928 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
5932 zig_panic("TODO comptime frame pointer");5929 zig_panic("TODO comptime frame pointer");
5933 }5930 }
5934 }5931 }
59355932
5936 return ir_build_cast(ira, source_instr, wanted_type, frame_ptr, CastOpBitCast);5933 return ir_build_cast(ira, scope, source_node, wanted_type, frame_ptr, CastOpBitCast);
5937}5934}
59385935
5939static IrInstGen *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInst* source_instr,5936static IrInstGen *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, Scope *scope, AstNode *source_node,
5940 IrInstGen *value, ZigType *wanted_type)5937 IrInstGen *value, ZigType *wanted_type)
5941{5938{
5942 if (instr_is_comptime(value)) {5939 if (instr_is_comptime(value)) {
5943 zig_panic("TODO comptime anyframe->T to anyframe");5940 zig_panic("TODO comptime anyframe->T to anyframe");
5944 }5941 }
59455942
5946 return ir_build_cast(ira, source_instr, wanted_type, value, CastOpBitCast);5943 return ir_build_cast(ira, scope, source_node, wanted_type, value, CastOpBitCast);
5947}5944}
59485945
59495946
5950static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,5947static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
5951 ZigType *wanted_type, ResultLoc *result_loc)5948 ZigType *wanted_type, ResultLoc *result_loc)
5952{5949{
5953 assert(wanted_type->id == ZigTypeIdErrorUnion);5950 assert(wanted_type->id == ZigTypeIdErrorUnion);
...@@ -5965,7 +5962,7 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr,...@@ -5965,7 +5962,7 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr,
5965 err_set_val->data.x_err_set = val->data.x_err_set;5962 err_set_val->data.x_err_set = val->data.x_err_set;
59665963
5967 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,5964 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
5968 source_instr->scope, source_instr->source_node);5965 scope, source_node);
5969 const_instruction->base.value->type = wanted_type;5966 const_instruction->base.value->type = wanted_type;
5970 const_instruction->base.value->special = ConstValSpecialStatic;5967 const_instruction->base.value->special = ConstValSpecialStatic;
5971 const_instruction->base.value->data.x_err_union.error_set = err_set_val;5968 const_instruction->base.value->data.x_err_union.error_set = err_set_val;
...@@ -5976,7 +5973,7 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr,...@@ -5976,7 +5973,7 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr,
5976 IrInstGen *result_loc_inst;5973 IrInstGen *result_loc_inst;
5977 if (handle_is_ptr(ira->codegen, wanted_type)) {5974 if (handle_is_ptr(ira->codegen, wanted_type)) {
5978 if (result_loc == nullptr) result_loc = no_result_loc();5975 if (result_loc == nullptr) result_loc = no_result_loc();
5979 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true);5976 result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, result_loc, wanted_type, nullptr, true, true);
5980 if (type_is_invalid(result_loc_inst->value->type) ||5977 if (type_is_invalid(result_loc_inst->value->type) ||
5981 result_loc_inst->value->type->id == ZigTypeIdUnreachable)5978 result_loc_inst->value->type->id == ZigTypeIdUnreachable)
5982 {5979 {
...@@ -5987,19 +5984,19 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr,...@@ -5987,19 +5984,19 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr,
5987 }5984 }
59885985
59895986
5990 IrInstGen *result = ir_build_err_wrap_code(ira, source_instr, wanted_type, value, result_loc_inst);5987 IrInstGen *result = ir_build_err_wrap_code(ira, scope, source_node, wanted_type, value, result_loc_inst);
5991 result->value->data.rh_error_union = RuntimeHintErrorUnionError;5988 result->value->data.rh_error_union = RuntimeHintErrorUnionError;
5992 return result;5989 return result;
5993}5990}
59945991
5995static IrInstGen *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value, ZigType *wanted_type) {5992static IrInstGen *ir_analyze_null_to_maybe(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value, ZigType *wanted_type) {
5996 assert(wanted_type->id == ZigTypeIdOptional);5993 assert(wanted_type->id == ZigTypeIdOptional);
5997 assert(instr_is_comptime(value));5994 assert(instr_is_comptime(value));
59985995
5999 ZigValue *val = ir_resolve_const(ira, value, UndefBad);5996 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
6000 assert(val != nullptr);5997 assert(val != nullptr);
60015998
6002 IrInstGen *result = ir_const(ira, source_instr, wanted_type);5999 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
6003 result->value->special = ConstValSpecialStatic;6000 result->value->special = ConstValSpecialStatic;
60046001
6005 if (get_src_ptr_type(wanted_type) != nullptr) {6002 if (get_src_ptr_type(wanted_type) != nullptr) {
...@@ -6012,7 +6009,7 @@ static IrInstGen *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInst *source_instr,...@@ -6012,7 +6009,7 @@ static IrInstGen *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInst *source_instr,
6012 return result;6009 return result;
6013}6010}
60146011
6015static IrInstGen *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInst *source_instr,6012static IrInstGen *ir_analyze_null_to_c_pointer(IrAnalyze *ira, Scope *scope, AstNode *source_node,
6016 IrInstGen *value, ZigType *wanted_type)6013 IrInstGen *value, ZigType *wanted_type)
6017{6014{
6018 assert(wanted_type->id == ZigTypeIdPointer);6015 assert(wanted_type->id == ZigTypeIdPointer);
...@@ -6022,13 +6019,13 @@ static IrInstGen *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInst *source_in...@@ -6022,13 +6019,13 @@ static IrInstGen *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInst *source_in
6022 ZigValue *val = ir_resolve_const(ira, value, UndefBad);6019 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
6023 assert(val != nullptr);6020 assert(val != nullptr);
60246021
6025 IrInstGen *result = ir_const(ira, source_instr, wanted_type);6022 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
6026 result->value->data.x_ptr.special = ConstPtrSpecialNull;6023 result->value->data.x_ptr.special = ConstPtrSpecialNull;
6027 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;6024 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;
6028 return result;6025 return result;
6029}6026}
60306027
6031static IrInstGen *ir_get_ref2(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *value,6028static IrInstGen *ir_get_ref2(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
6032 ZigType *elem_type, bool is_const, bool is_volatile)6029 ZigType *elem_type, bool is_const, bool is_volatile)
6033{6030{
6034 Error err;6031 Error err;
...@@ -6040,7 +6037,7 @@ static IrInstGen *ir_get_ref2(IrAnalyze *ira, IrInst* source_instruction, IrInst...@@ -6040,7 +6037,7 @@ static IrInstGen *ir_get_ref2(IrAnalyze *ira, IrInst* source_instruction, IrInst
6040 ZigValue *val = ir_resolve_const(ira, value, LazyOk);6037 ZigValue *val = ir_resolve_const(ira, value, LazyOk);
6041 if (!val)6038 if (!val)
6042 return ira->codegen->invalid_inst_gen;6039 return ira->codegen->invalid_inst_gen;
6043 return ir_get_const_ptr(ira, source_instruction, val, elem_type,6040 return ir_get_const_ptr(ira, scope, source_node, val, elem_type,
6044 ConstPtrMutComptimeConst, is_const, is_volatile, 0);6041 ConstPtrMutComptimeConst, is_const, is_volatile, 0);
6045 }6042 }
60466043
...@@ -6052,20 +6049,20 @@ static IrInstGen *ir_get_ref2(IrAnalyze *ira, IrInst* source_instruction, IrInst...@@ -6052,20 +6049,20 @@ static IrInstGen *ir_get_ref2(IrAnalyze *ira, IrInst* source_instruction, IrInst
60526049
6053 IrInstGen *result_loc;6050 IrInstGen *result_loc;
6054 if (type_has_bits(ira->codegen, ptr_type) && !handle_is_ptr(ira->codegen, elem_type)) {6051 if (type_has_bits(ira->codegen, ptr_type) && !handle_is_ptr(ira->codegen, elem_type)) {
6055 result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), elem_type, nullptr, true, true);6052 result_loc = ir_resolve_result(ira, ira->suspend_source_instr, no_result_loc(), elem_type, nullptr, true, true);
6056 } else {6053 } else {
6057 result_loc = nullptr;6054 result_loc = nullptr;
6058 }6055 }
60596056
6060 IrInstGen *new_instruction = ir_build_ref_gen(ira, source_instruction, ptr_type, value, result_loc);6057 IrInstGen *new_instruction = ir_build_ref_gen(ira, scope, source_node, ptr_type, value, result_loc);
6061 new_instruction->value->data.rh_ptr = RuntimeHintPtrStack;6058 new_instruction->value->data.rh_ptr = RuntimeHintPtrStack;
6062 return new_instruction;6059 return new_instruction;
6063}6060}
60646061
6065static IrInstGen *ir_get_ref(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *value,6062static IrInstGen *ir_get_ref(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
6066 bool is_const, bool is_volatile)6063 bool is_const, bool is_volatile)
6067{6064{
6068 return ir_get_ref2(ira, source_instruction, value, value->value->type, is_const, is_volatile);6065 return ir_get_ref2(ira, scope, source_node, value, value->value->type, is_const, is_volatile);
6069}6066}
60706067
6071static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, AstNode *source_node, ZigType *union_type) {6068static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, AstNode *source_node, ZigType *union_type) {
...@@ -6099,13 +6096,13 @@ static bool can_fold_enum_type(ZigType *ty) {...@@ -6099,13 +6096,13 @@ static bool can_fold_enum_type(ZigType *ty) {
6099 (tag_int_type->id == ZigTypeIdInt && tag_int_type->data.integral.bit_count == 0);6096 (tag_int_type->id == ZigTypeIdInt && tag_int_type->data.integral.bit_count == 0);
6100}6097}
61016098
6102static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target) {6099static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target) {
6103 Error err;6100 Error err;
61046101
6105 IrInstGen *enum_target;6102 IrInstGen *enum_target;
6106 ZigType *enum_type;6103 ZigType *enum_type;
6107 if (target->value->type->id == ZigTypeIdUnion) {6104 if (target->value->type->id == ZigTypeIdUnion) {
6108 enum_type = ir_resolve_union_tag_type(ira, target->base.source_node, target->value->type);6105 enum_type = ir_resolve_union_tag_type(ira, target->source_node, target->value->type);
6109 if (type_is_invalid(enum_type))6106 if (type_is_invalid(enum_type))
6110 return ira->codegen->invalid_inst_gen;6107 return ira->codegen->invalid_inst_gen;
6111 enum_target = ir_implicit_cast(ira, target, enum_type);6108 enum_target = ir_implicit_cast(ira, target, enum_type);
...@@ -6115,7 +6112,7 @@ static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, I...@@ -6115,7 +6112,7 @@ static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, I
6115 enum_target = target;6112 enum_target = target;
6116 enum_type = target->value->type;6113 enum_type = target->value->type;
6117 } else {6114 } else {
6118 ir_add_error_node(ira, target->base.source_node,6115 ir_add_error_node(ira, target->source_node,
6119 buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value->type->name)));6116 buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value->type->name)));
6120 return ira->codegen->invalid_inst_gen;6117 return ira->codegen->invalid_inst_gen;
6121 }6118 }
...@@ -6128,7 +6125,7 @@ static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, I...@@ -6128,7 +6125,7 @@ static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, I
61286125
6129 // If there is only one possible tag, then we know at comptime what it is.6126 // If there is only one possible tag, then we know at comptime what it is.
6130 if (can_fold_enum_type(enum_type)) {6127 if (can_fold_enum_type(enum_type)) {
6131 IrInstGen *result = ir_const(ira, source_instr, tag_type);6128 IrInstGen *result = ir_const(ira, scope, source_node, tag_type);
6132 init_const_bigint(result->value, tag_type,6129 init_const_bigint(result->value, tag_type,
6133 &enum_type->data.enumeration.fields[0].value);6130 &enum_type->data.enumeration.fields[0].value);
6134 return result;6131 return result;
...@@ -6138,15 +6135,15 @@ static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, I...@@ -6138,15 +6135,15 @@ static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, I
6138 ZigValue *val = ir_resolve_const(ira, enum_target, UndefBad);6135 ZigValue *val = ir_resolve_const(ira, enum_target, UndefBad);
6139 if (!val)6136 if (!val)
6140 return ira->codegen->invalid_inst_gen;6137 return ira->codegen->invalid_inst_gen;
6141 IrInstGen *result = ir_const(ira, source_instr, tag_type);6138 IrInstGen *result = ir_const(ira, scope, source_node, tag_type);
6142 init_const_bigint(result->value, tag_type, &val->data.x_enum_tag);6139 init_const_bigint(result->value, tag_type, &val->data.x_enum_tag);
6143 return result;6140 return result;
6144 }6141 }
61456142
6146 return ir_build_widen_or_shorten(ira, source_instr->scope, source_instr->source_node, enum_target, tag_type);6143 return ir_build_widen_or_shorten(ira, scope, source_node, enum_target, tag_type);
6147}6144}
61486145
6149static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr,6146static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, Scope *scope, AstNode *source_node,
6150 IrInstGen *target, ZigType *wanted_type)6147 IrInstGen *target, ZigType *wanted_type)
6151{6148{
6152 assert(target->value->type->id == ZigTypeIdUnion);6149 assert(target->value->type->id == ZigTypeIdUnion);
...@@ -6157,7 +6154,7 @@ static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr,...@@ -6157,7 +6154,7 @@ static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr,
6157 ZigValue *val = ir_resolve_const(ira, target, UndefBad);6154 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
6158 if (!val)6155 if (!val)
6159 return ira->codegen->invalid_inst_gen;6156 return ira->codegen->invalid_inst_gen;
6160 IrInstGen *result = ir_const(ira, source_instr, wanted_type);6157 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
6161 result->value->special = ConstValSpecialStatic;6158 result->value->special = ConstValSpecialStatic;
6162 result->value->type = wanted_type;6159 result->value->type = wanted_type;
6163 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_union.tag);6160 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_union.tag);
...@@ -6166,7 +6163,7 @@ static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr,...@@ -6166,7 +6163,7 @@ static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr,
61666163
6167 // If there is only 1 possible tag, then we know at comptime what it is.6164 // If there is only 1 possible tag, then we know at comptime what it is.
6168 if (can_fold_enum_type(wanted_type)) {6165 if (can_fold_enum_type(wanted_type)) {
6169 IrInstGen *result = ir_const(ira, source_instr, wanted_type);6166 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
6170 result->value->special = ConstValSpecialStatic;6167 result->value->special = ConstValSpecialStatic;
6171 result->value->type = wanted_type;6168 result->value->type = wanted_type;
6172 TypeEnumField *enum_field = target->value->type->data.unionation.fields[0].enum_field;6169 TypeEnumField *enum_field = target->value->type->data.unionation.fields[0].enum_field;
...@@ -6174,18 +6171,18 @@ static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr,...@@ -6174,18 +6171,18 @@ static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr,
6174 return result;6171 return result;
6175 }6172 }
61766173
6177 return ir_build_union_tag(ira, source_instr, target, wanted_type);6174 return ir_build_union_tag(ira, scope, source_node, target, wanted_type);
6178}6175}
61796176
6180static IrInstGen *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInst* source_instr,6177static IrInstGen *ir_analyze_undefined_to_anything(IrAnalyze *ira, Scope *scope, AstNode *source_node,
6181 IrInstGen *target, ZigType *wanted_type)6178 IrInstGen *target, ZigType *wanted_type)
6182{6179{
6183 IrInstGen *result = ir_const(ira, source_instr, wanted_type);6180 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
6184 result->value->special = ConstValSpecialUndef;6181 result->value->special = ConstValSpecialUndef;
6185 return result;6182 return result;
6186}6183}
61876184
6188static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,6185static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, Scope *scope, AstNode *source_node,
6189 IrInstGen *uncasted_target, ZigType *wanted_type)6186 IrInstGen *uncasted_target, ZigType *wanted_type)
6190{6187{
6191 Error err;6188 Error err;
...@@ -6207,7 +6204,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,...@@ -6207,7 +6204,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
6207 Buf *int_buf = buf_alloc();6204 Buf *int_buf = buf_alloc();
6208 bigint_append_buf(int_buf, &target->value->data.x_enum_tag, 10);6205 bigint_append_buf(int_buf, &target->value->data.x_enum_tag, 10);
62096206
6210 ir_add_error(ira, &target->base,6207 ir_add_error(ira, target,
6211 buf_sprintf("no tag by value %s", buf_ptr(int_buf)));6208 buf_sprintf("no tag by value %s", buf_ptr(int_buf)));
6212 return ira->codegen->invalid_inst_gen;6209 return ira->codegen->invalid_inst_gen;
6213 }6210 }
...@@ -6223,7 +6220,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,...@@ -6223,7 +6220,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
6223 case OnePossibleValueNo: {6220 case OnePossibleValueNo: {
6224 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(6221 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(
6225 union_field->enum_field->decl_index);6222 union_field->enum_field->decl_index);
6226 ErrorMsg *msg = ir_add_error(ira, source_instr,6223 ErrorMsg *msg = ir_add_error_node(ira, source_node,
6227 buf_sprintf("cast to union '%s' must initialize '%s' field '%s'",6224 buf_sprintf("cast to union '%s' must initialize '%s' field '%s'",
6228 buf_ptr(&wanted_type->name),6225 buf_ptr(&wanted_type->name),
6229 buf_ptr(&field_type->name),6226 buf_ptr(&field_type->name),
...@@ -6236,7 +6233,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,...@@ -6236,7 +6233,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
6236 break;6233 break;
6237 }6234 }
62386235
6239 IrInstGen *result = ir_const(ira, source_instr, wanted_type);6236 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
6240 result->value->special = ConstValSpecialStatic;6237 result->value->special = ConstValSpecialStatic;
6241 result->value->type = wanted_type;6238 result->value->type = wanted_type;
6242 bigint_init_bigint(&result->value->data.x_union.tag, &val->data.x_enum_tag);6239 bigint_init_bigint(&result->value->data.x_union.tag, &val->data.x_enum_tag);
...@@ -6247,7 +6244,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,...@@ -6247,7 +6244,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
6247 }6244 }
62486245
6249 if (target->value->type->data.enumeration.non_exhaustive) {6246 if (target->value->type->data.enumeration.non_exhaustive) {
6250 ir_add_error(ira, source_instr,6247 ir_add_error_node(ira, source_node,
6251 buf_sprintf("runtime cast to union '%s' from non-exhustive enum",6248 buf_sprintf("runtime cast to union '%s' from non-exhustive enum",
6252 buf_ptr(&wanted_type->name)));6249 buf_ptr(&wanted_type->name)));
6253 return ira->codegen->invalid_inst_gen;6250 return ira->codegen->invalid_inst_gen;
...@@ -6256,10 +6253,10 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,...@@ -6256,10 +6253,10 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
6256 // if the union has all fields 0 bits, we can do it6253 // if the union has all fields 0 bits, we can do it
6257 // and in fact it's a noop cast because the union value is just the enum value6254 // and in fact it's a noop cast because the union value is just the enum value
6258 if (wanted_type->data.unionation.gen_field_count == 0) {6255 if (wanted_type->data.unionation.gen_field_count == 0) {
6259 return ir_build_cast(ira, &target->base, wanted_type, target, CastOpNoop);6256 return ir_build_cast(ira, target->scope, target->source_node, wanted_type, target, CastOpNoop);
6260 }6257 }
62616258
6262 ErrorMsg *msg = ir_add_error(ira, source_instr,6259 ErrorMsg *msg = ir_add_error_node(ira, source_node,
6263 buf_sprintf("runtime cast to union '%s' which has non-void fields",6260 buf_sprintf("runtime cast to union '%s' which has non-void fields",
6264 buf_ptr(&wanted_type->name)));6261 buf_ptr(&wanted_type->name)));
6265 for (uint32_t i = 0; i < wanted_type->data.unionation.src_field_count; i += 1) {6262 for (uint32_t i = 0; i < wanted_type->data.unionation.src_field_count; i += 1) {
...@@ -6283,7 +6280,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,...@@ -6283,7 +6280,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
62836280
6284static bool value_numeric_fits_in_type(ZigValue *value, ZigType *type_entry);6281static bool value_numeric_fits_in_type(ZigValue *value, ZigType *type_entry);
62856282
6286static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_instr,6283static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, Scope *scope, AstNode *source_node,
6287 IrInstGen *target, ZigType *wanted_type)6284 IrInstGen *target, ZigType *wanted_type)
6288{6285{
6289 ZigType *wanted_scalar_type = (target->value->type->id == ZigTypeIdVector) ?6286 ZigType *wanted_scalar_type = (target->value->type->id == ZigTypeIdVector) ?
...@@ -6298,19 +6295,19 @@ static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_ins...@@ -6298,19 +6295,19 @@ static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_ins
62986295
6299 if (wanted_scalar_type->id == ZigTypeIdInt) {6296 if (wanted_scalar_type->id == ZigTypeIdInt) {
6300 if (!wanted_scalar_type->data.integral.is_signed && value_cmp_numeric_val_any(val, CmpLT, nullptr)) {6297 if (!wanted_scalar_type->data.integral.is_signed && value_cmp_numeric_val_any(val, CmpLT, nullptr)) {
6301 ir_add_error(ira, source_instr,6298 ir_add_error_node(ira, source_node,
6302 buf_sprintf("attempt to cast negative value to unsigned integer"));6299 buf_sprintf("attempt to cast negative value to unsigned integer"));
6303 return ira->codegen->invalid_inst_gen;6300 return ira->codegen->invalid_inst_gen;
6304 }6301 }
6305 if (!value_numeric_fits_in_type(val, wanted_scalar_type)) {6302 if (!value_numeric_fits_in_type(val, wanted_scalar_type)) {
6306 ir_add_error(ira, source_instr,6303 ir_add_error_node(ira, source_node,
6307 buf_sprintf("cast from '%s' to '%s' truncates bits",6304 buf_sprintf("cast from '%s' to '%s' truncates bits",
6308 buf_ptr(&target->value->type->name), buf_ptr(&wanted_scalar_type->name)));6305 buf_ptr(&target->value->type->name), buf_ptr(&wanted_scalar_type->name)));
6309 return ira->codegen->invalid_inst_gen;6306 return ira->codegen->invalid_inst_gen;
6310 }6307 }
6311 }6308 }
63126309
6313 IrInstGen *result = ir_const(ira, source_instr, wanted_type);6310 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
6314 result->value->type = wanted_type;6311 result->value->type = wanted_type;
63156312
6316 if (wanted_type->id == ZigTypeIdVector) {6313 if (wanted_type->id == ZigTypeIdVector) {
...@@ -6346,16 +6343,16 @@ static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_ins...@@ -6346,16 +6343,16 @@ static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_ins
6346 if (!type_has_bits(ira->codegen, wanted_type)) {6343 if (!type_has_bits(ira->codegen, wanted_type)) {
6347 assert(wanted_type->id == ZigTypeIdInt);6344 assert(wanted_type->id == ZigTypeIdInt);
6348 assert(type_has_bits(ira->codegen, target->value->type));6345 assert(type_has_bits(ira->codegen, target->value->type));
6349 ir_build_assert_zero(ira, source_instr, target);6346 ir_build_assert_zero(ira, scope, source_node, target);
6350 IrInstGen *result = ir_const_unsigned(ira, source_instr, 0);6347 IrInstGen *result = ir_const_unsigned(ira, scope, source_node, 0);
6351 result->value->type = wanted_type;6348 result->value->type = wanted_type;
6352 return result;6349 return result;
6353 }6350 }
63546351
6355 return ir_build_widen_or_shorten(ira, source_instr->scope, source_instr->source_node, target, wanted_type);6352 return ir_build_widen_or_shorten(ira, scope, source_node, target, wanted_type);
6356}6353}
63576354
6358static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr,6355static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, Scope *scope, AstNode *source_node,
6359 IrInstGen *target, ZigType *wanted_type)6356 IrInstGen *target, ZigType *wanted_type)
6360{6357{
6361 Error err;6358 Error err;
...@@ -6367,7 +6364,7 @@ static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr,...@@ -6367,7 +6364,7 @@ static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr,
6367 return ira->codegen->invalid_inst_gen;6364 return ira->codegen->invalid_inst_gen;
63686365
6369 if (actual_type != wanted_type->data.enumeration.tag_int_type) {6366 if (actual_type != wanted_type->data.enumeration.tag_int_type) {
6370 ir_add_error(ira, source_instr,6367 ir_add_error_node(ira, source_node,
6371 buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'",6368 buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'",
6372 buf_ptr(&actual_type->name),6369 buf_ptr(&actual_type->name),
6373 buf_ptr(&wanted_type->data.enumeration.tag_int_type->name)));6370 buf_ptr(&wanted_type->data.enumeration.tag_int_type->name)));
...@@ -6385,7 +6382,7 @@ static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr,...@@ -6385,7 +6382,7 @@ static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr,
6385 if (field == nullptr && !wanted_type->data.enumeration.non_exhaustive) {6382 if (field == nullptr && !wanted_type->data.enumeration.non_exhaustive) {
6386 Buf *val_buf = buf_alloc();6383 Buf *val_buf = buf_alloc();
6387 bigint_append_buf(val_buf, &val->data.x_bigint, 10);6384 bigint_append_buf(val_buf, &val->data.x_bigint, 10);
6388 ErrorMsg *msg = ir_add_error(ira, source_instr,6385 ErrorMsg *msg = ir_add_error_node(ira, source_node,
6389 buf_sprintf("enum '%s' has no tag matching integer value %s",6386 buf_sprintf("enum '%s' has no tag matching integer value %s",
6390 buf_ptr(&wanted_type->name), buf_ptr(val_buf)));6387 buf_ptr(&wanted_type->name), buf_ptr(val_buf)));
6391 add_error_note(ira->codegen, msg, wanted_type->data.enumeration.decl_node,6388 add_error_note(ira->codegen, msg, wanted_type->data.enumeration.decl_node,
...@@ -6393,22 +6390,22 @@ static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr,...@@ -6393,22 +6390,22 @@ static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr,
6393 return ira->codegen->invalid_inst_gen;6390 return ira->codegen->invalid_inst_gen;
6394 }6391 }
63956392
6396 IrInstGen *result = ir_const(ira, source_instr, wanted_type);6393 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
6397 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_bigint);6394 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_bigint);
6398 return result;6395 return result;
6399 }6396 }
64006397
6401 return ir_build_int_to_enum_gen(ira, source_instr->scope, source_instr->source_node, wanted_type, target);6398 return ir_build_int_to_enum_gen(ira, scope, source_node, wanted_type, target);
6402}6399}
64036400
6404static IrInstGen *ir_analyze_number_to_literal(IrAnalyze *ira, IrInst* source_instr,6401static IrInstGen *ir_analyze_number_to_literal(IrAnalyze *ira, Scope *scope, AstNode *source_node,
6405 IrInstGen *target, ZigType *wanted_type)6402 IrInstGen *target, ZigType *wanted_type)
6406{6403{
6407 ZigValue *val = ir_resolve_const(ira, target, UndefBad);6404 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
6408 if (!val)6405 if (!val)
6409 return ira->codegen->invalid_inst_gen;6406 return ira->codegen->invalid_inst_gen;
64106407
6411 IrInstGen *result = ir_const(ira, source_instr, wanted_type);6408 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
6412 if (wanted_type->id == ZigTypeIdComptimeFloat) {6409 if (wanted_type->id == ZigTypeIdComptimeFloat) {
6413 float_init_float(result->value, val);6410 float_init_float(result->value, val);
6414 } else if (wanted_type->id == ZigTypeIdComptimeInt) {6411 } else if (wanted_type->id == ZigTypeIdComptimeInt) {
...@@ -6419,7 +6416,7 @@ static IrInstGen *ir_analyze_number_to_literal(IrAnalyze *ira, IrInst* source_in...@@ -6419,7 +6416,7 @@ static IrInstGen *ir_analyze_number_to_literal(IrAnalyze *ira, IrInst* source_in
6419 return result;6416 return result;
6420}6417}
64216418
6422static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,6419static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
6423 ZigType *wanted_type)6420 ZigType *wanted_type)
6424{6421{
6425 assert(target->value->type->id == ZigTypeIdInt);6422 assert(target->value->type->id == ZigTypeIdInt);
...@@ -6431,9 +6428,9 @@ static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, Ir...@@ -6431,9 +6428,9 @@ static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, Ir
6431 if (!val)6428 if (!val)
6432 return ira->codegen->invalid_inst_gen;6429 return ira->codegen->invalid_inst_gen;
64336430
6434 IrInstGen *result = ir_const(ira, source_instr, wanted_type);6431 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
64356432
6436 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) {6433 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_node)) {
6437 return ira->codegen->invalid_inst_gen;6434 return ira->codegen->invalid_inst_gen;
6438 }6435 }
64396436
...@@ -6444,7 +6441,7 @@ static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, Ir...@@ -6444,7 +6441,7 @@ static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, Ir
6444 if (bigint_cmp_zero(&val->data.x_bigint) == CmpEQ || bigint_cmp(&val->data.x_bigint, &err_count) != CmpLT) {6441 if (bigint_cmp_zero(&val->data.x_bigint) == CmpEQ || bigint_cmp(&val->data.x_bigint, &err_count) != CmpLT) {
6445 Buf *val_buf = buf_alloc();6442 Buf *val_buf = buf_alloc();
6446 bigint_append_buf(val_buf, &val->data.x_bigint, 10);6443 bigint_append_buf(val_buf, &val->data.x_bigint, 10);
6447 ir_add_error(ira, source_instr,6444 ir_add_error_node(ira, source_node,
6448 buf_sprintf("integer value %s represents no error", buf_ptr(val_buf)));6445 buf_sprintf("integer value %s represents no error", buf_ptr(val_buf)));
6449 return ira->codegen->invalid_inst_gen;6446 return ira->codegen->invalid_inst_gen;
6450 }6447 }
...@@ -6468,7 +6465,7 @@ static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, Ir...@@ -6468,7 +6465,7 @@ static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, Ir
6468 if (err == nullptr) {6465 if (err == nullptr) {
6469 Buf *val_buf = buf_alloc();6466 Buf *val_buf = buf_alloc();
6470 bigint_append_buf(val_buf, &val->data.x_bigint, 10);6467 bigint_append_buf(val_buf, &val->data.x_bigint, 10);
6471 ir_add_error(ira, source_instr,6468 ir_add_error_node(ira, source_node,
6472 buf_sprintf("integer value %s represents no error in '%s'", buf_ptr(val_buf), buf_ptr(&wanted_type->name)));6469 buf_sprintf("integer value %s represents no error in '%s'", buf_ptr(val_buf), buf_ptr(&wanted_type->name)));
6473 return ira->codegen->invalid_inst_gen;6470 return ira->codegen->invalid_inst_gen;
6474 }6471 }
...@@ -6478,10 +6475,10 @@ static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, Ir...@@ -6478,10 +6475,10 @@ static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, Ir
6478 }6475 }
6479 }6476 }
64806477
6481 return ir_build_int_to_err_gen(ira, source_instr->scope, source_instr->source_node, target, wanted_type);6478 return ir_build_int_to_err_gen(ira, scope, source_node, target, wanted_type);
6482}6479}
64836480
6484static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,6481static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
6485 ZigType *wanted_type)6482 ZigType *wanted_type)
6486{6483{
6487 assert(wanted_type->id == ZigTypeIdInt);6484 assert(wanted_type->id == ZigTypeIdInt);
...@@ -6493,7 +6490,7 @@ static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, Ir...@@ -6493,7 +6490,7 @@ static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, Ir
6493 if (!val)6490 if (!val)
6494 return ira->codegen->invalid_inst_gen;6491 return ira->codegen->invalid_inst_gen;
64956492
6496 IrInstGen *result = ir_const(ira, source_instr, wanted_type);6493 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
64976494
6498 ErrorTableEntry *err;6495 ErrorTableEntry *err;
6499 if (err_type->id == ZigTypeIdErrorUnion) {6496 if (err_type->id == ZigTypeIdErrorUnion) {
...@@ -6510,7 +6507,7 @@ static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, Ir...@@ -6510,7 +6507,7 @@ static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, Ir
6510 if (!bigint_fits_in_bits(&result->value->data.x_bigint,6507 if (!bigint_fits_in_bits(&result->value->data.x_bigint,
6511 wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed))6508 wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed))
6512 {6509 {
6513 ir_add_error_node(ira, source_instr->source_node,6510 ir_add_error_node(ira, source_node,
6514 buf_sprintf("error code '%s' does not fit in '%s'",6511 buf_sprintf("error code '%s' does not fit in '%s'",
6515 buf_ptr(&err->name), buf_ptr(&wanted_type->name)));6512 buf_ptr(&err->name), buf_ptr(&wanted_type->name)));
6516 return ira->codegen->invalid_inst_gen;6513 return ira->codegen->invalid_inst_gen;
...@@ -6528,15 +6525,15 @@ static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, Ir...@@ -6528,15 +6525,15 @@ static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, Ir
6528 zig_unreachable();6525 zig_unreachable();
6529 }6526 }
6530 if (!type_is_global_error_set(err_set_type)) {6527 if (!type_is_global_error_set(err_set_type)) {
6531 if (!resolve_inferred_error_set(ira->codegen, err_set_type, source_instr->source_node)) {6528 if (!resolve_inferred_error_set(ira->codegen, err_set_type, source_node)) {
6532 return ira->codegen->invalid_inst_gen;6529 return ira->codegen->invalid_inst_gen;
6533 }6530 }
6534 if (err_set_type->data.error_set.err_count == 0) {6531 if (err_set_type->data.error_set.err_count == 0) {
6535 IrInstGen *result = ir_const(ira, source_instr, wanted_type);6532 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
6536 bigint_init_unsigned(&result->value->data.x_bigint, 0);6533 bigint_init_unsigned(&result->value->data.x_bigint, 0);
6537 return result;6534 return result;
6538 } else if (err_set_type->data.error_set.err_count == 1) {6535 } else if (err_set_type->data.error_set.err_count == 1) {
6539 IrInstGen *result = ir_const(ira, source_instr, wanted_type);6536 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
6540 ErrorTableEntry *err = err_set_type->data.error_set.errors[0];6537 ErrorTableEntry *err = err_set_type->data.error_set.errors[0];
6541 bigint_init_unsigned(&result->value->data.x_bigint, err->value);6538 bigint_init_unsigned(&result->value->data.x_bigint, err->value);
6542 return result;6539 return result;
...@@ -6546,15 +6543,15 @@ static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, Ir...@@ -6546,15 +6543,15 @@ static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, Ir
6546 BigInt bn;6543 BigInt bn;
6547 bigint_init_unsigned(&bn, ira->codegen->errors_by_index.length);6544 bigint_init_unsigned(&bn, ira->codegen->errors_by_index.length);
6548 if (!bigint_fits_in_bits(&bn, wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed)) {6545 if (!bigint_fits_in_bits(&bn, wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed)) {
6549 ir_add_error_node(ira, source_instr->source_node,6546 ir_add_error_node(ira, source_node,
6550 buf_sprintf("too many error values to fit in '%s'", buf_ptr(&wanted_type->name)));6547 buf_sprintf("too many error values to fit in '%s'", buf_ptr(&wanted_type->name)));
6551 return ira->codegen->invalid_inst_gen;6548 return ira->codegen->invalid_inst_gen;
6552 }6549 }
65536550
6554 return ir_build_err_to_int_gen(ira, source_instr->scope, source_instr->source_node, target, wanted_type);6551 return ir_build_err_to_int_gen(ira, scope, source_node, target, wanted_type);
6555}6552}
65566553
6557static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,6554static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
6558 ZigType *wanted_type)6555 ZigType *wanted_type)
6559{6556{
6560 assert(wanted_type->id == ZigTypeIdPointer);6557 assert(wanted_type->id == ZigTypeIdPointer);
...@@ -6573,7 +6570,7 @@ static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr,...@@ -6573,7 +6570,7 @@ static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr,
6573 return ira->codegen->invalid_inst_gen;6570 return ira->codegen->invalid_inst_gen;
65746571
6575 assert(val->type->id == ZigTypeIdPointer);6572 assert(val->type->id == ZigTypeIdPointer);
6576 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);6573 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_node);
6577 if (pointee == nullptr)6574 if (pointee == nullptr)
6578 return ira->codegen->invalid_inst_gen;6575 return ira->codegen->invalid_inst_gen;
6579 if (pointee->special != ConstValSpecialRuntime) {6576 if (pointee->special != ConstValSpecialRuntime) {
...@@ -6586,7 +6583,7 @@ static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr,...@@ -6586,7 +6583,7 @@ static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr,
6586 array_val->parent.data.p_scalar.scalar_val = pointee;6583 array_val->parent.data.p_scalar.scalar_val = pointee;
65876584
6588 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,6585 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
6589 source_instr->scope, source_instr->source_node);6586 scope, source_node);
6590 const_instruction->base.value->type = wanted_type;6587 const_instruction->base.value->type = wanted_type;
6591 const_instruction->base.value->special = ConstValSpecialStatic;6588 const_instruction->base.value->special = ConstValSpecialStatic;
6592 const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialRef;6589 const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialRef;
...@@ -6597,7 +6594,7 @@ static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr,...@@ -6597,7 +6594,7 @@ static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr,
6597 }6594 }
65986595
6599 // pointer to array and pointer to single item are represented the same way at runtime6596 // pointer to array and pointer to single item are represented the same way at runtime
6600 return ir_build_cast(ira, &target->base, wanted_type, target, CastOpBitCast);6597 return ir_build_cast(ira, target->scope, target->source_node, wanted_type, target, CastOpBitCast);
6601}6598}
66026599
6603static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCastOnly *cast_result,6600static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCastOnly *cast_result,
...@@ -6794,25 +6791,25 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa...@@ -6794,25 +6791,25 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa
6794 }6791 }
6795}6792}
67966793
6797static IrInstGen *ir_analyze_array_to_vector(IrAnalyze *ira, IrInst* source_instr,6794static IrInstGen *ir_analyze_array_to_vector(IrAnalyze *ira, Scope *scope, AstNode *source_node,
6798 IrInstGen *array, ZigType *vector_type)6795 IrInstGen *array, ZigType *vector_type)
6799{6796{
6800 if (instr_is_comptime(array)) {6797 if (instr_is_comptime(array)) {
6801 // arrays and vectors have the same ZigValue representation6798 // arrays and vectors have the same ZigValue representation
6802 IrInstGen *result = ir_const(ira, source_instr, vector_type);6799 IrInstGen *result = ir_const(ira, scope, source_node, vector_type);
6803 copy_const_val(ira->codegen, result->value, array->value);6800 copy_const_val(ira->codegen, result->value, array->value);
6804 result->value->type = vector_type;6801 result->value->type = vector_type;
6805 return result;6802 return result;
6806 }6803 }
6807 return ir_build_array_to_vector(ira, source_instr, array, vector_type);6804 return ir_build_array_to_vector(ira, scope, source_node, array, vector_type);
6808}6805}
68096806
6810static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, IrInst* source_instr,6807static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, Scope *scope, AstNode *source_node,
6811 IrInstGen *vector, ZigType *array_type, ResultLoc *result_loc)6808 IrInstGen *vector, ZigType *array_type, ResultLoc *result_loc)
6812{6809{
6813 if (instr_is_comptime(vector)) {6810 if (instr_is_comptime(vector)) {
6814 // arrays and vectors have the same ZigValue representation6811 // arrays and vectors have the same ZigValue representation
6815 IrInstGen *result = ir_const(ira, source_instr, array_type);6812 IrInstGen *result = ir_const(ira, scope, source_node, array_type);
6816 copy_const_val(ira->codegen, result->value, vector->value);6813 copy_const_val(ira->codegen, result->value, vector->value);
6817 result->value->type = array_type;6814 result->value->type = array_type;
6818 return result;6815 return result;
...@@ -6820,14 +6817,14 @@ static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, IrInst* source_inst...@@ -6820,14 +6817,14 @@ static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, IrInst* source_inst
6820 if (result_loc == nullptr) {6817 if (result_loc == nullptr) {
6821 result_loc = no_result_loc();6818 result_loc = no_result_loc();
6822 }6819 }
6823 IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, true, true);6820 IrInstGen *result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, result_loc, array_type, nullptr, true, true);
6824 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {6821 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
6825 return result_loc_inst;6822 return result_loc_inst;
6826 }6823 }
6827 return ir_build_vector_to_array(ira, source_instr, array_type, vector, result_loc_inst);6824 return ir_build_vector_to_array(ira, scope, source_node, array_type, vector, result_loc_inst);
6828}6825}
68296826
6830static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr,6827static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node,
6831 IrInstGen *integer, ZigType *dest_type)6828 IrInstGen *integer, ZigType *dest_type)
6832{6829{
6833 IrInstGen *unsigned_integer;6830 IrInstGen *unsigned_integer;
...@@ -6839,7 +6836,7 @@ static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr,...@@ -6839,7 +6836,7 @@ static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr,
6839 if (integer->value->type->data.integral.bit_count >6836 if (integer->value->type->data.integral.bit_count >
6840 ira->codegen->builtin_types.entry_usize->data.integral.bit_count)6837 ira->codegen->builtin_types.entry_usize->data.integral.bit_count)
6841 {6838 {
6842 ir_add_error(ira, source_instr,6839 ir_add_error_node(ira, source_node,
6843 buf_sprintf("integer type '%s' too big for implicit @intToPtr to type '%s'",6840 buf_sprintf("integer type '%s' too big for implicit @intToPtr to type '%s'",
6844 buf_ptr(&integer->value->type->name),6841 buf_ptr(&integer->value->type->name),
6845 buf_ptr(&dest_type->name)));6842 buf_ptr(&dest_type->name)));
...@@ -6849,7 +6846,7 @@ static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr,...@@ -6849,7 +6846,7 @@ static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr,
6849 if (integer->value->type->data.integral.is_signed) {6846 if (integer->value->type->data.integral.is_signed) {
6850 ZigType *unsigned_int_type = get_int_type(ira->codegen, false,6847 ZigType *unsigned_int_type = get_int_type(ira->codegen, false,
6851 integer->value->type->data.integral.bit_count);6848 integer->value->type->data.integral.bit_count);
6852 unsigned_integer = ir_analyze_bit_cast(ira, source_instr, integer, unsigned_int_type);6849 unsigned_integer = ir_analyze_bit_cast(ira, scope, source_node, integer, unsigned_int_type);
6853 if (type_is_invalid(unsigned_integer->value->type))6850 if (type_is_invalid(unsigned_integer->value->type))
6854 return ira->codegen->invalid_inst_gen;6851 return ira->codegen->invalid_inst_gen;
6855 } else {6852 } else {
...@@ -6857,7 +6854,7 @@ static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr,...@@ -6857,7 +6854,7 @@ static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr,
6857 }6854 }
6858 }6855 }
68596856
6860 return ir_analyze_int_to_ptr(ira, source_instr, unsigned_integer, dest_type);6857 return ir_analyze_int_to_ptr(ira, scope, source_node, unsigned_integer, dest_type);
6861}6858}
68626859
6863static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) {6860static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) {
...@@ -6871,7 +6868,7 @@ static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) {...@@ -6871,7 +6868,7 @@ static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) {
6871 return false;6868 return false;
6872}6869}
68736870
6874static IrInstGen *ir_analyze_enum_literal(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,6871static IrInstGen *ir_analyze_enum_literal(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
6875 ZigType *enum_type)6872 ZigType *enum_type)
6876{6873{
6877 assert(enum_type->id == ZigTypeIdEnum);6874 assert(enum_type->id == ZigTypeIdEnum);
...@@ -6882,19 +6879,19 @@ static IrInstGen *ir_analyze_enum_literal(IrAnalyze *ira, IrInst* source_instr,...@@ -6882,19 +6879,19 @@ static IrInstGen *ir_analyze_enum_literal(IrAnalyze *ira, IrInst* source_instr,
68826879
6883 TypeEnumField *field = find_enum_type_field(enum_type, value->value->data.x_enum_literal);6880 TypeEnumField *field = find_enum_type_field(enum_type, value->value->data.x_enum_literal);
6884 if (field == nullptr) {6881 if (field == nullptr) {
6885 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("enum '%s' has no field named '%s'",6882 ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("enum '%s' has no field named '%s'",
6886 buf_ptr(&enum_type->name), buf_ptr(value->value->data.x_enum_literal)));6883 buf_ptr(&enum_type->name), buf_ptr(value->value->data.x_enum_literal)));
6887 add_error_note(ira->codegen, msg, enum_type->data.enumeration.decl_node,6884 add_error_note(ira->codegen, msg, enum_type->data.enumeration.decl_node,
6888 buf_sprintf("'%s' declared here", buf_ptr(&enum_type->name)));6885 buf_sprintf("'%s' declared here", buf_ptr(&enum_type->name)));
6889 return ira->codegen->invalid_inst_gen;6886 return ira->codegen->invalid_inst_gen;
6890 }6887 }
6891 IrInstGen *result = ir_const(ira, source_instr, enum_type);6888 IrInstGen *result = ir_const(ira, scope, source_node, enum_type);
6892 bigint_init_bigint(&result->value->data.x_enum_tag, &field->value);6889 bigint_init_bigint(&result->value->data.x_enum_tag, &field->value);
68936890
6894 return result;6891 return result;
6895}6892}
68966893
6897static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* source_instr,6894static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, Scope *scope, AstNode *source_node,
6898 IrInstGen *struct_ptr, ZigType *actual_type, ZigType *wanted_type)6895 IrInstGen *struct_ptr, ZigType *actual_type, ZigType *wanted_type)
6899{6896{
6900 Error err;6897 Error err;
...@@ -6906,7 +6903,7 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou...@@ -6906,7 +6903,7 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou
6906 size_t instr_field_count = actual_type->data.structure.src_field_count;6903 size_t instr_field_count = actual_type->data.structure.src_field_count;
6907 assert(array_len == instr_field_count);6904 assert(array_len == instr_field_count);
69086905
6909 bool need_comptime = ir_should_inline(ira->zir, source_instr->scope)6906 bool need_comptime = ir_should_inline(ira->zir, scope)
6910 || type_requires_comptime(ira->codegen, wanted_type) == ReqCompTimeYes;6907 || type_requires_comptime(ira->codegen, wanted_type) == ReqCompTimeYes;
6911 bool is_comptime = true;6908 bool is_comptime = true;
69126909
...@@ -6915,16 +6912,16 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou...@@ -6915,16 +6912,16 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou
6915 // Determine if the struct_operand will be comptime.6912 // Determine if the struct_operand will be comptime.
6916 ZigValue *elem_values = heap::c_allocator.allocate<ZigValue>(array_len);6913 ZigValue *elem_values = heap::c_allocator.allocate<ZigValue>(array_len);
6917 IrInstGen **casted_fields = heap::c_allocator.allocate<IrInstGen *>(array_len);6914 IrInstGen **casted_fields = heap::c_allocator.allocate<IrInstGen *>(array_len);
6918 IrInstGen *const_result = ir_const(ira, source_instr, wanted_type);6915 IrInstGen *const_result = ir_const(ira, scope, source_node, wanted_type);
69196916
6920 for (size_t i = 0; i < array_len; i += 1) {6917 for (size_t i = 0; i < array_len; i += 1) {
6921 TypeStructField *src_field = actual_type->data.structure.fields[i];6918 TypeStructField *src_field = actual_type->data.structure.fields[i];
69226919
6923 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, src_field, struct_ptr,6920 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, src_field, struct_ptr,
6924 actual_type, false);6921 actual_type, false);
6925 if (type_is_invalid(field_ptr->value->type))6922 if (type_is_invalid(field_ptr->value->type))
6926 return ira->codegen->invalid_inst_gen;6923 return ira->codegen->invalid_inst_gen;
6927 IrInstGen *field_value = ir_get_deref(ira, source_instr, field_ptr, nullptr);6924 IrInstGen *field_value = ir_get_deref(ira, scope, source_node, field_ptr, nullptr);
6928 if (type_is_invalid(field_value->value->type))6925 if (type_is_invalid(field_value->value->type))
6929 return ira->codegen->invalid_inst_gen;6926 return ira->codegen->invalid_inst_gen;
6930 IrInstGen *casted_value = ir_implicit_cast(ira, field_value, elem_type);6927 IrInstGen *casted_value = ir_implicit_cast(ira, field_value, elem_type);
...@@ -6950,13 +6947,13 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou...@@ -6950,13 +6947,13 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou
6950 }6947 }
69516948
6952 if (is_comptime) {6949 if (is_comptime) {
6953 IrInstGen *const_result = ir_const(ira, source_instr, wanted_type);6950 IrInstGen *const_result = ir_const(ira, scope, source_node, wanted_type);
6954 const_result->value->data.x_array.special = ConstArraySpecialNone;6951 const_result->value->data.x_array.special = ConstArraySpecialNone;
6955 const_result->value->data.x_array.data.s_none.elements = elem_values;6952 const_result->value->data.x_array.data.s_none.elements = elem_values;
6956 return const_result;6953 return const_result;
6957 }6954 }
69586955
6959 IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, no_result_loc(),6956 IrInstGen *result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, no_result_loc(),
6960 wanted_type, nullptr, true, true);6957 wanted_type, nullptr, true, true);
6961 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {6958 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
6962 return ira->codegen->invalid_inst_gen;6959 return ira->codegen->invalid_inst_gen;
...@@ -6964,12 +6961,12 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou...@@ -6964,12 +6961,12 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou
69646961
6965 ZigType *elem_type_ptr = get_pointer_to_type(ira->codegen, elem_type, false);6962 ZigType *elem_type_ptr = get_pointer_to_type(ira->codegen, elem_type, false);
6966 for (size_t i = 0; i < array_len; i += 1) {6963 for (size_t i = 0; i < array_len; i += 1) {
6967 IrInstGen *index_val = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize);6964 IrInstGen *index_val = ir_const(ira, scope, source_node, ira->codegen->builtin_types.entry_usize);
6968 bigint_init_unsigned(&index_val->value->data.x_bigint, i);6965 bigint_init_unsigned(&index_val->value->data.x_bigint, i);
69696966
6970 IrInstGen *elem_ptr = ir_build_elem_ptr_gen(ira, source_instr->scope, source_instr->source_node,6967 IrInstGen *elem_ptr = ir_build_elem_ptr_gen(ira, scope, source_node,
6971 result_loc_inst, index_val, false, elem_type_ptr);6968 result_loc_inst, index_val, false, elem_type_ptr);
6972 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, elem_ptr, casted_fields[i], true);6969 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, scope, source_node, elem_ptr, casted_fields[i], true);
6973 if (type_is_invalid(store_ptr_inst->value->type))6970 if (type_is_invalid(store_ptr_inst->value->type))
6974 return ira->codegen->invalid_inst_gen;6971 return ira->codegen->invalid_inst_gen;
6975 }6972 }
...@@ -6980,13 +6977,13 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou...@@ -6980,13 +6977,13 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou
6980 return result_loc_inst;6977 return result_loc_inst;
6981}6978}
69826979
6983static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* source_instr,6980static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, Scope *scope, AstNode *source_node,
6984 IrInstGen *struct_ptr, ZigType *actual_type, ZigType *wanted_type)6981 IrInstGen *struct_ptr, ZigType *actual_type, ZigType *wanted_type)
6985{6982{
6986 Error err;6983 Error err;
69876984
6988 if (wanted_type->data.structure.resolve_status == ResolveStatusBeingInferred) {6985 if (wanted_type->data.structure.resolve_status == ResolveStatusBeingInferred) {
6989 ir_add_error(ira, source_instr, buf_sprintf("type coercion of anon struct literal to inferred struct"));6986 ir_add_error_node(ira, source_node, buf_sprintf("type coercion of anon struct literal to inferred struct"));
6990 return ira->codegen->invalid_inst_gen;6987 return ira->codegen->invalid_inst_gen;
6991 }6988 }
69926989
...@@ -6996,7 +6993,7 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so...@@ -6996,7 +6993,7 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so
6996 size_t actual_field_count = wanted_type->data.structure.src_field_count;6993 size_t actual_field_count = wanted_type->data.structure.src_field_count;
6997 size_t instr_field_count = actual_type->data.structure.src_field_count;6994 size_t instr_field_count = actual_type->data.structure.src_field_count;
69986995
6999 bool need_comptime = ir_should_inline(ira->zir, source_instr->scope)6996 bool need_comptime = ir_should_inline(ira->zir, scope)
7000 || type_requires_comptime(ira->codegen, wanted_type) == ReqCompTimeYes;6997 || type_requires_comptime(ira->codegen, wanted_type) == ReqCompTimeYes;
7001 bool is_comptime = true;6998 bool is_comptime = true;
70026999
...@@ -7005,13 +7002,13 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so...@@ -7005,13 +7002,13 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so
7005 AstNode **field_assign_nodes = heap::c_allocator.allocate<AstNode *>(actual_field_count);7002 AstNode **field_assign_nodes = heap::c_allocator.allocate<AstNode *>(actual_field_count);
7006 ZigValue **field_values = heap::c_allocator.allocate<ZigValue *>(actual_field_count);7003 ZigValue **field_values = heap::c_allocator.allocate<ZigValue *>(actual_field_count);
7007 IrInstGen **casted_fields = heap::c_allocator.allocate<IrInstGen *>(actual_field_count);7004 IrInstGen **casted_fields = heap::c_allocator.allocate<IrInstGen *>(actual_field_count);
7008 IrInstGen *const_result = ir_const(ira, source_instr, wanted_type);7005 IrInstGen *const_result = ir_const(ira, scope, source_node, wanted_type);
70097006
7010 for (size_t i = 0; i < instr_field_count; i += 1) {7007 for (size_t i = 0; i < instr_field_count; i += 1) {
7011 TypeStructField *src_field = actual_type->data.structure.fields[i];7008 TypeStructField *src_field = actual_type->data.structure.fields[i];
7012 TypeStructField *dst_field = find_struct_type_field(wanted_type, src_field->name);7009 TypeStructField *dst_field = find_struct_type_field(wanted_type, src_field->name);
7013 if (dst_field == nullptr) {7010 if (dst_field == nullptr) {
7014 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("no field named '%s' in struct '%s'",7011 ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("no field named '%s' in struct '%s'",
7015 buf_ptr(src_field->name), buf_ptr(&wanted_type->name)));7012 buf_ptr(src_field->name), buf_ptr(&wanted_type->name)));
7016 if (wanted_type->data.structure.decl_node) {7013 if (wanted_type->data.structure.decl_node) {
7017 add_error_note(ira->codegen, msg, wanted_type->data.structure.decl_node,7014 add_error_note(ira->codegen, msg, wanted_type->data.structure.decl_node,
...@@ -7022,20 +7019,20 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so...@@ -7022,20 +7019,20 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so
7022 return ira->codegen->invalid_inst_gen;7019 return ira->codegen->invalid_inst_gen;
7023 }7020 }
70247021
7025 ir_assert(src_field->decl_node != nullptr, source_instr);7022 src_assert(src_field->decl_node != nullptr, source_node);
7026 AstNode *existing_assign_node = field_assign_nodes[dst_field->src_index];7023 AstNode *existing_assign_node = field_assign_nodes[dst_field->src_index];
7027 if (existing_assign_node != nullptr) {7024 if (existing_assign_node != nullptr) {
7028 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("duplicate field"));7025 ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("duplicate field"));
7029 add_error_note(ira->codegen, msg, existing_assign_node, buf_sprintf("other field here"));7026 add_error_note(ira->codegen, msg, existing_assign_node, buf_sprintf("other field here"));
7030 return ira->codegen->invalid_inst_gen;7027 return ira->codegen->invalid_inst_gen;
7031 }7028 }
7032 field_assign_nodes[dst_field->src_index] = src_field->decl_node;7029 field_assign_nodes[dst_field->src_index] = src_field->decl_node;
70337030
7034 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, src_field, struct_ptr,7031 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, src_field, struct_ptr,
7035 actual_type, false);7032 actual_type, false);
7036 if (type_is_invalid(field_ptr->value->type))7033 if (type_is_invalid(field_ptr->value->type))
7037 return ira->codegen->invalid_inst_gen;7034 return ira->codegen->invalid_inst_gen;
7038 IrInstGen *field_value = ir_get_deref(ira, source_instr, field_ptr, nullptr);7035 IrInstGen *field_value = ir_get_deref(ira, scope, source_node, field_ptr, nullptr);
7039 if (type_is_invalid(field_value->value->type))7036 if (type_is_invalid(field_value->value->type))
7040 return ira->codegen->invalid_inst_gen;7037 return ira->codegen->invalid_inst_gen;
7041 IrInstGen *casted_value = ir_implicit_cast(ira, field_value, dst_field->type_entry);7038 IrInstGen *casted_value = ir_implicit_cast(ira, field_value, dst_field->type_entry);
...@@ -7067,7 +7064,7 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so...@@ -7067,7 +7064,7 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so
7067 TypeStructField *field = wanted_type->data.structure.fields[i];7064 TypeStructField *field = wanted_type->data.structure.fields[i];
7068 memoize_field_init_val(ira->codegen, wanted_type, field);7065 memoize_field_init_val(ira->codegen, wanted_type, field);
7069 if (field->init_val == nullptr) {7066 if (field->init_val == nullptr) {
7070 ir_add_error(ira, source_instr,7067 ir_add_error_node(ira, source_node,
7071 buf_sprintf("missing field: '%s'", buf_ptr(field->name)));7068 buf_sprintf("missing field: '%s'", buf_ptr(field->name)));
7072 any_missing = true;7069 any_missing = true;
7073 continue;7070 continue;
...@@ -7080,19 +7077,19 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so...@@ -7080,19 +7077,19 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so
7080 init_val_copy->parent.data.p_struct.struct_val = const_result->value;7077 init_val_copy->parent.data.p_struct.struct_val = const_result->value;
7081 init_val_copy->parent.data.p_struct.field_index = i;7078 init_val_copy->parent.data.p_struct.field_index = i;
7082 field_values[i] = init_val_copy;7079 field_values[i] = init_val_copy;
7083 casted_fields[i] = ir_const_move(ira, source_instr, init_val_copy);7080 casted_fields[i] = ir_const_move(ira, scope, source_node, init_val_copy);
7084 }7081 }
7085 if (any_missing)7082 if (any_missing)
7086 return ira->codegen->invalid_inst_gen;7083 return ira->codegen->invalid_inst_gen;
70877084
7088 if (is_comptime) {7085 if (is_comptime) {
7089 heap::c_allocator.deallocate(field_assign_nodes, actual_field_count);7086 heap::c_allocator.deallocate(field_assign_nodes, actual_field_count);
7090 IrInstGen *const_result = ir_const(ira, source_instr, wanted_type);7087 IrInstGen *const_result = ir_const(ira, scope, source_node, wanted_type);
7091 const_result->value->data.x_struct.fields = field_values;7088 const_result->value->data.x_struct.fields = field_values;
7092 return const_result;7089 return const_result;
7093 }7090 }
70947091
7095 IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, no_result_loc(),7092 IrInstGen *result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, no_result_loc(),
7096 wanted_type, nullptr, true, true);7093 wanted_type, nullptr, true, true);
7097 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {7094 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
7098 return ira->codegen->invalid_inst_gen;7095 return ira->codegen->invalid_inst_gen;
...@@ -7100,10 +7097,10 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so...@@ -7100,10 +7097,10 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so
71007097
7101 for (size_t i = 0; i < actual_field_count; i += 1) {7098 for (size_t i = 0; i < actual_field_count; i += 1) {
7102 TypeStructField *field = wanted_type->data.structure.fields[i];7099 TypeStructField *field = wanted_type->data.structure.fields[i];
7103 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, result_loc_inst, wanted_type, true);7100 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, field, result_loc_inst, wanted_type, true);
7104 if (type_is_invalid(field_ptr->value->type))7101 if (type_is_invalid(field_ptr->value->type))
7105 return ira->codegen->invalid_inst_gen;7102 return ira->codegen->invalid_inst_gen;
7106 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, field_ptr, casted_fields[i], true);7103 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, scope, source_node, field_ptr, casted_fields[i], true);
7107 if (type_is_invalid(store_ptr_inst->value->type))7104 if (type_is_invalid(store_ptr_inst->value->type))
7108 return ira->codegen->invalid_inst_gen;7105 return ira->codegen->invalid_inst_gen;
7109 }7106 }
...@@ -7115,7 +7112,7 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so...@@ -7115,7 +7112,7 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so
7115 return result_loc_inst;7112 return result_loc_inst;
7116}7113}
71177114
7118static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* source_instr,7115static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, Scope *scope, AstNode *source_node,
7119 IrInstGen *struct_ptr, ZigType *struct_type, ZigType *union_type)7116 IrInstGen *struct_ptr, ZigType *struct_type, ZigType *union_type)
7120{7117{
7121 Error err;7118 Error err;
...@@ -7141,11 +7138,11 @@ static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* sou...@@ -7141,11 +7138,11 @@ static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* sou
7141 if (payload_type == nullptr)7138 if (payload_type == nullptr)
7142 return ira->codegen->invalid_inst_gen;7139 return ira->codegen->invalid_inst_gen;
71437140
7144 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, only_field, struct_ptr,7141 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, only_field, struct_ptr,
7145 struct_type, false);7142 struct_type, false);
7146 if (type_is_invalid(field_ptr->value->type))7143 if (type_is_invalid(field_ptr->value->type))
7147 return ira->codegen->invalid_inst_gen;7144 return ira->codegen->invalid_inst_gen;
7148 IrInstGen *field_value = ir_get_deref(ira, source_instr, field_ptr, nullptr);7145 IrInstGen *field_value = ir_get_deref(ira, scope, source_node, field_ptr, nullptr);
7149 if (type_is_invalid(field_value->value->type))7146 if (type_is_invalid(field_value->value->type))
7150 return ira->codegen->invalid_inst_gen;7147 return ira->codegen->invalid_inst_gen;
71517148
...@@ -7158,7 +7155,7 @@ static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* sou...@@ -7158,7 +7155,7 @@ static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* sou
7158 if (val == nullptr)7155 if (val == nullptr)
7159 return ira->codegen->invalid_inst_gen;7156 return ira->codegen->invalid_inst_gen;
71607157
7161 IrInstGen *result = ir_const(ira, source_instr, union_type);7158 IrInstGen *result = ir_const(ira, scope, source_node, union_type);
7162 bigint_init_bigint(&result->value->data.x_union.tag, &union_field->enum_field->value);7159 bigint_init_bigint(&result->value->data.x_union.tag, &union_field->enum_field->value);
7163 result->value->data.x_union.payload = val;7160 result->value->data.x_union.payload = val;
71647161
...@@ -7168,18 +7165,18 @@ static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* sou...@@ -7168,18 +7165,18 @@ static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* sou
7168 return result;7165 return result;
7169 }7166 }
71707167
7171 IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, no_result_loc(),7168 IrInstGen *result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, no_result_loc(),
7172 union_type, nullptr, true, true);7169 union_type, nullptr, true, true);
7173 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {7170 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
7174 return ira->codegen->invalid_inst_gen;7171 return ira->codegen->invalid_inst_gen;
7175 }7172 }
71767173
7177 IrInstGen *payload_ptr = ir_analyze_container_field_ptr(ira, only_field->name, source_instr,7174 IrInstGen *payload_ptr = ir_analyze_container_field_ptr(ira, only_field->name,
7178 result_loc_inst, source_instr, union_type, true);7175 scope, source_node, result_loc_inst, source_node, union_type, true);
7179 if (type_is_invalid(payload_ptr->value->type))7176 if (type_is_invalid(payload_ptr->value->type))
7180 return ira->codegen->invalid_inst_gen;7177 return ira->codegen->invalid_inst_gen;
71817178
7182 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, payload_ptr, casted_value, false);7179 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, scope, source_node, payload_ptr, casted_value, false);
7183 if (type_is_invalid(store_ptr_inst->value->type))7180 if (type_is_invalid(store_ptr_inst->value->type))
7184 return ira->codegen->invalid_inst_gen;7181 return ira->codegen->invalid_inst_gen;
71857182
...@@ -7190,13 +7187,13 @@ static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* sou...@@ -7190,13 +7187,13 @@ static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* sou
7190// otherwise return ErrorNone. Does not emit any instructions.7187// otherwise return ErrorNone. Does not emit any instructions.
7191// Assumes that the pointer types have element types with the same ABI alignment. Avoids resolving the7188// Assumes that the pointer types have element types with the same ABI alignment. Avoids resolving the
7192// pointer types' alignments if both of the pointer types are ABI aligned.7189// pointer types' alignments if both of the pointer types are ABI aligned.
7193static Error ir_cast_ptr_align(IrAnalyze *ira, IrInst* source_instr, ZigType *dest_ptr_type,7190static Error ir_cast_ptr_align(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *dest_ptr_type,
7194 ZigType *src_ptr_type, AstNode *src_source_node)7191 ZigType *src_ptr_type, AstNode *src_source_node)
7195{7192{
7196 Error err;7193 Error err;
71977194
7198 ir_assert(dest_ptr_type->id == ZigTypeIdPointer, source_instr);7195 src_assert(dest_ptr_type->id == ZigTypeIdPointer, source_node);
7199 ir_assert(src_ptr_type->id == ZigTypeIdPointer, source_instr);7196 src_assert(src_ptr_type->id == ZigTypeIdPointer, source_node);
72007197
7201 if (dest_ptr_type->data.pointer.explicit_alignment == 0 &&7198 if (dest_ptr_type->data.pointer.explicit_alignment == 0 &&
7202 src_ptr_type->data.pointer.explicit_alignment == 0)7199 src_ptr_type->data.pointer.explicit_alignment == 0)
...@@ -7213,10 +7210,10 @@ static Error ir_cast_ptr_align(IrAnalyze *ira, IrInst* source_instr, ZigType *de...@@ -7213,10 +7210,10 @@ static Error ir_cast_ptr_align(IrAnalyze *ira, IrInst* source_instr, ZigType *de
7213 uint32_t wanted_align = get_ptr_align(ira->codegen, dest_ptr_type);7210 uint32_t wanted_align = get_ptr_align(ira->codegen, dest_ptr_type);
7214 uint32_t actual_align = get_ptr_align(ira->codegen, src_ptr_type);7211 uint32_t actual_align = get_ptr_align(ira->codegen, src_ptr_type);
7215 if (wanted_align > actual_align) {7212 if (wanted_align > actual_align) {
7216 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment"));7213 ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("cast increases pointer alignment"));
7217 add_error_note(ira->codegen, msg, src_source_node,7214 add_error_note(ira->codegen, msg, src_source_node,
7218 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_ptr_type->name), actual_align));7215 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_ptr_type->name), actual_align));
7219 add_error_note(ira->codegen, msg, source_instr->source_node,7216 add_error_note(ira->codegen, msg, source_node,
7220 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_ptr_type->name), wanted_align));7217 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_ptr_type->name), wanted_align));
7221 return ErrorSemanticAnalyzeFail;7218 return ErrorSemanticAnalyzeFail;
7222 }7219 }
...@@ -7224,34 +7221,33 @@ static Error ir_cast_ptr_align(IrAnalyze *ira, IrInst* source_instr, ZigType *de...@@ -7224,34 +7221,33 @@ static Error ir_cast_ptr_align(IrAnalyze *ira, IrInst* source_instr, ZigType *de
7224 return ErrorNone;7221 return ErrorNone;
7225}7222}
72267223
7227static IrInstGen *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInst* source_instr,7224static IrInstGen *ir_analyze_struct_value_field_value(IrAnalyze *ira, Scope *scope, AstNode *source_node,
7228 IrInstGen *struct_operand, TypeStructField *field)7225 IrInstGen *struct_operand, TypeStructField *field)
7229{7226{
7230 IrInstGen *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false);7227 IrInstGen *struct_ptr = ir_get_ref(ira, scope, source_node, struct_operand, true, false);
7231 if (type_is_invalid(struct_ptr->value->type))7228 if (type_is_invalid(struct_ptr->value->type))
7232 return ira->codegen->invalid_inst_gen;7229 return ira->codegen->invalid_inst_gen;
7233 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr,7230 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, field, struct_ptr,
7234 struct_operand->value->type, false);7231 struct_operand->value->type, false);
7235 if (type_is_invalid(field_ptr->value->type))7232 if (type_is_invalid(field_ptr->value->type))
7236 return ira->codegen->invalid_inst_gen;7233 return ira->codegen->invalid_inst_gen;
7237 return ir_get_deref(ira, source_instr, field_ptr, nullptr);7234 return ir_get_deref(ira, scope, source_node, field_ptr, nullptr);
7238}7235}
72397236
7240static IrInstGen *ir_analyze_optional_value_payload_value(IrAnalyze *ira, IrInst* source_instr,7237static IrInstGen *ir_analyze_optional_value_payload_value(IrAnalyze *ira, Scope *scope, AstNode *source_node,
7241 IrInstGen *optional_operand, bool safety_check_on)7238 IrInstGen *optional_operand, bool safety_check_on)
7242{7239{
7243 IrInstGen *opt_ptr = ir_get_ref(ira, source_instr, optional_operand, true, false);7240 IrInstGen *opt_ptr = ir_get_ref(ira, scope, source_node, optional_operand, true, false);
7244 IrInstGen *payload_ptr = ir_analyze_unwrap_optional_payload(ira, source_instr, opt_ptr,7241 IrInstGen *payload_ptr = ir_analyze_unwrap_optional_payload(ira, scope, source_node, opt_ptr,
7245 safety_check_on, false);7242 safety_check_on, false);
7246 return ir_get_deref(ira, source_instr, payload_ptr, nullptr);7243 return ir_get_deref(ira, scope, source_node, payload_ptr, nullptr);
7247}7244}
72487245
7249static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,7246static IrInstGen *ir_analyze_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node,
7250 ZigType *wanted_type, IrInstGen *value)7247 ZigType *wanted_type, IrInstGen *value)
7251{7248{
7252 Error err;7249 Error err;
7253 ZigType *actual_type = value->value->type;7250 ZigType *actual_type = value->value->type;
7254 AstNode *source_node = source_instr->source_node;
72557251
7256 if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) {7252 if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) {
7257 return ira->codegen->invalid_inst_gen;7253 return ira->codegen->invalid_inst_gen;
...@@ -7268,21 +7264,21 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7268,21 +7264,21 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7268 if (const_cast_result.id == ConstCastResultIdInvalid)7264 if (const_cast_result.id == ConstCastResultIdInvalid)
7269 return ira->codegen->invalid_inst_gen;7265 return ira->codegen->invalid_inst_gen;
7270 if (const_cast_result.id == ConstCastResultIdOk) {7266 if (const_cast_result.id == ConstCastResultIdOk) {
7271 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop);7267 return ir_resolve_cast(ira, scope, source_node, value, wanted_type, CastOpNoop);
7272 }7268 }
72737269
7274 if (const_cast_result.id == ConstCastResultIdFnCC) {7270 if (const_cast_result.id == ConstCastResultIdFnCC) {
7275 ir_assert(value->value->type->id == ZigTypeIdFn, source_instr);7271 src_assert(value->value->type->id == ZigTypeIdFn, source_node);
7276 // ConstCastResultIdFnCC is guaranteed to be the last one reported, meaning everything else is ok.7272 // ConstCastResultIdFnCC is guaranteed to be the last one reported, meaning everything else is ok.
7277 if (wanted_type->data.fn.fn_type_id.cc == CallingConventionAsync &&7273 if (wanted_type->data.fn.fn_type_id.cc == CallingConventionAsync &&
7278 actual_type->data.fn.fn_type_id.cc == CallingConventionUnspecified)7274 actual_type->data.fn.fn_type_id.cc == CallingConventionUnspecified)
7279 {7275 {
7280 ir_assert(value->value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr);7276 src_assert(value->value->data.x_ptr.special == ConstPtrSpecialFunction, source_node);
7281 ZigFn *fn = value->value->data.x_ptr.data.fn.fn_entry;7277 ZigFn *fn = value->value->data.x_ptr.data.fn.fn_entry;
7282 if (fn->inferred_async_node == nullptr) {7278 if (fn->inferred_async_node == nullptr) {
7283 fn->inferred_async_node = source_instr->source_node;7279 fn->inferred_async_node = source_node;
7284 }7280 }
7285 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop);7281 return ir_resolve_cast(ira, scope, source_node, value, wanted_type, CastOpNoop);
7286 }7282 }
7287 }7283 }
72887284
...@@ -7293,12 +7289,12 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7293,12 +7289,12 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7293 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node,7289 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node,
7294 false).id == ConstCastResultIdOk)7290 false).id == ConstCastResultIdOk)
7295 {7291 {
7296 return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr);7292 return ir_analyze_optional_wrap(ira, scope, source_node, value, wanted_type, nullptr);
7297 } else if (actual_type->id == ZigTypeIdComptimeInt ||7293 } else if (actual_type->id == ZigTypeIdComptimeInt ||
7298 actual_type->id == ZigTypeIdComptimeFloat)7294 actual_type->id == ZigTypeIdComptimeFloat)
7299 {7295 {
7300 if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) {7296 if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) {
7301 return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr);7297 return ir_analyze_optional_wrap(ira, scope, source_node, value, wanted_type, nullptr);
7302 } else {7298 } else {
7303 return ira->codegen->invalid_inst_gen;7299 return ira->codegen->invalid_inst_gen;
7304 }7300 }
...@@ -7318,11 +7314,11 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7318,11 +7314,11 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7318 actual_type->data.pointer.child_type->data.array.child_type, source_node,7314 actual_type->data.pointer.child_type->data.array.child_type, source_node,
7319 !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk)7315 !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk)
7320 {7316 {
7321 IrInstGen *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value,7317 IrInstGen *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, scope, source_node, value,
7322 wanted_child_type);7318 wanted_child_type);
7323 if (type_is_invalid(cast1->value->type))7319 if (type_is_invalid(cast1->value->type))
7324 return ira->codegen->invalid_inst_gen;7320 return ira->codegen->invalid_inst_gen;
7325 return ir_analyze_optional_wrap(ira, source_instr, cast1, wanted_type, nullptr);7321 return ir_analyze_optional_wrap(ira, scope, source_node, cast1, wanted_type, nullptr);
7326 }7322 }
7327 }7323 }
7328 }7324 }
...@@ -7332,12 +7328,12 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7332,12 +7328,12 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7332 if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type,7328 if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type,
7333 source_node, false).id == ConstCastResultIdOk)7329 source_node, false).id == ConstCastResultIdOk)
7334 {7330 {
7335 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr);7331 return ir_analyze_err_wrap_payload(ira, scope, source_node, value, wanted_type, nullptr);
7336 } else if (actual_type->id == ZigTypeIdComptimeInt ||7332 } else if (actual_type->id == ZigTypeIdComptimeInt ||
7337 actual_type->id == ZigTypeIdComptimeFloat)7333 actual_type->id == ZigTypeIdComptimeFloat)
7338 {7334 {
7339 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) {7335 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) {
7340 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr);7336 return ir_analyze_err_wrap_payload(ira, scope, source_node, value, wanted_type, nullptr);
7341 } else {7337 } else {
7342 return ira->codegen->invalid_inst_gen;7338 return ira->codegen->invalid_inst_gen;
7343 }7339 }
...@@ -7355,11 +7351,11 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7355,11 +7351,11 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7355 actual_type->id == ZigTypeIdComptimeInt ||7351 actual_type->id == ZigTypeIdComptimeInt ||
7356 actual_type->id == ZigTypeIdComptimeFloat)7352 actual_type->id == ZigTypeIdComptimeFloat)
7357 {7353 {
7358 IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);7354 IrInstGen *cast1 = ir_analyze_cast(ira, scope, source_node, wanted_type->data.error_union.payload_type, value);
7359 if (type_is_invalid(cast1->value->type))7355 if (type_is_invalid(cast1->value->type))
7360 return ira->codegen->invalid_inst_gen;7356 return ira->codegen->invalid_inst_gen;
73617357
7362 IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);7358 IrInstGen *cast2 = ir_analyze_cast(ira, scope, source_node, wanted_type, cast1);
7363 if (type_is_invalid(cast2->value->type))7359 if (type_is_invalid(cast2->value->type))
7364 return ira->codegen->invalid_inst_gen;7360 return ira->codegen->invalid_inst_gen;
73657361
...@@ -7376,13 +7372,13 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7376,13 +7372,13 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7376 wanted_type->id == ZigTypeIdFloat || wanted_type->id == ZigTypeIdComptimeFloat))7372 wanted_type->id == ZigTypeIdFloat || wanted_type->id == ZigTypeIdComptimeFloat))
7377 {7373 {
7378 if (value->value->special == ConstValSpecialUndef) {7374 if (value->value->special == ConstValSpecialUndef) {
7379 IrInstGen *result = ir_const(ira, source_instr, wanted_type);7375 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
7380 result->value->special = ConstValSpecialUndef;7376 result->value->special = ConstValSpecialUndef;
7381 return result;7377 return result;
7382 }7378 }
7383 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {7379 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {
7384 if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) {7380 if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) {
7385 IrInstGen *result = ir_const(ira, source_instr, wanted_type);7381 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
7386 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {7382 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
7387 copy_const_val(ira->codegen, result->value, value->value);7383 copy_const_val(ira->codegen, result->value, value->value);
7388 result->value->type = wanted_type;7384 result->value->type = wanted_type;
...@@ -7391,7 +7387,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7391,7 +7387,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7391 }7387 }
7392 return result;7388 return result;
7393 } else if (wanted_type->id == ZigTypeIdComptimeFloat || wanted_type->id == ZigTypeIdFloat) {7389 } else if (wanted_type->id == ZigTypeIdComptimeFloat || wanted_type->id == ZigTypeIdFloat) {
7394 IrInstGen *result = ir_const(ira, source_instr, wanted_type);7390 IrInstGen *result = ir_const(ira, scope, source_node, wanted_type);
7395 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {7391 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
7396 BigFloat bf;7392 BigFloat bf;
7397 bigfloat_init_bigint(&bf, &value->value->data.x_bigint);7393 bigfloat_init_bigint(&bf, &value->value->data.x_bigint);
...@@ -7413,7 +7409,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7413,7 +7409,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7413 wanted_type->data.integral.is_signed == actual_type->data.integral.is_signed &&7409 wanted_type->data.integral.is_signed == actual_type->data.integral.is_signed &&
7414 wanted_type->data.integral.bit_count >= actual_type->data.integral.bit_count)7410 wanted_type->data.integral.bit_count >= actual_type->data.integral.bit_count)
7415 {7411 {
7416 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);7412 return ir_analyze_widen_or_shorten(ira, scope, source_node, value, wanted_type);
7417 }7413 }
74187414
7419 // small enough unsigned ints can get casted to large enough signed ints7415 // small enough unsigned ints can get casted to large enough signed ints
...@@ -7421,7 +7417,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7421,7 +7417,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7421 actual_type->id == ZigTypeIdInt && !actual_type->data.integral.is_signed &&7417 actual_type->id == ZigTypeIdInt && !actual_type->data.integral.is_signed &&
7422 wanted_type->data.integral.bit_count > actual_type->data.integral.bit_count)7418 wanted_type->data.integral.bit_count > actual_type->data.integral.bit_count)
7423 {7419 {
7424 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);7420 return ir_analyze_widen_or_shorten(ira, scope, source_node, value, wanted_type);
7425 }7421 }
74267422
7427 // float widening conversion7423 // float widening conversion
...@@ -7429,7 +7425,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7429,7 +7425,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7429 actual_type->id == ZigTypeIdFloat &&7425 actual_type->id == ZigTypeIdFloat &&
7430 wanted_type->data.floating.bit_count >= actual_type->data.floating.bit_count)7426 wanted_type->data.floating.bit_count >= actual_type->data.floating.bit_count)
7431 {7427 {
7432 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);7428 return ir_analyze_widen_or_shorten(ira, scope, source_node, value, wanted_type);
7433 }7429 }
74347430
7435 // *[N]T to ?[]T7431 // *[N]T to ?[]T
...@@ -7439,11 +7435,11 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7439,11 +7435,11 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7439 actual_type->data.pointer.ptr_len == PtrLenSingle &&7435 actual_type->data.pointer.ptr_len == PtrLenSingle &&
7440 actual_type->data.pointer.child_type->id == ZigTypeIdArray)7436 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
7441 {7437 {
7442 IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);7438 IrInstGen *cast1 = ir_analyze_cast(ira, scope, source_node, wanted_type->data.maybe.child_type, value);
7443 if (type_is_invalid(cast1->value->type))7439 if (type_is_invalid(cast1->value->type))
7444 return ira->codegen->invalid_inst_gen;7440 return ira->codegen->invalid_inst_gen;
74457441
7446 IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);7442 IrInstGen *cast2 = ir_analyze_cast(ira, scope, source_node, wanted_type, cast1);
7447 if (type_is_invalid(cast2->value->type))7443 if (type_is_invalid(cast2->value->type))
7448 return ira->codegen->invalid_inst_gen;7444 return ira->codegen->invalid_inst_gen;
74497445
...@@ -7474,7 +7470,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7474,7 +7470,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7474 actual_type->data.pointer.child_type->data.array.child_type, source_node,7470 actual_type->data.pointer.child_type->data.array.child_type, source_node,
7475 !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)7471 !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)
7476 {7472 {
7477 return ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, wanted_type);7473 return ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, scope, source_node, value, wanted_type);
7478 }7474 }
7479 }7475 }
7480 }7476 }
...@@ -7525,17 +7521,17 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7525,17 +7521,17 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7525 }7521 }
7526 if (ok_align) {7522 if (ok_align) {
7527 if (wanted_type->id == ZigTypeIdErrorUnion) {7523 if (wanted_type->id == ZigTypeIdErrorUnion) {
7528 IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value);7524 IrInstGen *cast1 = ir_analyze_cast(ira, scope, source_node, slice_type, value);
7529 if (type_is_invalid(cast1->value->type))7525 if (type_is_invalid(cast1->value->type))
7530 return ira->codegen->invalid_inst_gen;7526 return ira->codegen->invalid_inst_gen;
75317527
7532 IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);7528 IrInstGen *cast2 = ir_analyze_cast(ira, scope, source_node, wanted_type, cast1);
7533 if (type_is_invalid(cast2->value->type))7529 if (type_is_invalid(cast2->value->type))
7534 return ira->codegen->invalid_inst_gen;7530 return ira->codegen->invalid_inst_gen;
75357531
7536 return cast2;7532 return cast2;
7537 } else {7533 } else {
7538 return ir_resolve_ptr_of_array_to_slice(ira, source_instr, value, slice_type, nullptr);7534 return ir_resolve_ptr_of_array_to_slice(ira, scope, source_node, value, slice_type, nullptr);
7539 }7535 }
7540 }7536 }
7541 }7537 }
...@@ -7554,7 +7550,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7554,7 +7550,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7554 scalar_wanted_type->data.integral.is_signed == scalar_actual_type->data.integral.is_signed &&7550 scalar_wanted_type->data.integral.is_signed == scalar_actual_type->data.integral.is_signed &&
7555 scalar_wanted_type->data.integral.bit_count >= scalar_actual_type->data.integral.bit_count)7551 scalar_wanted_type->data.integral.bit_count >= scalar_actual_type->data.integral.bit_count)
7556 {7552 {
7557 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);7553 return ir_analyze_widen_or_shorten(ira, scope, source_node, value, wanted_type);
7558 }7554 }
75597555
7560 // small enough unsigned ints can get casted to large enough signed ints7556 // small enough unsigned ints can get casted to large enough signed ints
...@@ -7562,7 +7558,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7562,7 +7558,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7562 scalar_actual_type->id == ZigTypeIdInt && !scalar_actual_type->data.integral.is_signed &&7558 scalar_actual_type->id == ZigTypeIdInt && !scalar_actual_type->data.integral.is_signed &&
7563 scalar_wanted_type->data.integral.bit_count > scalar_actual_type->data.integral.bit_count)7559 scalar_wanted_type->data.integral.bit_count > scalar_actual_type->data.integral.bit_count)
7564 {7560 {
7565 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);7561 return ir_analyze_widen_or_shorten(ira, scope, source_node, value, wanted_type);
7566 }7562 }
75677563
7568 // float widening conversion7564 // float widening conversion
...@@ -7570,7 +7566,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7570,7 +7566,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7570 scalar_actual_type->id == ZigTypeIdFloat &&7566 scalar_actual_type->id == ZigTypeIdFloat &&
7571 scalar_wanted_type->data.floating.bit_count >= scalar_actual_type->data.floating.bit_count)7567 scalar_wanted_type->data.floating.bit_count >= scalar_actual_type->data.floating.bit_count)
7572 {7568 {
7573 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);7569 return ir_analyze_widen_or_shorten(ira, scope, source_node, value, wanted_type);
7574 }7570 }
7575 }7571 }
75767572
...@@ -7605,10 +7601,10 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7605,10 +7601,10 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7605 }7601 }
7606 }7602 }
7607 if (ok) {7603 if (ok) {
7608 IrInstGen *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, anyframe_type);7604 IrInstGen *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, scope, source_node, value, anyframe_type);
7609 if (anyframe_type == wanted_type)7605 if (anyframe_type == wanted_type)
7610 return cast1;7606 return cast1;
7611 return ir_analyze_cast(ira, source_instr, wanted_type, cast1);7607 return ir_analyze_cast(ira, scope, source_node, wanted_type, cast1);
7612 }7608 }
7613 }7609 }
7614 }7610 }
...@@ -7617,28 +7613,28 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7617,28 +7613,28 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7617 if (actual_type->id == ZigTypeIdAnyFrame && actual_type->data.any_frame.result_type != nullptr &&7613 if (actual_type->id == ZigTypeIdAnyFrame && actual_type->data.any_frame.result_type != nullptr &&
7618 wanted_type->id == ZigTypeIdAnyFrame && wanted_type->data.any_frame.result_type == nullptr)7614 wanted_type->id == ZigTypeIdAnyFrame && wanted_type->data.any_frame.result_type == nullptr)
7619 {7615 {
7620 return ir_analyze_anyframe_to_anyframe(ira, source_instr, value, wanted_type);7616 return ir_analyze_anyframe_to_anyframe(ira, scope, source_node, value, wanted_type);
7621 }7617 }
76227618
7623 // cast from null literal to maybe type7619 // cast from null literal to maybe type
7624 if (wanted_type->id == ZigTypeIdOptional &&7620 if (wanted_type->id == ZigTypeIdOptional &&
7625 actual_type->id == ZigTypeIdNull)7621 actual_type->id == ZigTypeIdNull)
7626 {7622 {
7627 return ir_analyze_null_to_maybe(ira, source_instr, value, wanted_type);7623 return ir_analyze_null_to_maybe(ira, scope, source_node, value, wanted_type);
7628 }7624 }
76297625
7630 // cast from null literal to C pointer7626 // cast from null literal to C pointer
7631 if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenC &&7627 if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenC &&
7632 actual_type->id == ZigTypeIdNull)7628 actual_type->id == ZigTypeIdNull)
7633 {7629 {
7634 return ir_analyze_null_to_c_pointer(ira, source_instr, value, wanted_type);7630 return ir_analyze_null_to_c_pointer(ira, scope, source_node, value, wanted_type);
7635 }7631 }
76367632
7637 // cast from E to E!T7633 // cast from E to E!T
7638 if (wanted_type->id == ZigTypeIdErrorUnion &&7634 if (wanted_type->id == ZigTypeIdErrorUnion &&
7639 actual_type->id == ZigTypeIdErrorSet)7635 actual_type->id == ZigTypeIdErrorSet)
7640 {7636 {
7641 return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type, nullptr);7637 return ir_analyze_err_wrap_code(ira, scope, source_node, value, wanted_type, nullptr);
7642 }7638 }
76437639
7644 // cast from typed number to integer or float literal.7640 // cast from typed number to integer or float literal.
...@@ -7647,35 +7643,35 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7647,35 +7643,35 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7647 ((actual_type->id == ZigTypeIdInt && wanted_type->id == ZigTypeIdComptimeInt) ||7643 ((actual_type->id == ZigTypeIdInt && wanted_type->id == ZigTypeIdComptimeInt) ||
7648 (actual_type->id == ZigTypeIdFloat && wanted_type->id == ZigTypeIdComptimeFloat)))7644 (actual_type->id == ZigTypeIdFloat && wanted_type->id == ZigTypeIdComptimeFloat)))
7649 {7645 {
7650 return ir_analyze_number_to_literal(ira, source_instr, value, wanted_type);7646 return ir_analyze_number_to_literal(ira, scope, source_node, value, wanted_type);
7651 }7647 }
76527648
7653 // cast from enum literal to enum with matching field name7649 // cast from enum literal to enum with matching field name
7654 if (actual_type->id == ZigTypeIdEnumLiteral && wanted_type->id == ZigTypeIdEnum)7650 if (actual_type->id == ZigTypeIdEnumLiteral && wanted_type->id == ZigTypeIdEnum)
7655 {7651 {
7656 return ir_analyze_enum_literal(ira, source_instr, value, wanted_type);7652 return ir_analyze_enum_literal(ira, scope, source_node, value, wanted_type);
7657 }7653 }
76587654
7659 // cast from enum literal to optional enum7655 // cast from enum literal to optional enum
7660 if (actual_type->id == ZigTypeIdEnumLiteral &&7656 if (actual_type->id == ZigTypeIdEnumLiteral &&
7661 (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdEnum))7657 (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdEnum))
7662 {7658 {
7663 IrInstGen *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.maybe.child_type);7659 IrInstGen *result = ir_analyze_enum_literal(ira, scope, source_node, value, wanted_type->data.maybe.child_type);
7664 if (type_is_invalid(result->value->type))7660 if (type_is_invalid(result->value->type))
7665 return result;7661 return result;
76667662
7667 return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr);7663 return ir_analyze_optional_wrap(ira, scope, source_node, value, wanted_type, nullptr);
7668 }7664 }
76697665
7670 // cast from enum literal to error union when payload is an enum7666 // cast from enum literal to error union when payload is an enum
7671 if (actual_type->id == ZigTypeIdEnumLiteral &&7667 if (actual_type->id == ZigTypeIdEnumLiteral &&
7672 (wanted_type->id == ZigTypeIdErrorUnion && wanted_type->data.error_union.payload_type->id == ZigTypeIdEnum))7668 (wanted_type->id == ZigTypeIdErrorUnion && wanted_type->data.error_union.payload_type->id == ZigTypeIdEnum))
7673 {7669 {
7674 IrInstGen *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.error_union.payload_type);7670 IrInstGen *result = ir_analyze_enum_literal(ira, scope, source_node, value, wanted_type->data.error_union.payload_type);
7675 if (type_is_invalid(result->value->type))7671 if (type_is_invalid(result->value->type))
7676 return result;7672 return result;
76777673
7678 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr);7674 return ir_analyze_err_wrap_payload(ira, scope, source_node, value, wanted_type, nullptr);
7679 }7675 }
76807676
7681 // cast from union to the enum type of the union7677 // cast from union to the enum type of the union
...@@ -7684,7 +7680,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7684,7 +7680,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7684 return ira->codegen->invalid_inst_gen;7680 return ira->codegen->invalid_inst_gen;
76857681
7686 if (actual_type->data.unionation.tag_type == wanted_type) {7682 if (actual_type->data.unionation.tag_type == wanted_type) {
7687 return ir_analyze_union_to_tag(ira, source_instr, value, wanted_type);7683 return ir_analyze_union_to_tag(ira, scope, source_node, value, wanted_type);
7688 }7684 }
7689 }7685 }
76907686
...@@ -7693,7 +7689,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7693,7 +7689,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7693 if (is_tagged_union(wanted_type) && (actual_type->id == ZigTypeIdEnum ||7689 if (is_tagged_union(wanted_type) && (actual_type->id == ZigTypeIdEnum ||
7694 actual_type->id == ZigTypeIdEnumLiteral))7690 actual_type->id == ZigTypeIdEnumLiteral))
7695 {7691 {
7696 return ir_analyze_enum_to_union(ira, source_instr, value, wanted_type);7692 return ir_analyze_enum_to_union(ira, scope, source_node, value, wanted_type);
7697 }7693 }
76987694
7699 // cast from *T to *[1]T7695 // cast from *T to *[1]T
...@@ -7709,10 +7705,10 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7709,10 +7705,10 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7709 (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) &&7705 (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) &&
7710 (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile))7706 (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile))
7711 {7707 {
7712 if ((err = ir_cast_ptr_align(ira, source_instr, wanted_type, actual_type, value->base.source_node)))7708 if ((err = ir_cast_ptr_align(ira, scope, source_node, wanted_type, actual_type, value->source_node)))
7713 return ira->codegen->invalid_inst_gen;7709 return ira->codegen->invalid_inst_gen;
77147710
7715 return ir_analyze_ptr_to_array(ira, source_instr, value, wanted_type);7711 return ir_analyze_ptr_to_array(ira, scope, source_node, value, wanted_type);
7716 }7712 }
7717 }7713 }
77187714
...@@ -7733,8 +7729,8 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7733,8 +7729,8 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7733 slice_ptr_type->data.pointer.sentinel))))7729 slice_ptr_type->data.pointer.sentinel))))
7734 {7730 {
7735 TypeStructField *ptr_field = actual_type->data.structure.fields[slice_ptr_index];7731 TypeStructField *ptr_field = actual_type->data.structure.fields[slice_ptr_index];
7736 IrInstGen *slice_ptr = ir_analyze_struct_value_field_value(ira, source_instr, value, ptr_field);7732 IrInstGen *slice_ptr = ir_analyze_struct_value_field_value(ira, scope, source_node, value, ptr_field);
7737 return ir_implicit_cast2(ira, source_instr, slice_ptr, wanted_type);7733 return ir_implicit_cast2(ira, scope, source_node, slice_ptr, wanted_type);
7738 }7734 }
7739 }7735 }
77407736
...@@ -7754,8 +7750,8 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7754,8 +7750,8 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7754 dest_ptr_type = wanted_type->data.maybe.child_type;7750 dest_ptr_type = wanted_type->data.maybe.child_type;
7755 }7751 }
7756 if (dest_ptr_type != nullptr) {7752 if (dest_ptr_type != nullptr) {
7757 return ir_analyze_ptr_cast(ira, source_instr, value, source_instr, wanted_type, source_instr, true,7753 return ir_analyze_ptr_cast(ira, scope, source_node, value, source_node,
7758 false);7754 wanted_type, source_node, true, false);
7759 }7755 }
7760 }7756 }
77617757
...@@ -7768,7 +7764,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7768,7 +7764,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7768 if ((err = type_has_bits2(ira->codegen, actual_type, &has_bits)))7764 if ((err = type_has_bits2(ira->codegen, actual_type, &has_bits)))
7769 return ira->codegen->invalid_inst_gen;7765 return ira->codegen->invalid_inst_gen;
7770 if (!has_bits) {7766 if (!has_bits) {
7771 return ir_get_ref(ira, source_instr, value, false, false);7767 return ir_get_ref(ira, scope, source_node, value, false, false);
7772 }7768 }
7773 }7769 }
77747770
...@@ -7778,7 +7774,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7778,7 +7774,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7778 types_match_const_cast_only(ira, wanted_type->data.array.child_type,7774 types_match_const_cast_only(ira, wanted_type->data.array.child_type,
7779 actual_type->data.vector.elem_type, source_node, false).id == ConstCastResultIdOk)7775 actual_type->data.vector.elem_type, source_node, false).id == ConstCastResultIdOk)
7780 {7776 {
7781 return ir_analyze_vector_to_array(ira, source_instr, value, wanted_type, nullptr);7777 return ir_analyze_vector_to_array(ira, scope, source_node, value, wanted_type, nullptr);
7782 }7778 }
77837779
7784 // cast from [N]T to @Vector(N, T)7780 // cast from [N]T to @Vector(N, T)
...@@ -7787,7 +7783,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7787,7 +7783,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7787 types_match_const_cast_only(ira, actual_type->data.array.child_type,7783 types_match_const_cast_only(ira, actual_type->data.array.child_type,
7788 wanted_type->data.vector.elem_type, source_node, false).id == ConstCastResultIdOk)7784 wanted_type->data.vector.elem_type, source_node, false).id == ConstCastResultIdOk)
7789 {7785 {
7790 return ir_analyze_array_to_vector(ira, source_instr, value, wanted_type);7786 return ir_analyze_array_to_vector(ira, scope, source_node, value, wanted_type);
7791 }7787 }
77927788
7793 // casting between C pointers and normal pointers7789 // casting between C pointers and normal pointers
...@@ -7797,14 +7793,15 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7797,14 +7793,15 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7797 actual_type->data.pointer.child_type, source_node,7793 actual_type->data.pointer.child_type, source_node,
7798 !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)7794 !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)
7799 {7795 {
7800 return ir_analyze_ptr_cast(ira, source_instr, value, source_instr, wanted_type, source_instr, true, false);7796 return ir_analyze_ptr_cast(ira, scope, source_node, value, source_node,
7797 wanted_type, source_node, true, false);
7801 }7798 }
78027799
7803 // cast from integer to C pointer7800 // cast from integer to C pointer
7804 if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenC &&7801 if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenC &&
7805 (actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt))7802 (actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt))
7806 {7803 {
7807 return ir_analyze_int_to_c_ptr(ira, source_instr, value, wanted_type);7804 return ir_analyze_int_to_c_ptr(ira, scope, source_node, value, wanted_type);
7808 }7805 }
78097806
7810 // cast from inferred struct type to array, union, or struct7807 // cast from inferred struct type to array, union, or struct
...@@ -7816,34 +7813,34 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7816,34 +7813,34 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7816 if (wanted_type->id == ZigTypeIdArray && (is_array_init || field_count == 0) &&7813 if (wanted_type->id == ZigTypeIdArray && (is_array_init || field_count == 0) &&
7817 wanted_type->data.array.len == field_count)7814 wanted_type->data.array.len == field_count)
7818 {7815 {
7819 IrInstGen *struct_ptr = ir_get_ref(ira, source_instr, value, true, false);7816 IrInstGen *struct_ptr = ir_get_ref(ira, scope, source_node, value, true, false);
7820 if (type_is_invalid(struct_ptr->value->type))7817 if (type_is_invalid(struct_ptr->value->type))
7821 return ira->codegen->invalid_inst_gen;7818 return ira->codegen->invalid_inst_gen;
78227819
7823 IrInstGen *ptr = ir_analyze_struct_literal_to_array(ira, source_instr, struct_ptr, actual_type, wanted_type);7820 IrInstGen *ptr = ir_analyze_struct_literal_to_array(ira, scope, source_node, struct_ptr, actual_type, wanted_type);
7824 if (ptr->value->type->id != ZigTypeIdPointer)7821 if (ptr->value->type->id != ZigTypeIdPointer)
7825 return ptr;7822 return ptr;
7826 return ir_get_deref(ira, source_instr, ptr, nullptr);7823 return ir_get_deref(ira, scope, source_node, ptr, nullptr);
7827 } else if (wanted_type->id == ZigTypeIdStruct && !is_slice(wanted_type) &&7824 } else if (wanted_type->id == ZigTypeIdStruct && !is_slice(wanted_type) &&
7828 (!is_array_init || field_count == 0))7825 (!is_array_init || field_count == 0))
7829 {7826 {
7830 IrInstGen *struct_ptr = ir_get_ref(ira, source_instr, value, true, false);7827 IrInstGen *struct_ptr = ir_get_ref(ira, scope, source_node, value, true, false);
7831 if (type_is_invalid(struct_ptr->value->type))7828 if (type_is_invalid(struct_ptr->value->type))
7832 return ira->codegen->invalid_inst_gen;7829 return ira->codegen->invalid_inst_gen;
78337830
7834 IrInstGen *ptr = ir_analyze_struct_literal_to_struct(ira, source_instr, struct_ptr, actual_type, wanted_type);7831 IrInstGen *ptr = ir_analyze_struct_literal_to_struct(ira, scope, source_node, struct_ptr, actual_type, wanted_type);
7835 if (ptr->value->type->id != ZigTypeIdPointer)7832 if (ptr->value->type->id != ZigTypeIdPointer)
7836 return ptr;7833 return ptr;
7837 return ir_get_deref(ira, source_instr, ptr, nullptr);7834 return ir_get_deref(ira, scope, source_node, ptr, nullptr);
7838 } else if (wanted_type->id == ZigTypeIdUnion && !is_array_init && field_count == 1) {7835 } else if (wanted_type->id == ZigTypeIdUnion && !is_array_init && field_count == 1) {
7839 IrInstGen *struct_ptr = ir_get_ref(ira, source_instr, value, true, false);7836 IrInstGen *struct_ptr = ir_get_ref(ira, scope, source_node, value, true, false);
7840 if (type_is_invalid(struct_ptr->value->type))7837 if (type_is_invalid(struct_ptr->value->type))
7841 return ira->codegen->invalid_inst_gen;7838 return ira->codegen->invalid_inst_gen;
78427839
7843 IrInstGen *ptr = ir_analyze_struct_literal_to_union(ira, source_instr, struct_ptr, actual_type, wanted_type);7840 IrInstGen *ptr = ir_analyze_struct_literal_to_union(ira, scope, source_node, struct_ptr, actual_type, wanted_type);
7844 if (ptr->value->type->id != ZigTypeIdPointer)7841 if (ptr->value->type->id != ZigTypeIdPointer)
7845 return ptr;7842 return ptr;
7846 return ir_get_deref(ira, source_instr, ptr, nullptr);7843 return ir_get_deref(ira, scope, source_node, ptr, nullptr);
7847 }7844 }
7848 }7845 }
78497846
...@@ -7862,22 +7859,22 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7862,22 +7859,22 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7862 if (wanted_child->id == ZigTypeIdArray && (is_array_init || field_count == 0) &&7859 if (wanted_child->id == ZigTypeIdArray && (is_array_init || field_count == 0) &&
7863 wanted_child->data.array.len == field_count && (const_ok || field_count == 0))7860 wanted_child->data.array.len == field_count && (const_ok || field_count == 0))
7864 {7861 {
7865 IrInstGen *res = ir_analyze_struct_literal_to_array(ira, source_instr, value, anon_type, wanted_child);7862 IrInstGen *res = ir_analyze_struct_literal_to_array(ira, scope, source_node, value, anon_type, wanted_child);
7866 if (res->value->type->id == ZigTypeIdPointer)7863 if (res->value->type->id == ZigTypeIdPointer)
7867 return res;7864 return res;
7868 return ir_get_ref(ira, source_instr, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile);7865 return ir_get_ref(ira, scope, source_node, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile);
7869 } else if (wanted_child->id == ZigTypeIdStruct && !is_slice(wanted_type) &&7866 } else if (wanted_child->id == ZigTypeIdStruct && !is_slice(wanted_type) &&
7870 (!is_array_init || field_count == 0) && const_ok)7867 (!is_array_init || field_count == 0) && const_ok)
7871 {7868 {
7872 IrInstGen *res = ir_analyze_struct_literal_to_struct(ira, source_instr, value, anon_type, wanted_child);7869 IrInstGen *res = ir_analyze_struct_literal_to_struct(ira, scope, source_node, value, anon_type, wanted_child);
7873 if (res->value->type->id == ZigTypeIdPointer)7870 if (res->value->type->id == ZigTypeIdPointer)
7874 return res;7871 return res;
7875 return ir_get_ref(ira, source_instr, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile);7872 return ir_get_ref(ira, scope, source_node, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile);
7876 } else if (wanted_child->id == ZigTypeIdUnion && !is_array_init && field_count == 1 && const_ok) {7873 } else if (wanted_child->id == ZigTypeIdUnion && !is_array_init && field_count == 1 && const_ok) {
7877 IrInstGen *res = ir_analyze_struct_literal_to_union(ira, source_instr, value, anon_type, wanted_child);7874 IrInstGen *res = ir_analyze_struct_literal_to_union(ira, scope, source_node, value, anon_type, wanted_child);
7878 if (res->value->type->id == ZigTypeIdPointer)7875 if (res->value->type->id == ZigTypeIdPointer)
7879 return res;7876 return res;
7880 return ir_get_ref(ira, source_instr, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile);7877 return ir_get_ref(ira, scope, source_node, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile);
7881 }7878 }
7882 } else if (is_slice(wanted_type) && (is_array_init || field_count == 0)) {7879 } else if (is_slice(wanted_type) && (is_array_init || field_count == 0)) {
7883 ZigType *slice_type = wanted_type->data.structure.fields[slice_ptr_index]->type_entry;7880 ZigType *slice_type = wanted_type->data.structure.fields[slice_ptr_index]->type_entry;
...@@ -7886,49 +7883,49 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -7886,49 +7883,49 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
7886 {7883 {
7887 ZigType *slice_child_type = slice_type->data.pointer.child_type;7884 ZigType *slice_child_type = slice_type->data.pointer.child_type;
7888 ZigType *slice_array_type = get_array_type(ira->codegen, slice_child_type, field_count, nullptr);7885 ZigType *slice_array_type = get_array_type(ira->codegen, slice_child_type, field_count, nullptr);
7889 IrInstGen *res = ir_analyze_struct_literal_to_array(ira, source_instr, value, anon_type, slice_array_type);7886 IrInstGen *res = ir_analyze_struct_literal_to_array(ira, scope, source_node, value, anon_type, slice_array_type);
7890 if (type_is_invalid(res->value->type))7887 if (type_is_invalid(res->value->type))
7891 return ira->codegen->invalid_inst_gen;7888 return ira->codegen->invalid_inst_gen;
7892 if (res->value->type->id != ZigTypeIdPointer)7889 if (res->value->type->id != ZigTypeIdPointer)
7893 res = ir_get_ref(ira, source_instr, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile);7890 res = ir_get_ref(ira, scope, source_node, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile);
78947891
7895 return ir_resolve_ptr_of_array_to_slice(ira, source_instr, res, wanted_type, nullptr);7892 return ir_resolve_ptr_of_array_to_slice(ira, scope, source_node, res, wanted_type, nullptr);
7896 }7893 }
7897 }7894 }
7898 }7895 }
78997896
7900 // cast from undefined to anything7897 // cast from undefined to anything
7901 if (actual_type->id == ZigTypeIdUndefined) {7898 if (actual_type->id == ZigTypeIdUndefined) {
7902 return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);7899 return ir_analyze_undefined_to_anything(ira, scope, source_node, value, wanted_type);
7903 }7900 }
79047901
7905 // T to ?U, where T implicitly casts to U7902 // T to ?U, where T implicitly casts to U
7906 if (wanted_type->id == ZigTypeIdOptional && actual_type->id != ZigTypeIdOptional) {7903 if (wanted_type->id == ZigTypeIdOptional && actual_type->id != ZigTypeIdOptional) {
7907 IrInstGen *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.maybe.child_type);7904 IrInstGen *cast1 = ir_implicit_cast2(ira, scope, source_node, value, wanted_type->data.maybe.child_type);
7908 if (type_is_invalid(cast1->value->type))7905 if (type_is_invalid(cast1->value->type))
7909 return ira->codegen->invalid_inst_gen;7906 return ira->codegen->invalid_inst_gen;
7910 return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);7907 return ir_implicit_cast2(ira, scope, source_node, cast1, wanted_type);
7911 }7908 }
79127909
7913 // T to E!U, where T implicitly casts to U7910 // T to E!U, where T implicitly casts to U
7914 if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id != ZigTypeIdErrorUnion &&7911 if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id != ZigTypeIdErrorUnion &&
7915 actual_type->id != ZigTypeIdErrorSet)7912 actual_type->id != ZigTypeIdErrorSet)
7916 {7913 {
7917 IrInstGen *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.error_union.payload_type);7914 IrInstGen *cast1 = ir_implicit_cast2(ira, scope, source_node, value, wanted_type->data.error_union.payload_type);
7918 if (type_is_invalid(cast1->value->type))7915 if (type_is_invalid(cast1->value->type))
7919 return ira->codegen->invalid_inst_gen;7916 return ira->codegen->invalid_inst_gen;
7920 return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);7917 return ir_implicit_cast2(ira, scope, source_node, cast1, wanted_type);
7921 }7918 }
79227919
7923 ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,7920 ErrorMsg *parent_msg = ir_add_error_node(ira, source_node,
7924 buf_sprintf("expected type '%s', found '%s'",7921 buf_sprintf("expected type '%s', found '%s'",
7925 buf_ptr(&wanted_type->name),7922 buf_ptr(&wanted_type->name),
7926 buf_ptr(&actual_type->name)));7923 buf_ptr(&actual_type->name)));
7927 report_recursive_error(ira, source_instr->source_node, &const_cast_result, parent_msg);7924 report_recursive_error(ira, source_node, &const_cast_result, parent_msg);
7928 return ira->codegen->invalid_inst_gen;7925 return ira->codegen->invalid_inst_gen;
7929}7926}
79307927
7931static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr,7928static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, Scope *scope, AstNode *source_node,
7932 IrInstGen *value, ZigType *expected_type)7929 IrInstGen *value, ZigType *expected_type)
7933{7930{
7934 assert(value);7931 assert(value);
...@@ -7942,20 +7939,20 @@ static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr,...@@ -7942,20 +7939,20 @@ static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr,
7942 if (value->value->type->id == ZigTypeIdUnreachable)7939 if (value->value->type->id == ZigTypeIdUnreachable)
7943 return value;7940 return value;
79447941
7945 return ir_analyze_cast(ira, value_source_instr, expected_type, value);7942 return ir_analyze_cast(ira, scope, source_node, expected_type, value);
7946}7943}
79477944
7948static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type) {7945static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type) {
7949 return ir_implicit_cast2(ira, &value->base, value, expected_type);7946 return ir_implicit_cast2(ira, value->scope, value->source_node, value, expected_type);
7950}7947}
79517948
7952static ZigType *get_ptr_elem_type(CodeGen *g, IrInstGen *ptr) {7949static ZigType *get_ptr_elem_type(CodeGen *g, IrInstGen *ptr) {
7953 ir_assert_gen(ptr->value->type->id == ZigTypeIdPointer, ptr);7950 ir_assert(ptr->value->type->id == ZigTypeIdPointer, ptr);
7954 ZigType *elem_type = ptr->value->type->data.pointer.child_type;7951 ZigType *elem_type = ptr->value->type->data.pointer.child_type;
7955 if (elem_type != g->builtin_types.entry_anytype)7952 if (elem_type != g->builtin_types.entry_anytype)
7956 return elem_type;7953 return elem_type;
79577954
7958 if (ir_resolve_lazy(g, ptr->base.source_node, ptr->value))7955 if (ir_resolve_lazy(g, ptr->source_node, ptr->value))
7959 return g->builtin_types.entry_invalid;7956 return g->builtin_types.entry_invalid;
79607957
7961 assert(value_is_comptime(ptr->value));7958 assert(value_is_comptime(ptr->value));
...@@ -7963,7 +7960,7 @@ static ZigType *get_ptr_elem_type(CodeGen *g, IrInstGen *ptr) {...@@ -7963,7 +7960,7 @@ static ZigType *get_ptr_elem_type(CodeGen *g, IrInstGen *ptr) {
7963 return pointee->type;7960 return pointee->type;
7964}7961}
79657962
7966static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *ptr,7963static IrInstGen *ir_get_deref(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *ptr,
7967 ResultLoc *result_loc)7964 ResultLoc *result_loc)
7968{7965{
7969 Error err;7966 Error err;
...@@ -7972,7 +7969,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns...@@ -7972,7 +7969,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns
7972 return ira->codegen->invalid_inst_gen;7969 return ira->codegen->invalid_inst_gen;
79737970
7974 if (ptr_type->id != ZigTypeIdPointer) {7971 if (ptr_type->id != ZigTypeIdPointer) {
7975 ir_add_error_node(ira, source_instruction->source_node,7972 ir_add_error_node(ira, source_node,
7976 buf_sprintf("attempt to dereference non-pointer type '%s'",7973 buf_sprintf("attempt to dereference non-pointer type '%s'",
7977 buf_ptr(&ptr_type->name)));7974 buf_ptr(&ptr_type->name)));
7978 return ira->codegen->invalid_inst_gen;7975 return ira->codegen->invalid_inst_gen;
...@@ -7986,7 +7983,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns...@@ -7986,7 +7983,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns
7986 case OnePossibleValueInvalid:7983 case OnePossibleValueInvalid:
7987 return ira->codegen->invalid_inst_gen;7984 return ira->codegen->invalid_inst_gen;
7988 case OnePossibleValueYes:7985 case OnePossibleValueYes:
7989 return ir_const_move(ira, source_instruction,7986 return ir_const_move(ira, scope, source_node,
7990 get_the_one_possible_value(ira->codegen, child_type));7987 get_the_one_possible_value(ira->codegen, child_type));
7991 case OnePossibleValueNo:7988 case OnePossibleValueNo:
7992 break;7989 break;
...@@ -7995,11 +7992,11 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns...@@ -7995,11 +7992,11 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns
7995 if (ptr->value->special == ConstValSpecialUndef) {7992 if (ptr->value->special == ConstValSpecialUndef) {
7996 // If we are in a TypeOf call, we return an undefined value instead of erroring7993 // If we are in a TypeOf call, we return an undefined value instead of erroring
7997 // since we know the type.7994 // since we know the type.
7998 if (get_scope_typeof(source_instruction->scope)) {7995 if (get_scope_typeof(scope)) {
7999 return ir_const_undef(ira, source_instruction, child_type);7996 return ir_const_undef(ira, scope, source_node, child_type);
8000 }7997 }
80017998
8002 ir_add_error(ira, &ptr->base, buf_sprintf("attempt to dereference undefined value"));7999 ir_add_error(ira, ptr, buf_sprintf("attempt to dereference undefined value"));
8003 return ira->codegen->invalid_inst_gen;8000 return ira->codegen->invalid_inst_gen;
8004 }8001 }
8005 if (ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {8002 if (ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
...@@ -8008,9 +8005,9 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns...@@ -8008,9 +8005,9 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns
8008 child_type = pointee->type;8005 child_type = pointee->type;
8009 }8006 }
8010 if (pointee->special != ConstValSpecialRuntime) {8007 if (pointee->special != ConstValSpecialRuntime) {
8011 IrInstGen *result = ir_const(ira, source_instruction, child_type);8008 IrInstGen *result = ir_const(ira, scope, source_node, child_type);
80128009
8013 if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, result->value,8010 if ((err = ir_read_const_ptr(ira, ira->codegen, source_node, result->value,
8014 ptr->value)))8011 ptr->value)))
8015 {8012 {
8016 return ira->codegen->invalid_inst_gen;8013 return ira->codegen->invalid_inst_gen;
...@@ -8038,12 +8035,12 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns...@@ -8038,12 +8035,12 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns
8038 if (ptr_type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {8035 if (ptr_type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {
8039 if (ptr->id == IrInstGenIdElemPtr) {8036 if (ptr->id == IrInstGenIdElemPtr) {
8040 IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr;8037 IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr;
8041 IrInstGen *vector_loaded = ir_get_deref(ira, &elem_ptr->array_ptr->base,8038 IrInstGen *vector_loaded = ir_get_deref(ira, elem_ptr->array_ptr->scope,
8042 elem_ptr->array_ptr, nullptr);8039 elem_ptr->array_ptr->source_node, elem_ptr->array_ptr, nullptr);
8043 IrInstGen *elem_index = elem_ptr->elem_index;8040 IrInstGen *elem_index = elem_ptr->elem_index;
8044 return ir_build_vector_extract_elem(ira, source_instruction, vector_loaded, elem_index);8041 return ir_build_vector_extract_elem(ira, scope, source_node, vector_loaded, elem_index);
8045 }8042 }
8046 ir_add_error(ira, &ptr->base,8043 ir_add_error(ira, ptr,
8047 buf_sprintf("unable to determine vector element index of type '%s'", buf_ptr(&ptr_type->name)));8044 buf_sprintf("unable to determine vector element index of type '%s'", buf_ptr(&ptr_type->name)));
8048 return ira->codegen->invalid_inst_gen;8045 return ira->codegen->invalid_inst_gen;
8049 }8046 }
...@@ -8051,7 +8048,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns...@@ -8051,7 +8048,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns
8051 IrInstGen *result_loc_inst;8048 IrInstGen *result_loc_inst;
8052 if (ptr_type->data.pointer.host_int_bytes != 0 && handle_is_ptr(ira->codegen, child_type)) {8049 if (ptr_type->data.pointer.host_int_bytes != 0 && handle_is_ptr(ira->codegen, child_type)) {
8053 if (result_loc == nullptr) result_loc = no_result_loc();8050 if (result_loc == nullptr) result_loc = no_result_loc();
8054 result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, true, true);8051 result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, result_loc, child_type, nullptr, true, true);
8055 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {8052 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
8056 return result_loc_inst;8053 return result_loc_inst;
8057 }8054 }
...@@ -8059,7 +8056,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns...@@ -8059,7 +8056,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns
8059 result_loc_inst = nullptr;8056 result_loc_inst = nullptr;
8060 }8057 }
80618058
8062 return ir_build_load_ptr_gen(ira, source_instruction, ptr, child_type, result_loc_inst);8059 return ir_build_load_ptr_gen(ira, scope, source_node, ptr, child_type, result_loc_inst);
8063}8060}
80648061
8065static bool ir_resolve_const_align(CodeGen *codegen, Stage1Air *exec, AstNode *source_node,8062static bool ir_resolve_const_align(CodeGen *codegen, Stage1Air *exec, AstNode *source_node,
...@@ -8110,7 +8107,7 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstGen *value, ZigType *elem_typ...@@ -8110,7 +8107,7 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstGen *value, ZigType *elem_typ
8110 if (type_is_invalid(casted_value->value->type))8107 if (type_is_invalid(casted_value->value->type))
8111 return false;8108 return false;
81128109
8113 return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->base.source_node,8110 return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->source_node,
8114 casted_value->value, out);8111 casted_value->value, out);
8115}8112}
81168113
...@@ -8279,7 +8276,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstGen *value) {...@@ -8279,7 +8276,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstGen *value) {
8279 size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i;8276 size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i;
8280 ZigValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index];8277 ZigValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index];
8281 if (char_val->special == ConstValSpecialUndef) {8278 if (char_val->special == ConstValSpecialUndef) {
8282 ir_add_error(ira, &casted_value->base, buf_sprintf("use of undefined value"));8279 ir_add_error(ira, casted_value, buf_sprintf("use of undefined value"));
8283 return nullptr;8280 return nullptr;
8284 }8281 }
8285 uint64_t big_c = bigint_as_u64(&char_val->data.x_bigint);8282 uint64_t big_c = bigint_as_u64(&char_val->data.x_bigint);
...@@ -8301,13 +8298,13 @@ static IrInstGen *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira...@@ -8301,13 +8298,13 @@ static IrInstGen *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira
8301 ira->src_implicit_return_type_list.append(value);8298 ira->src_implicit_return_type_list.append(value);
8302 }8299 }
83038300
8304 return ir_const_void(ira, &instruction->base.base);8301 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
8305}8302}
83068303
8307static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn *instruction) {8304static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn *instruction) {
8308 if (instruction->operand == nullptr) {8305 if (instruction->operand == nullptr) {
8309 // result location mechanism took care of it.8306 // result location mechanism took care of it.
8310 IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, nullptr);8307 IrInstGen *result = ir_build_return_gen(ira, instruction->base.scope, instruction->base.source_node, nullptr);
8311 return ir_finish_anal(ira, result);8308 return ir_finish_anal(ira, result);
8312 }8309 }
83138310
...@@ -8330,7 +8327,7 @@ static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn...@@ -8330,7 +8327,7 @@ static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn
8330 handle_is_ptr(ira->codegen, ira->explicit_return_type))8327 handle_is_ptr(ira->codegen, ira->explicit_return_type))
8331 {8328 {
8332 // result location mechanism took care of it.8329 // result location mechanism took care of it.
8333 IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, nullptr);8330 IrInstGen *result = ir_build_return_gen(ira, instruction->base.scope, instruction->base.source_node, nullptr);
8334 return ir_finish_anal(ira, result);8331 return ir_finish_anal(ira, result);
8335 }8332 }
83368333
...@@ -8338,16 +8335,17 @@ static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn...@@ -8338,16 +8335,17 @@ static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn
8338 casted_operand->value->type->id == ZigTypeIdPointer &&8335 casted_operand->value->type->id == ZigTypeIdPointer &&
8339 casted_operand->value->data.rh_ptr == RuntimeHintPtrStack)8336 casted_operand->value->data.rh_ptr == RuntimeHintPtrStack)
8340 {8337 {
8341 ir_add_error(ira, &instruction->operand->base, buf_sprintf("function returns address of local variable"));8338 ir_add_error_node(ira, instruction->operand->source_node,
8339 buf_sprintf("function returns address of local variable"));
8342 return ir_unreach_error(ira);8340 return ir_unreach_error(ira);
8343 }8341 }
83448342
8345 IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, casted_operand);8343 IrInstGen *result = ir_build_return_gen(ira, instruction->base.scope, instruction->base.source_node, casted_operand);
8346 return ir_finish_anal(ira, result);8344 return ir_finish_anal(ira, result);
8347}8345}
83488346
8349static IrInstGen *ir_analyze_instruction_const(IrAnalyze *ira, IrInstSrcConst *instruction) {8347static IrInstGen *ir_analyze_instruction_const(IrAnalyze *ira, IrInstSrcConst *instruction) {
8350 return ir_const_move(ira, &instruction->base.base, instruction->value);8348 return ir_const_move(ira, instruction->base.scope, instruction->base.source_node, instruction->value);
8351}8349}
83528350
8353static IrInstGen *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {8351static IrInstGen *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {
...@@ -8388,11 +8386,13 @@ static IrInstGen *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstSrcBinOp *bin_op_...@@ -8388,11 +8386,13 @@ static IrInstGen *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstSrcBinOp *bin_op_
8388 } else {8386 } else {
8389 zig_unreachable();8387 zig_unreachable();
8390 }8388 }
8391 return ir_const_bool(ira, &bin_op_instruction->base.base, result_bool);8389 return ir_const_bool(ira, bin_op_instruction->base.scope,
8390 bin_op_instruction->base.source_node, result_bool);
8392 }8391 }
83938392
8394 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, bool_type,8393 return ir_build_bin_op_gen(ira, bin_op_instruction->base.scope,
8395 bin_op_instruction->op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);8394 bin_op_instruction->base.source_node, bool_type, bin_op_instruction->op_id,
8395 casted_op1, casted_op2, bin_op_instruction->safety_check_on);
8396}8396}
83978397
8398static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) {8398static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) {
...@@ -8444,12 +8444,12 @@ static void set_optional_payload(ZigValue *opt_val, ZigValue *payload) {...@@ -8444,12 +8444,12 @@ static void set_optional_payload(ZigValue *opt_val, ZigValue *payload) {
8444}8444}
84458445
8446static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,8446static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,
8447 ZigValue *op1_val, ZigValue *op2_val, IrInst *source_instr, IrBinOp op_id,8447 ZigValue *op1_val, ZigValue *op2_val, Scope *scope, AstNode *source_node, IrBinOp op_id,
8448 bool one_possible_value)8448 bool one_possible_value)
8449{8449{
8450 if (op1_val->special == ConstValSpecialUndef ||8450 if (op1_val->special == ConstValSpecialUndef ||
8451 op2_val->special == ConstValSpecialUndef)8451 op2_val->special == ConstValSpecialUndef)
8452 return ir_const_undef(ira, source_instr, resolved_type);8452 return ir_const_undef(ira, scope, source_node, resolved_type);
8453 if (resolved_type->id == ZigTypeIdPointer && op_id != IrBinOpCmpEq && op_id != IrBinOpCmpNotEq) {8453 if (resolved_type->id == ZigTypeIdPointer && op_id != IrBinOpCmpEq && op_id != IrBinOpCmpNotEq) {
8454 if ((op1_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr ||8454 if ((op1_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr ||
8455 op1_val->data.x_ptr.special == ConstPtrSpecialNull) &&8455 op1_val->data.x_ptr.special == ConstPtrSpecialNull) &&
...@@ -8469,7 +8469,7 @@ static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,...@@ -8469,7 +8469,7 @@ static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,
8469 cmp_result = CmpEQ;8469 cmp_result = CmpEQ;
8470 }8470 }
8471 bool answer = resolve_cmp_op_id(op_id, cmp_result);8471 bool answer = resolve_cmp_op_id(op_id, cmp_result);
8472 return ir_const_bool(ira, source_instr, answer);8472 return ir_const_bool(ira, scope, source_node, answer);
8473 }8473 }
8474 } else {8474 } else {
8475 bool are_equal = one_possible_value || const_values_equal(ira->codegen, op1_val, op2_val);8475 bool are_equal = one_possible_value || const_values_equal(ira->codegen, op1_val, op2_val);
...@@ -8481,12 +8481,12 @@ static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,...@@ -8481,12 +8481,12 @@ static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,
8481 } else {8481 } else {
8482 zig_unreachable();8482 zig_unreachable();
8483 }8483 }
8484 return ir_const_bool(ira, source_instr, answer);8484 return ir_const_bool(ira, scope, source_node, answer);
8485 }8485 }
8486 zig_unreachable();8486 zig_unreachable();
8487}8487}
84888488
8489static IrInstGen *ir_try_evaluate_bin_op_cmp_const(IrAnalyze *ira, IrInst *source_instr, IrInstGen *op1, IrInstGen *op2,8489static IrInstGen *ir_try_evaluate_bin_op_cmp_const(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *op1, IrInstGen *op2,
8490 ZigType *resolved_type, IrBinOp op_id)8490 ZigType *resolved_type, IrBinOp op_id)
8491{8491{
8492 assert(op1->value->type == resolved_type && op2->value->type == resolved_type);8492 assert(op1->value->type == resolved_type && op2->value->type == resolved_type);
...@@ -8510,8 +8510,8 @@ static IrInstGen *ir_try_evaluate_bin_op_cmp_const(IrAnalyze *ira, IrInst *sourc...@@ -8510,8 +8510,8 @@ static IrInstGen *ir_try_evaluate_bin_op_cmp_const(IrAnalyze *ira, IrInst *sourc
8510 if (op2_val == nullptr)8510 if (op2_val == nullptr)
8511 return ira->codegen->invalid_inst_gen;8511 return ira->codegen->invalid_inst_gen;
8512 if (resolved_type->id != ZigTypeIdVector)8512 if (resolved_type->id != ZigTypeIdVector)
8513 return ir_evaluate_bin_op_cmp(ira, resolved_type, op1_val, op2_val, source_instr, op_id, one_possible_value);8513 return ir_evaluate_bin_op_cmp(ira, resolved_type, op1_val, op2_val, scope, source_node, op_id, one_possible_value);
8514 IrInstGen *result = ir_const(ira, source_instr,8514 IrInstGen *result = ir_const(ira, scope, source_node,
8515 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool));8515 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool));
8516 result->value->data.x_array.data.s_none.elements =8516 result->value->data.x_array.data.s_none.elements =
8517 ira->codegen->pass1_arena->allocate<ZigValue>(resolved_type->data.vector.len);8517 ira->codegen->pass1_arena->allocate<ZigValue>(resolved_type->data.vector.len);
...@@ -8521,7 +8521,7 @@ static IrInstGen *ir_try_evaluate_bin_op_cmp_const(IrAnalyze *ira, IrInst *sourc...@@ -8521,7 +8521,7 @@ static IrInstGen *ir_try_evaluate_bin_op_cmp_const(IrAnalyze *ira, IrInst *sourc
8521 IrInstGen *cur_res = ir_evaluate_bin_op_cmp(ira, resolved_type->data.vector.elem_type,8521 IrInstGen *cur_res = ir_evaluate_bin_op_cmp(ira, resolved_type->data.vector.elem_type,
8522 &op1_val->data.x_array.data.s_none.elements[i],8522 &op1_val->data.x_array.data.s_none.elements[i],
8523 &op2_val->data.x_array.data.s_none.elements[i],8523 &op2_val->data.x_array.data.s_none.elements[i],
8524 source_instr, op_id, one_possible_value);8524 scope, source_node, op_id, one_possible_value);
8525 copy_const_val(ira->codegen, &result->value->data.x_array.data.s_none.elements[i], cur_res->value);8525 copy_const_val(ira->codegen, &result->value->data.x_array.data.s_none.elements[i], cur_res->value);
8526 }8526 }
8527 return result;8527 return result;
...@@ -8608,7 +8608,7 @@ static Error lazy_cmp_zero(CodeGen *codegen, AstNode *source_node, ZigValue *val...@@ -8608,7 +8608,7 @@ static Error lazy_cmp_zero(CodeGen *codegen, AstNode *source_node, ZigValue *val
8608 zig_unreachable();8608 zig_unreachable();
8609}8609}
86108610
8611static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInst* source_instr,8611static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, Scope *scope, AstNode *source_node,
8612 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)8612 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)
8613{8613{
8614 Error err;8614 Error err;
...@@ -8616,12 +8616,12 @@ static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInst* source_instr,...@@ -8616,12 +8616,12 @@ static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInst* source_instr,
8616 // Before resolving the values, we special case comparisons against zero. These can often8616 // Before resolving the values, we special case comparisons against zero. These can often
8617 // be done without resolving lazy values, preventing potential dependency loops.8617 // be done without resolving lazy values, preventing potential dependency loops.
8618 Cmp op1_cmp_zero;8618 Cmp op1_cmp_zero;
8619 if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op1_val, &op1_cmp_zero))) {8619 if ((err = lazy_cmp_zero(ira->codegen, source_node, op1_val, &op1_cmp_zero))) {
8620 if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally;8620 if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally;
8621 return ira->codegen->trace_err;8621 return ira->codegen->trace_err;
8622 }8622 }
8623 Cmp op2_cmp_zero;8623 Cmp op2_cmp_zero;
8624 if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op2_val, &op2_cmp_zero))) {8624 if ((err = lazy_cmp_zero(ira->codegen, source_node, op2_val, &op2_cmp_zero))) {
8625 if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally;8625 if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally;
8626 return ira->codegen->trace_err;8626 return ira->codegen->trace_err;
8627 }8627 }
...@@ -8658,12 +8658,12 @@ static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInst* source_instr,...@@ -8658,12 +8658,12 @@ static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInst* source_instr,
8658 }8658 }
8659never_mind_just_calculate_it_normally:8659never_mind_just_calculate_it_normally:
86608660
8661 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_instr->source_node,8661 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_node,
8662 op1_val, UndefOk)))8662 op1_val, UndefOk)))
8663 {8663 {
8664 return ira->codegen->trace_err;8664 return ira->codegen->trace_err;
8665 }8665 }
8666 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_instr->source_node,8666 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_node,
8667 op2_val, UndefOk)))8667 op2_val, UndefOk)))
8668 {8668 {
8669 return ira->codegen->trace_err;8669 return ira->codegen->trace_err;
...@@ -8686,12 +8686,12 @@ never_mind_just_calculate_it_normally:...@@ -8686,12 +8686,12 @@ never_mind_just_calculate_it_normally:
8686 return nullptr;8686 return nullptr;
8687 }8687 }
8688 if (op1_val->type->id == ZigTypeIdComptimeFloat) {8688 if (op1_val->type->id == ZigTypeIdComptimeFloat) {
8689 IrInstGen *tmp = ir_const_noval(ira, source_instr);8689 IrInstGen *tmp = ir_const_noval(ira, scope, source_node);
8690 tmp->value = op1_val;8690 tmp->value = op1_val;
8691 IrInstGen *casted = ir_implicit_cast(ira, tmp, op2_val->type);8691 IrInstGen *casted = ir_implicit_cast(ira, tmp, op2_val->type);
8692 op1_val = casted->value;8692 op1_val = casted->value;
8693 } else if (op2_val->type->id == ZigTypeIdComptimeFloat) {8693 } else if (op2_val->type->id == ZigTypeIdComptimeFloat) {
8694 IrInstGen *tmp = ir_const_noval(ira, source_instr);8694 IrInstGen *tmp = ir_const_noval(ira, scope, source_node);
8695 tmp->value = op2_val;8695 tmp->value = op2_val;
8696 IrInstGen *casted = ir_implicit_cast(ira, tmp, op1_val->type);8696 IrInstGen *casted = ir_implicit_cast(ira, tmp, op1_val->type);
8697 op2_val = casted->value;8697 op2_val = casted->value;
...@@ -8746,7 +8746,7 @@ never_mind_just_calculate_it_normally:...@@ -8746,7 +8746,7 @@ never_mind_just_calculate_it_normally:
8746 return nullptr;8746 return nullptr;
8747}8747}
87488748
8749static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_instr,8749static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, Scope *scope, AstNode *source_node,
8750 IrInstGen *op1, IrInstGen *op2, IrBinOp op_id)8750 IrInstGen *op1, IrInstGen *op2, IrBinOp op_id)
8751{8751{
8752 Error err;8752 Error err;
...@@ -8757,7 +8757,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -8757,7 +8757,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
8757 ZigType *op2_scalar_type = op2->value->type;8757 ZigType *op2_scalar_type = op2->value->type;
8758 if (op1->value->type->id == ZigTypeIdVector && op2->value->type->id == ZigTypeIdVector) {8758 if (op1->value->type->id == ZigTypeIdVector && op2->value->type->id == ZigTypeIdVector) {
8759 if (op1->value->type->data.vector.len != op2->value->type->data.vector.len) {8759 if (op1->value->type->data.vector.len != op2->value->type->data.vector.len) {
8760 ir_add_error(ira, source_instr,8760 ir_add_error_node(ira, source_node,
8761 buf_sprintf("vector length mismatch: %" PRIu64 " and %" PRIu64,8761 buf_sprintf("vector length mismatch: %" PRIu64 " and %" PRIu64,
8762 op1->value->type->data.vector.len, op2->value->type->data.vector.len));8762 op1->value->type->data.vector.len, op2->value->type->data.vector.len));
8763 return ira->codegen->invalid_inst_gen;8763 return ira->codegen->invalid_inst_gen;
...@@ -8766,7 +8766,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -8766,7 +8766,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
8766 op1_scalar_type = op1->value->type->data.vector.elem_type;8766 op1_scalar_type = op1->value->type->data.vector.elem_type;
8767 op2_scalar_type = op2->value->type->data.vector.elem_type;8767 op2_scalar_type = op2->value->type->data.vector.elem_type;
8768 } else if (op1->value->type->id == ZigTypeIdVector || op2->value->type->id == ZigTypeIdVector) {8768 } else if (op1->value->type->id == ZigTypeIdVector || op2->value->type->id == ZigTypeIdVector) {
8769 ir_add_error(ira, source_instr,8769 ir_add_error_node(ira, source_node,
8770 buf_sprintf("mixed scalar and vector operands to comparison operator: '%s' and '%s'",8770 buf_sprintf("mixed scalar and vector operands to comparison operator: '%s' and '%s'",
8771 buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name)));8771 buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name)));
8772 return ira->codegen->invalid_inst_gen;8772 return ira->codegen->invalid_inst_gen;
...@@ -8796,14 +8796,14 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -8796,14 +8796,14 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
8796 }8796 }
8797 Cmp op1_cmp_zero;8797 Cmp op1_cmp_zero;
8798 bool have_op1_cmp_zero = false;8798 bool have_op1_cmp_zero = false;
8799 if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op1->value, &op1_cmp_zero))) {8799 if ((err = lazy_cmp_zero(ira->codegen, source_node, op1->value, &op1_cmp_zero))) {
8800 if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen;8800 if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen;
8801 } else {8801 } else {
8802 have_op1_cmp_zero = true;8802 have_op1_cmp_zero = true;
8803 }8803 }
8804 Cmp op2_cmp_zero;8804 Cmp op2_cmp_zero;
8805 bool have_op2_cmp_zero = false;8805 bool have_op2_cmp_zero = false;
8806 if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op2->value, &op2_cmp_zero))) {8806 if ((err = lazy_cmp_zero(ira->codegen, source_node, op2->value, &op2_cmp_zero))) {
8807 if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen;8807 if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen;
8808 } else {8808 } else {
8809 have_op2_cmp_zero = true;8809 have_op2_cmp_zero = true;
...@@ -8811,7 +8811,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -8811,7 +8811,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
8811 if (((opv_op1 || instr_is_comptime(op1)) && (opv_op2 || instr_is_comptime(op2))) ||8811 if (((opv_op1 || instr_is_comptime(op1)) && (opv_op2 || instr_is_comptime(op2))) ||
8812 (have_op1_cmp_zero && have_op2_cmp_zero))8812 (have_op1_cmp_zero && have_op2_cmp_zero))
8813 {8813 {
8814 IrInstGen *result_instruction = ir_const(ira, source_instr, result_type);8814 IrInstGen *result_instruction = ir_const(ira, scope, source_node, result_type);
8815 ZigValue *out_val = result_instruction->value;8815 ZigValue *out_val = result_instruction->value;
8816 if (result_type->id == ZigTypeIdVector) {8816 if (result_type->id == ZigTypeIdVector) {
8817 size_t len = result_type->data.vector.len;8817 size_t len = result_type->data.vector.len;
...@@ -8824,10 +8824,10 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -8824,10 +8824,10 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
8824 ZigValue *scalar_op2_val = &op2->value->data.x_array.data.s_none.elements[i];8824 ZigValue *scalar_op2_val = &op2->value->data.x_array.data.s_none.elements[i];
8825 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];8825 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];
8826 assert(scalar_out_val->type == scalar_result_type);8826 assert(scalar_out_val->type == scalar_result_type);
8827 ErrorMsg *msg = ir_eval_bin_op_cmp_scalar(ira, source_instr,8827 ErrorMsg *msg = ir_eval_bin_op_cmp_scalar(ira, scope, source_node,
8828 scalar_op1_val, op_id, scalar_op2_val, scalar_out_val);8828 scalar_op1_val, op_id, scalar_op2_val, scalar_out_val);
8829 if (msg != nullptr) {8829 if (msg != nullptr) {
8830 add_error_note(ira->codegen, msg, source_instr->source_node,8830 add_error_note(ira->codegen, msg, source_node,
8831 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));8831 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
8832 return ira->codegen->invalid_inst_gen;8832 return ira->codegen->invalid_inst_gen;
8833 }8833 }
...@@ -8835,7 +8835,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -8835,7 +8835,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
8835 out_val->type = result_type;8835 out_val->type = result_type;
8836 out_val->special = ConstValSpecialStatic;8836 out_val->special = ConstValSpecialStatic;
8837 } else {8837 } else {
8838 if (ir_eval_bin_op_cmp_scalar(ira, source_instr, op1->value, op_id,8838 if (ir_eval_bin_op_cmp_scalar(ira, scope, source_node, op1->value, op_id,
8839 op2->value, out_val) != nullptr)8839 op2->value, out_val) != nullptr)
8840 {8840 {
8841 return ira->codegen->invalid_inst_gen;8841 return ira->codegen->invalid_inst_gen;
...@@ -8853,9 +8853,9 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -8853,9 +8853,9 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
8853 // 0 > unsigned_x // false8853 // 0 > unsigned_x // false
8854 switch (op_id) {8854 switch (op_id) {
8855 case IrBinOpCmpLessOrEq:8855 case IrBinOpCmpLessOrEq:
8856 return ir_const_bool(ira, source_instr, true);8856 return ir_const_bool(ira, scope, source_node, true);
8857 case IrBinOpCmpGreaterThan:8857 case IrBinOpCmpGreaterThan:
8858 return ir_const_bool(ira, source_instr, false);8858 return ir_const_bool(ira, scope, source_node, false);
8859 default:8859 default:
8860 break;8860 break;
8861 }8861 }
...@@ -8870,11 +8870,11 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -8870,11 +8870,11 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
8870 case IrBinOpCmpNotEq:8870 case IrBinOpCmpNotEq:
8871 case IrBinOpCmpLessOrEq:8871 case IrBinOpCmpLessOrEq:
8872 case IrBinOpCmpLessThan:8872 case IrBinOpCmpLessThan:
8873 return ir_const_bool(ira, source_instr, true);8873 return ir_const_bool(ira, scope, source_node, true);
8874 case IrBinOpCmpEq:8874 case IrBinOpCmpEq:
8875 case IrBinOpCmpGreaterOrEq:8875 case IrBinOpCmpGreaterOrEq:
8876 case IrBinOpCmpGreaterThan:8876 case IrBinOpCmpGreaterThan:
8877 return ir_const_bool(ira, source_instr, false);8877 return ir_const_bool(ira, scope, source_node, false);
8878 default:8878 default:
8879 break;8879 break;
8880 }8880 }
...@@ -8886,9 +8886,9 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -8886,9 +8886,9 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
8886 // unsigned_x >= 0 // true8886 // unsigned_x >= 0 // true
8887 switch (op_id) {8887 switch (op_id) {
8888 case IrBinOpCmpLessThan:8888 case IrBinOpCmpLessThan:
8889 return ir_const_bool(ira, source_instr, false);8889 return ir_const_bool(ira, scope, source_node, false);
8890 case IrBinOpCmpGreaterOrEq:8890 case IrBinOpCmpGreaterOrEq:
8891 return ir_const_bool(ira, source_instr, true);8891 return ir_const_bool(ira, scope, source_node, true);
8892 default:8892 default:
8893 break;8893 break;
8894 }8894 }
...@@ -8903,11 +8903,11 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -8903,11 +8903,11 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
8903 case IrBinOpCmpNotEq:8903 case IrBinOpCmpNotEq:
8904 case IrBinOpCmpGreaterOrEq:8904 case IrBinOpCmpGreaterOrEq:
8905 case IrBinOpCmpGreaterThan:8905 case IrBinOpCmpGreaterThan:
8906 return ir_const_bool(ira, source_instr, true);8906 return ir_const_bool(ira, scope, source_node, true);
8907 case IrBinOpCmpEq:8907 case IrBinOpCmpEq:
8908 case IrBinOpCmpLessThan:8908 case IrBinOpCmpLessThan:
8909 case IrBinOpCmpLessOrEq:8909 case IrBinOpCmpLessOrEq:
8910 return ir_const_bool(ira, source_instr, false);8910 return ir_const_bool(ira, scope, source_node, false);
8911 default:8911 default:
8912 break;8912 break;
8913 }8913 }
...@@ -8936,7 +8936,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -8936,7 +8936,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
8936 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type);8936 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type);
8937 if (type_is_invalid(casted_op1->value->type) || type_is_invalid(casted_op2->value->type))8937 if (type_is_invalid(casted_op1->value->type) || type_is_invalid(casted_op2->value->type))
8938 return ira->codegen->invalid_inst_gen;8938 return ira->codegen->invalid_inst_gen;
8939 return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true);8939 return ir_build_bin_op_gen(ira, scope, source_node, result_type, op_id, casted_op1, casted_op2, true);
8940 }8940 }
89418941
8942 // For mixed unsigned integer sizes, implicit cast both operands to the larger integer.8942 // For mixed unsigned integer sizes, implicit cast both operands to the larger integer.
...@@ -8967,7 +8967,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -8967,7 +8967,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
8967 if (op1_val == nullptr)8967 if (op1_val == nullptr)
8968 return ira->codegen->invalid_inst_gen;8968 return ira->codegen->invalid_inst_gen;
8969 if (op1_val->special == ConstValSpecialUndef)8969 if (op1_val->special == ConstValSpecialUndef)
8970 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);8970 return ir_const_undef(ira, scope, source_node, ira->codegen->builtin_types.entry_bool);
8971 bool is_unsigned;8971 bool is_unsigned;
8972 if (op1_is_float) {8972 if (op1_is_float) {
8973 BigInt bigint = {};8973 BigInt bigint = {};
...@@ -8975,7 +8975,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -8975,7 +8975,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
8975 Cmp zcmp = float_cmp_zero(op1_val);8975 Cmp zcmp = float_cmp_zero(op1_val);
8976 if (float_has_fraction(op1_val)) {8976 if (float_has_fraction(op1_val)) {
8977 if (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq) {8977 if (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq) {
8978 return ir_const_bool(ira, source_instr, op_id == IrBinOpCmpNotEq);8978 return ir_const_bool(ira, scope, source_node, op_id == IrBinOpCmpNotEq);
8979 }8979 }
8980 if (zcmp == CmpLT) {8980 if (zcmp == CmpLT) {
8981 bigint_decr(&bigint);8981 bigint_decr(&bigint);
...@@ -8993,10 +8993,10 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -8993,10 +8993,10 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
8993 op1_bits += 1;8993 op1_bits += 1;
8994 }8994 }
8995 } else if (op1_is_float) {8995 } else if (op1_is_float) {
8996 ir_assert(op1_scalar_type->id == ZigTypeIdFloat, source_instr);8996 src_assert(op1_scalar_type->id == ZigTypeIdFloat, source_node);
8997 dest_float_type = op1_scalar_type;8997 dest_float_type = op1_scalar_type;
8998 } else {8998 } else {
8999 ir_assert(op1_scalar_type->id == ZigTypeIdInt, source_instr);8999 src_assert(op1_scalar_type->id == ZigTypeIdInt, source_node);
9000 op1_bits = op1_scalar_type->data.integral.bit_count;9000 op1_bits = op1_scalar_type->data.integral.bit_count;
9001 if (!op1_scalar_type->data.integral.is_signed && dest_int_is_signed) {9001 if (!op1_scalar_type->data.integral.is_signed && dest_int_is_signed) {
9002 op1_bits += 1;9002 op1_bits += 1;
...@@ -9008,7 +9008,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -9008,7 +9008,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
9008 if (op2_val == nullptr)9008 if (op2_val == nullptr)
9009 return ira->codegen->invalid_inst_gen;9009 return ira->codegen->invalid_inst_gen;
9010 if (op2_val->special == ConstValSpecialUndef)9010 if (op2_val->special == ConstValSpecialUndef)
9011 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);9011 return ir_const_undef(ira, scope, source_node, ira->codegen->builtin_types.entry_bool);
9012 bool is_unsigned;9012 bool is_unsigned;
9013 if (op2_is_float) {9013 if (op2_is_float) {
9014 BigInt bigint = {};9014 BigInt bigint = {};
...@@ -9016,7 +9016,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -9016,7 +9016,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
9016 Cmp zcmp = float_cmp_zero(op2_val);9016 Cmp zcmp = float_cmp_zero(op2_val);
9017 if (float_has_fraction(op2_val)) {9017 if (float_has_fraction(op2_val)) {
9018 if (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq) {9018 if (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq) {
9019 return ir_const_bool(ira, source_instr, op_id == IrBinOpCmpNotEq);9019 return ir_const_bool(ira, scope, source_node, op_id == IrBinOpCmpNotEq);
9020 }9020 }
9021 if (zcmp == CmpLT) {9021 if (zcmp == CmpLT) {
9022 bigint_decr(&bigint);9022 bigint_decr(&bigint);
...@@ -9034,10 +9034,10 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -9034,10 +9034,10 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
9034 op2_bits += 1;9034 op2_bits += 1;
9035 }9035 }
9036 } else if (op2_is_float) {9036 } else if (op2_is_float) {
9037 ir_assert(op2_scalar_type->id == ZigTypeIdFloat, source_instr);9037 src_assert(op2_scalar_type->id == ZigTypeIdFloat, source_node);
9038 dest_float_type = op2_scalar_type;9038 dest_float_type = op2_scalar_type;
9039 } else {9039 } else {
9040 ir_assert(op2_scalar_type->id == ZigTypeIdInt, source_instr);9040 src_assert(op2_scalar_type->id == ZigTypeIdInt, source_node);
9041 op2_bits = op2_scalar_type->data.integral.bit_count;9041 op2_bits = op2_scalar_type->data.integral.bit_count;
9042 if (!op2_scalar_type->data.integral.is_signed && dest_int_is_signed) {9042 if (!op2_scalar_type->data.integral.is_signed && dest_int_is_signed) {
9043 op2_bits += 1;9043 op2_bits += 1;
...@@ -9055,7 +9055,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i...@@ -9055,7 +9055,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
9055 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type);9055 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type);
9056 if (type_is_invalid(casted_op2->value->type))9056 if (type_is_invalid(casted_op2->value->type))
9057 return ira->codegen->invalid_inst_gen;9057 return ira->codegen->invalid_inst_gen;
9058 return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true);9058 return ir_build_bin_op_gen(ira, scope, source_node, result_type, op_id, casted_op1, casted_op2, true);
9059}9059}
90609060
9061static bool type_is_self_comparable(ZigType *ty, bool is_equality_cmp) {9061static bool type_is_self_comparable(ZigType *ty, bool is_equality_cmp) {
...@@ -9106,7 +9106,7 @@ static bool type_is_self_comparable(ZigType *ty, bool is_equality_cmp) {...@@ -9106,7 +9106,7 @@ static bool type_is_self_comparable(ZigType *ty, bool is_equality_cmp) {
9106 zig_unreachable();9106 zig_unreachable();
9107}9107}
91089108
9109static IrInstGen *ir_try_evaluate_cmp_optional_non_optional_const(IrAnalyze *ira, IrInst *source_instr, ZigType *child_type,9109static IrInstGen *ir_try_evaluate_cmp_optional_non_optional_const(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *child_type,
9110 IrInstGen *optional, IrInstGen *non_optional, IrBinOp op_id)9110 IrInstGen *optional, IrInstGen *non_optional, IrBinOp op_id)
9111{9111{
9112 assert(optional->value->type->id == ZigTypeIdOptional);9112 assert(optional->value->type->id == ZigTypeIdOptional);
...@@ -9126,22 +9126,22 @@ static IrInstGen *ir_try_evaluate_cmp_optional_non_optional_const(IrAnalyze *ira...@@ -9126,22 +9126,22 @@ static IrInstGen *ir_try_evaluate_cmp_optional_non_optional_const(IrAnalyze *ira
9126 }9126 }
91279127
9128 if (!optional_value_is_null(optional_val)) {9128 if (!optional_value_is_null(optional_val)) {
9129 IrInstGen *optional_unwrapped = ir_analyze_optional_value_payload_value(ira, source_instr, optional, false);9129 IrInstGen *optional_unwrapped = ir_analyze_optional_value_payload_value(ira, scope, source_node, optional, false);
9130 if (type_is_invalid(optional_unwrapped->value->type)) {9130 if (type_is_invalid(optional_unwrapped->value->type)) {
9131 return ira->codegen->invalid_inst_gen;9131 return ira->codegen->invalid_inst_gen;
9132 }9132 }
91339133
9134 IrInstGen *ret = ir_try_evaluate_bin_op_cmp_const(ira, source_instr, optional_unwrapped, non_optional, child_type, op_id);9134 IrInstGen *ret = ir_try_evaluate_bin_op_cmp_const(ira, scope, source_node, optional_unwrapped, non_optional, child_type, op_id);
9135 assert(ret != nullptr);9135 assert(ret != nullptr);
9136 return ret;9136 return ret;
9137 }9137 }
9138 return ir_const_bool(ira, source_instr, (op_id != IrBinOpCmpEq));9138 return ir_const_bool(ira, scope, source_node, (op_id != IrBinOpCmpEq));
9139 } else {9139 } else {
9140 return nullptr;9140 return nullptr;
9141 }9141 }
9142}9142}
91439143
9144static IrInstGen *ir_evaluate_cmp_optional_non_optional(IrAnalyze *ira, IrInst *source_instr, ZigType *child_type,9144static IrInstGen *ir_evaluate_cmp_optional_non_optional(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *child_type,
9145 IrInstGen *optional, IrInstGen *non_optional, IrBinOp op_id)9145 IrInstGen *optional, IrInstGen *non_optional, IrBinOp op_id)
9146{9146{
9147 assert(optional->value->type->id == ZigTypeIdOptional);9147 assert(optional->value->type->id == ZigTypeIdOptional);
...@@ -9152,26 +9152,26 @@ static IrInstGen *ir_evaluate_cmp_optional_non_optional(IrAnalyze *ira, IrInst *...@@ -9152,26 +9152,26 @@ static IrInstGen *ir_evaluate_cmp_optional_non_optional(IrAnalyze *ira, IrInst *
9152 ZigType *result_type = ira->codegen->builtin_types.entry_bool;9152 ZigType *result_type = ira->codegen->builtin_types.entry_bool;
9153 ir_append_basic_block_gen(&ira->new_irb, ira->new_irb.current_basic_block);9153 ir_append_basic_block_gen(&ira->new_irb, ira->new_irb.current_basic_block);
91549154
9155 IrBasicBlockGen *null_block = ir_create_basic_block_gen(ira, source_instr->scope, "CmpOptionalNonOptionalOptionalNull");9155 IrBasicBlockGen *null_block = ir_create_basic_block_gen(ira, scope, "CmpOptionalNonOptionalOptionalNull");
9156 IrBasicBlockGen *non_null_block = ir_create_basic_block_gen(ira, source_instr->scope, "CmpOptionalNonOptionalOptionalNotNull");9156 IrBasicBlockGen *non_null_block = ir_create_basic_block_gen(ira, scope, "CmpOptionalNonOptionalOptionalNotNull");
9157 IrBasicBlockGen *end_block = ir_create_basic_block_gen(ira, source_instr->scope, "CmpOptionalNonOptionalEnd");9157 IrBasicBlockGen *end_block = ir_create_basic_block_gen(ira, scope, "CmpOptionalNonOptionalEnd");
91589158
9159 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, source_instr, optional);9159 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, scope, source_node, optional);
9160 ir_build_cond_br_gen(ira, source_instr, is_non_null, non_null_block, null_block);9160 ir_build_cond_br_gen(ira, scope, source_node, is_non_null, non_null_block, null_block);
91619161
9162 ir_set_cursor_at_end_and_append_block_gen(&ira->new_irb, non_null_block);9162 ir_set_cursor_at_end_and_append_block_gen(&ira->new_irb, non_null_block);
9163 IrInstGen *optional_unwrapped = ir_analyze_optional_value_payload_value(ira, source_instr, optional, false);9163 IrInstGen *optional_unwrapped = ir_analyze_optional_value_payload_value(ira, scope, source_node, optional, false);
9164 if (type_is_invalid(optional_unwrapped->value->type)) {9164 if (type_is_invalid(optional_unwrapped->value->type)) {
9165 return ira->codegen->invalid_inst_gen;9165 return ira->codegen->invalid_inst_gen;
9166 }9166 }
9167 IrInstGen *non_null_cmp_result = ir_build_bin_op_gen(ira, source_instr, result_type, op_id,9167 IrInstGen *non_null_cmp_result = ir_build_bin_op_gen(ira, scope, source_node, result_type, op_id,
9168 optional_unwrapped, non_optional, false); // safety check unnecessary for comparison operators9168 optional_unwrapped, non_optional, false); // safety check unnecessary for comparison operators
9169 ir_build_br_gen(ira, source_instr, end_block);9169 ir_build_br_gen(ira, scope, source_node, end_block);
91709170
91719171
9172 ir_set_cursor_at_end_and_append_block_gen(&ira->new_irb, null_block);9172 ir_set_cursor_at_end_and_append_block_gen(&ira->new_irb, null_block);
9173 IrInstGen *null_result = ir_const_bool(ira, source_instr, (op_id != IrBinOpCmpEq));9173 IrInstGen *null_result = ir_const_bool(ira, scope, source_node, (op_id != IrBinOpCmpEq));
9174 ir_build_br_gen(ira, source_instr, end_block);9174 ir_build_br_gen(ira, scope, source_node, end_block);
91759175
9176 ir_set_cursor_at_end_gen(&ira->new_irb, end_block);9176 ir_set_cursor_at_end_gen(&ira->new_irb, end_block);
9177 int incoming_count = 2;9177 int incoming_count = 2;
...@@ -9182,10 +9182,10 @@ static IrInstGen *ir_evaluate_cmp_optional_non_optional(IrAnalyze *ira, IrInst *...@@ -9182,10 +9182,10 @@ static IrInstGen *ir_evaluate_cmp_optional_non_optional(IrAnalyze *ira, IrInst *
9182 incoming_values[0] = null_result;9182 incoming_values[0] = null_result;
9183 incoming_values[1] = non_null_cmp_result;9183 incoming_values[1] = non_null_cmp_result;
91849184
9185 return ir_build_phi_gen(ira, source_instr, incoming_count, incoming_blocks, incoming_values, result_type);9185 return ir_build_phi_gen(ira, scope, source_node, incoming_count, incoming_blocks, incoming_values, result_type);
9186}9186}
91879187
9188static IrInstGen *ir_analyze_cmp_optional_non_optional(IrAnalyze *ira, IrInst *source_instr,9188static IrInstGen *ir_analyze_cmp_optional_non_optional(IrAnalyze *ira, Scope *scope, AstNode *source_node,
9189 IrInstGen *op1, IrInstGen *op2, IrInstGen *optional, IrBinOp op_id)9189 IrInstGen *op1, IrInstGen *op2, IrInstGen *optional, IrBinOp op_id)
9190{9190{
9191 assert(op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);9191 assert(op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);
...@@ -9204,22 +9204,22 @@ static IrInstGen *ir_analyze_cmp_optional_non_optional(IrAnalyze *ira, IrInst *s...@@ -9204,22 +9204,22 @@ static IrInstGen *ir_analyze_cmp_optional_non_optional(IrAnalyze *ira, IrInst *s
9204 ZigType *child_type = optional->value->type->data.maybe.child_type;9204 ZigType *child_type = optional->value->type->data.maybe.child_type;
9205 bool child_type_matches = (child_type == non_optional->value->type);9205 bool child_type_matches = (child_type == non_optional->value->type);
9206 if (!child_type_matches || !type_is_self_comparable(child_type, true)) {9206 if (!child_type_matches || !type_is_self_comparable(child_type, true)) {
9207 ErrorMsg *msg = ir_add_error_node(ira, source_instr->source_node, buf_sprintf("cannot compare types '%s' and '%s'",9207 ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("cannot compare types '%s' and '%s'",
9208 buf_ptr(&op1->value->type->name),9208 buf_ptr(&op1->value->type->name),
9209 buf_ptr(&op2->value->type->name)));9209 buf_ptr(&op2->value->type->name)));
92109210
9211 if (!child_type_matches) {9211 if (!child_type_matches) {
9212 if (non_optional->value->type->id == ZigTypeIdOptional) {9212 if (non_optional->value->type->id == ZigTypeIdOptional) {
9213 add_error_note(ira->codegen, msg, source_instr->source_node, buf_sprintf(9213 add_error_note(ira->codegen, msg, source_node, buf_sprintf(
9214 "optional to optional comparison is only supported for optional pointer types"));9214 "optional to optional comparison is only supported for optional pointer types"));
9215 } else {9215 } else {
9216 add_error_note(ira->codegen, msg, source_instr->source_node,9216 add_error_note(ira->codegen, msg, source_node,
9217 buf_sprintf("optional child type '%s' must be the same as non-optional type '%s'",9217 buf_sprintf("optional child type '%s' must be the same as non-optional type '%s'",
9218 buf_ptr(&child_type->name),9218 buf_ptr(&child_type->name),
9219 buf_ptr(&non_optional->value->type->name)));9219 buf_ptr(&non_optional->value->type->name)));
9220 }9220 }
9221 } else {9221 } else {
9222 add_error_note(ira->codegen, msg, source_instr->source_node,9222 add_error_note(ira->codegen, msg, source_node,
9223 buf_sprintf("operator not supported for type '%s'",9223 buf_sprintf("operator not supported for type '%s'",
9224 buf_ptr(&child_type->name)));9224 buf_ptr(&child_type->name)));
9225 }9225 }
...@@ -9227,17 +9227,17 @@ static IrInstGen *ir_analyze_cmp_optional_non_optional(IrAnalyze *ira, IrInst *s...@@ -9227,17 +9227,17 @@ static IrInstGen *ir_analyze_cmp_optional_non_optional(IrAnalyze *ira, IrInst *s
9227 }9227 }
92289228
9229 if (child_type->id == ZigTypeIdVector) {9229 if (child_type->id == ZigTypeIdVector) {
9230 ir_add_error_node(ira, source_instr->source_node, buf_sprintf("TODO add comparison of optional vector"));9230 ir_add_error_node(ira, source_node, buf_sprintf("TODO add comparison of optional vector"));
9231 return ira->codegen->invalid_inst_gen;9231 return ira->codegen->invalid_inst_gen;
9232 }9232 }
92339233
9234 if (IrInstGen *const_result = ir_try_evaluate_cmp_optional_non_optional_const(ira, source_instr, child_type,9234 if (IrInstGen *const_result = ir_try_evaluate_cmp_optional_non_optional_const(ira, scope, source_node, child_type,
9235 optional, non_optional, op_id))9235 optional, non_optional, op_id))
9236 {9236 {
9237 return const_result;9237 return const_result;
9238 }9238 }
92399239
9240 return ir_evaluate_cmp_optional_non_optional(ira, source_instr, child_type, optional, non_optional, op_id);9240 return ir_evaluate_cmp_optional_non_optional(ira, scope, source_node, child_type, optional, non_optional, op_id);
9241}9241}
92429242
9243static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {9243static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {
...@@ -9249,12 +9249,13 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i...@@ -9249,12 +9249,13 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
9249 if (type_is_invalid(op2->value->type))9249 if (type_is_invalid(op2->value->type))
9250 return ira->codegen->invalid_inst_gen;9250 return ira->codegen->invalid_inst_gen;
92519251
9252 AstNode *source_node = bin_op_instruction->base.base.source_node;9252 AstNode *source_node = bin_op_instruction->base.source_node;
92539253
9254 IrBinOp op_id = bin_op_instruction->op_id;9254 IrBinOp op_id = bin_op_instruction->op_id;
9255 bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);9255 bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);
9256 if (is_equality_cmp && op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdNull) {9256 if (is_equality_cmp && op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdNull) {
9257 return ir_const_bool(ira, &bin_op_instruction->base.base, (op_id == IrBinOpCmpEq));9257 return ir_const_bool(ira, bin_op_instruction->base.scope,
9258 bin_op_instruction->base.source_node, (op_id == IrBinOpCmpEq));
9258 } else if (is_equality_cmp &&9259 } else if (is_equality_cmp &&
9259 ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdOptional) ||9260 ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdOptional) ||
9260 (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdOptional)))9261 (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdOptional)))
...@@ -9273,13 +9274,16 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i...@@ -9273,13 +9274,16 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
9273 return ira->codegen->invalid_inst_gen;9274 return ira->codegen->invalid_inst_gen;
9274 bool is_null = optional_value_is_null(maybe_val);9275 bool is_null = optional_value_is_null(maybe_val);
9275 bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null;9276 bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null;
9276 return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result);9277 return ir_const_bool(ira, bin_op_instruction->base.scope,
9278 bin_op_instruction->base.source_node, bool_result);
9277 }9279 }
92789280
9279 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, &bin_op_instruction->base.base, maybe_op);9281 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, bin_op_instruction->base.scope,
9282 bin_op_instruction->base.source_node, maybe_op);
92809283
9281 if (op_id == IrBinOpCmpEq) {9284 if (op_id == IrBinOpCmpEq) {
9282 return ir_build_bool_not_gen(ira, &bin_op_instruction->base.base, is_non_null);9285 return ir_build_bool_not_gen(ira, bin_op_instruction->base.scope,
9286 bin_op_instruction->base.source_node, is_non_null);
9283 } else {9287 } else {
9284 return is_non_null;9288 return is_non_null;
9285 }9289 }
...@@ -9302,28 +9306,28 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i...@@ -9302,28 +9306,28 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
9302 if (!c_ptr_val)9306 if (!c_ptr_val)
9303 return ira->codegen->invalid_inst_gen;9307 return ira->codegen->invalid_inst_gen;
9304 if (c_ptr_val->special == ConstValSpecialUndef)9308 if (c_ptr_val->special == ConstValSpecialUndef)
9305 return ir_const_undef(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool);9309 return ir_const_undef(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, ira->codegen->builtin_types.entry_bool);
9306 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||9310 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||
9307 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&9311 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
9308 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);9312 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);
9309 bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null;9313 bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null;
9310 return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result);9314 return ir_const_bool(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, bool_result);
9311 }9315 }
9312 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, &bin_op_instruction->base.base, c_ptr_op);9316 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, c_ptr_op);
93139317
9314 if (op_id == IrBinOpCmpEq) {9318 if (op_id == IrBinOpCmpEq) {
9315 return ir_build_bool_not_gen(ira, &bin_op_instruction->base.base, is_non_null);9319 return ir_build_bool_not_gen(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, is_non_null);
9316 } else {9320 } else {
9317 return is_non_null;9321 return is_non_null;
9318 }9322 }
9319 } else if (is_equality_cmp &&9323 } else if (is_equality_cmp &&
9320 (op1->value->type->id == ZigTypeIdOptional && get_src_ptr_type(op1->value->type) == nullptr))9324 (op1->value->type->id == ZigTypeIdOptional && get_src_ptr_type(op1->value->type) == nullptr))
9321 {9325 {
9322 return ir_analyze_cmp_optional_non_optional(ira, &bin_op_instruction->base.base, op1, op2, op1, op_id);9326 return ir_analyze_cmp_optional_non_optional(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op1, op2, op1, op_id);
9323 } else if(is_equality_cmp &&9327 } else if(is_equality_cmp &&
9324 (op2->value->type->id == ZigTypeIdOptional && get_src_ptr_type(op2->value->type) == nullptr))9328 (op2->value->type->id == ZigTypeIdOptional && get_src_ptr_type(op2->value->type) == nullptr))
9325 {9329 {
9326 return ir_analyze_cmp_optional_non_optional(ira, &bin_op_instruction->base.base, op1, op2, op2, op_id);9330 return ir_analyze_cmp_optional_non_optional(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op1, op2, op2, op_id);
9327 } else if (op1->value->type->id == ZigTypeIdNull || op2->value->type->id == ZigTypeIdNull) {9331 } else if (op1->value->type->id == ZigTypeIdNull || op2->value->type->id == ZigTypeIdNull) {
9328 ZigType *non_null_type = (op1->value->type->id == ZigTypeIdNull) ? op2->value->type : op1->value->type;9332 ZigType *non_null_type = (op1->value->type->id == ZigTypeIdNull) ? op2->value->type : op1->value->type;
9329 ir_add_error_node(ira, source_node, buf_sprintf("comparison of '%s' with null",9333 ir_add_error_node(ira, source_node, buf_sprintf("comparison of '%s' with null",
...@@ -9369,10 +9373,10 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i...@@ -9369,10 +9373,10 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
9369 Cmp cmp_result = bigint_cmp(&const_union_val->data.x_union.tag, &const_enum_val->data.x_enum_tag);9373 Cmp cmp_result = bigint_cmp(&const_union_val->data.x_union.tag, &const_enum_val->data.x_enum_tag);
9370 bool bool_result = (op_id == IrBinOpCmpEq) ? cmp_result == CmpEQ : cmp_result != CmpEQ;9374 bool bool_result = (op_id == IrBinOpCmpEq) ? cmp_result == CmpEQ : cmp_result != CmpEQ;
93719375
9372 return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result);9376 return ir_const_bool(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, bool_result);
9373 }9377 }
93749378
9375 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool,9379 return ir_build_bin_op_gen(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, ira->codegen->builtin_types.entry_bool,
9376 op_id, casted_union, casted_val, bin_op_instruction->safety_check_on);9380 op_id, casted_union, casted_val, bin_op_instruction->safety_check_on);
9377 }9381 }
93789382
...@@ -9404,7 +9408,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i...@@ -9404,7 +9408,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
9404 } else {9408 } else {
9405 zig_unreachable();9409 zig_unreachable();
9406 }9410 }
9407 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);9411 return ir_const_bool(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, answer);
9408 }9412 }
94099413
9410 if (!type_is_global_error_set(intersect_type)) {9414 if (!type_is_global_error_set(intersect_type)) {
...@@ -9424,7 +9428,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i...@@ -9424,7 +9428,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
9424 } else {9428 } else {
9425 zig_unreachable();9429 zig_unreachable();
9426 }9430 }
9427 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);9431 return ir_const_bool(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, answer);
9428 }9432 }
9429 }9433 }
94309434
...@@ -9446,10 +9450,10 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i...@@ -9446,10 +9450,10 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
9446 zig_unreachable();9450 zig_unreachable();
9447 }9451 }
94489452
9449 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);9453 return ir_const_bool(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, answer);
9450 }9454 }
94519455
9452 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool,9456 return ir_build_bin_op_gen(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, ira->codegen->builtin_types.entry_bool,
9453 op_id, op1, op2, bin_op_instruction->safety_check_on);9457 op_id, op1, op2, bin_op_instruction->safety_check_on);
9454 }9458 }
94559459
...@@ -9457,7 +9461,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i...@@ -9457,7 +9461,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
9457 // This operation allows any combination of integer and float types, regardless of the9461 // This operation allows any combination of integer and float types, regardless of the
9458 // signed-ness, comptime-ness, and bit-width. So peer type resolution is incorrect for9462 // signed-ness, comptime-ness, and bit-width. So peer type resolution is incorrect for
9459 // numeric types.9463 // numeric types.
9460 return ir_analyze_bin_op_cmp_numeric(ira, &bin_op_instruction->base.base, op1, op2, op_id);9464 return ir_analyze_bin_op_cmp_numeric(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op1, op2, op_id);
9461 }9465 }
94629466
9463 IrInstGen *instructions[] = {op1, op2};9467 IrInstGen *instructions[] = {op1, op2};
...@@ -9481,7 +9485,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i...@@ -9481,7 +9485,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
9481 if (type_is_invalid(casted_op2->value->type))9485 if (type_is_invalid(casted_op2->value->type))
9482 return ira->codegen->invalid_inst_gen;9486 return ira->codegen->invalid_inst_gen;
94839487
9484 IrInstGen *resolve_const_result = ir_try_evaluate_bin_op_cmp_const(ira, &bin_op_instruction->base.base, casted_op1,9488 IrInstGen *resolve_const_result = ir_try_evaluate_bin_op_cmp_const(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, casted_op1,
9485 casted_op2, resolved_type, op_id);9489 casted_op2, resolved_type, op_id);
9486 if (resolve_const_result != nullptr) {9490 if (resolve_const_result != nullptr) {
9487 return resolve_const_result;9491 return resolve_const_result;
...@@ -9490,11 +9494,11 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i...@@ -9490,11 +9494,11 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
9490 ZigType *res_type = (resolved_type->id == ZigTypeIdVector) ?9494 ZigType *res_type = (resolved_type->id == ZigTypeIdVector) ?
9491 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool) :9495 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool) :
9492 ira->codegen->builtin_types.entry_bool;9496 ira->codegen->builtin_types.entry_bool;
9493 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, res_type,9497 return ir_build_bin_op_gen(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, res_type,
9494 op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);9498 op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);
9495}9499}
94969500
9497static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, ZigType *type_entry,9501static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *type_entry,
9498 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)9502 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)
9499{9503{
9500 bool is_int;9504 bool is_int;
...@@ -9517,10 +9521,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi...@@ -9517,10 +9521,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi
9517 if ((op_id == IrBinOpDivUnspecified || op_id == IrBinOpRemRem || op_id == IrBinOpRemMod ||9521 if ((op_id == IrBinOpDivUnspecified || op_id == IrBinOpRemRem || op_id == IrBinOpRemMod ||
9518 op_id == IrBinOpDivTrunc || op_id == IrBinOpDivFloor) && op2_zcmp == CmpEQ)9522 op_id == IrBinOpDivTrunc || op_id == IrBinOpDivFloor) && op2_zcmp == CmpEQ)
9519 {9523 {
9520 return ir_add_error(ira, source_instr, buf_sprintf("division by zero"));9524 return ir_add_error_node(ira, source_node, buf_sprintf("division by zero"));
9521 }9525 }
9522 if ((op_id == IrBinOpRemRem || op_id == IrBinOpRemMod) && op2_zcmp == CmpLT) {9526 if ((op_id == IrBinOpRemRem || op_id == IrBinOpRemMod) && op2_zcmp == CmpLT) {
9523 return ir_add_error(ira, source_instr, buf_sprintf("negative denominator"));9527 return ir_add_error_node(ira, source_node, buf_sprintf("negative denominator"));
9524 }9528 }
95259529
9526 switch (op_id) {9530 switch (op_id) {
...@@ -9565,7 +9569,7 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi...@@ -9565,7 +9569,7 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi
9565 BigInt orig_bigint;9569 BigInt orig_bigint;
9566 bigint_shl(&orig_bigint, &out_val->data.x_bigint, &op2_val->data.x_bigint);9570 bigint_shl(&orig_bigint, &out_val->data.x_bigint, &op2_val->data.x_bigint);
9567 if (bigint_cmp(&op1_val->data.x_bigint, &orig_bigint) != CmpEQ) {9571 if (bigint_cmp(&op1_val->data.x_bigint, &orig_bigint) != CmpEQ) {
9568 return ir_add_error(ira, source_instr, buf_sprintf("exact shift shifted out 1 bits"));9572 return ir_add_error_node(ira, source_node, buf_sprintf("exact shift shifted out 1 bits"));
9569 }9573 }
9570 break;9574 break;
9571 }9575 }
...@@ -9633,14 +9637,14 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi...@@ -9633,14 +9637,14 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi
9633 BigInt remainder;9637 BigInt remainder;
9634 bigint_rem(&remainder, &op1_val->data.x_bigint, &op2_val->data.x_bigint);9638 bigint_rem(&remainder, &op1_val->data.x_bigint, &op2_val->data.x_bigint);
9635 if (bigint_cmp_zero(&remainder) != CmpEQ) {9639 if (bigint_cmp_zero(&remainder) != CmpEQ) {
9636 return ir_add_error(ira, source_instr, buf_sprintf("exact division had a remainder"));9640 return ir_add_error_node(ira, source_node, buf_sprintf("exact division had a remainder"));
9637 }9641 }
9638 } else {9642 } else {
9639 float_div_trunc(out_val, op1_val, op2_val);9643 float_div_trunc(out_val, op1_val, op2_val);
9640 ZigValue remainder = {};9644 ZigValue remainder = {};
9641 float_rem(&remainder, op1_val, op2_val);9645 float_rem(&remainder, op1_val, op2_val);
9642 if (float_cmp_zero(&remainder) != CmpEQ) {9646 if (float_cmp_zero(&remainder) != CmpEQ) {
9643 return ir_add_error(ira, source_instr, buf_sprintf("exact division had a remainder"));9647 return ir_add_error_node(ira, source_node, buf_sprintf("exact division had a remainder"));
9644 }9648 }
9645 }9649 }
9646 break;9650 break;
...@@ -9664,7 +9668,7 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi...@@ -9664,7 +9668,7 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi
9664 if (!bigint_fits_in_bits(&out_val->data.x_bigint, type_entry->data.integral.bit_count,9668 if (!bigint_fits_in_bits(&out_val->data.x_bigint, type_entry->data.integral.bit_count,
9665 type_entry->data.integral.is_signed))9669 type_entry->data.integral.is_signed))
9666 {9670 {
9667 return ir_add_error(ira, source_instr, buf_sprintf("operation caused overflow"));9671 return ir_add_error_node(ira, source_node, buf_sprintf("operation caused overflow"));
9668 }9672 }
9669 }9673 }
96709674
...@@ -9674,10 +9678,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi...@@ -9674,10 +9678,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi
9674}9678}
96759679
9676// This works on operands that have already been checked to be comptime known.9680// This works on operands that have already been checked to be comptime known.
9677static IrInstGen *ir_analyze_math_op(IrAnalyze *ira, IrInst* source_instr,9681static IrInstGen *ir_analyze_math_op(IrAnalyze *ira, Scope *scope, AstNode *source_node,
9678 ZigType *type_entry, ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val)9682 ZigType *type_entry, ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val)
9679{9683{
9680 IrInstGen *result_instruction = ir_const(ira, source_instr, type_entry);9684 IrInstGen *result_instruction = ir_const(ira, scope, source_node, type_entry);
9681 ZigValue *out_val = result_instruction->value;9685 ZigValue *out_val = result_instruction->value;
9682 if (type_entry->id == ZigTypeIdVector) {9686 if (type_entry->id == ZigTypeIdVector) {
9683 expand_undef_array(ira->codegen, op1_val);9687 expand_undef_array(ira->codegen, op1_val);
...@@ -9692,10 +9696,10 @@ static IrInstGen *ir_analyze_math_op(IrAnalyze *ira, IrInst* source_instr,...@@ -9692,10 +9696,10 @@ static IrInstGen *ir_analyze_math_op(IrAnalyze *ira, IrInst* source_instr,
9692 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];9696 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];
9693 assert(scalar_op1_val->type == scalar_type);9697 assert(scalar_op1_val->type == scalar_type);
9694 assert(scalar_out_val->type == scalar_type);9698 assert(scalar_out_val->type == scalar_type);
9695 ErrorMsg *msg = ir_eval_math_op_scalar(ira, source_instr, scalar_type,9699 ErrorMsg *msg = ir_eval_math_op_scalar(ira, scope, source_node, scalar_type,
9696 scalar_op1_val, op_id, scalar_op2_val, scalar_out_val);9700 scalar_op1_val, op_id, scalar_op2_val, scalar_out_val);
9697 if (msg != nullptr) {9701 if (msg != nullptr) {
9698 add_error_note(ira->codegen, msg, source_instr->source_node,9702 add_error_note(ira->codegen, msg, source_node,
9699 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));9703 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
9700 return ira->codegen->invalid_inst_gen;9704 return ira->codegen->invalid_inst_gen;
9701 }9705 }
...@@ -9703,7 +9707,7 @@ static IrInstGen *ir_analyze_math_op(IrAnalyze *ira, IrInst* source_instr,...@@ -9703,7 +9707,7 @@ static IrInstGen *ir_analyze_math_op(IrAnalyze *ira, IrInst* source_instr,
9703 out_val->type = type_entry;9707 out_val->type = type_entry;
9704 out_val->special = ConstValSpecialStatic;9708 out_val->special = ConstValSpecialStatic;
9705 } else {9709 } else {
9706 if (ir_eval_math_op_scalar(ira, source_instr, type_entry, op1_val, op_id, op2_val, out_val) != nullptr) {9710 if (ir_eval_math_op_scalar(ira, scope, source_node, type_entry, op1_val, op_id, op2_val, out_val) != nullptr) {
9707 return ira->codegen->invalid_inst_gen;9711 return ira->codegen->invalid_inst_gen;
9708 }9712 }
9709 }9713 }
...@@ -9723,14 +9727,14 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in...@@ -9723,14 +9727,14 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in
9723 ZigType *op2_type = op2->value->type;9727 ZigType *op2_type = op2->value->type;
97249728
9725 if (op1_type->id == ZigTypeIdVector && op2_type->id != ZigTypeIdVector) {9729 if (op1_type->id == ZigTypeIdVector && op2_type->id != ZigTypeIdVector) {
9726 ir_add_error(ira, &bin_op_instruction->op1->base,9730 ir_add_error_node(ira, bin_op_instruction->op1->source_node,
9727 buf_sprintf("bit shifting operation expected vector type, found '%s'",9731 buf_sprintf("bit shifting operation expected vector type, found '%s'",
9728 buf_ptr(&op2_type->name)));9732 buf_ptr(&op2_type->name)));
9729 return ira->codegen->invalid_inst_gen;9733 return ira->codegen->invalid_inst_gen;
9730 }9734 }
97319735
9732 if (op1_type->id != ZigTypeIdVector && op2_type->id == ZigTypeIdVector) {9736 if (op1_type->id != ZigTypeIdVector && op2_type->id == ZigTypeIdVector) {
9733 ir_add_error(ira, &bin_op_instruction->op1->base,9737 ir_add_error_node(ira, bin_op_instruction->op1->source_node,
9734 buf_sprintf("bit shifting operation expected vector type, found '%s'",9738 buf_sprintf("bit shifting operation expected vector type, found '%s'",
9735 buf_ptr(&op1_type->name)));9739 buf_ptr(&op1_type->name)));
9736 return ira->codegen->invalid_inst_gen;9740 return ira->codegen->invalid_inst_gen;
...@@ -9742,14 +9746,14 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in...@@ -9742,14 +9746,14 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in
9742 op2_type->data.vector.elem_type : op2_type;9746 op2_type->data.vector.elem_type : op2_type;
97439747
9744 if (op1_scalar_type->id != ZigTypeIdInt && op1_scalar_type->id != ZigTypeIdComptimeInt) {9748 if (op1_scalar_type->id != ZigTypeIdInt && op1_scalar_type->id != ZigTypeIdComptimeInt) {
9745 ir_add_error(ira, &bin_op_instruction->op1->base,9749 ir_add_error_node(ira, bin_op_instruction->op1->source_node,
9746 buf_sprintf("bit shifting operation expected integer type, found '%s'",9750 buf_sprintf("bit shifting operation expected integer type, found '%s'",
9747 buf_ptr(&op1_scalar_type->name)));9751 buf_ptr(&op1_scalar_type->name)));
9748 return ira->codegen->invalid_inst_gen;9752 return ira->codegen->invalid_inst_gen;
9749 }9753 }
97509754
9751 if (op2_scalar_type->id != ZigTypeIdInt && op2_scalar_type->id != ZigTypeIdComptimeInt) {9755 if (op2_scalar_type->id != ZigTypeIdInt && op2_scalar_type->id != ZigTypeIdComptimeInt) {
9752 ir_add_error(ira, &bin_op_instruction->op2->base,9756 ir_add_error_node(ira, bin_op_instruction->op2->source_node,
9753 buf_sprintf("shift amount has to be an integer type, but found '%s'",9757 buf_sprintf("shift amount has to be an integer type, but found '%s'",
9754 buf_ptr(&op2_scalar_type->name)));9758 buf_ptr(&op2_scalar_type->name)));
9755 return ira->codegen->invalid_inst_gen;9759 return ira->codegen->invalid_inst_gen;
...@@ -9766,7 +9770,7 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in...@@ -9766,7 +9770,7 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in
9766 }9770 }
97679771
9768 if (!instr_is_comptime(op2)) {9772 if (!instr_is_comptime(op2)) {
9769 ir_add_error(ira, &bin_op_instruction->base.base,9773 ir_add_error_node(ira, bin_op_instruction->base.source_node,
9770 buf_sprintf("LHS of shift must be a fixed-width integer type, or RHS must be compile-time known"));9774 buf_sprintf("LHS of shift must be a fixed-width integer type, or RHS must be compile-time known"));
9771 return ira->codegen->invalid_inst_gen;9775 return ira->codegen->invalid_inst_gen;
9772 }9776 }
...@@ -9778,7 +9782,7 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in...@@ -9778,7 +9782,7 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in
9778 if (op2_val->data.x_bigint.is_negative) {9782 if (op2_val->data.x_bigint.is_negative) {
9779 Buf *val_buf = buf_alloc();9783 Buf *val_buf = buf_alloc();
9780 bigint_append_buf(val_buf, &op2_val->data.x_bigint, 10);9784 bigint_append_buf(val_buf, &op2_val->data.x_bigint, 10);
9781 ir_add_error(ira, &casted_op2->base,9785 ir_add_error(ira, casted_op2,
9782 buf_sprintf("shift by negative value %s", buf_ptr(val_buf)));9786 buf_sprintf("shift by negative value %s", buf_ptr(val_buf)));
9783 return ira->codegen->invalid_inst_gen;9787 return ira->codegen->invalid_inst_gen;
9784 }9788 }
...@@ -9806,10 +9810,10 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in...@@ -9806,10 +9810,10 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in
9806 init_const_usize(ira->codegen, &bit_count_value, bit_count);9810 init_const_usize(ira->codegen, &bit_count_value, bit_count);
98079811
9808 if (!value_cmp_numeric_val_all(op2_val, CmpLT, &bit_count_value)) {9812 if (!value_cmp_numeric_val_all(op2_val, CmpLT, &bit_count_value)) {
9809 ErrorMsg* msg = ir_add_error(ira,9813 ErrorMsg* msg = ir_add_error_node(ira,
9810 &bin_op_instruction->base.base,9814 bin_op_instruction->base.source_node,
9811 buf_sprintf("RHS of shift is too large for LHS type"));9815 buf_sprintf("RHS of shift is too large for LHS type"));
9812 add_error_note(ira->codegen, msg, op1->base.source_node,9816 add_error_note(ira->codegen, msg, op1->source_node,
9813 buf_sprintf("type %s has only %u bits",9817 buf_sprintf("type %s has only %u bits",
9814 buf_ptr(&op1->value->type->name), bit_count));9818 buf_ptr(&op1->value->type->name), bit_count));
98159819
...@@ -9825,7 +9829,7 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in...@@ -9825,7 +9829,7 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in
9825 return ira->codegen->invalid_inst_gen;9829 return ira->codegen->invalid_inst_gen;
98269830
9827 if (value_cmp_numeric_val_all(op2_val, CmpEQ, nullptr))9831 if (value_cmp_numeric_val_all(op2_val, CmpEQ, nullptr))
9828 return ir_analyze_cast(ira, &bin_op_instruction->base.base, op1->value->type, op1);9832 return ir_analyze_cast(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op1->value->type, op1);
9829 }9833 }
98309834
9831 if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) {9835 if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) {
...@@ -9837,10 +9841,10 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in...@@ -9837,10 +9841,10 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in
9837 if (op2_val == nullptr)9841 if (op2_val == nullptr)
9838 return ira->codegen->invalid_inst_gen;9842 return ira->codegen->invalid_inst_gen;
98399843
9840 return ir_analyze_math_op(ira, &bin_op_instruction->base.base, op1_type, op1_val, op_id, op2_val);9844 return ir_analyze_math_op(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op1_type, op1_val, op_id, op2_val);
9841 }9845 }
98429846
9843 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, op1->value->type,9847 return ir_build_bin_op_gen(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op1->value->type,
9844 op_id, op1, casted_op2, bin_op_instruction->safety_check_on);9848 op_id, op1, casted_op2, bin_op_instruction->safety_check_on);
9845}9849}
98469850
...@@ -10006,14 +10010,14 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc...@@ -10006,14 +10010,14 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
10006 if (op1_val == nullptr)10010 if (op1_val == nullptr)
10007 return ira->codegen->invalid_inst_gen;10011 return ira->codegen->invalid_inst_gen;
10008 if (op1_val->special == ConstValSpecialUndef)10012 if (op1_val->special == ConstValSpecialUndef)
10009 return ir_const_undef(ira, &instruction->base.base, op1->value->type);10013 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, op1->value->type);
10010 }10014 }
10011 if (instr_is_comptime(casted_op2)) {10015 if (instr_is_comptime(casted_op2)) {
10012 op2_val = ir_resolve_const(ira, casted_op2, UndefOk);10016 op2_val = ir_resolve_const(ira, casted_op2, UndefOk);
10013 if (op2_val == nullptr)10017 if (op2_val == nullptr)
10014 return ira->codegen->invalid_inst_gen;10018 return ira->codegen->invalid_inst_gen;
10015 if (op2_val->special == ConstValSpecialUndef)10019 if (op2_val->special == ConstValSpecialUndef)
10016 return ir_const_undef(ira, &instruction->base.base, op1->value->type);10020 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, op1->value->type);
10017 }10021 }
1001810022
10019 ZigType *elem_type = op1->value->type->data.pointer.child_type;10023 ZigType *elem_type = op1->value->type->data.pointer.child_type;
...@@ -10069,18 +10073,18 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc...@@ -10069,18 +10073,18 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
10069 } else {10073 } else {
10070 zig_unreachable();10074 zig_unreachable();
10071 }10075 }
10072 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);10076 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, result_type);
10073 result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;10077 result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
10074 result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;10078 result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
10075 result->value->data.x_ptr.data.hard_coded_addr.addr = new_addr;10079 result->value->data.x_ptr.data.hard_coded_addr.addr = new_addr;
10076 return result;10080 return result;
10077 }10081 }
1007810082
10079 return ir_build_bin_op_gen(ira, &instruction->base.base, result_type, op_id, op1, casted_op2, true);10083 return ir_build_bin_op_gen(ira, instruction->base.scope, instruction->base.source_node, result_type, op_id, op1, casted_op2, true);
10080 }10084 }
1008110085
10082 IrInstGen *instructions[] = {op1, op2};10086 IrInstGen *instructions[] = {op1, op2};
10083 ZigType *resolved_type = ir_resolve_peer_types(ira, instruction->base.base.source_node, nullptr, instructions, 2);10087 ZigType *resolved_type = ir_resolve_peer_types(ira, instruction->base.source_node, nullptr, instructions, 2);
10084 if (type_is_invalid(resolved_type))10088 if (type_is_invalid(resolved_type))
10085 return ira->codegen->invalid_inst_gen;10089 return ira->codegen->invalid_inst_gen;
1008610090
...@@ -10091,7 +10095,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc...@@ -10091,7 +10095,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
10091 bool is_float = scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat;10095 bool is_float = scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat;
1009210096
10093 if (!is_int && !(is_float && ok_float_op(op_id))) {10097 if (!is_int && !(is_float && ok_float_op(op_id))) {
10094 AstNode *source_node = instruction->base.base.source_node;10098 AstNode *source_node = instruction->base.source_node;
10095 ir_add_error_node(ira, source_node,10099 ir_add_error_node(ira, source_node,
10096 buf_sprintf("invalid operands to binary expression: '%s' and '%s'",10100 buf_sprintf("invalid operands to binary expression: '%s' and '%s'",
10097 buf_ptr(&op1->value->type->name),10101 buf_ptr(&op1->value->type->name),
...@@ -10144,17 +10148,17 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc...@@ -10144,17 +10148,17 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
10144 // division function ambiguity problem.10148 // division function ambiguity problem.
10145 ok = true;10149 ok = true;
10146 } else {10150 } else {
10147 IrInstGen *trunc_val = ir_analyze_math_op(ira, &instruction->base.base, resolved_type,10151 IrInstGen *trunc_val = ir_analyze_math_op(ira, instruction->base.scope, instruction->base.source_node, resolved_type,
10148 op1_val, IrBinOpDivTrunc, op2_val);10152 op1_val, IrBinOpDivTrunc, op2_val);
10149 if (type_is_invalid(trunc_val->value->type))10153 if (type_is_invalid(trunc_val->value->type))
10150 return ira->codegen->invalid_inst_gen;10154 return ira->codegen->invalid_inst_gen;
1015110155
10152 IrInstGen *floor_val = ir_analyze_math_op(ira, &instruction->base.base, resolved_type,10156 IrInstGen *floor_val = ir_analyze_math_op(ira, instruction->base.scope, instruction->base.source_node, resolved_type,
10153 op1_val, IrBinOpDivFloor, op2_val);10157 op1_val, IrBinOpDivFloor, op2_val);
10154 if (type_is_invalid(floor_val->value->type))10158 if (type_is_invalid(floor_val->value->type))
10155 return ira->codegen->invalid_inst_gen;10159 return ira->codegen->invalid_inst_gen;
1015610160
10157 IrInstGen *cmp_val = ir_analyze_bin_op_cmp_numeric(ira, &instruction->base.base,10161 IrInstGen *cmp_val = ir_analyze_bin_op_cmp_numeric(ira, instruction->base.scope, instruction->base.source_node,
10158 trunc_val, floor_val, IrBinOpCmpEq);10162 trunc_val, floor_val, IrBinOpCmpEq);
10159 if (type_is_invalid(cmp_val->value->type))10163 if (type_is_invalid(cmp_val->value->type))
10160 return ira->codegen->invalid_inst_gen;10164 return ira->codegen->invalid_inst_gen;
...@@ -10165,7 +10169,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc...@@ -10165,7 +10169,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
10165 }10169 }
1016610170
10167 if (!ok) {10171 if (!ok) {
10168 ir_add_error(ira, &instruction->base.base,10172 ir_add_error_node(ira, instruction->base.source_node,
10169 buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact",10173 buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact",
10170 buf_ptr(&op1->value->type->name),10174 buf_ptr(&op1->value->type->name),
10171 buf_ptr(&op2->value->type->name)));10175 buf_ptr(&op2->value->type->name)));
...@@ -10183,17 +10187,17 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc...@@ -10183,17 +10187,17 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
10183 // division function ambiguity problem.10187 // division function ambiguity problem.
10184 ok = true;10188 ok = true;
10185 } else {10189 } else {
10186 IrInstGen *rem_val = ir_analyze_math_op(ira, &instruction->base.base, resolved_type,10190 IrInstGen *rem_val = ir_analyze_math_op(ira, instruction->base.scope, instruction->base.source_node, resolved_type,
10187 op1_val, IrBinOpRemRem, op2_val);10191 op1_val, IrBinOpRemRem, op2_val);
10188 if (type_is_invalid(rem_val->value->type))10192 if (type_is_invalid(rem_val->value->type))
10189 return ira->codegen->invalid_inst_gen;10193 return ira->codegen->invalid_inst_gen;
1019010194
10191 IrInstGen *mod_val = ir_analyze_math_op(ira, &instruction->base.base, resolved_type,10195 IrInstGen *mod_val = ir_analyze_math_op(ira, instruction->base.scope, instruction->base.source_node, resolved_type,
10192 op1_val, IrBinOpRemMod, op2_val);10196 op1_val, IrBinOpRemMod, op2_val);
10193 if (type_is_invalid(mod_val->value->type))10197 if (type_is_invalid(mod_val->value->type))
10194 return ira->codegen->invalid_inst_gen;10198 return ira->codegen->invalid_inst_gen;
1019510199
10196 IrInstGen *cmp_val = ir_analyze_bin_op_cmp_numeric(ira, &instruction->base.base,10200 IrInstGen *cmp_val = ir_analyze_bin_op_cmp_numeric(ira, instruction->base.scope, instruction->base.source_node,
10197 rem_val, mod_val, IrBinOpCmpEq);10201 rem_val, mod_val, IrBinOpCmpEq);
10198 if (type_is_invalid(cmp_val->value->type))10202 if (type_is_invalid(cmp_val->value->type))
10199 return ira->codegen->invalid_inst_gen;10203 return ira->codegen->invalid_inst_gen;
...@@ -10204,7 +10208,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc...@@ -10204,7 +10208,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
10204 }10208 }
1020510209
10206 if (!ok) {10210 if (!ok) {
10207 ir_add_error(ira, &instruction->base.base,10211 ir_add_error_node(ira, instruction->base.source_node,
10208 buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod",10212 buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod",
10209 buf_ptr(&op1->value->type->name),10213 buf_ptr(&op1->value->type->name),
10210 buf_ptr(&op2->value->type->name)));10214 buf_ptr(&op2->value->type->name)));
...@@ -10213,7 +10217,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc...@@ -10213,7 +10217,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
10213 }10217 }
10214 }10218 }
1021510219
10216 return ir_analyze_math_op(ira, &instruction->base.base, resolved_type, op1_val, op_id, op2_val);10220 return ir_analyze_math_op(ira, instruction->base.scope, instruction->base.source_node, resolved_type, op1_val, op_id, op2_val);
10217 }10221 }
1021810222
10219 const bool is_signed_div =10223 const bool is_signed_div =
...@@ -10225,7 +10229,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc...@@ -10225,7 +10229,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
10225 op_id = IrBinOpDivTrunc;10229 op_id = IrBinOpDivTrunc;
1022610230
10227 if (is_signed_div) {10231 if (is_signed_div) {
10228 ir_add_error(ira, &instruction->base.base,10232 ir_add_error_node(ira, instruction->base.source_node,
10229 buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact",10233 buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact",
10230 buf_ptr(&op1->value->type->name),10234 buf_ptr(&op1->value->type->name),
10231 buf_ptr(&op2->value->type->name)));10235 buf_ptr(&op2->value->type->name)));
...@@ -10235,7 +10239,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc...@@ -10235,7 +10239,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
10235 op_id = IrBinOpRemRem;10239 op_id = IrBinOpRemRem;
1023610240
10237 if (is_signed_div) {10241 if (is_signed_div) {
10238 ir_add_error(ira, &instruction->base.base,10242 ir_add_error_node(ira, instruction->base.source_node,
10239 buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod",10243 buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod",
10240 buf_ptr(&op1->value->type->name),10244 buf_ptr(&op1->value->type->name),
10241 buf_ptr(&op2->value->type->name)));10245 buf_ptr(&op2->value->type->name)));
...@@ -10243,11 +10247,11 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc...@@ -10243,11 +10247,11 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc
10243 }10247 }
10244 }10248 }
1024510249
10246 return ir_build_bin_op_gen(ira, &instruction->base.base, resolved_type,10250 return ir_build_bin_op_gen(ira, instruction->base.scope, instruction->base.source_node, resolved_type,
10247 op_id, casted_op1, casted_op2, instruction->safety_check_on);10251 op_id, casted_op1, casted_op2, instruction->safety_check_on);
10248}10252}
1024910253
10250static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr,10254static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, Scope *scope, AstNode *source_node,
10251 IrInstGen *op1, IrInstGen *op2)10255 IrInstGen *op1, IrInstGen *op2)
10252{10256{
10253 Error err;10257 Error err;
...@@ -10259,9 +10263,9 @@ static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr,...@@ -10259,9 +10263,9 @@ static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr,
1025910263
10260 Buf *bare_name = buf_alloc();10264 Buf *bare_name = buf_alloc();
10261 Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct),10265 Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct),
10262 source_instr->scope, source_instr->source_node, bare_name);10266 scope, source_node, bare_name);
10263 ZigType *new_type = get_partial_container_type(ira->codegen, source_instr->scope,10267 ZigType *new_type = get_partial_container_type(ira->codegen, scope,
10264 ContainerKindStruct, source_instr->source_node, buf_ptr(name), bare_name, ContainerLayoutAuto);10268 ContainerKindStruct, source_node, buf_ptr(name), bare_name, ContainerLayoutAuto);
10265 new_type->data.structure.special = StructSpecialInferredTuple;10269 new_type->data.structure.special = StructSpecialInferredTuple;
10266 new_type->data.structure.resolve_status = ResolveStatusBeingInferred;10270 new_type->data.structure.resolve_status = ResolveStatusBeingInferred;
10267 uint32_t new_field_count = op1_field_count + op2_field_count;10271 uint32_t new_field_count = op1_field_count + op2_field_count;
...@@ -10270,7 +10274,7 @@ static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr,...@@ -10270,7 +10274,7 @@ static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr,
10270 new_type->data.structure.fields = realloc_type_struct_fields(new_type->data.structure.fields,10274 new_type->data.structure.fields = realloc_type_struct_fields(new_type->data.structure.fields,
10271 0, new_field_count);10275 0, new_field_count);
1027210276
10273 IrInstGen *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(),10277 IrInstGen *new_struct_ptr = ir_resolve_result(ira, ira->suspend_source_instr, no_result_loc(),
10274 new_type, nullptr, false, true);10278 new_type, nullptr, false, true);
1027510279
10276 for (uint32_t i = 0; i < new_field_count; i += 1) {10280 for (uint32_t i = 0; i < new_field_count; i += 1) {
...@@ -10304,18 +10308,18 @@ static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr,...@@ -10304,18 +10308,18 @@ static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr,
10304 src_field = op2_type->data.structure.fields[i - op1_field_count];10308 src_field = op2_type->data.structure.fields[i - op1_field_count];
10305 src_struct_op = op2;10309 src_struct_op = op2;
10306 }10310 }
10307 IrInstGen *field_value = ir_analyze_struct_value_field_value(ira, source_instr,10311 IrInstGen *field_value = ir_analyze_struct_value_field_value(ira, scope, source_node,
10308 src_struct_op, src_field);10312 src_struct_op, src_field);
10309 if (type_is_invalid(field_value->value->type))10313 if (type_is_invalid(field_value->value->type))
10310 return ira->codegen->invalid_inst_gen;10314 return ira->codegen->invalid_inst_gen;
10311 IrInstGen *dest_ptr = ir_analyze_struct_field_ptr(ira, source_instr, dst_field,10315 IrInstGen *dest_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, dst_field,
10312 new_struct_ptr, new_type, true);10316 new_struct_ptr, new_type, true);
10313 if (type_is_invalid(dest_ptr->value->type))10317 if (type_is_invalid(dest_ptr->value->type))
10314 return ira->codegen->invalid_inst_gen;10318 return ira->codegen->invalid_inst_gen;
10315 if (instr_is_comptime(field_value)) {10319 if (instr_is_comptime(field_value)) {
10316 const_ptrs.append(dest_ptr);10320 const_ptrs.append(dest_ptr);
10317 }10321 }
10318 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, dest_ptr, field_value,10322 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, scope, source_node, dest_ptr, field_value,
10319 true);10323 true);
10320 if (type_is_invalid(store_ptr_inst->value->type))10324 if (type_is_invalid(store_ptr_inst->value->type))
10321 return ira->codegen->invalid_inst_gen;10325 return ira->codegen->invalid_inst_gen;
...@@ -10329,17 +10333,18 @@ static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr,...@@ -10329,17 +10333,18 @@ static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr,
10329 // This field will be generated comptime; no need to do this.10333 // This field will be generated comptime; no need to do this.
10330 continue;10334 continue;
10331 }10335 }
10332 IrInstGen *deref = ir_get_deref(ira, &elem_result_loc->base, elem_result_loc, nullptr);10336 IrInstGen *deref = ir_get_deref(ira, elem_result_loc->scope,
10337 elem_result_loc->source_node, elem_result_loc, nullptr);
10333 if (!type_requires_comptime(ira->codegen, elem_result_loc->value->type->data.pointer.child_type)) {10338 if (!type_requires_comptime(ira->codegen, elem_result_loc->value->type->data.pointer.child_type)) {
10334 elem_result_loc->value->special = ConstValSpecialRuntime;10339 elem_result_loc->value->special = ConstValSpecialRuntime;
10335 }10340 }
10336 ir_analyze_store_ptr(ira, &elem_result_loc->base, elem_result_loc, deref, true);10341 ir_analyze_store_ptr(ira, elem_result_loc->scope, elem_result_loc->source_node, elem_result_loc, deref, true);
10337 }10342 }
10338 }10343 }
1033910344
10340 const_ptrs.deinit();10345 const_ptrs.deinit();
1034110346
10342 return ir_get_deref(ira, source_instr, new_struct_ptr, nullptr);10347 return ir_get_deref(ira, scope, source_node, new_struct_ptr, nullptr);
10343}10348}
1034410349
10345static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instruction) {10350static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instruction) {
...@@ -10354,7 +10359,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi...@@ -10354,7 +10359,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
10354 return ira->codegen->invalid_inst_gen;10359 return ira->codegen->invalid_inst_gen;
1035510360
10356 if (is_tuple(op1_type) && is_tuple(op2_type)) {10361 if (is_tuple(op1_type) && is_tuple(op2_type)) {
10357 return ir_analyze_tuple_cat(ira, &instruction->base.base, op1, op2);10362 return ir_analyze_tuple_cat(ira, instruction->base.scope, instruction->base.source_node, op1, op2);
10358 }10363 }
1035910364
10360 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);10365 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
...@@ -10402,14 +10407,14 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi...@@ -10402,14 +10407,14 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
10402 {10407 {
10403 ZigType *array_type = op1_type->data.pointer.child_type;10408 ZigType *array_type = op1_type->data.pointer.child_type;
10404 child_type = array_type->data.array.child_type;10409 child_type = array_type->data.array.child_type;
10405 op1_array_val = const_ptr_pointee(ira, ira->codegen, op1_val, op1->base.source_node);10410 op1_array_val = const_ptr_pointee(ira, ira->codegen, op1_val, op1->source_node);
10406 if (op1_array_val == nullptr)10411 if (op1_array_val == nullptr)
10407 return ira->codegen->invalid_inst_gen;10412 return ira->codegen->invalid_inst_gen;
10408 op1_array_index = 0;10413 op1_array_index = 0;
10409 op1_array_end = array_type->data.array.len;10414 op1_array_end = array_type->data.array.len;
10410 sentinel1 = array_type->data.array.sentinel;10415 sentinel1 = array_type->data.array.sentinel;
10411 } else {10416 } else {
10412 ir_add_error(ira, &op1->base, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name)));10417 ir_add_error(ira, op1, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name)));
10413 return ira->codegen->invalid_inst_gen;10418 return ira->codegen->invalid_inst_gen;
10414 }10419 }
1041510420
...@@ -10450,7 +10455,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi...@@ -10450,7 +10455,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
10450 {10455 {
10451 ZigType *array_type = op2_type->data.pointer.child_type;10456 ZigType *array_type = op2_type->data.pointer.child_type;
10452 op2_type_valid = array_type->data.array.child_type == child_type;10457 op2_type_valid = array_type->data.array.child_type == child_type;
10453 op2_array_val = const_ptr_pointee(ira, ira->codegen, op2_val, op2->base.source_node);10458 op2_array_val = const_ptr_pointee(ira, ira->codegen, op2_val, op2->source_node);
10454 if (op2_array_val == nullptr)10459 if (op2_array_val == nullptr)
10455 return ira->codegen->invalid_inst_gen;10460 return ira->codegen->invalid_inst_gen;
10456 op2_array_index = 0;10461 op2_array_index = 0;
...@@ -10458,12 +10463,12 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi...@@ -10458,12 +10463,12 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
1045810463
10459 sentinel2 = array_type->data.array.sentinel;10464 sentinel2 = array_type->data.array.sentinel;
10460 } else {10465 } else {
10461 ir_add_error(ira, &op2->base,10466 ir_add_error(ira, op2,
10462 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value->type->name)));10467 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value->type->name)));
10463 return ira->codegen->invalid_inst_gen;10468 return ira->codegen->invalid_inst_gen;
10464 }10469 }
10465 if (!op2_type_valid) {10470 if (!op2_type_valid) {
10466 ir_add_error(ira, &op2->base, buf_sprintf("expected array of type '%s', found '%s'",10471 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
10467 buf_ptr(&child_type->name),10472 buf_ptr(&child_type->name),
10468 buf_ptr(&op2->value->type->name)));10473 buf_ptr(&op2->value->type->name)));
10469 return ira->codegen->invalid_inst_gen;10474 return ira->codegen->invalid_inst_gen;
...@@ -10483,7 +10488,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi...@@ -10483,7 +10488,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
10483 }10488 }
1048410489
10485 // The type of result is populated in the following if blocks10490 // The type of result is populated in the following if blocks
10486 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);10491 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr);
10487 ZigValue *out_val = result->value;10492 ZigValue *out_val = result->value;
1048810493
10489 ZigValue *out_array_val;10494 ZigValue *out_array_val;
...@@ -10571,7 +10576,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi...@@ -10571,7 +10576,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
10571 return result;10576 return result;
10572}10577}
1057310578
10574static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr,10579static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, Scope *scope, AstNode *source_node,
10575 IrInstGen *op1, IrInstGen *op2)10580 IrInstGen *op1, IrInstGen *op2)
10576{10581{
10577 Error err;10582 Error err;
...@@ -10584,22 +10589,22 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr,...@@ -10584,22 +10589,22 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr,
1058410589
10585 uint64_t new_field_count;10590 uint64_t new_field_count;
10586 if (mul_u64_overflow(op1_field_count, mult_amt, &new_field_count)) {10591 if (mul_u64_overflow(op1_field_count, mult_amt, &new_field_count)) {
10587 ir_add_error(ira, source_instr, buf_sprintf("operation results in overflow"));10592 ir_add_error_node(ira, source_node, buf_sprintf("operation results in overflow"));
10588 return ira->codegen->invalid_inst_gen;10593 return ira->codegen->invalid_inst_gen;
10589 }10594 }
1059010595
10591 Buf *bare_name = buf_alloc();10596 Buf *bare_name = buf_alloc();
10592 Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct),10597 Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct),
10593 source_instr->scope, source_instr->source_node, bare_name);10598 scope, source_node, bare_name);
10594 ZigType *new_type = get_partial_container_type(ira->codegen, source_instr->scope,10599 ZigType *new_type = get_partial_container_type(ira->codegen, scope,
10595 ContainerKindStruct, source_instr->source_node, buf_ptr(name), bare_name, ContainerLayoutAuto);10600 ContainerKindStruct, source_node, buf_ptr(name), bare_name, ContainerLayoutAuto);
10596 new_type->data.structure.special = StructSpecialInferredTuple;10601 new_type->data.structure.special = StructSpecialInferredTuple;
10597 new_type->data.structure.resolve_status = ResolveStatusBeingInferred;10602 new_type->data.structure.resolve_status = ResolveStatusBeingInferred;
10598 new_type->data.structure.src_field_count = new_field_count;10603 new_type->data.structure.src_field_count = new_field_count;
10599 new_type->data.structure.fields = realloc_type_struct_fields(10604 new_type->data.structure.fields = realloc_type_struct_fields(
10600 new_type->data.structure.fields, 0, new_field_count);10605 new_type->data.structure.fields, 0, new_field_count);
1060110606
10602 IrInstGen *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(),10607 IrInstGen *new_struct_ptr = ir_resolve_result(ira, ira->suspend_source_instr, no_result_loc(),
10603 new_type, nullptr, false, true);10608 new_type, nullptr, false, true);
1060410609
10605 for (uint64_t i = 0; i < new_field_count; i += 1) {10610 for (uint64_t i = 0; i < new_field_count; i += 1) {
...@@ -10624,12 +10629,12 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr,...@@ -10624,12 +10629,12 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr,
10624 TypeStructField *dst_field = new_type->data.structure.fields[i];10629 TypeStructField *dst_field = new_type->data.structure.fields[i];
1062510630
10626 IrInstGen *field_value = ir_analyze_struct_value_field_value(10631 IrInstGen *field_value = ir_analyze_struct_value_field_value(
10627 ira, source_instr, op1, src_field);10632 ira, scope, source_node, op1, src_field);
10628 if (type_is_invalid(field_value->value->type))10633 if (type_is_invalid(field_value->value->type))
10629 return ira->codegen->invalid_inst_gen;10634 return ira->codegen->invalid_inst_gen;
1063010635
10631 IrInstGen *dest_ptr = ir_analyze_struct_field_ptr(10636 IrInstGen *dest_ptr = ir_analyze_struct_field_ptr(
10632 ira, source_instr, dst_field, new_struct_ptr, new_type, true);10637 ira, scope, source_node, dst_field, new_struct_ptr, new_type, true);
10633 if (type_is_invalid(dest_ptr->value->type))10638 if (type_is_invalid(dest_ptr->value->type))
10634 return ira->codegen->invalid_inst_gen;10639 return ira->codegen->invalid_inst_gen;
1063510640
...@@ -10638,7 +10643,7 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr,...@@ -10638,7 +10643,7 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr,
10638 }10643 }
1063910644
10640 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(10645 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(
10641 ira, source_instr, dest_ptr, field_value, true);10646 ira, scope, source_node, dest_ptr, field_value, true);
10642 if (type_is_invalid(store_ptr_inst->value->type))10647 if (type_is_invalid(store_ptr_inst->value->type))
10643 return ira->codegen->invalid_inst_gen;10648 return ira->codegen->invalid_inst_gen;
10644 }10649 }
...@@ -10652,12 +10657,13 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr,...@@ -10652,12 +10657,13 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr,
10652 // This field will be generated comptime; no need to do this.10657 // This field will be generated comptime; no need to do this.
10653 continue;10658 continue;
10654 }10659 }
10655 IrInstGen *deref = ir_get_deref(ira, &elem_result_loc->base, elem_result_loc, nullptr);10660 IrInstGen *deref = ir_get_deref(ira, elem_result_loc->scope,
10661 elem_result_loc->source_node, elem_result_loc, nullptr);
10656 if (!type_requires_comptime(ira->codegen, elem_result_loc->value->type->data.pointer.child_type)) {10662 if (!type_requires_comptime(ira->codegen, elem_result_loc->value->type->data.pointer.child_type)) {
10657 elem_result_loc->value->special = ConstValSpecialRuntime;10663 elem_result_loc->value->special = ConstValSpecialRuntime;
10658 }10664 }
10659 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(10665 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, elem_result_loc->scope,
10660 ira, &elem_result_loc->base, elem_result_loc, deref, true);10666 elem_result_loc->source_node, elem_result_loc, deref, true);
10661 if (type_is_invalid(store_ptr_inst->value->type))10667 if (type_is_invalid(store_ptr_inst->value->type))
10662 return ira->codegen->invalid_inst_gen;10668 return ira->codegen->invalid_inst_gen;
10663 }10669 }
...@@ -10665,7 +10671,7 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr,...@@ -10665,7 +10671,7 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr,
1066510671
10666 const_ptrs.deinit();10672 const_ptrs.deinit();
1066710673
10668 return ir_get_deref(ira, source_instr, new_struct_ptr, nullptr);10674 return ir_get_deref(ira, scope, source_node, new_struct_ptr, nullptr);
10669}10675}
1067010676
10671static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruction) {10677static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruction) {
...@@ -10690,7 +10696,7 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct...@@ -10690,7 +10696,7 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct
10690 op1->value->type->data.pointer.child_type->id == ZigTypeIdArray)10696 op1->value->type->data.pointer.child_type->id == ZigTypeIdArray)
10691 {10697 {
10692 array_type = op1->value->type->data.pointer.child_type;10698 array_type = op1->value->type->data.pointer.child_type;
10693 IrInstGen *array_inst = ir_get_deref(ira, &op1->base, op1, nullptr);10699 IrInstGen *array_inst = ir_get_deref(ira, op1->scope, op1->source_node, op1, nullptr);
10694 if (type_is_invalid(array_inst->value->type))10700 if (type_is_invalid(array_inst->value->type))
10695 return ira->codegen->invalid_inst_gen;10701 return ira->codegen->invalid_inst_gen;
10696 array_val = ir_resolve_const(ira, array_inst, UndefOk);10702 array_val = ir_resolve_const(ira, array_inst, UndefOk);
...@@ -10698,9 +10704,9 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct...@@ -10698,9 +10704,9 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct
10698 return ira->codegen->invalid_inst_gen;10704 return ira->codegen->invalid_inst_gen;
10699 want_ptr_to_array = true;10705 want_ptr_to_array = true;
10700 } else if (is_tuple(op1->value->type)) {10706 } else if (is_tuple(op1->value->type)) {
10701 return ir_analyze_tuple_mult(ira, &instruction->base.base, op1, op2);10707 return ir_analyze_tuple_mult(ira, instruction->base.scope, instruction->base.source_node, op1, op2);
10702 } else {10708 } else {
10703 ir_add_error(ira, &op1->base, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name)));10709 ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name)));
10704 return ira->codegen->invalid_inst_gen;10710 return ira->codegen->invalid_inst_gen;
10705 }10711 }
1070610712
...@@ -10712,7 +10718,7 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct...@@ -10712,7 +10718,7 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct
10712 uint64_t new_array_len;10718 uint64_t new_array_len;
1071310719
10714 if (mul_u64_overflow(old_array_len, mult_amt, &new_array_len)) {10720 if (mul_u64_overflow(old_array_len, mult_amt, &new_array_len)) {
10715 ir_add_error(ira, &instruction->base.base, buf_sprintf("operation results in overflow"));10721 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("operation results in overflow"));
10716 return ira->codegen->invalid_inst_gen;10722 return ira->codegen->invalid_inst_gen;
10717 }10723 }
1071810724
...@@ -10722,9 +10728,9 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct...@@ -10722,9 +10728,9 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct
1072210728
10723 IrInstGen *array_result;10729 IrInstGen *array_result;
10724 if (array_val->special == ConstValSpecialUndef || array_val->data.x_array.special == ConstArraySpecialUndef) {10730 if (array_val->special == ConstValSpecialUndef || array_val->data.x_array.special == ConstArraySpecialUndef) {
10725 array_result = ir_const_undef(ira, &instruction->base.base, result_array_type);10731 array_result = ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, result_array_type);
10726 } else {10732 } else {
10727 array_result = ir_const(ira, &instruction->base.base, result_array_type);10733 array_result = ir_const(ira, instruction->base.scope, instruction->base.source_node, result_array_type);
10728 ZigValue *out_val = array_result->value;10734 ZigValue *out_val = array_result->value;
1072910735
10730 switch (type_has_one_possible_value(ira->codegen, result_array_type)) {10736 switch (type_has_one_possible_value(ira->codegen, result_array_type)) {
...@@ -10765,7 +10771,7 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct...@@ -10765,7 +10771,7 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct
10765 }10771 }
10766skip_computation:10772skip_computation:
10767 if (want_ptr_to_array) {10773 if (want_ptr_to_array) {
10768 return ir_get_ref(ira, &instruction->base.base, array_result, true, false);10774 return ir_get_ref(ira, instruction->base.scope, instruction->base.source_node, array_result, true, false);
10769 } else {10775 } else {
10770 return array_result;10776 return array_result;
10771 }10777 }
...@@ -10774,26 +10780,26 @@ skip_computation:...@@ -10774,26 +10780,26 @@ skip_computation:
10774static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,10780static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
10775 IrInstSrcMergeErrSets *instruction)10781 IrInstSrcMergeErrSets *instruction)
10776{10782{
10777 ZigType *op1_type = ir_resolve_error_set_type(ira, &instruction->base.base, instruction->op1->child);10783 ZigType *op1_type = ir_resolve_error_set_type(ira, instruction->base.source_node, instruction->op1->child);
10778 if (type_is_invalid(op1_type))10784 if (type_is_invalid(op1_type))
10779 return ira->codegen->invalid_inst_gen;10785 return ira->codegen->invalid_inst_gen;
1078010786
10781 ZigType *op2_type = ir_resolve_error_set_type(ira, &instruction->base.base, instruction->op2->child);10787 ZigType *op2_type = ir_resolve_error_set_type(ira, instruction->base.source_node, instruction->op2->child);
10782 if (type_is_invalid(op2_type))10788 if (type_is_invalid(op2_type))
10783 return ira->codegen->invalid_inst_gen;10789 return ira->codegen->invalid_inst_gen;
1078410790
10785 if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->base.source_node)) {10791 if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->source_node)) {
10786 return ira->codegen->invalid_inst_gen;10792 return ira->codegen->invalid_inst_gen;
10787 }10793 }
1078810794
10789 if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->base.source_node)) {10795 if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->source_node)) {
10790 return ira->codegen->invalid_inst_gen;10796 return ira->codegen->invalid_inst_gen;
10791 }10797 }
1079210798
10793 if (type_is_global_error_set(op1_type) ||10799 if (type_is_global_error_set(op1_type) ||
10794 type_is_global_error_set(op2_type))10800 type_is_global_error_set(op2_type))
10795 {10801 {
10796 return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_global_error_set);10802 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_global_error_set);
10797 }10803 }
1079810804
10799 size_t errors_count = ira->codegen->errors_by_index.length;10805 size_t errors_count = ira->codegen->errors_by_index.length;
...@@ -10806,7 +10812,7 @@ static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,...@@ -10806,7 +10812,7 @@ static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
10806 ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type, instruction->type_name);10812 ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type, instruction->type_name);
10807 heap::c_allocator.deallocate(errors, errors_count);10813 heap::c_allocator.deallocate(errors, errors_count);
1080810814
10809 return ir_const_type(ira, &instruction->base.base, result_type);10815 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, result_type);
10810}10816}
1081110817
1081210818
...@@ -10871,7 +10877,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV...@@ -10871,7 +10877,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
10871 }10877 }
10872 }10878 }
1087310879
10874 AstNode *source_node = decl_var_instruction->base.base.source_node;10880 AstNode *source_node = decl_var_instruction->base.source_node;
1087510881
10876 bool is_comptime_var = ir_get_var_is_comptime(var);10882 bool is_comptime_var = ir_get_var_is_comptime(var);
1087710883
...@@ -10881,13 +10887,14 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV...@@ -10881,13 +10887,14 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
10881 // if this is null, a compiler error happened and did not initialize the variable.10887 // if this is null, a compiler error happened and did not initialize the variable.
10882 // if there are no compile errors there may be a missing ir_expr_wrap in pass1 IR generation.10888 // if there are no compile errors there may be a missing ir_expr_wrap in pass1 IR generation.
10883 if (var_ptr == nullptr || type_is_invalid(var_ptr->value->type)) {10889 if (var_ptr == nullptr || type_is_invalid(var_ptr->value->type)) {
10884 ir_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, &decl_var_instruction->base.base);10890 src_assert(var_ptr != nullptr || ira->codegen->errors.length != 0,
10891 decl_var_instruction->base.source_node);
10885 var->var_type = ira->codegen->builtin_types.entry_invalid;10892 var->var_type = ira->codegen->builtin_types.entry_invalid;
10886 return ira->codegen->invalid_inst_gen;10893 return ira->codegen->invalid_inst_gen;
10887 }10894 }
1088810895
10889 // The ir_build_var_decl_src call is supposed to pass a pointer to the allocation, not an initialization value.10896 // The ir_build_var_decl_src call is supposed to pass a pointer to the allocation, not an initialization value.
10890 ir_assert(var_ptr->value->type->id == ZigTypeIdPointer, &decl_var_instruction->base.base);10897 src_assert(var_ptr->value->type->id == ZigTypeIdPointer, decl_var_instruction->base.source_node);
1089110898
10892 ZigType *result_type = var_ptr->value->type->data.pointer.child_type;10899 ZigType *result_type = var_ptr->value->type->data.pointer.child_type;
10893 if (type_is_invalid(result_type)) {10900 if (type_is_invalid(result_type)) {
...@@ -10902,7 +10909,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV...@@ -10902,7 +10909,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
10902 if (ptr_val == nullptr)10909 if (ptr_val == nullptr)
10903 return ira->codegen->invalid_inst_gen;10910 return ira->codegen->invalid_inst_gen;
1090410911
10905 init_val = const_ptr_pointee(ira, ira->codegen, ptr_val, decl_var_instruction->base.base.source_node);10912 init_val = const_ptr_pointee(ira, ira->codegen, ptr_val, decl_var_instruction->base.source_node);
10906 if (init_val == nullptr)10913 if (init_val == nullptr)
10907 return ira->codegen->invalid_inst_gen;10914 return ira->codegen->invalid_inst_gen;
1090810915
...@@ -10935,7 +10942,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV...@@ -10935,7 +10942,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
10935 case ReqCompTimeNo:10942 case ReqCompTimeNo:
10936 if (init_val != nullptr && value_is_comptime(init_val)) {10943 if (init_val != nullptr && value_is_comptime(init_val)) {
10937 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,10944 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
10938 decl_var_instruction->base.base.source_node, init_val, UndefOk)))10945 decl_var_instruction->base.source_node, init_val, UndefOk)))
10939 {10946 {
10940 result_type = ira->codegen->builtin_types.entry_invalid;10947 result_type = ira->codegen->builtin_types.entry_invalid;
10941 } else if (init_val->type->id == ZigTypeIdFn &&10948 } else if (init_val->type->id == ZigTypeIdFn &&
...@@ -10968,13 +10975,13 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV...@@ -10968,13 +10975,13 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
10968 assert(var->var_type);10975 assert(var->var_type);
1096910976
10970 if (type_is_invalid(result_type)) {10977 if (type_is_invalid(result_type)) {
10971 return ir_const_void(ira, &decl_var_instruction->base.base);10978 return ir_const_void(ira, decl_var_instruction->base.scope, decl_var_instruction->base.source_node);
10972 }10979 }
1097310980
10974 if (decl_var_instruction->align_value == nullptr) {10981 if (decl_var_instruction->align_value == nullptr) {
10975 if ((err = type_resolve(ira->codegen, result_type, ResolveStatusAlignmentKnown))) {10982 if ((err = type_resolve(ira->codegen, result_type, ResolveStatusAlignmentKnown))) {
10976 var->var_type = ira->codegen->builtin_types.entry_invalid;10983 var->var_type = ira->codegen->builtin_types.entry_invalid;
10977 return ir_const_void(ira, &decl_var_instruction->base.base);10984 return ir_const_void(ira, decl_var_instruction->base.scope, decl_var_instruction->base.source_node);
10978 }10985 }
10979 var->align_bytes = get_ptr_align(ira->codegen, var_ptr->value->type);10986 var->align_bytes = get_ptr_align(ira->codegen, var_ptr->value->type);
10980 } else {10987 } else {
...@@ -10993,7 +11000,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV...@@ -10993,7 +11000,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
10993 // we need a runtime ptr but we have a comptime val.11000 // we need a runtime ptr but we have a comptime val.
10994 // since it's a comptime val there are no instructions for it.11001 // since it's a comptime val there are no instructions for it.
10995 // we memcpy the init value here11002 // we memcpy the init value here
10996 IrInstGen *deref = ir_get_deref(ira, &var_ptr->base, var_ptr, nullptr);11003 IrInstGen *deref = ir_get_deref(ira, var_ptr->scope, var_ptr->source_node, var_ptr, nullptr);
10997 if (type_is_invalid(deref->value->type)) {11004 if (type_is_invalid(deref->value->type)) {
10998 var->var_type = ira->codegen->builtin_types.entry_invalid;11005 var->var_type = ira->codegen->builtin_types.entry_invalid;
10999 return ira->codegen->invalid_inst_gen;11006 return ira->codegen->invalid_inst_gen;
...@@ -11003,13 +11010,13 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV...@@ -11003,13 +11010,13 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
11003 // instruction.11010 // instruction.
11004 assert(deref->value->special != ConstValSpecialRuntime);11011 assert(deref->value->special != ConstValSpecialRuntime);
11005 var_ptr->value->special = ConstValSpecialRuntime;11012 var_ptr->value->special = ConstValSpecialRuntime;
11006 ir_analyze_store_ptr(ira, &var_ptr->base, var_ptr, deref, false);11013 ir_analyze_store_ptr(ira, var_ptr->scope, var_ptr->source_node, var_ptr, deref, false);
11007 }11014 }
11008 if (instr_is_comptime(var_ptr) && (is_comptime_var || (var_class_requires_const && var->gen_is_const))) {11015 if (instr_is_comptime(var_ptr) && (is_comptime_var || (var_class_requires_const && var->gen_is_const))) {
11009 return ir_const_void(ira, &decl_var_instruction->base.base);11016 return ir_const_void(ira, decl_var_instruction->base.scope, decl_var_instruction->base.source_node);
11010 }11017 }
11011 } else if (is_comptime_var) {11018 } else if (is_comptime_var) {
11012 ir_add_error(ira, &decl_var_instruction->base.base,11019 ir_add_error_node(ira, decl_var_instruction->base.source_node,
11013 buf_sprintf("cannot store runtime value in compile time variable"));11020 buf_sprintf("cannot store runtime value in compile time variable"));
11014 var->var_type = ira->codegen->builtin_types.entry_invalid;11021 var->var_type = ira->codegen->builtin_types.entry_invalid;
11015 return ira->codegen->invalid_inst_gen;11022 return ira->codegen->invalid_inst_gen;
...@@ -11019,7 +11026,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV...@@ -11019,7 +11026,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
11019 if (fn_entry)11026 if (fn_entry)
11020 fn_entry->variable_list.append(var);11027 fn_entry->variable_list.append(var);
1102111028
11022 return ir_build_var_decl_gen(ira, &decl_var_instruction->base.base, var, var_ptr);11029 return ir_build_var_decl_gen(ira, decl_var_instruction->base.scope, decl_var_instruction->base.source_node, var, var_ptr);
11023}11030}
1102411031
11025static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport *instruction) {11032static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport *instruction) {
...@@ -11035,32 +11042,32 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport...@@ -11035,32 +11042,32 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
11035 assert(options_type->id == ZigTypeIdStruct);11042 assert(options_type->id == ZigTypeIdStruct);
1103611043
11037 TypeStructField *name_field = find_struct_type_field(options_type, buf_create_from_str("name"));11044 TypeStructField *name_field = find_struct_type_field(options_type, buf_create_from_str("name"));
11038 ir_assert(name_field != nullptr, &instruction->base.base);11045 src_assert(name_field != nullptr, instruction->base.source_node);
11039 IrInstGen *name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, name_field);11046 IrInstGen *name_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, name_field);
11040 if (type_is_invalid(name_inst->value->type))11047 if (type_is_invalid(name_inst->value->type))
11041 return ira->codegen->invalid_inst_gen;11048 return ira->codegen->invalid_inst_gen;
1104211049
11043 TypeStructField *linkage_field = find_struct_type_field(options_type, buf_create_from_str("linkage"));11050 TypeStructField *linkage_field = find_struct_type_field(options_type, buf_create_from_str("linkage"));
11044 ir_assert(linkage_field != nullptr, &instruction->base.base);11051 src_assert(linkage_field != nullptr, instruction->base.source_node);
11045 IrInstGen *linkage_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, linkage_field);11052 IrInstGen *linkage_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, linkage_field);
11046 if (type_is_invalid(linkage_inst->value->type))11053 if (type_is_invalid(linkage_inst->value->type))
11047 return ira->codegen->invalid_inst_gen;11054 return ira->codegen->invalid_inst_gen;
1104811055
11049 TypeStructField *section_field = find_struct_type_field(options_type, buf_create_from_str("section"));11056 TypeStructField *section_field = find_struct_type_field(options_type, buf_create_from_str("section"));
11050 ir_assert(section_field != nullptr, &instruction->base.base);11057 src_assert(section_field != nullptr, instruction->base.source_node);
11051 IrInstGen *section_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, section_field);11058 IrInstGen *section_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, section_field);
11052 if (type_is_invalid(section_inst->value->type))11059 if (type_is_invalid(section_inst->value->type))
11053 return ira->codegen->invalid_inst_gen;11060 return ira->codegen->invalid_inst_gen;
1105411061
11055 // The `section` field is optional, we have to unwrap it first11062 // The `section` field is optional, we have to unwrap it first
11056 IrInstGen *non_null_check = ir_analyze_test_non_null(ira, &instruction->base.base, section_inst);11063 IrInstGen *non_null_check = ir_analyze_test_non_null(ira, instruction->base.scope, instruction->base.source_node, section_inst);
11057 bool is_non_null;11064 bool is_non_null;
11058 if (!ir_resolve_bool(ira, non_null_check, &is_non_null))11065 if (!ir_resolve_bool(ira, non_null_check, &is_non_null))
11059 return ira->codegen->invalid_inst_gen;11066 return ira->codegen->invalid_inst_gen;
1106011067
11061 IrInstGen *section_str_inst = nullptr;11068 IrInstGen *section_str_inst = nullptr;
11062 if (is_non_null) {11069 if (is_non_null) {
11063 section_str_inst = ir_analyze_optional_value_payload_value(ira, &instruction->base.base, section_inst, false);11070 section_str_inst = ir_analyze_optional_value_payload_value(ira, instruction->base.scope, instruction->base.source_node, section_inst, false);
11064 if (type_is_invalid(section_str_inst->value->type))11071 if (type_is_invalid(section_str_inst->value->type))
11065 return ira->codegen->invalid_inst_gen;11072 return ira->codegen->invalid_inst_gen;
11066 }11073 }
...@@ -11071,7 +11078,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport...@@ -11071,7 +11078,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
11071 return ira->codegen->invalid_inst_gen;11078 return ira->codegen->invalid_inst_gen;
1107211079
11073 if (buf_len(symbol_name) < 1) {11080 if (buf_len(symbol_name) < 1) {
11074 ir_add_error(ira, &name_inst->base,11081 ir_add_error(ira, name_inst,
11075 buf_sprintf("exported symbol name cannot be empty"));11082 buf_sprintf("exported symbol name cannot be empty"));
11076 return ira->codegen->invalid_inst_gen;11083 return ira->codegen->invalid_inst_gen;
11077 }11084 }
...@@ -11090,12 +11097,12 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport...@@ -11090,12 +11097,12 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
11090 // in another file.11097 // in another file.
11091 TldFn *tld_fn = heap::c_allocator.create<TldFn>();11098 TldFn *tld_fn = heap::c_allocator.create<TldFn>();
11092 tld_fn->base.id = TldIdFn;11099 tld_fn->base.id = TldIdFn;
11093 tld_fn->base.source_node = instruction->base.base.source_node;11100 tld_fn->base.source_node = instruction->base.source_node;
1109411101
11095 auto entry = ira->codegen->exported_symbol_names.put_unique(symbol_name, &tld_fn->base);11102 auto entry = ira->codegen->exported_symbol_names.put_unique(symbol_name, &tld_fn->base);
11096 if (entry) {11103 if (entry) {
11097 AstNode *other_export_node = entry->value->source_node;11104 AstNode *other_export_node = entry->value->source_node;
11098 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,11105 ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node,
11099 buf_sprintf("exported symbol collision: '%s'", buf_ptr(symbol_name)));11106 buf_sprintf("exported symbol collision: '%s'", buf_ptr(symbol_name)));
11100 add_error_note(ira->codegen, msg, other_export_node, buf_sprintf("other symbol here"));11107 add_error_note(ira->codegen, msg, other_export_node, buf_sprintf("other symbol here"));
11101 return ira->codegen->invalid_inst_gen;11108 return ira->codegen->invalid_inst_gen;
...@@ -11114,17 +11121,17 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport...@@ -11114,17 +11121,17 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
11114 CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;11121 CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;
11115 switch (cc) {11122 switch (cc) {
11116 case CallingConventionUnspecified: {11123 case CallingConventionUnspecified: {
11117 ErrorMsg *msg = ir_add_error(ira, &target->base,11124 ErrorMsg *msg = ir_add_error(ira, target,
11118 buf_sprintf("exported function must specify calling convention"));11125 buf_sprintf("exported function must specify calling convention"));
11119 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));11126 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));
11120 } break;11127 } break;
11121 case CallingConventionAsync: {11128 case CallingConventionAsync: {
11122 ErrorMsg *msg = ir_add_error(ira, &target->base,11129 ErrorMsg *msg = ir_add_error(ira, target,
11123 buf_sprintf("exported function cannot be async"));11130 buf_sprintf("exported function cannot be async"));
11124 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));11131 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));
11125 } break;11132 } break;
11126 case CallingConventionInline: {11133 case CallingConventionInline: {
11127 ErrorMsg *msg = ir_add_error(ira, &target->base,11134 ErrorMsg *msg = ir_add_error(ira, target,
11128 buf_sprintf("exported function cannot be inline"));11135 buf_sprintf("exported function cannot be inline"));
11129 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));11136 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));
11130 } break;11137 } break;
...@@ -11147,10 +11154,10 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport...@@ -11147,10 +11154,10 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
11147 } break;11154 } break;
11148 case ZigTypeIdStruct:11155 case ZigTypeIdStruct:
11149 if (is_slice(target->value->type)) {11156 if (is_slice(target->value->type)) {
11150 ir_add_error(ira, &target->base,11157 ir_add_error(ira, target,
11151 buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value->type->name)));11158 buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value->type->name)));
11152 } else if (target->value->type->data.structure.layout != ContainerLayoutExtern) {11159 } else if (target->value->type->data.structure.layout != ContainerLayoutExtern) {
11153 ErrorMsg *msg = ir_add_error(ira, &target->base,11160 ErrorMsg *msg = ir_add_error(ira, target,
11154 buf_sprintf("exported struct value must be declared extern"));11161 buf_sprintf("exported struct value must be declared extern"));
11155 add_error_note(ira->codegen, msg, target->value->type->data.structure.decl_node, buf_sprintf("declared here"));11162 add_error_note(ira->codegen, msg, target->value->type->data.structure.decl_node, buf_sprintf("declared here"));
11156 } else {11163 } else {
...@@ -11159,7 +11166,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport...@@ -11159,7 +11166,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
11159 break;11166 break;
11160 case ZigTypeIdUnion:11167 case ZigTypeIdUnion:
11161 if (target->value->type->data.unionation.layout != ContainerLayoutExtern) {11168 if (target->value->type->data.unionation.layout != ContainerLayoutExtern) {
11162 ErrorMsg *msg = ir_add_error(ira, &target->base,11169 ErrorMsg *msg = ir_add_error(ira, target,
11163 buf_sprintf("exported union value must be declared extern"));11170 buf_sprintf("exported union value must be declared extern"));
11164 add_error_note(ira->codegen, msg, target->value->type->data.unionation.decl_node, buf_sprintf("declared here"));11171 add_error_note(ira->codegen, msg, target->value->type->data.unionation.decl_node, buf_sprintf("declared here"));
11165 } else {11172 } else {
...@@ -11168,7 +11175,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport...@@ -11168,7 +11175,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
11168 break;11175 break;
11169 case ZigTypeIdEnum:11176 case ZigTypeIdEnum:
11170 if (target->value->type->data.enumeration.layout != ContainerLayoutExtern) {11177 if (target->value->type->data.enumeration.layout != ContainerLayoutExtern) {
11171 ErrorMsg *msg = ir_add_error(ira, &target->base,11178 ErrorMsg *msg = ir_add_error(ira, target,
11172 buf_sprintf("exported enum value must be declared extern"));11179 buf_sprintf("exported enum value must be declared extern"));
11173 add_error_note(ira->codegen, msg, target->value->type->data.enumeration.decl_node, buf_sprintf("declared here"));11180 add_error_note(ira->codegen, msg, target->value->type->data.enumeration.decl_node, buf_sprintf("declared here"));
11174 } else {11181 } else {
...@@ -11181,7 +11188,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport...@@ -11181,7 +11188,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
11181 return ira->codegen->invalid_inst_gen;11188 return ira->codegen->invalid_inst_gen;
1118211189
11183 if (!ok_type) {11190 if (!ok_type) {
11184 ir_add_error(ira, &target->base,11191 ir_add_error(ira, target,
11185 buf_sprintf("array element type '%s' not extern-compatible",11192 buf_sprintf("array element type '%s' not extern-compatible",
11186 buf_ptr(&target->value->type->data.array.child_type->name)));11193 buf_ptr(&target->value->type->data.array.child_type->name)));
11187 } else {11194 } else {
...@@ -11196,31 +11203,31 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport...@@ -11196,31 +11203,31 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
11196 zig_unreachable();11203 zig_unreachable();
11197 case ZigTypeIdStruct:11204 case ZigTypeIdStruct:
11198 if (is_slice(type_value)) {11205 if (is_slice(type_value)) {
11199 ir_add_error(ira, &target->base,11206 ir_add_error(ira, target,
11200 buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name)));11207 buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name)));
11201 } else if (type_value->data.structure.layout != ContainerLayoutExtern) {11208 } else if (type_value->data.structure.layout != ContainerLayoutExtern) {
11202 ErrorMsg *msg = ir_add_error(ira, &target->base,11209 ErrorMsg *msg = ir_add_error(ira, target,
11203 buf_sprintf("exported struct must be declared extern"));11210 buf_sprintf("exported struct must be declared extern"));
11204 add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here"));11211 add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here"));
11205 }11212 }
11206 break;11213 break;
11207 case ZigTypeIdUnion:11214 case ZigTypeIdUnion:
11208 if (type_value->data.unionation.layout != ContainerLayoutExtern) {11215 if (type_value->data.unionation.layout != ContainerLayoutExtern) {
11209 ErrorMsg *msg = ir_add_error(ira, &target->base,11216 ErrorMsg *msg = ir_add_error(ira, target,
11210 buf_sprintf("exported union must be declared extern"));11217 buf_sprintf("exported union must be declared extern"));
11211 add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here"));11218 add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here"));
11212 }11219 }
11213 break;11220 break;
11214 case ZigTypeIdEnum:11221 case ZigTypeIdEnum:
11215 if (type_value->data.enumeration.layout != ContainerLayoutExtern) {11222 if (type_value->data.enumeration.layout != ContainerLayoutExtern) {
11216 ErrorMsg *msg = ir_add_error(ira, &target->base,11223 ErrorMsg *msg = ir_add_error(ira, target,
11217 buf_sprintf("exported enum must be declared extern"));11224 buf_sprintf("exported enum must be declared extern"));
11218 add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here"));11225 add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here"));
11219 }11226 }
11220 break;11227 break;
11221 case ZigTypeIdFn: {11228 case ZigTypeIdFn: {
11222 if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) {11229 if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) {
11223 ir_add_error(ira, &target->base,11230 ir_add_error(ira, target,
11224 buf_sprintf("exported function type must specify calling convention"));11231 buf_sprintf("exported function type must specify calling convention"));
11225 }11232 }
11226 } break;11233 } break;
...@@ -11246,7 +11253,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport...@@ -11246,7 +11253,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
11246 case ZigTypeIdOpaque:11253 case ZigTypeIdOpaque:
11247 case ZigTypeIdFnFrame:11254 case ZigTypeIdFnFrame:
11248 case ZigTypeIdAnyFrame:11255 case ZigTypeIdAnyFrame:
11249 ir_add_error(ira, &target->base,11256 ir_add_error(ira, target,
11250 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));11257 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));
11251 break;11258 break;
11252 }11259 }
...@@ -11272,7 +11279,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport...@@ -11272,7 +11279,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
11272 case ZigTypeIdEnumLiteral:11279 case ZigTypeIdEnumLiteral:
11273 case ZigTypeIdFnFrame:11280 case ZigTypeIdFnFrame:
11274 case ZigTypeIdAnyFrame:11281 case ZigTypeIdAnyFrame:
11275 ir_add_error(ira, &target->base,11282 ir_add_error(ira, target,
11276 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value->type->name)));11283 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value->type->name)));
11277 break;11284 break;
11278 }11285 }
...@@ -11288,7 +11295,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport...@@ -11288,7 +11295,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
11288 }11295 }
11289 }11296 }
1129011297
11291 return ir_const_void(ira, &instruction->base.base);11298 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
11292}11299}
1129311300
11294static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, AstNode *source_node);11301static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, AstNode *source_node);
...@@ -11306,38 +11313,38 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern...@@ -11306,38 +11313,38 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern
11306 assert(options_type->id == ZigTypeIdStruct);11313 assert(options_type->id == ZigTypeIdStruct);
1130711314
11308 TypeStructField *name_field = find_struct_type_field(options_type, buf_create_from_str("name"));11315 TypeStructField *name_field = find_struct_type_field(options_type, buf_create_from_str("name"));
11309 ir_assert(name_field != nullptr, &instruction->base.base);11316 src_assert(name_field != nullptr, instruction->base.source_node);
11310 IrInstGen *name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, name_field);11317 IrInstGen *name_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, name_field);
11311 if (type_is_invalid(name_inst->value->type))11318 if (type_is_invalid(name_inst->value->type))
11312 return ira->codegen->invalid_inst_gen;11319 return ira->codegen->invalid_inst_gen;
1131311320
11314 TypeStructField *linkage_field = find_struct_type_field(options_type, buf_create_from_str("linkage"));11321 TypeStructField *linkage_field = find_struct_type_field(options_type, buf_create_from_str("linkage"));
11315 ir_assert(linkage_field != nullptr, &instruction->base.base);11322 src_assert(linkage_field != nullptr, instruction->base.source_node);
11316 IrInstGen *linkage_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, linkage_field);11323 IrInstGen *linkage_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, linkage_field);
11317 if (type_is_invalid(linkage_inst->value->type))11324 if (type_is_invalid(linkage_inst->value->type))
11318 return ira->codegen->invalid_inst_gen;11325 return ira->codegen->invalid_inst_gen;
1131911326
11320 TypeStructField *is_thread_local_field = find_struct_type_field(options_type, buf_create_from_str("is_thread_local"));11327 TypeStructField *is_thread_local_field = find_struct_type_field(options_type, buf_create_from_str("is_thread_local"));
11321 ir_assert(is_thread_local_field != nullptr, &instruction->base.base);11328 src_assert(is_thread_local_field != nullptr, instruction->base.source_node);
11322 IrInstGen *is_thread_local_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, is_thread_local_field);11329 IrInstGen *is_thread_local_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, is_thread_local_field);
11323 if (type_is_invalid(is_thread_local_inst->value->type))11330 if (type_is_invalid(is_thread_local_inst->value->type))
11324 return ira->codegen->invalid_inst_gen;11331 return ira->codegen->invalid_inst_gen;
1132511332
11326 TypeStructField *library_name_field = find_struct_type_field(options_type, buf_create_from_str("library_name"));11333 TypeStructField *library_name_field = find_struct_type_field(options_type, buf_create_from_str("library_name"));
11327 ir_assert(library_name_field != nullptr, &instruction->base.base);11334 src_assert(library_name_field != nullptr, instruction->base.source_node);
11328 IrInstGen *library_name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, library_name_field);11335 IrInstGen *library_name_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, library_name_field);
11329 if (type_is_invalid(library_name_inst->value->type))11336 if (type_is_invalid(library_name_inst->value->type))
11330 return ira->codegen->invalid_inst_gen;11337 return ira->codegen->invalid_inst_gen;
1133111338
11332 // The `library_name` field is optional, we have to unwrap it first11339 // The `library_name` field is optional, we have to unwrap it first
11333 IrInstGen *non_null_check = ir_analyze_test_non_null(ira, &instruction->base.base, library_name_inst);11340 IrInstGen *non_null_check = ir_analyze_test_non_null(ira, instruction->base.scope, instruction->base.source_node, library_name_inst);
11334 bool is_non_null;11341 bool is_non_null;
11335 if (!ir_resolve_bool(ira, non_null_check, &is_non_null))11342 if (!ir_resolve_bool(ira, non_null_check, &is_non_null))
11336 return ira->codegen->invalid_inst_gen;11343 return ira->codegen->invalid_inst_gen;
1133711344
11338 IrInstGen *library_name_val_inst = nullptr;11345 IrInstGen *library_name_val_inst = nullptr;
11339 if (is_non_null) {11346 if (is_non_null) {
11340 library_name_val_inst = ir_analyze_optional_value_payload_value(ira, &instruction->base.base, library_name_inst, false);11347 library_name_val_inst = ir_analyze_optional_value_payload_value(ira, instruction->base.scope, instruction->base.source_node, library_name_inst, false);
11341 if (type_is_invalid(library_name_val_inst->value->type))11348 if (type_is_invalid(library_name_val_inst->value->type))
11342 return ira->codegen->invalid_inst_gen;11349 return ira->codegen->invalid_inst_gen;
11343 }11350 }
...@@ -11348,7 +11355,7 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern...@@ -11348,7 +11355,7 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern
11348 return ira->codegen->invalid_inst_gen;11355 return ira->codegen->invalid_inst_gen;
1134911356
11350 if (get_src_ptr_type(value_type) == nullptr) {11357 if (get_src_ptr_type(value_type) == nullptr) {
11351 ir_add_error(ira, &name_inst->base,11358 ir_add_error(ira, name_inst,
11352 buf_sprintf("expected (optional) pointer type or function"));11359 buf_sprintf("expected (optional) pointer type or function"));
11353 return ira->codegen->invalid_inst_gen;11360 return ira->codegen->invalid_inst_gen;
11354 }11361 }
...@@ -11358,7 +11365,7 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern...@@ -11358,7 +11365,7 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern
11358 return ira->codegen->invalid_inst_gen;11365 return ira->codegen->invalid_inst_gen;
1135911366
11360 if (buf_len(symbol_name) == 0) {11367 if (buf_len(symbol_name) == 0) {
11361 ir_add_error(ira, &name_inst->base,11368 ir_add_error(ira, name_inst,
11362 buf_sprintf("extern symbol name cannot be empty"));11369 buf_sprintf("extern symbol name cannot be empty"));
11363 return ira->codegen->invalid_inst_gen;11370 return ira->codegen->invalid_inst_gen;
11364 }11371 }
...@@ -11370,12 +11377,12 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern...@@ -11370,12 +11377,12 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern
11370 return ira->codegen->invalid_inst_gen;11377 return ira->codegen->invalid_inst_gen;
1137111378
11372 if (buf_len(library_name) == 0) {11379 if (buf_len(library_name) == 0) {
11373 ir_add_error(ira, &library_name_inst->base,11380 ir_add_error(ira, library_name_inst,
11374 buf_sprintf("library name name cannot be empty"));11381 buf_sprintf("library name name cannot be empty"));
11375 return ira->codegen->invalid_inst_gen;11382 return ira->codegen->invalid_inst_gen;
11376 }11383 }
1137711384
11378 add_link_lib_symbol(ira, library_name, symbol_name, instruction->base.base.source_node);11385 add_link_lib_symbol(ira, library_name, symbol_name, instruction->base.source_node);
1137911386
11380 buf_destroy(library_name);11387 buf_destroy(library_name);
11381 }11388 }
...@@ -11396,18 +11403,18 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern...@@ -11396,18 +11403,18 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern
11396 // XXX: Find a better way to do this (in stage2).11403 // XXX: Find a better way to do this (in stage2).
11397 TldFn *tld_fn = heap::c_allocator.create<TldFn>();11404 TldFn *tld_fn = heap::c_allocator.create<TldFn>();
11398 tld_fn->base.id = TldIdFn;11405 tld_fn->base.id = TldIdFn;
11399 tld_fn->base.source_node = instruction->base.base.source_node;11406 tld_fn->base.source_node = instruction->base.source_node;
1140011407
11401 auto entry = ira->codegen->external_symbol_names.put_unique(symbol_name, &tld_fn->base);11408 auto entry = ira->codegen->external_symbol_names.put_unique(symbol_name, &tld_fn->base);
11402 if (entry) {11409 if (entry) {
11403 AstNode *other_extern_node = entry->value->source_node;11410 AstNode *other_extern_node = entry->value->source_node;
11404 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,11411 ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node,
11405 buf_sprintf("extern symbol collision: '%s'", buf_ptr(symbol_name)));11412 buf_sprintf("extern symbol collision: '%s'", buf_ptr(symbol_name)));
11406 add_error_note(ira->codegen, msg, other_extern_node, buf_sprintf("other symbol here"));11413 add_error_note(ira->codegen, msg, other_extern_node, buf_sprintf("other symbol here"));
11407 return ira->codegen->invalid_inst_gen;11414 return ira->codegen->invalid_inst_gen;
11408 }11415 }
1140911416
11410 return ir_build_extern_gen(ira, &instruction->base.base, symbol_name, global_linkage_id,11417 return ir_build_extern_gen(ira, instruction->base.scope, instruction->base.source_node, symbol_name, global_linkage_id,
11411 is_thread_local, expr_type);11418 is_thread_local, expr_type);
11412}11419}
1141311420
...@@ -11423,24 +11430,24 @@ static IrInstGen *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,...@@ -11423,24 +11430,24 @@ static IrInstGen *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
11423 if (instruction->optional == IrInstErrorReturnTraceNull) {11430 if (instruction->optional == IrInstErrorReturnTraceNull) {
11424 ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type);11431 ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type);
11425 if (!ira_has_err_ret_trace(ira)) {11432 if (!ira_has_err_ret_trace(ira)) {
11426 IrInstGen *result = ir_const(ira, &instruction->base.base, optional_type);11433 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, optional_type);
11427 ZigValue *out_val = result->value;11434 ZigValue *out_val = result->value;
11428 assert(get_src_ptr_type(optional_type) != nullptr);11435 assert(get_src_ptr_type(optional_type) != nullptr);
11429 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;11436 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
11430 out_val->data.x_ptr.data.hard_coded_addr.addr = 0;11437 out_val->data.x_ptr.data.hard_coded_addr.addr = 0;
11431 return result;11438 return result;
11432 }11439 }
11433 return ir_build_error_return_trace_gen(ira, instruction->base.base.scope,11440 return ir_build_error_return_trace_gen(ira, instruction->base.scope,
11434 instruction->base.base.source_node, instruction->optional, optional_type);11441 instruction->base.source_node, instruction->optional, optional_type);
11435 } else {11442 } else {
11436 assert(ira->codegen->have_err_ret_tracing);11443 assert(ira->codegen->have_err_ret_tracing);
11437 return ir_build_error_return_trace_gen(ira, instruction->base.base.scope,11444 return ir_build_error_return_trace_gen(ira, instruction->base.scope,
11438 instruction->base.base.source_node, instruction->optional, ptr_to_stack_trace_type);11445 instruction->base.source_node, instruction->optional, ptr_to_stack_trace_type);
11439 }11446 }
11440}11447}
1144111448
11442static IrInstGen *ir_analyze_instruction_error_union(IrAnalyze *ira, IrInstSrcErrorUnion *instruction) {11449static IrInstGen *ir_analyze_instruction_error_union(IrAnalyze *ira, IrInstSrcErrorUnion *instruction) {
11443 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);11450 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_type);
11444 result->value->special = ConstValSpecialLazy;11451 result->value->special = ConstValSpecialLazy;
1144511452
11446 LazyValueErrUnionType *lazy_err_union_type = heap::c_allocator.create<LazyValueErrUnionType>();11453 LazyValueErrUnionType *lazy_err_union_type = heap::c_allocator.create<LazyValueErrUnionType>();
...@@ -11459,7 +11466,7 @@ static IrInstGen *ir_analyze_instruction_error_union(IrAnalyze *ira, IrInstSrcEr...@@ -11459,7 +11466,7 @@ static IrInstGen *ir_analyze_instruction_error_union(IrAnalyze *ira, IrInstSrcEr
11459 return result;11466 return result;
11460}11467}
1146111468
11462static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType *var_type,11469static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *var_type,
11463 uint32_t align, const char *name_hint, bool force_comptime)11470 uint32_t align, const char *name_hint, bool force_comptime)
11464{11471{
11465 Error err;11472 Error err;
...@@ -11468,7 +11475,7 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType...@@ -11468,7 +11475,7 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType
11468 pointee->special = ConstValSpecialUndef;11475 pointee->special = ConstValSpecialUndef;
11469 pointee->llvm_align = align;11476 pointee->llvm_align = align;
1147011477
11471 IrInstGenAlloca *result = ir_build_alloca_gen(ira, source_inst, align, name_hint);11478 IrInstGenAlloca *result = ir_build_alloca_gen(ira, scope, source_node, align, name_hint);
11472 result->base.value->special = ConstValSpecialStatic;11479 result->base.value->special = ConstValSpecialStatic;
11473 result->base.value->data.x_ptr.special = ConstPtrSpecialRef;11480 result->base.value->data.x_ptr.special = ConstPtrSpecialRef;
11474 result->base.value->data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer;11481 result->base.value->data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer;
...@@ -11481,7 +11488,7 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType...@@ -11481,7 +11488,7 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType
11481 if ((err = type_resolve(ira->codegen, var_type, ResolveStatusAlignmentKnown)))11488 if ((err = type_resolve(ira->codegen, var_type, ResolveStatusAlignmentKnown)))
11482 return ira->codegen->invalid_inst_gen;11489 return ira->codegen->invalid_inst_gen;
11483 if (!var_type_has_bits) {11490 if (!var_type_has_bits) {
11484 ir_add_error(ira, source_inst,11491 ir_add_error_node(ira, source_node,
11485 buf_sprintf("variable '%s' of zero-bit type '%s' has no in-memory representation, it cannot be aligned",11492 buf_sprintf("variable '%s' of zero-bit type '%s' has no in-memory representation, it cannot be aligned",
11486 name_hint, buf_ptr(&var_type->name)));11493 name_hint, buf_ptr(&var_type->name)));
11487 return ira->codegen->invalid_inst_gen;11494 return ira->codegen->invalid_inst_gen;
...@@ -11502,9 +11509,7 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType...@@ -11502,9 +11509,7 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType
11502 return &result->base;11509 return &result->base;
11503}11510}
1150411511
11505static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInst *suspend_source_instr,11512static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, ResultLoc *result_loc) {
11506 ResultLoc *result_loc)
11507{
11508 switch (result_loc->id) {11513 switch (result_loc->id) {
11509 case ResultLocIdInvalid:11514 case ResultLocIdInvalid:
11510 case ResultLocIdPeerParent:11515 case ResultLocIdPeerParent:
...@@ -11584,12 +11589,13 @@ static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out...@@ -11584,12 +11589,13 @@ static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out
11584 zig_unreachable();11589 zig_unreachable();
11585}11590}
1158611591
11587static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInst *suspend_source_instr,11592static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstSrc *suspend_source_instr,
11588 ResultLoc *result_loc, ZigType *value_type)11593 ResultLoc *result_loc, ZigType *value_type)
11589{11594{
11590 if (type_is_invalid(value_type))11595 if (type_is_invalid(value_type))
11591 return ira->codegen->invalid_inst_gen;11596 return ira->codegen->invalid_inst_gen;
11592 IrInstGenAlloca *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");11597 IrInstGenAlloca *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr->scope,
11598 suspend_source_instr->source_node, 0, "");
11593 alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,11599 alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,
11594 PtrLenSingle, 0, 0, 0, false);11600 PtrLenSingle, 0, 0, 0, false);
11595 set_up_result_loc_for_inferred_comptime(ira, &alloca_gen->base);11601 set_up_result_loc_for_inferred_comptime(ira, &alloca_gen->base);
...@@ -11618,7 +11624,7 @@ static bool result_loc_is_discard(ResultLoc *result_loc_pass1) {...@@ -11618,7 +11624,7 @@ static bool result_loc_is_discard(ResultLoc *result_loc_pass1) {
11618}11624}
1161911625
11620// when calling this function, at the callsite must check for result type noreturn and propagate it up11626// when calling this function, at the callsite must check for result type noreturn and propagate it up
11621static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr,11627static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInstSrc *suspend_source_instr,
11622 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime,11628 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime,
11623 bool allow_discard)11629 bool allow_discard)
11624{11630{
...@@ -11662,7 +11668,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i...@@ -11662,7 +11668,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
11662 var = new_var;11668 var = new_var;
11663 }11669 }
11664 if (value_type->id == ZigTypeIdUnreachable || value_type->id == ZigTypeIdOpaque) {11670 if (value_type->id == ZigTypeIdUnreachable || value_type->id == ZigTypeIdOpaque) {
11665 ir_add_error(ira, &result_loc->source_instruction->base,11671 ir_add_error_node(ira, result_loc->source_instruction->source_node,
11666 buf_sprintf("variable of type '%s' not allowed", buf_ptr(&value_type->name)));11672 buf_sprintf("variable of type '%s' not allowed", buf_ptr(&value_type->name)));
11667 return ira->codegen->invalid_inst_gen;11673 return ira->codegen->invalid_inst_gen;
11668 }11674 }
...@@ -11674,14 +11680,16 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i...@@ -11674,14 +11680,16 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
11674 if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, nullptr, &align)) {11680 if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, nullptr, &align)) {
11675 return ira->codegen->invalid_inst_gen;11681 return ira->codegen->invalid_inst_gen;
11676 }11682 }
11677 IrInstGen *alloca_gen = ir_analyze_alloca(ira, &result_loc->source_instruction->base, value_type,11683 IrInstGen *alloca_gen = ir_analyze_alloca(ira,
11684 result_loc->source_instruction->scope,
11685 result_loc->source_instruction->source_node, value_type,
11678 align, alloca_src->name_hint, force_comptime);11686 align, alloca_src->name_hint, force_comptime);
11679 if (force_runtime) {11687 if (force_runtime) {
11680 alloca_gen->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;11688 alloca_gen->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
11681 alloca_gen->value->special = ConstValSpecialRuntime;11689 alloca_gen->value->special = ConstValSpecialRuntime;
11682 }11690 }
11683 if (alloca_src->base.child != nullptr && !result_loc->written) {11691 if (alloca_src->base.child != nullptr && !result_loc->written) {
11684 alloca_src->base.child->base.ref_count = 0;11692 alloca_src->base.child->ref_count = 0;
11685 }11693 }
11686 alloca_src->base.child = alloca_gen;11694 alloca_src->base.child = alloca_gen;
11687 var->ptr_instruction = alloca_gen;11695 var->ptr_instruction = alloca_gen;
...@@ -11786,7 +11794,8 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i...@@ -11786,7 +11794,8 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
1178611794
11787 IrInstGen *casted_value;11795 IrInstGen *casted_value;
11788 if (value != nullptr) {11796 if (value != nullptr) {
11789 casted_value = ir_implicit_cast2(ira, suspend_source_instr, value, dest_type);11797 casted_value = ir_implicit_cast2(ira, suspend_source_instr->scope,
11798 suspend_source_instr->source_node, value, dest_type);
11790 if (type_is_invalid(casted_value->value->type))11799 if (type_is_invalid(casted_value->value->type))
11791 return ira->codegen->invalid_inst_gen;11800 return ira->codegen->invalid_inst_gen;
11792 dest_type = casted_value->value->type;11801 dest_type = casted_value->value->type;
...@@ -11835,7 +11844,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i...@@ -11835,7 +11844,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
1183511844
11836 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,11845 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,
11837 parent_result_loc->value->type, ptr_type,11846 parent_result_loc->value->type, ptr_type,
11838 result_cast->base.source_instruction->base.source_node, false);11847 result_cast->base.source_instruction->source_node, false);
11839 if (const_cast_result.id == ConstCastResultIdInvalid)11848 if (const_cast_result.id == ConstCastResultIdInvalid)
11840 return ira->codegen->invalid_inst_gen;11849 return ira->codegen->invalid_inst_gen;
11841 if (const_cast_result.id != ConstCastResultIdOk) {11850 if (const_cast_result.id != ConstCastResultIdOk) {
...@@ -11849,8 +11858,10 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i...@@ -11849,8 +11858,10 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
11849 }11858 }
1185011859
11851 result_loc->written = true;11860 result_loc->written = true;
11852 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,11861 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr->scope,
11853 &parent_result_loc->base, ptr_type, &result_cast->base.source_instruction->base, false, false);11862 suspend_source_instr->source_node, parent_result_loc,
11863 parent_result_loc->source_node, ptr_type,
11864 result_cast->base.source_instruction->source_node, false, false);
11854 return result_loc->resolved_loc;11865 return result_loc->resolved_loc;
11855 }11866 }
11856 case ResultLocIdBitCast: {11867 case ResultLocIdBitCast: {
...@@ -11863,13 +11874,13 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i...@@ -11863,13 +11874,13 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
11863 if ((err = get_codegen_ptr_type(ira->codegen, dest_type, &dest_cg_ptr_type)))11874 if ((err = get_codegen_ptr_type(ira->codegen, dest_type, &dest_cg_ptr_type)))
11864 return ira->codegen->invalid_inst_gen;11875 return ira->codegen->invalid_inst_gen;
11865 if (dest_cg_ptr_type != nullptr) {11876 if (dest_cg_ptr_type != nullptr) {
11866 ir_add_error(ira, &result_loc->source_instruction->base,11877 ir_add_error_node(ira, result_loc->source_instruction->source_node,
11867 buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name)));11878 buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name)));
11868 return ira->codegen->invalid_inst_gen;11879 return ira->codegen->invalid_inst_gen;
11869 }11880 }
1187011881
11871 if (!type_can_bit_cast(dest_type)) {11882 if (!type_can_bit_cast(dest_type)) {
11872 ir_add_error(ira, &result_loc->source_instruction->base,11883 ir_add_error_node(ira, result_loc->source_instruction->source_node,
11873 buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name)));11884 buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name)));
11874 return ira->codegen->invalid_inst_gen;11885 return ira->codegen->invalid_inst_gen;
11875 }11886 }
...@@ -11878,20 +11889,21 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i...@@ -11878,20 +11889,21 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
11878 if ((err = get_codegen_ptr_type(ira->codegen, value_type, &value_cg_ptr_type)))11889 if ((err = get_codegen_ptr_type(ira->codegen, value_type, &value_cg_ptr_type)))
11879 return ira->codegen->invalid_inst_gen;11890 return ira->codegen->invalid_inst_gen;
11880 if (value_cg_ptr_type != nullptr) {11891 if (value_cg_ptr_type != nullptr) {
11881 ir_add_error(ira, suspend_source_instr,11892 ir_add_error_node(ira, suspend_source_instr->source_node,
11882 buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&value_type->name)));11893 buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&value_type->name)));
11883 return ira->codegen->invalid_inst_gen;11894 return ira->codegen->invalid_inst_gen;
11884 }11895 }
1188511896
11886 if (!type_can_bit_cast(value_type)) {11897 if (!type_can_bit_cast(value_type)) {
11887 ir_add_error(ira, suspend_source_instr,11898 ir_add_error_node(ira, suspend_source_instr->source_node,
11888 buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&value_type->name)));11899 buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&value_type->name)));
11889 return ira->codegen->invalid_inst_gen;11900 return ira->codegen->invalid_inst_gen;
11890 }11901 }
1189111902
11892 IrInstGen *bitcasted_value;11903 IrInstGen *bitcasted_value;
11893 if (value != nullptr) {11904 if (value != nullptr) {
11894 bitcasted_value = ir_analyze_bit_cast(ira, &result_loc->source_instruction->base, value, dest_type);11905 bitcasted_value = ir_analyze_bit_cast(ira, result_loc->source_instruction->scope,
11906 result_loc->source_instruction->source_node, value, dest_type);
11895 dest_type = bitcasted_value->value->type;11907 dest_type = bitcasted_value->value->type;
11896 } else {11908 } else {
11897 bitcasted_value = nullptr;11909 bitcasted_value = nullptr;
...@@ -11943,15 +11955,17 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i...@@ -11943,15 +11955,17 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
11943 parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);11955 parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);
1194411956
11945 result_loc->written = true;11957 result_loc->written = true;
11946 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,11958 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr->scope,
11947 &parent_result_loc->base, ptr_type, &result_bit_cast->base.source_instruction->base, false, false);11959 suspend_source_instr->source_node, parent_result_loc,
11960 parent_result_loc->source_node, ptr_type,
11961 result_bit_cast->base.source_instruction->source_node, false, false);
11948 return result_loc->resolved_loc;11962 return result_loc->resolved_loc;
11949 }11963 }
11950 }11964 }
11951 zig_unreachable();11965 zig_unreachable();
11952}11966}
1195311967
11954static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr,11968static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInstSrc *suspend_source_instr,
11955 ResultLoc *result_loc_pass1, ZigType *value_type, IrInstGen *value, bool force_runtime,11969 ResultLoc *result_loc_pass1, ZigType *value_type, IrInstGen *value, bool force_runtime,
11956 bool allow_discard)11970 bool allow_discard)
11957{11971{
...@@ -11994,7 +12008,7 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr...@@ -11994,7 +12008,7 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr
11994 field->type_entry = value_type;12008 field->type_entry = value_type;
11995 field->type_val = create_const_type(ira->codegen, field->type_entry);12009 field->type_val = create_const_type(ira->codegen, field->type_entry);
11996 field->src_index = old_field_count;12010 field->src_index = old_field_count;
11997 field->decl_node = value ? value->base.source_node : suspend_source_instr->source_node;12011 field->decl_node = value ? value->source_node : suspend_source_instr->source_node;
11998 if (value && instr_is_comptime(value)) {12012 if (value && instr_is_comptime(value)) {
11999 ZigValue *val = ir_resolve_const(ira, value, UndefOk);12013 ZigValue *val = ir_resolve_const(ira, value, UndefOk);
12000 if (!val)12014 if (!val)
...@@ -12007,7 +12021,8 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr...@@ -12007,7 +12021,8 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr
1200712021
12008 ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false);12022 ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false);
12009 if (instr_is_comptime(result_loc)) {12023 if (instr_is_comptime(result_loc)) {
12010 casted_ptr = ir_const(ira, suspend_source_instr, struct_ptr_type);12024 casted_ptr = ir_const(ira, suspend_source_instr->scope,
12025 suspend_source_instr->source_node, struct_ptr_type);
12011 copy_const_val(ira->codegen, casted_ptr->value, result_loc->value);12026 copy_const_val(ira->codegen, casted_ptr->value, result_loc->value);
12012 casted_ptr->value->type = struct_ptr_type;12027 casted_ptr->value->type = struct_ptr_type;
12013 } else {12028 } else {
...@@ -12034,7 +12049,8 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr...@@ -12034,7 +12049,8 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr
12034 }12049 }
12035 }12050 }
1203612051
12037 result_loc = ir_analyze_struct_field_ptr(ira, suspend_source_instr, field, casted_ptr,12052 result_loc = ir_analyze_struct_field_ptr(ira, suspend_source_instr->scope,
12053 suspend_source_instr->source_node, field, casted_ptr,
12038 isf->inferred_struct_type, true);12054 isf->inferred_struct_type, true);
12039 if (type_is_invalid(result_loc->value->type)) {12055 if (type_is_invalid(result_loc->value->type)) {
12040 return result_loc;12056 return result_loc;
...@@ -12046,7 +12062,7 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr...@@ -12046,7 +12062,7 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr
12046 return result_loc;12062 return result_loc;
12047 }12063 }
1204812064
12049 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr);12065 src_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr->source_node);
12050 ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type;12066 ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type;
12051 if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&12067 if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
12052 value_type->id != ZigTypeIdNull && value_type->id != ZigTypeIdUndefined)12068 value_type->id != ZigTypeIdNull && value_type->id != ZigTypeIdUndefined)
...@@ -12054,21 +12070,25 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr...@@ -12054,21 +12070,25 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr
12054 bool same_comptime_repr = types_have_same_zig_comptime_repr(ira->codegen, actual_elem_type, value_type);12070 bool same_comptime_repr = types_have_same_zig_comptime_repr(ira->codegen, actual_elem_type, value_type);
12055 if (!same_comptime_repr) {12071 if (!same_comptime_repr) {
12056 result_loc_pass1->written = was_written;12072 result_loc_pass1->written = was_written;
12057 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true);12073 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr->scope,
12074 suspend_source_instr->source_node, result_loc, false, true);
12058 }12075 }
12059 } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion &&12076 } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion &&
12060 value_type->id != ZigTypeIdUndefined)12077 value_type->id != ZigTypeIdUndefined)
12061 {12078 {
12062 if (value_type->id == ZigTypeIdErrorSet) {12079 if (value_type->id == ZigTypeIdErrorSet) {
12063 return ir_analyze_unwrap_err_code(ira, suspend_source_instr, result_loc, true);12080 return ir_analyze_unwrap_err_code(ira, suspend_source_instr->scope,
12081 suspend_source_instr->source_node, result_loc, true);
12064 } else {12082 } else {
12065 IrInstGen *unwrapped_err_ptr = ir_analyze_unwrap_error_payload(ira, suspend_source_instr,12083 IrInstGen *unwrapped_err_ptr = ir_analyze_unwrap_error_payload(ira,
12084 suspend_source_instr->scope, suspend_source_instr->source_node,
12066 result_loc, false, true);12085 result_loc, false, true);
12067 ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type;12086 ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type;
12068 if (actual_payload_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&12087 if (actual_payload_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
12069 value_type->id != ZigTypeIdNull && value_type->id != ZigTypeIdUndefined)12088 value_type->id != ZigTypeIdNull && value_type->id != ZigTypeIdUndefined)
12070 {12089 {
12071 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, unwrapped_err_ptr, false, true);12090 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr->scope,
12091 suspend_source_instr->source_node, unwrapped_err_ptr, false, true);
12072 } else {12092 } else {
12073 return unwrapped_err_ptr;12093 return unwrapped_err_ptr;
12074 }12094 }
...@@ -12095,17 +12115,17 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr...@@ -12095,17 +12115,17 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr
12095 if (implicit_elem_type == ira->codegen->builtin_types.entry_anytype) {12115 if (implicit_elem_type == ira->codegen->builtin_types.entry_anytype) {
12096 Buf *bare_name = buf_alloc();12116 Buf *bare_name = buf_alloc();
12097 Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct),12117 Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct),
12098 instruction->base.base.scope, instruction->base.base.source_node, bare_name);12118 instruction->base.scope, instruction->base.source_node, bare_name);
1209912119
12100 StructSpecial struct_special = StructSpecialInferredStruct;12120 StructSpecial struct_special = StructSpecialInferredStruct;
12101 if (instruction->base.base.source_node->type == NodeTypeContainerInitExpr &&12121 if (instruction->base.source_node->type == NodeTypeContainerInitExpr &&
12102 instruction->base.base.source_node->data.container_init_expr.kind == ContainerInitKindArray)12122 instruction->base.source_node->data.container_init_expr.kind == ContainerInitKindArray)
12103 {12123 {
12104 struct_special = StructSpecialInferredTuple;12124 struct_special = StructSpecialInferredTuple;
12105 }12125 }
1210612126
12107 ZigType *inferred_struct_type = get_partial_container_type(ira->codegen,12127 ZigType *inferred_struct_type = get_partial_container_type(ira->codegen,
12108 instruction->base.base.scope, ContainerKindStruct, instruction->base.base.source_node,12128 instruction->base.scope, ContainerKindStruct, instruction->base.source_node,
12109 buf_ptr(name), bare_name, ContainerLayoutAuto);12129 buf_ptr(name), bare_name, ContainerLayoutAuto);
12110 inferred_struct_type->data.structure.special = struct_special;12130 inferred_struct_type->data.structure.special = struct_special;
12111 inferred_struct_type->data.structure.resolve_status = ResolveStatusBeingInferred;12131 inferred_struct_type->data.structure.resolve_status = ResolveStatusBeingInferred;
...@@ -12116,7 +12136,7 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr...@@ -12116,7 +12136,7 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr
12116 if (type_is_invalid(implicit_elem_type))12136 if (type_is_invalid(implicit_elem_type))
12117 return ira->codegen->invalid_inst_gen;12137 return ira->codegen->invalid_inst_gen;
12118 }12138 }
12119 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,12139 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
12120 implicit_elem_type, nullptr, false, true);12140 implicit_elem_type, nullptr, false, true);
12121 if (result_loc != nullptr)12141 if (result_loc != nullptr)
12122 return result_loc;12142 return result_loc;
...@@ -12125,7 +12145,7 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr...@@ -12125,7 +12145,7 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr
12125 if (fn != nullptr && fn->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync &&12145 if (fn != nullptr && fn->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync &&
12126 instruction->result_loc->id == ResultLocIdReturn)12146 instruction->result_loc->id == ResultLocIdReturn)
12127 {12147 {
12128 result_loc = ir_resolve_result(ira, &instruction->base.base, no_result_loc(),12148 result_loc = ir_resolve_result(ira, &instruction->base, no_result_loc(),
12129 implicit_elem_type, nullptr, false, true);12149 implicit_elem_type, nullptr, false, true);
12130 if (result_loc != nullptr &&12150 if (result_loc != nullptr &&
12131 (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))12151 (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))
...@@ -12136,9 +12156,9 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr...@@ -12136,9 +12156,9 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr
12136 return result_loc;12156 return result_loc;
12137 }12157 }
1213812158
12139 IrInstGen *result = ir_const(ira, &instruction->base.base, implicit_elem_type);12159 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, implicit_elem_type);
12140 result->value->special = ConstValSpecialUndef;12160 result->value->special = ConstValSpecialUndef;
12141 IrInstGen *ptr = ir_get_ref(ira, &instruction->base.base, result, false, false);12161 IrInstGen *ptr = ir_get_ref(ira, instruction->base.scope, instruction->base.source_node, result, false, false);
12142 ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar;12162 ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar;
12143 return ptr;12163 return ptr;
12144}12164}
...@@ -12180,14 +12200,14 @@ static void ir_reset_result(ResultLoc *result_loc) {...@@ -12180,14 +12200,14 @@ static void ir_reset_result(ResultLoc *result_loc) {
1218012200
12181static IrInstGen *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInstSrcResetResult *instruction) {12201static IrInstGen *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInstSrcResetResult *instruction) {
12182 ir_reset_result(instruction->result_loc);12202 ir_reset_result(instruction->result_loc);
12183 return ir_const_void(ira, &instruction->base.base);12203 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
12184}12204}
1218512205
12186static IrInstGen *get_async_call_result_loc(IrAnalyze *ira, IrInst* source_instr,12206static IrInstGen *get_async_call_result_loc(IrAnalyze *ira, Scope *scope, AstNode *source_node,
12187 ZigType *fn_ret_type, bool is_async_call_builtin, IrInstGen **args_ptr, size_t args_len,12207 ZigType *fn_ret_type, bool is_async_call_builtin, IrInstGen **args_ptr, size_t args_len,
12188 IrInstGen *ret_ptr_uncasted)12208 IrInstGen *ret_ptr_uncasted)
12189{12209{
12190 ir_assert(is_async_call_builtin, source_instr);12210 src_assert(is_async_call_builtin, source_node);
12191 if (type_is_invalid(ret_ptr_uncasted->value->type))12211 if (type_is_invalid(ret_ptr_uncasted->value->type))
12192 return ira->codegen->invalid_inst_gen;12212 return ira->codegen->invalid_inst_gen;
12193 if (ret_ptr_uncasted->value->type->id == ZigTypeIdVoid) {12213 if (ret_ptr_uncasted->value->type->id == ZigTypeIdVoid) {
...@@ -12197,47 +12217,47 @@ static IrInstGen *get_async_call_result_loc(IrAnalyze *ira, IrInst* source_instr...@@ -12197,47 +12217,47 @@ static IrInstGen *get_async_call_result_loc(IrAnalyze *ira, IrInst* source_instr
12197 return ir_implicit_cast(ira, ret_ptr_uncasted, get_pointer_to_type(ira->codegen, fn_ret_type, false));12217 return ir_implicit_cast(ira, ret_ptr_uncasted, get_pointer_to_type(ira->codegen, fn_ret_type, false));
12198}12218}
1219912219
12200static IrInstGen *ir_analyze_async_call(IrAnalyze *ira, IrInst* source_instr, ZigFn *fn_entry,12220static IrInstGen *ir_analyze_async_call(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigFn *fn_entry,
12201 ZigType *fn_type, IrInstGen *fn_ref, IrInstGen **casted_args, size_t arg_count,12221 ZigType *fn_type, IrInstGen *fn_ref, IrInstGen **casted_args, size_t arg_count,
12202 IrInstGen *casted_new_stack, bool is_async_call_builtin, IrInstGen *ret_ptr_uncasted,12222 IrInstGen *casted_new_stack, bool is_async_call_builtin, IrInstGen *ret_ptr_uncasted,
12203 ResultLoc *call_result_loc)12223 ResultLoc *call_result_loc)
12204{12224{
12205 if (fn_entry == nullptr) {12225 if (fn_entry == nullptr) {
12206 if (fn_type->data.fn.fn_type_id.cc != CallingConventionAsync) {12226 if (fn_type->data.fn.fn_type_id.cc != CallingConventionAsync) {
12207 ir_add_error(ira, &fn_ref->base,12227 ir_add_error(ira, fn_ref,
12208 buf_sprintf("expected async function, found '%s'", buf_ptr(&fn_type->name)));12228 buf_sprintf("expected async function, found '%s'", buf_ptr(&fn_type->name)));
12209 return ira->codegen->invalid_inst_gen;12229 return ira->codegen->invalid_inst_gen;
12210 }12230 }
12211 if (casted_new_stack == nullptr) {12231 if (casted_new_stack == nullptr) {
12212 ir_add_error(ira, &fn_ref->base, buf_sprintf("function is not comptime-known; @asyncCall required"));12232 ir_add_error(ira, fn_ref, buf_sprintf("function is not comptime-known; @asyncCall required"));
12213 return ira->codegen->invalid_inst_gen;12233 return ira->codegen->invalid_inst_gen;
12214 }12234 }
12215 }12235 }
12216 if (casted_new_stack != nullptr) {12236 if (casted_new_stack != nullptr) {
12217 ZigType *fn_ret_type = fn_type->data.fn.fn_type_id.return_type;12237 ZigType *fn_ret_type = fn_type->data.fn.fn_type_id.return_type;
12218 IrInstGen *ret_ptr = get_async_call_result_loc(ira, source_instr, fn_ret_type, is_async_call_builtin,12238 IrInstGen *ret_ptr = get_async_call_result_loc(ira, scope, source_node, fn_ret_type, is_async_call_builtin,
12219 casted_args, arg_count, ret_ptr_uncasted);12239 casted_args, arg_count, ret_ptr_uncasted);
12220 if (ret_ptr != nullptr && type_is_invalid(ret_ptr->value->type))12240 if (ret_ptr != nullptr && type_is_invalid(ret_ptr->value->type))
12221 return ira->codegen->invalid_inst_gen;12241 return ira->codegen->invalid_inst_gen;
1222212242
12223 ZigType *anyframe_type = get_any_frame_type(ira->codegen, fn_ret_type);12243 ZigType *anyframe_type = get_any_frame_type(ira->codegen, fn_ret_type);
1222412244
12225 IrInstGenCall *call_gen = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref,12245 IrInstGenCall *call_gen = ir_build_call_gen(ira, scope, source_node, fn_entry, fn_ref,
12226 arg_count, casted_args, CallModifierAsync, casted_new_stack,12246 arg_count, casted_args, CallModifierAsync, casted_new_stack,
12227 is_async_call_builtin, ret_ptr, anyframe_type);12247 is_async_call_builtin, ret_ptr, anyframe_type);
12228 return &call_gen->base;12248 return &call_gen->base;
12229 } else {12249 } else {
12230 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry);12250 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry);
12231 IrInstGen *result_loc = ir_resolve_result(ira, source_instr, call_result_loc,12251 IrInstGen *result_loc = ir_resolve_result(ira, ira->suspend_source_instr, call_result_loc,
12232 frame_type, nullptr, true, false);12252 frame_type, nullptr, true, false);
12233 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {12253 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
12234 return result_loc;12254 return result_loc;
12235 }12255 }
12236 result_loc = ir_implicit_cast2(ira, source_instr, result_loc,12256 result_loc = ir_implicit_cast2(ira, scope, source_node, result_loc,
12237 get_pointer_to_type(ira->codegen, frame_type, false));12257 get_pointer_to_type(ira->codegen, frame_type, false));
12238 if (type_is_invalid(result_loc->value->type))12258 if (type_is_invalid(result_loc->value->type))
12239 return ira->codegen->invalid_inst_gen;12259 return ira->codegen->invalid_inst_gen;
12240 return &ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, arg_count,12260 return &ir_build_call_gen(ira, scope, source_node, fn_entry, fn_ref, arg_count,
12241 casted_args, CallModifierAsync, casted_new_stack,12261 casted_args, CallModifierAsync, casted_new_stack,
12242 is_async_call_builtin, result_loc, frame_type)->base;12262 is_async_call_builtin, result_loc, frame_type)->base;
12243 }12263 }
...@@ -12276,7 +12296,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node...@@ -12276,7 +12296,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
12276}12296}
1227712297
12278static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node,12298static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node,
12279 IrInstGen *arg, IrInst *arg_src, Scope **child_scope, size_t *next_proto_i,12299 IrInstGen *arg, AstNode *arg_src, Scope **child_scope, size_t *next_proto_i,
12280 GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstGen **casted_args,12300 GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstGen **casted_args,
12281 ZigFn *impl_fn)12301 ZigFn *impl_fn)
12282{12302{
...@@ -12298,7 +12318,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -12298,7 +12318,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
12298 if (type_is_invalid(param_type))12318 if (type_is_invalid(param_type))
12299 return false;12319 return false;
1230012320
12301 casted_arg = ir_implicit_cast2(ira, arg_src, arg, param_type);12321 casted_arg = ir_implicit_cast2(ira, arg->scope, arg_src, arg, param_type);
12302 if (type_is_invalid(casted_arg->value->type))12322 if (type_is_invalid(casted_arg->value->type))
12303 return false;12323 return false;
1230412324
...@@ -12326,7 +12346,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -12326,7 +12346,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
12326 ZigValue *arg_val;12346 ZigValue *arg_val;
1232712347
12328 if (comptime_arg && !instr_is_comptime(casted_arg)) {12348 if (comptime_arg && !instr_is_comptime(casted_arg)) {
12329 ir_add_error(ira, &casted_arg->base,12349 ir_add_error(ira, casted_arg,
12330 buf_sprintf("runtime value cannot be passed to comptime arg"));12350 buf_sprintf("runtime value cannot be passed to comptime arg"));
12331 return false;12351 return false;
12332 }12352 }
...@@ -12355,7 +12375,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -12355,7 +12375,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
12355 } else if (casted_arg->value->type->id == ZigTypeIdComptimeInt ||12375 } else if (casted_arg->value->type->id == ZigTypeIdComptimeInt ||
12356 casted_arg->value->type->id == ZigTypeIdComptimeFloat)12376 casted_arg->value->type->id == ZigTypeIdComptimeFloat)
12357 {12377 {
12358 ir_add_error(ira, &casted_arg->base,12378 ir_add_error(ira, casted_arg,
12359 buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557"));12379 buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557"));
12360 return false;12380 return false;
12361 }12381 }
...@@ -12372,7 +12392,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -12372,7 +12392,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
12372 return true;12392 return true;
12373}12393}
1237412394
12375static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var) {12395static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigVar *var) {
12376 while (var->next_var != nullptr) {12396 while (var->next_var != nullptr) {
12377 var = var->next_var;12397 var = var->next_var;
12378 }12398 }
...@@ -12391,7 +12411,7 @@ static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *v...@@ -12391,7 +12411,7 @@ static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *v
12391 bool comptime_var_mem = ir_get_var_is_comptime(var);12411 bool comptime_var_mem = ir_get_var_is_comptime(var);
12392 bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern;12412 bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern;
1239312413
12394 IrInstGen *result = ir_build_var_ptr_gen(ira, source_instr, var);12414 IrInstGen *result = ir_build_var_ptr_gen(ira, scope, source_node, var);
12395 result->value->type = var_ptr_type;12415 result->value->type = var_ptr_type;
1239612416
12397 if (!linkage_makes_it_runtime && !var->is_thread_local && value_is_comptime(var->const_value)) {12417 if (!linkage_makes_it_runtime && !var->is_thread_local && value_is_comptime(var->const_value)) {
...@@ -12427,20 +12447,20 @@ static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *v...@@ -12427,20 +12447,20 @@ static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *v
12427}12447}
1242812448
12429// This function is called when a comptime value becomes accessible at runtime.12449// This function is called when a comptime value becomes accessible at runtime.
12430static void mark_comptime_value_escape(IrAnalyze *ira, IrInst* source_instr, ZigValue *val) {12450static void mark_comptime_value_escape(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigValue *val) {
12431 ir_assert(value_is_comptime(val), source_instr);12451 src_assert(value_is_comptime(val), source_node);
12432 if (val->special == ConstValSpecialUndef)12452 if (val->special == ConstValSpecialUndef)
12433 return;12453 return;
1243412454
12435 if (val->type->id == ZigTypeIdFn && val->type->data.fn.fn_type_id.cc == CallingConventionUnspecified) {12455 if (val->type->id == ZigTypeIdFn && val->type->data.fn.fn_type_id.cc == CallingConventionUnspecified) {
12436 ir_assert(val->data.x_ptr.special == ConstPtrSpecialFunction, source_instr);12456 src_assert(val->data.x_ptr.special == ConstPtrSpecialFunction, source_node);
12437 if (val->data.x_ptr.data.fn.fn_entry->non_async_node == nullptr) {12457 if (val->data.x_ptr.data.fn.fn_entry->non_async_node == nullptr) {
12438 val->data.x_ptr.data.fn.fn_entry->non_async_node = source_instr->source_node;12458 val->data.x_ptr.data.fn.fn_entry->non_async_node = source_node;
12439 }12459 }
12440 }12460 }
12441}12461}
1244212462
12443static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,12463static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node,
12444 IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const)12464 IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const)
12445{12465{
12446 assert(ptr->value->type->id == ZigTypeIdPointer);12466 assert(ptr->value->type->id == ZigTypeIdPointer);
...@@ -12449,14 +12469,14 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,...@@ -12449,14 +12469,14 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
12449 if (uncasted_value->value->type->id == ZigTypeIdErrorUnion ||12469 if (uncasted_value->value->type->id == ZigTypeIdErrorUnion ||
12450 uncasted_value->value->type->id == ZigTypeIdErrorSet)12470 uncasted_value->value->type->id == ZigTypeIdErrorSet)
12451 {12471 {
12452 ir_add_error(ira, source_instr, buf_sprintf("error is discarded. consider using `try`, `catch`, or `if`"));12472 ir_add_error_node(ira, source_node, buf_sprintf("error is discarded. consider using `try`, `catch`, or `if`"));
12453 return ira->codegen->invalid_inst_gen;12473 return ira->codegen->invalid_inst_gen;
12454 }12474 }
12455 return ir_const_void(ira, source_instr);12475 return ir_const_void(ira, scope, source_node);
12456 }12476 }
1245712477
12458 if (ptr->value->type->data.pointer.is_const && !allow_write_through_const) {12478 if (ptr->value->type->data.pointer.is_const && !allow_write_through_const) {
12459 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));12479 ir_add_error_node(ira, source_node, buf_sprintf("cannot assign to constant"));
12460 return ira->codegen->invalid_inst_gen;12480 return ira->codegen->invalid_inst_gen;
12461 }12481 }
1246212482
...@@ -12469,14 +12489,14 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,...@@ -12469,14 +12489,14 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
12469 case OnePossibleValueInvalid:12489 case OnePossibleValueInvalid:
12470 return ira->codegen->invalid_inst_gen;12490 return ira->codegen->invalid_inst_gen;
12471 case OnePossibleValueYes:12491 case OnePossibleValueYes:
12472 return ir_const_void(ira, source_instr);12492 return ir_const_void(ira, scope, source_node);
12473 case OnePossibleValueNo:12493 case OnePossibleValueNo:
12474 break;12494 break;
12475 }12495 }
1247612496
12477 if (instr_is_comptime(ptr) && ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {12497 if (instr_is_comptime(ptr) && ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
12478 if (!allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) {12498 if (!allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) {
12479 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));12499 ir_add_error_node(ira, source_node, buf_sprintf("cannot assign to constant"));
12480 return ira->codegen->invalid_inst_gen;12500 return ira->codegen->invalid_inst_gen;
12481 }12501 }
12482 if ((allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) ||12502 if ((allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) ||
...@@ -12484,24 +12504,24 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,...@@ -12484,24 +12504,24 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
12484 ptr->value->data.x_ptr.mut == ConstPtrMutInfer)12504 ptr->value->data.x_ptr.mut == ConstPtrMutInfer)
12485 {12505 {
12486 if (instr_is_comptime(value)) {12506 if (instr_is_comptime(value)) {
12487 ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, ptr->value, source_instr->source_node);12507 ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, ptr->value, source_node);
12488 if (dest_val == nullptr)12508 if (dest_val == nullptr)
12489 return ira->codegen->invalid_inst_gen;12509 return ira->codegen->invalid_inst_gen;
12490 if (dest_val->special != ConstValSpecialRuntime) {12510 if (dest_val->special != ConstValSpecialRuntime) {
12491 copy_const_val(ira->codegen, dest_val, value->value);12511 copy_const_val(ira->codegen, dest_val, value->value);
1249212512
12493 if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar &&12513 if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar &&
12494 !ira->new_irb.current_basic_block->must_be_comptime_source_instr)12514 ira->new_irb.current_basic_block->must_be_comptime_source_node == nullptr)
12495 {12515 {
12496 ira->new_irb.current_basic_block->must_be_comptime_source_instr = source_instr;12516 ira->new_irb.current_basic_block->must_be_comptime_source_node = source_node;
12497 }12517 }
12498 return ir_const_void(ira, source_instr);12518 return ir_const_void(ira, scope, source_node);
12499 }12519 }
12500 }12520 }
12501 if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) {12521 if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) {
12502 ptr->value->special = ConstValSpecialRuntime;12522 ptr->value->special = ConstValSpecialRuntime;
12503 } else {12523 } else {
12504 ir_add_error(ira, source_instr,12524 ir_add_error_node(ira, source_node,
12505 buf_sprintf("cannot store runtime value in compile time variable"));12525 buf_sprintf("cannot store runtime value in compile time variable"));
12506 ZigValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, ptr->value);12526 ZigValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, ptr->value);
12507 dest_val->type = ira->codegen->builtin_types.entry_invalid;12527 dest_val->type = ira->codegen->builtin_types.entry_invalid;
...@@ -12525,11 +12545,11 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,...@@ -12525,11 +12545,11 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
12525 case OnePossibleValueInvalid:12545 case OnePossibleValueInvalid:
12526 return ira->codegen->invalid_inst_gen;12546 return ira->codegen->invalid_inst_gen;
12527 case OnePossibleValueNo:12547 case OnePossibleValueNo:
12528 ir_add_error(ira, source_instr,12548 ir_add_error_node(ira, source_node,
12529 buf_sprintf("cannot store runtime value in type '%s'", buf_ptr(&child_type->name)));12549 buf_sprintf("cannot store runtime value in type '%s'", buf_ptr(&child_type->name)));
12530 return ira->codegen->invalid_inst_gen;12550 return ira->codegen->invalid_inst_gen;
12531 case OnePossibleValueYes:12551 case OnePossibleValueYes:
12532 return ir_const_void(ira, source_instr);12552 return ir_const_void(ira, scope, source_node);
12533 }12553 }
12534 zig_unreachable();12554 zig_unreachable();
12535 case ReqCompTimeNo:12555 case ReqCompTimeNo:
...@@ -12537,7 +12557,7 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,...@@ -12537,7 +12557,7 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
12537 }12557 }
1253812558
12539 if (instr_is_comptime(value)) {12559 if (instr_is_comptime(value)) {
12540 mark_comptime_value_escape(ira, source_instr, value->value);12560 mark_comptime_value_escape(ira, scope, source_node, value->value);
12541 }12561 }
1254212562
12543 // If this is a store to a pointer with a runtime-known vector index,12563 // If this is a store to a pointer with a runtime-known vector index,
...@@ -12549,20 +12569,20 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,...@@ -12549,20 +12569,20 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
12549 if (ptr->value->type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {12569 if (ptr->value->type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {
12550 if (ptr->id == IrInstGenIdElemPtr) {12570 if (ptr->id == IrInstGenIdElemPtr) {
12551 IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr;12571 IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr;
12552 return ir_build_vector_store_elem(ira, source_instr, elem_ptr->array_ptr,12572 return ir_build_vector_store_elem(ira, scope, source_node, elem_ptr->array_ptr,
12553 elem_ptr->elem_index, value);12573 elem_ptr->elem_index, value);
12554 }12574 }
12555 ir_add_error(ira, &ptr->base,12575 ir_add_error(ira, ptr,
12556 buf_sprintf("unable to determine vector element index of type '%s'",12576 buf_sprintf("unable to determine vector element index of type '%s'",
12557 buf_ptr(&ptr->value->type->name)));12577 buf_ptr(&ptr->value->type->name)));
12558 return ira->codegen->invalid_inst_gen;12578 return ira->codegen->invalid_inst_gen;
12559 }12579 }
1256012580
12561 return ir_build_store_ptr_gen(ira, source_instr, ptr, value);12581 return ir_build_store_ptr_gen(ira, scope, source_node, ptr, value);
12562}12582}
1256312583
12564static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr,12584static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, Scope *scope, AstNode *source_node,
12565 IrInstGen *new_stack, IrInst *new_stack_src, bool is_async_call_builtin, ZigFn *fn_entry)12585 IrInstGen *new_stack, AstNode *new_stack_src, bool is_async_call_builtin, ZigFn *fn_entry)
12566{12586{
12567 if (new_stack == nullptr)12587 if (new_stack == nullptr)
12568 return nullptr;12588 return nullptr;
...@@ -12570,7 +12590,7 @@ static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr,...@@ -12570,7 +12590,7 @@ static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr,
12570 if (!is_async_call_builtin &&12590 if (!is_async_call_builtin &&
12571 arch_stack_pointer_register_name(ira->codegen->zig_target->arch) == nullptr)12591 arch_stack_pointer_register_name(ira->codegen->zig_target->arch) == nullptr)
12572 {12592 {
12573 ir_add_error(ira, source_instr,12593 ir_add_error_node(ira, source_node,
12574 buf_sprintf("target arch '%s' does not support calling with a new stack",12594 buf_sprintf("target arch '%s' does not support calling with a new stack",
12575 target_arch_name(ira->codegen->zig_target->arch)));12595 target_arch_name(ira->codegen->zig_target->arch)));
12576 }12596 }
...@@ -12591,14 +12611,14 @@ static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr,...@@ -12591,14 +12611,14 @@ static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr,
12591 false, false, PtrLenUnknown, required_align, 0, 0, false);12611 false, false, PtrLenUnknown, required_align, 0, 0, false);
12592 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);12612 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
12593 ira->codegen->need_frame_size_prefix_data = true;12613 ira->codegen->need_frame_size_prefix_data = true;
12594 return ir_implicit_cast2(ira, new_stack_src, new_stack, u8_slice);12614 return ir_implicit_cast2(ira, new_stack->scope, new_stack_src, new_stack, u8_slice);
12595 }12615 }
12596}12616}
1259712617
12598static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,12618static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, Scope *scope, AstNode *source_node,
12599 ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref,12619 ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref,
12600 IrInstGen *first_arg_ptr, IrInst *first_arg_ptr_src, CallModifier modifier,12620 IrInstGen *first_arg_ptr, AstNode *first_arg_ptr_src, CallModifier modifier,
12601 IrInstGen *new_stack, IrInst *new_stack_src, bool is_async_call_builtin,12621 IrInstGen *new_stack, AstNode *new_stack_src, bool is_async_call_builtin,
12602 IrInstGen **args_ptr, size_t args_len, IrInstGen *ret_ptr, ResultLoc *call_result_loc)12622 IrInstGen **args_ptr, size_t args_len, IrInstGen *ret_ptr, ResultLoc *call_result_loc)
12603{12623{
12604 Error err;12624 Error err;
...@@ -12615,12 +12635,11 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -12615,12 +12635,11 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
12615 }12635 }
12616 size_t src_param_count = fn_type_id->param_count - var_args_1_or_0;12636 size_t src_param_count = fn_type_id->param_count - var_args_1_or_0;
12617 size_t call_param_count = args_len + first_arg_1_or_0;12637 size_t call_param_count = args_len + first_arg_1_or_0;
12618 AstNode *source_node = source_instr->source_node;
1261912638
12620 AstNode *fn_proto_node = fn_entry ? fn_entry->proto_node : nullptr;;12639 AstNode *fn_proto_node = fn_entry ? fn_entry->proto_node : nullptr;;
1262112640
12622 if (fn_type_id->cc == CallingConventionNaked) {12641 if (fn_type_id->cc == CallingConventionNaked) {
12623 ErrorMsg *msg = ir_add_error(ira, &fn_ref->base, buf_sprintf("unable to call function with naked calling convention"));12642 ErrorMsg *msg = ir_add_error(ira, fn_ref, buf_sprintf("unable to call function with naked calling convention"));
12624 if (fn_proto_node) {12643 if (fn_proto_node) {
12625 add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("declared here"));12644 add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("declared here"));
12626 }12645 }
...@@ -12652,25 +12671,25 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -12652,25 +12671,25 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
12652 if (modifier == CallModifierCompileTime) {12671 if (modifier == CallModifierCompileTime) {
12653 // If we are evaluating an extern function in a TypeOf call, we can return an undefined value12672 // If we are evaluating an extern function in a TypeOf call, we can return an undefined value
12654 // of its return type.12673 // of its return type.
12655 if (fn_entry != nullptr && get_scope_typeof(source_instr->scope) != nullptr &&12674 if (fn_entry != nullptr && get_scope_typeof(scope) != nullptr &&
12656 fn_proto_node->data.fn_proto.is_extern) {12675 fn_proto_node->data.fn_proto.is_extern) {
1265712676
12658 assert(fn_entry->body_node == nullptr);12677 assert(fn_entry->body_node == nullptr);
12659 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;12678 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
12660 ZigType *return_type = ir_analyze_type_expr(ira, source_instr->scope, return_type_node);12679 ZigType *return_type = ir_analyze_type_expr(ira, scope, return_type_node);
12661 if (type_is_invalid(return_type))12680 if (type_is_invalid(return_type))
12662 return ira->codegen->invalid_inst_gen;12681 return ira->codegen->invalid_inst_gen;
1266312682
12664 return ir_const_undef(ira, source_instr, return_type);12683 return ir_const_undef(ira, scope, source_node, return_type);
12665 }12684 }
1266612685
12667 // No special handling is needed for compile time evaluation of generic functions.12686 // No special handling is needed for compile time evaluation of generic functions.
12668 if (!fn_entry || fn_entry->body_node == nullptr) {12687 if (!fn_entry || fn_entry->body_node == nullptr) {
12669 ir_add_error(ira, &fn_ref->base, buf_sprintf("unable to evaluate constant expression"));12688 ir_add_error(ira, fn_ref, buf_sprintf("unable to evaluate constant expression"));
12670 return ira->codegen->invalid_inst_gen;12689 return ira->codegen->invalid_inst_gen;
12671 }12690 }
1267212691
12673 if (!ir_emit_backward_branch(ira, source_instr))12692 if (!ir_emit_backward_branch(ira, source_node))
12674 return ira->codegen->invalid_inst_gen;12693 return ira->codegen->invalid_inst_gen;
1267512694
12676 // Fork a scope of the function with known values for the parameters.12695 // Fork a scope of the function with known values for the parameters.
...@@ -12692,7 +12711,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -12692,7 +12711,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
12692 if (!first_arg_known_bare) {12711 if (!first_arg_known_bare) {
12693 first_arg = first_arg_ptr;12712 first_arg = first_arg_ptr;
12694 } else {12713 } else {
12695 first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr);12714 first_arg = ir_get_deref(ira, first_arg_ptr->scope, first_arg_ptr->source_node, first_arg_ptr, nullptr);
12696 if (type_is_invalid(first_arg->value->type))12715 if (type_is_invalid(first_arg->value->type))
12697 return ira->codegen->invalid_inst_gen;12716 return ira->codegen->invalid_inst_gen;
12698 }12717 }
...@@ -12710,7 +12729,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -12710,7 +12729,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1271012729
12711 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;12730 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
12712 if (return_type_node == nullptr) {12731 if (return_type_node == nullptr) {
12713 ir_add_error(ira, &fn_ref->base,12732 ir_add_error(ira, fn_ref,
12714 buf_sprintf("TODO implement inferred return types https://github.com/ziglang/zig/issues/447"));12733 buf_sprintf("TODO implement inferred return types https://github.com/ziglang/zig/issues/447"));
12715 return ira->codegen->invalid_inst_gen;12734 return ira->codegen->invalid_inst_gen;
12716 }12735 }
...@@ -12744,7 +12763,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -12744,7 +12763,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1274412763
12745 if ((err = ir_eval_const_value(ira->codegen, exec_scope, body_node, result_ptr,12764 if ((err = ir_eval_const_value(ira->codegen, exec_scope, body_node, result_ptr,
12746 ira->backward_branch_count, ira->backward_branch_quota,12765 ira->backward_branch_count, ira->backward_branch_quota,
12747 fn_entry, nullptr, source_instr->source_node, nullptr, ira->new_irb.exec, return_type_node,12766 fn_entry, nullptr, source_node, nullptr, ira->new_irb.exec, return_type_node,
12748 UndefOk)))12767 UndefOk)))
12749 {12768 {
12750 return ira->codegen->invalid_inst_gen;12769 return ira->codegen->invalid_inst_gen;
...@@ -12777,13 +12796,13 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -12777,13 +12796,13 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
12777 }12796 }
12778 }12797 }
1277912798
12780 IrInstGen *new_instruction = ir_const_move(ira, source_instr, result);12799 IrInstGen *new_instruction = ir_const_move(ira, scope, source_node, result);
12781 return ir_finish_anal(ira, new_instruction);12800 return ir_finish_anal(ira, new_instruction);
12782 }12801 }
1278312802
12784 if (fn_type->data.fn.is_generic) {12803 if (fn_type->data.fn.is_generic) {
12785 if (!fn_entry) {12804 if (!fn_entry) {
12786 ir_add_error(ira, &fn_ref->base,12805 ir_add_error(ira, fn_ref,
12787 buf_sprintf("calling a generic function requires compile-time known function value"));12806 buf_sprintf("calling a generic function requires compile-time known function value"));
12788 return ira->codegen->invalid_inst_gen;12807 return ira->codegen->invalid_inst_gen;
12789 }12808 }
...@@ -12827,7 +12846,8 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -12827,7 +12846,8 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
12827 if (!first_arg_known_bare) {12846 if (!first_arg_known_bare) {
12828 first_arg = first_arg_ptr;12847 first_arg = first_arg_ptr;
12829 } else {12848 } else {
12830 first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr);12849 first_arg = ir_get_deref(ira, first_arg_ptr->scope, first_arg_ptr->source_node,
12850 first_arg_ptr, nullptr);
12831 if (type_is_invalid(first_arg->value->type))12851 if (type_is_invalid(first_arg->value->type))
12832 return ira->codegen->invalid_inst_gen;12852 return ira->codegen->invalid_inst_gen;
12833 }12853 }
...@@ -12847,7 +12867,8 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -12847,7 +12867,8 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
12847 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);12867 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);
12848 assert(param_decl_node->type == NodeTypeParamDecl);12868 assert(param_decl_node->type == NodeTypeParamDecl);
1284912869
12850 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &arg->base, &impl_fn->child_scope,12870 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, arg->source_node,
12871 &impl_fn->child_scope,
12851 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))12872 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))
12852 {12873 {
12853 return ira->codegen->invalid_inst_gen;12874 return ira->codegen->invalid_inst_gen;
...@@ -12882,7 +12903,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -12882,7 +12903,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
12882 return ira->codegen->invalid_inst_gen;12903 return ira->codegen->invalid_inst_gen;
1288312904
12884 if(!is_valid_return_type(specified_return_type)){12905 if(!is_valid_return_type(specified_return_type)){
12885 ErrorMsg *msg = ir_add_error(ira, source_instr,12906 ErrorMsg *msg = ir_add_error_node(ira, source_node,
12886 buf_sprintf("call to generic function with %s return type '%s' not allowed", type_id_name(specified_return_type->id), buf_ptr(&specified_return_type->name)));12907 buf_sprintf("call to generic function with %s return type '%s' not allowed", type_id_name(specified_return_type->id), buf_ptr(&specified_return_type->name)));
12887 add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("function declared here"));12908 add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("function declared here"));
1288812909
...@@ -12905,7 +12926,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -12905,7 +12926,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
12905 switch (type_requires_comptime(ira->codegen, specified_return_type)) {12926 switch (type_requires_comptime(ira->codegen, specified_return_type)) {
12906 case ReqCompTimeYes:12927 case ReqCompTimeYes:
12907 // Throw out our work and call the function as if it were comptime.12928 // Throw out our work and call the function as if it were comptime.
12908 return ir_analyze_fn_call(ira, source_instr, fn_entry, fn_type, fn_ref, first_arg_ptr,12929 return ir_analyze_fn_call(ira, scope, source_node, fn_entry, fn_type, fn_ref, first_arg_ptr,
12909 first_arg_ptr_src, CallModifierCompileTime, new_stack, new_stack_src, is_async_call_builtin,12930 first_arg_ptr_src, CallModifierCompileTime, new_stack, new_stack_src, is_async_call_builtin,
12910 args_ptr, args_len, ret_ptr, call_result_loc);12931 args_ptr, args_len, ret_ptr, call_result_loc);
12911 case ReqCompTimeInvalid:12932 case ReqCompTimeInvalid:
...@@ -12924,7 +12945,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -12924,7 +12945,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
12924 if (type_is_invalid(impl_fn->type_entry))12945 if (type_is_invalid(impl_fn->type_entry))
12925 return ira->codegen->invalid_inst_gen;12946 return ira->codegen->invalid_inst_gen;
1292612947
12927 impl_fn->analyzed_executable.source_node = source_instr->source_node;12948 impl_fn->analyzed_executable.source_node = source_node;
12928 impl_fn->analyzed_executable.parent_exec = ira->new_irb.exec;12949 impl_fn->analyzed_executable.parent_exec = ira->new_irb.exec;
12929 impl_fn->branch_quota = *ira->backward_branch_quota;12950 impl_fn->branch_quota = *ira->backward_branch_quota;
1293012951
...@@ -12937,14 +12958,14 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -12937,14 +12958,14 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
12937 parent_fn_entry->calls_or_awaits_errorable_fn = true;12958 parent_fn_entry->calls_or_awaits_errorable_fn = true;
12938 }12959 }
1293912960
12940 IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack,12961 IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, scope, source_node, new_stack,
12941 new_stack_src, is_async_call_builtin, impl_fn);12962 new_stack_src, is_async_call_builtin, impl_fn);
12942 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))12963 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))
12943 return ira->codegen->invalid_inst_gen;12964 return ira->codegen->invalid_inst_gen;
1294412965
12945 size_t impl_param_count = impl_fn_type_id->param_count;12966 size_t impl_param_count = impl_fn_type_id->param_count;
12946 if (modifier == CallModifierAsync) {12967 if (modifier == CallModifierAsync) {
12947 IrInstGen *result = ir_analyze_async_call(ira, source_instr, impl_fn, impl_fn->type_entry,12968 IrInstGen *result = ir_analyze_async_call(ira, scope, source_node, impl_fn, impl_fn->type_entry,
12948 nullptr, casted_args, impl_param_count, casted_new_stack, is_async_call_builtin, ret_ptr,12969 nullptr, casted_args, impl_param_count, casted_new_stack, is_async_call_builtin, ret_ptr,
12949 call_result_loc);12970 call_result_loc);
12950 return ir_finish_anal(ira, result);12971 return ir_finish_anal(ira, result);
...@@ -12952,20 +12973,20 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -12952,20 +12973,20 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1295212973
12953 IrInstGen *result_loc;12974 IrInstGen *result_loc;
12954 if (handle_is_ptr(ira->codegen, impl_fn_type_id->return_type)) {12975 if (handle_is_ptr(ira->codegen, impl_fn_type_id->return_type)) {
12955 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,12976 result_loc = ir_resolve_result(ira, ira->suspend_source_instr, call_result_loc,
12956 impl_fn_type_id->return_type, nullptr, true, false);12977 impl_fn_type_id->return_type, nullptr, true, false);
12957 if (result_loc != nullptr) {12978 if (result_loc != nullptr) {
12958 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {12979 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
12959 return result_loc;12980 return result_loc;
12960 }12981 }
12961 if (result_loc->value->type->data.pointer.is_const) {12982 if (result_loc->value->type->data.pointer.is_const) {
12962 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));12983 ir_add_error_node(ira, source_node, buf_sprintf("cannot assign to constant"));
12963 return ira->codegen->invalid_inst_gen;12984 return ira->codegen->invalid_inst_gen;
12964 }12985 }
1296512986
12966 IrInstGen *dummy_value = ir_const(ira, source_instr, impl_fn_type_id->return_type);12987 IrInstGen *dummy_value = ir_const(ira, scope, source_node, impl_fn_type_id->return_type);
12967 dummy_value->value->special = ConstValSpecialRuntime;12988 dummy_value->value->special = ConstValSpecialRuntime;
12968 IrInstGen *dummy_result = ir_implicit_cast2(ira, source_instr,12989 IrInstGen *dummy_result = ir_implicit_cast2(ira, scope, source_node,
12969 dummy_value, result_loc->value->type->data.pointer.child_type);12990 dummy_value, result_loc->value->type->data.pointer.child_type);
12970 if (type_is_invalid(dummy_result->value->type))12991 if (type_is_invalid(dummy_result->value->type))
12971 return ira->codegen->invalid_inst_gen;12992 return ira->codegen->invalid_inst_gen;
...@@ -12979,7 +13000,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -12979,7 +13000,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
12979 }13000 }
12980 }13001 }
12981 } else if (is_async_call_builtin) {13002 } else if (is_async_call_builtin) {
12982 result_loc = get_async_call_result_loc(ira, source_instr, impl_fn_type_id->return_type,13003 result_loc = get_async_call_result_loc(ira, scope, source_node, impl_fn_type_id->return_type,
12983 is_async_call_builtin, args_ptr, args_len, ret_ptr);13004 is_async_call_builtin, args_ptr, args_len, ret_ptr);
12984 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))13005 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))
12985 return ira->codegen->invalid_inst_gen;13006 return ira->codegen->invalid_inst_gen;
...@@ -12991,15 +13012,15 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -12991,15 +13012,15 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
12991 parent_fn_entry->inferred_async_node == nullptr &&13012 parent_fn_entry->inferred_async_node == nullptr &&
12992 modifier != CallModifierNoSuspend)13013 modifier != CallModifierNoSuspend)
12993 {13014 {
12994 parent_fn_entry->inferred_async_node = fn_ref->base.source_node;13015 parent_fn_entry->inferred_async_node = fn_ref->source_node;
12995 parent_fn_entry->inferred_async_fn = impl_fn;13016 parent_fn_entry->inferred_async_fn = impl_fn;
12996 }13017 }
1299713018
12998 IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, source_instr,13019 IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, scope, source_node,
12999 impl_fn, nullptr, impl_param_count, casted_args, modifier, casted_new_stack,13020 impl_fn, nullptr, impl_param_count, casted_args, modifier, casted_new_stack,
13000 is_async_call_builtin, result_loc, impl_fn_type_id->return_type);13021 is_async_call_builtin, result_loc, impl_fn_type_id->return_type);
1300113022
13002 if (get_scope_typeof(source_instr->scope) == nullptr) {13023 if (get_scope_typeof(scope) == nullptr) {
13003 parent_fn_entry->call_list.append(new_call_instruction);13024 parent_fn_entry->call_list.append(new_call_instruction);
13004 }13025 }
1300513026
...@@ -13027,12 +13048,13 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -13027,12 +13048,13 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
13027 if (param_type->id == ZigTypeIdPointer) {13048 if (param_type->id == ZigTypeIdPointer) {
13028 first_arg = first_arg_ptr;13049 first_arg = first_arg_ptr;
13029 } else {13050 } else {
13030 first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr);13051 first_arg = ir_get_deref(ira, first_arg_ptr->scope, first_arg_ptr->source_node,
13052 first_arg_ptr, nullptr);
13031 if (type_is_invalid(first_arg->value->type))13053 if (type_is_invalid(first_arg->value->type))
13032 return ira->codegen->invalid_inst_gen;13054 return ira->codegen->invalid_inst_gen;
13033 }13055 }
1303413056
13035 IrInstGen *casted_arg = ir_implicit_cast2(ira, first_arg_ptr_src, first_arg, param_type);13057 IrInstGen *casted_arg = ir_implicit_cast2(ira, first_arg->scope, first_arg_ptr_src, first_arg, param_type);
13036 if (type_is_invalid(casted_arg->value->type))13058 if (type_is_invalid(casted_arg->value->type))
13037 return ira->codegen->invalid_inst_gen;13059 return ira->codegen->invalid_inst_gen;
1303813060
...@@ -13067,18 +13089,18 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -13067,18 +13089,18 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
13067 return ira->codegen->invalid_inst_gen;13089 return ira->codegen->invalid_inst_gen;
1306813090
13069 if (fn_entry != nullptr && fn_type_id->cc == CallingConventionInline && modifier == CallModifierNeverInline) {13091 if (fn_entry != nullptr && fn_type_id->cc == CallingConventionInline && modifier == CallModifierNeverInline) {
13070 ir_add_error(ira, source_instr,13092 ir_add_error_node(ira, source_node,
13071 buf_sprintf("no-inline call of inline function"));13093 buf_sprintf("no-inline call of inline function"));
13072 return ira->codegen->invalid_inst_gen;13094 return ira->codegen->invalid_inst_gen;
13073 }13095 }
1307413096
13075 IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack, new_stack_src,13097 IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, scope, source_node, new_stack, new_stack_src,
13076 is_async_call_builtin, fn_entry);13098 is_async_call_builtin, fn_entry);
13077 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))13099 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))
13078 return ira->codegen->invalid_inst_gen;13100 return ira->codegen->invalid_inst_gen;
1307913101
13080 if (modifier == CallModifierAsync) {13102 if (modifier == CallModifierAsync) {
13081 IrInstGen *result = ir_analyze_async_call(ira, source_instr, fn_entry, fn_type, fn_ref,13103 IrInstGen *result = ir_analyze_async_call(ira, scope, source_node, fn_entry, fn_type, fn_ref,
13082 casted_args, call_param_count, casted_new_stack, is_async_call_builtin, ret_ptr, call_result_loc);13104 casted_args, call_param_count, casted_new_stack, is_async_call_builtin, ret_ptr, call_result_loc);
13083 return ir_finish_anal(ira, result);13105 return ir_finish_anal(ira, result);
13084 }13106 }
...@@ -13087,28 +13109,28 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -13087,28 +13109,28 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
13087 parent_fn_entry->inferred_async_node == nullptr &&13109 parent_fn_entry->inferred_async_node == nullptr &&
13088 modifier != CallModifierNoSuspend)13110 modifier != CallModifierNoSuspend)
13089 {13111 {
13090 parent_fn_entry->inferred_async_node = fn_ref->base.source_node;13112 parent_fn_entry->inferred_async_node = fn_ref->source_node;
13091 parent_fn_entry->inferred_async_fn = fn_entry;13113 parent_fn_entry->inferred_async_fn = fn_entry;
13092 }13114 }
1309313115
13094 IrInstGen *result_loc;13116 IrInstGen *result_loc;
13095 if (handle_is_ptr(ira->codegen, return_type)) {13117 if (handle_is_ptr(ira->codegen, return_type)) {
13096 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,13118 result_loc = ir_resolve_result(ira, ira->suspend_source_instr, call_result_loc,
13097 return_type, nullptr, true, false);13119 return_type, nullptr, true, false);
13098 if (result_loc != nullptr) {13120 if (result_loc != nullptr) {
13099 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {13121 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
13100 return result_loc;13122 return result_loc;
13101 }13123 }
13102 if (result_loc->value->type->data.pointer.is_const) {13124 if (result_loc->value->type->data.pointer.is_const) {
13103 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));13125 ir_add_error_node(ira, source_node, buf_sprintf("cannot assign to constant"));
13104 return ira->codegen->invalid_inst_gen;13126 return ira->codegen->invalid_inst_gen;
13105 }13127 }
1310613128
13107 ZigType *expected_return_type = result_loc->value->type->data.pointer.child_type;13129 ZigType *expected_return_type = result_loc->value->type->data.pointer.child_type;
1310813130
13109 IrInstGen *dummy_value = ir_const(ira, source_instr, return_type);13131 IrInstGen *dummy_value = ir_const(ira, scope, source_node, return_type);
13110 dummy_value->value->special = ConstValSpecialRuntime;13132 dummy_value->value->special = ConstValSpecialRuntime;
13111 IrInstGen *dummy_result = ir_implicit_cast2(ira, source_instr,13133 IrInstGen *dummy_result = ir_implicit_cast2(ira, scope, source_node,
13112 dummy_value, expected_return_type);13134 dummy_value, expected_return_type);
13113 if (type_is_invalid(dummy_result->value->type)) {13135 if (type_is_invalid(dummy_result->value->type)) {
13114 if ((return_type->id == ZigTypeIdErrorUnion || return_type->id == ZigTypeIdErrorSet) &&13136 if ((return_type->id == ZigTypeIdErrorUnion || return_type->id == ZigTypeIdErrorSet) &&
...@@ -13118,7 +13140,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -13118,7 +13140,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
13118 add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg,13140 add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg,
13119 ira->explicit_return_type_source_node, buf_sprintf("function cannot return an error"));13141 ira->explicit_return_type_source_node, buf_sprintf("function cannot return an error"));
13120 } else {13142 } else {
13121 add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg, result_loc->base.source_node,13143 add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg, result_loc->source_node,
13122 buf_sprintf("cannot store an error in type '%s'", buf_ptr(&expected_return_type->name)));13144 buf_sprintf("cannot store an error in type '%s'", buf_ptr(&expected_return_type->name)));
13123 }13145 }
13124 }13146 }
...@@ -13133,7 +13155,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -13133,7 +13155,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
13133 }13155 }
13134 }13156 }
13135 } else if (is_async_call_builtin) {13157 } else if (is_async_call_builtin) {
13136 result_loc = get_async_call_result_loc(ira, source_instr, return_type, is_async_call_builtin,13158 result_loc = get_async_call_result_loc(ira, scope, source_node, return_type, is_async_call_builtin,
13137 args_ptr, args_len, ret_ptr);13159 args_ptr, args_len, ret_ptr);
13138 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))13160 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))
13139 return ira->codegen->invalid_inst_gen;13161 return ira->codegen->invalid_inst_gen;
...@@ -13141,10 +13163,10 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -13141,10 +13163,10 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
13141 result_loc = nullptr;13163 result_loc = nullptr;
13142 }13164 }
1314313165
13144 IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref,13166 IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, scope, source_node, fn_entry, fn_ref,
13145 call_param_count, casted_args, modifier, casted_new_stack,13167 call_param_count, casted_args, modifier, casted_new_stack,
13146 is_async_call_builtin, result_loc, return_type);13168 is_async_call_builtin, result_loc, return_type);
13147 if (get_scope_typeof(source_instr->scope) == nullptr) {13169 if (get_scope_typeof(scope) == nullptr) {
13148 parent_fn_entry->call_list.append(new_call_instruction);13170 parent_fn_entry->call_list.append(new_call_instruction);
13149 }13171 }
13150 return ir_finish_anal(ira, &new_call_instruction->base);13172 return ir_finish_anal(ira, &new_call_instruction->base);
...@@ -13152,15 +13174,15 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -13152,15 +13174,15 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1315213174
13153static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_instruction,13175static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_instruction,
13154 ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref,13176 ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref,
13155 IrInstGen *first_arg_ptr, IrInst *first_arg_ptr_src, CallModifier modifier)13177 IrInstGen *first_arg_ptr, AstNode *first_arg_ptr_src, CallModifier modifier)
13156{13178{
13157 IrInstGen *new_stack = nullptr;13179 IrInstGen *new_stack = nullptr;
13158 IrInst *new_stack_src = nullptr;13180 AstNode *new_stack_src = nullptr;
13159 if (call_instruction->new_stack) {13181 if (call_instruction->new_stack) {
13160 new_stack = call_instruction->new_stack->child;13182 new_stack = call_instruction->new_stack->child;
13161 if (type_is_invalid(new_stack->value->type))13183 if (type_is_invalid(new_stack->value->type))
13162 return ira->codegen->invalid_inst_gen;13184 return ira->codegen->invalid_inst_gen;
13163 new_stack_src = &call_instruction->new_stack->base;13185 new_stack_src = call_instruction->new_stack->source_node;
13164 }13186 }
13165 IrInstGen **args_ptr = heap::c_allocator.allocate<IrInstGen *>(call_instruction->arg_count);13187 IrInstGen **args_ptr = heap::c_allocator.allocate<IrInstGen *>(call_instruction->arg_count);
13166 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {13188 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
...@@ -13174,7 +13196,8 @@ static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_ins...@@ -13174,7 +13196,8 @@ static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_ins
13174 if (type_is_invalid(ret_ptr->value->type))13196 if (type_is_invalid(ret_ptr->value->type))
13175 return ira->codegen->invalid_inst_gen;13197 return ira->codegen->invalid_inst_gen;
13176 }13198 }
13177 IrInstGen *result = ir_analyze_fn_call(ira, &call_instruction->base.base, fn_entry, fn_type, fn_ref,13199 IrInstGen *result = ir_analyze_fn_call(ira, call_instruction->base.scope,
13200 call_instruction->base.source_node, fn_entry, fn_type, fn_ref,
13178 first_arg_ptr, first_arg_ptr_src, modifier, new_stack, new_stack_src,13201 first_arg_ptr, first_arg_ptr_src, modifier, new_stack, new_stack_src,
13179 call_instruction->is_async_call_builtin, args_ptr, call_instruction->arg_count, ret_ptr,13202 call_instruction->is_async_call_builtin, args_ptr, call_instruction->arg_count, ret_ptr,
13180 call_instruction->result_loc);13203 call_instruction->result_loc);
...@@ -13182,7 +13205,7 @@ static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_ins...@@ -13182,7 +13205,7 @@ static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_ins
13182 return result;13205 return result;
13183}13206}
1318413207
13185static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,13208static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, Scope *scope, AstNode *source_node,
13186 IrInstSrc *pass1_options, IrInstSrc *pass1_fn_ref, IrInstGen **args_ptr, size_t args_len,13209 IrInstSrc *pass1_options, IrInstSrc *pass1_fn_ref, IrInstGen **args_ptr, size_t args_len,
13187 ResultLoc *result_loc)13210 ResultLoc *result_loc)
13188{13211{
...@@ -13195,19 +13218,19 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,...@@ -13195,19 +13218,19 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,
13195 return ira->codegen->invalid_inst_gen;13218 return ira->codegen->invalid_inst_gen;
1319613219
13197 TypeStructField *modifier_field = find_struct_type_field(options->value->type, buf_create_from_str("modifier"));13220 TypeStructField *modifier_field = find_struct_type_field(options->value->type, buf_create_from_str("modifier"));
13198 ir_assert(modifier_field != nullptr, source_instr);13221 src_assert(modifier_field != nullptr, source_node);
13199 IrInstGen *modifier_inst = ir_analyze_struct_value_field_value(ira, source_instr, options, modifier_field);13222 IrInstGen *modifier_inst = ir_analyze_struct_value_field_value(ira, scope, source_node, options, modifier_field);
13200 ZigValue *modifier_val = ir_resolve_const(ira, modifier_inst, UndefBad);13223 ZigValue *modifier_val = ir_resolve_const(ira, modifier_inst, UndefBad);
13201 if (modifier_val == nullptr)13224 if (modifier_val == nullptr)
13202 return ira->codegen->invalid_inst_gen;13225 return ira->codegen->invalid_inst_gen;
13203 CallModifier modifier = (CallModifier)bigint_as_u32(&modifier_val->data.x_enum_tag);13226 CallModifier modifier = (CallModifier)bigint_as_u32(&modifier_val->data.x_enum_tag);
1320413227
13205 if (ir_should_inline(ira->zir, source_instr->scope)) {13228 if (ir_should_inline(ira->zir, scope)) {
13206 switch (modifier) {13229 switch (modifier) {
13207 case CallModifierBuiltin:13230 case CallModifierBuiltin:
13208 zig_unreachable();13231 zig_unreachable();
13209 case CallModifierAsync:13232 case CallModifierAsync:
13210 ir_add_error(ira, source_instr, buf_sprintf("TODO: comptime @call with async modifier"));13233 ir_add_error_node(ira, source_node, buf_sprintf("TODO: comptime @call with async modifier"));
13211 return ira->codegen->invalid_inst_gen;13234 return ira->codegen->invalid_inst_gen;
13212 case CallModifierCompileTime:13235 case CallModifierCompileTime:
13213 case CallModifierNone:13236 case CallModifierNone:
...@@ -13217,18 +13240,18 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,...@@ -13217,18 +13240,18 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,
13217 modifier = CallModifierCompileTime;13240 modifier = CallModifierCompileTime;
13218 break;13241 break;
13219 case CallModifierNeverInline:13242 case CallModifierNeverInline:
13220 ir_add_error(ira, source_instr,13243 ir_add_error_node(ira, source_node,
13221 buf_sprintf("unable to perform 'never_inline' call at compile-time"));13244 buf_sprintf("unable to perform 'never_inline' call at compile-time"));
13222 return ira->codegen->invalid_inst_gen;13245 return ira->codegen->invalid_inst_gen;
13223 case CallModifierNeverTail:13246 case CallModifierNeverTail:
13224 ir_add_error(ira, source_instr,13247 ir_add_error_node(ira, source_node,
13225 buf_sprintf("unable to perform 'never_tail' call at compile-time"));13248 buf_sprintf("unable to perform 'never_tail' call at compile-time"));
13226 return ira->codegen->invalid_inst_gen;13249 return ira->codegen->invalid_inst_gen;
13227 }13250 }
13228 }13251 }
1322913252
13230 IrInstGen *first_arg_ptr = nullptr;13253 IrInstGen *first_arg_ptr = nullptr;
13231 IrInst *first_arg_ptr_src = nullptr;13254 AstNode *first_arg_ptr_src = nullptr;
13232 ZigFn *fn = nullptr;13255 ZigFn *fn = nullptr;
13233 if (instr_is_comptime(fn_ref)) {13256 if (instr_is_comptime(fn_ref)) {
13234 if (fn_ref->value->type->id == ZigTypeIdBoundFn) {13257 if (fn_ref->value->type->id == ZigTypeIdBoundFn) {
...@@ -13249,7 +13272,7 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,...@@ -13249,7 +13272,7 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,
13249 case CallModifierAlwaysInline:13272 case CallModifierAlwaysInline:
13250 case CallModifierAsync:13273 case CallModifierAsync:
13251 if (fn == nullptr) {13274 if (fn == nullptr) {
13252 ir_add_error(ira, &modifier_inst->base,13275 ir_add_error(ira, modifier_inst,
13253 buf_sprintf("the specified modifier requires a comptime-known function"));13276 buf_sprintf("the specified modifier requires a comptime-known function"));
13254 return ira->codegen->invalid_inst_gen;13277 return ira->codegen->invalid_inst_gen;
13255 }13278 }
...@@ -13261,43 +13284,43 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,...@@ -13261,43 +13284,43 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,
13261 ZigType *fn_type = (fn != nullptr) ? fn->type_entry : fn_ref->value->type;13284 ZigType *fn_type = (fn != nullptr) ? fn->type_entry : fn_ref->value->type;
1326213285
13263 TypeStructField *stack_field = find_struct_type_field(options->value->type, buf_create_from_str("stack"));13286 TypeStructField *stack_field = find_struct_type_field(options->value->type, buf_create_from_str("stack"));
13264 ir_assert(stack_field != nullptr, source_instr);13287 src_assert(stack_field != nullptr, source_node);
13265 IrInstGen *opt_stack = ir_analyze_struct_value_field_value(ira, source_instr, options, stack_field);13288 IrInstGen *opt_stack = ir_analyze_struct_value_field_value(ira, scope, source_node, options, stack_field);
13266 if (type_is_invalid(opt_stack->value->type))13289 if (type_is_invalid(opt_stack->value->type))
13267 return ira->codegen->invalid_inst_gen;13290 return ira->codegen->invalid_inst_gen;
1326813291
13269 IrInstGen *stack_is_non_null_inst = ir_analyze_test_non_null(ira, source_instr, opt_stack);13292 IrInstGen *stack_is_non_null_inst = ir_analyze_test_non_null(ira, scope, source_node, opt_stack);
13270 bool stack_is_non_null;13293 bool stack_is_non_null;
13271 if (!ir_resolve_bool(ira, stack_is_non_null_inst, &stack_is_non_null))13294 if (!ir_resolve_bool(ira, stack_is_non_null_inst, &stack_is_non_null))
13272 return ira->codegen->invalid_inst_gen;13295 return ira->codegen->invalid_inst_gen;
1327313296
13274 IrInstGen *stack = nullptr;13297 IrInstGen *stack = nullptr;
13275 IrInst *stack_src = nullptr;13298 AstNode *stack_src = nullptr;
13276 if (stack_is_non_null) {13299 if (stack_is_non_null) {
13277 stack = ir_analyze_optional_value_payload_value(ira, source_instr, opt_stack, false);13300 stack = ir_analyze_optional_value_payload_value(ira, scope, source_node, opt_stack, false);
13278 if (type_is_invalid(stack->value->type))13301 if (type_is_invalid(stack->value->type))
13279 return ira->codegen->invalid_inst_gen;13302 return ira->codegen->invalid_inst_gen;
13280 stack_src = &stack->base;13303 stack_src = stack->source_node;
13281 }13304 }
1328213305
13283 return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr, first_arg_ptr_src,13306 return ir_analyze_fn_call(ira, scope, source_node, fn, fn_type, fn_ref, first_arg_ptr, first_arg_ptr_src,
13284 modifier, stack, stack_src, false, args_ptr, args_len, nullptr, result_loc);13307 modifier, stack, stack_src, false, args_ptr, args_len, nullptr, result_loc);
13285}13308}
1328613309
13287static IrInstGen *ir_analyze_async_call_extra(IrAnalyze *ira, IrInst* source_instr, CallModifier modifier,13310static IrInstGen *ir_analyze_async_call_extra(IrAnalyze *ira, Scope *scope, AstNode *source_node, CallModifier modifier,
13288 IrInstSrc *pass1_fn_ref, IrInstSrc *ret_ptr, IrInstSrc *new_stack, IrInstGen **args_ptr, size_t args_len, ResultLoc *result_loc)13311 IrInstSrc *pass1_fn_ref, IrInstSrc *ret_ptr, IrInstSrc *new_stack, IrInstGen **args_ptr, size_t args_len, ResultLoc *result_loc)
13289{13312{
13290 IrInstGen *fn_ref = pass1_fn_ref->child;13313 IrInstGen *fn_ref = pass1_fn_ref->child;
13291 if (type_is_invalid(fn_ref->value->type))13314 if (type_is_invalid(fn_ref->value->type))
13292 return ira->codegen->invalid_inst_gen;13315 return ira->codegen->invalid_inst_gen;
1329313316
13294 if (ir_should_inline(ira->zir, source_instr->scope)) {13317 if (ir_should_inline(ira->zir, scope)) {
13295 ir_add_error(ira, source_instr, buf_sprintf("TODO: comptime @asyncCall"));13318 ir_add_error_node(ira, source_node, buf_sprintf("TODO: comptime @asyncCall"));
13296 return ira->codegen->invalid_inst_gen;13319 return ira->codegen->invalid_inst_gen;
13297 }13320 }
1329813321
13299 IrInstGen *first_arg_ptr = nullptr;13322 IrInstGen *first_arg_ptr = nullptr;
13300 IrInst *first_arg_ptr_src = nullptr;13323 AstNode *first_arg_ptr_src = nullptr;
13301 ZigFn *fn = nullptr;13324 ZigFn *fn = nullptr;
13302 if (instr_is_comptime(fn_ref)) {13325 if (instr_is_comptime(fn_ref)) {
13303 if (fn_ref->value->type->id == ZigTypeIdBoundFn) {13326 if (fn_ref->value->type->id == ZigTypeIdBoundFn) {
...@@ -13320,22 +13343,23 @@ static IrInstGen *ir_analyze_async_call_extra(IrAnalyze *ira, IrInst* source_ins...@@ -13320,22 +13343,23 @@ static IrInstGen *ir_analyze_async_call_extra(IrAnalyze *ira, IrInst* source_ins
13320 }13343 }
1332113344
13322 ZigType *fn_type = (fn != nullptr) ? fn->type_entry : fn_ref->value->type;13345 ZigType *fn_type = (fn != nullptr) ? fn->type_entry : fn_ref->value->type;
13323 IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack->child,13346 IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, scope, source_node,
13324 &new_stack->base, true, fn);13347 new_stack->child, new_stack->source_node, true, fn);
13325 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))13348 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))
13326 return ira->codegen->invalid_inst_gen;13349 return ira->codegen->invalid_inst_gen;
1332713350
13328 return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr, first_arg_ptr_src,13351 return ir_analyze_fn_call(ira, scope, source_node, fn, fn_type, fn_ref, first_arg_ptr,
13329 modifier, casted_new_stack, &new_stack->base, true, args_ptr, args_len, ret_ptr_uncasted, result_loc);13352 first_arg_ptr_src, modifier, casted_new_stack, new_stack->source_node, true, args_ptr,
13353 args_len, ret_ptr_uncasted, result_loc);
13330}13354}
1333113355
13332static bool ir_extract_tuple_call_args(IrAnalyze *ira, IrInst *source_instr, IrInstGen *args, IrInstGen ***args_ptr, size_t *args_len) {13356static bool ir_extract_tuple_call_args(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *args, IrInstGen ***args_ptr, size_t *args_len) {
13333 ZigType *args_type = args->value->type;13357 ZigType *args_type = args->value->type;
13334 if (type_is_invalid(args_type))13358 if (type_is_invalid(args_type))
13335 return false;13359 return false;
1333613360
13337 if (args_type->id != ZigTypeIdStruct) {13361 if (args_type->id != ZigTypeIdStruct) {
13338 ir_add_error(ira, &args->base,13362 ir_add_error(ira, args,
13339 buf_sprintf("expected tuple or struct, found '%s'", buf_ptr(&args_type->name)));13363 buf_sprintf("expected tuple or struct, found '%s'", buf_ptr(&args_type->name)));
13340 return false;13364 return false;
13341 }13365 }
...@@ -13345,12 +13369,12 @@ static bool ir_extract_tuple_call_args(IrAnalyze *ira, IrInst *source_instr, IrI...@@ -13345,12 +13369,12 @@ static bool ir_extract_tuple_call_args(IrAnalyze *ira, IrInst *source_instr, IrI
13345 *args_ptr = heap::c_allocator.allocate<IrInstGen *>(*args_len);13369 *args_ptr = heap::c_allocator.allocate<IrInstGen *>(*args_len);
13346 for (size_t i = 0; i < *args_len; i += 1) {13370 for (size_t i = 0; i < *args_len; i += 1) {
13347 TypeStructField *arg_field = args_type->data.structure.fields[i];13371 TypeStructField *arg_field = args_type->data.structure.fields[i];
13348 (*args_ptr)[i] = ir_analyze_struct_value_field_value(ira, source_instr, args, arg_field);13372 (*args_ptr)[i] = ir_analyze_struct_value_field_value(ira, scope, source_node, args, arg_field);
13349 if (type_is_invalid((*args_ptr)[i]->value->type))13373 if (type_is_invalid((*args_ptr)[i]->value->type))
13350 return false;13374 return false;
13351 }13375 }
13352 } else {13376 } else {
13353 ir_add_error(ira, &args->base, buf_sprintf("TODO: struct args"));13377 ir_add_error(ira, args, buf_sprintf("TODO: struct args"));
13354 return false;13378 return false;
13355 }13379 }
13356 return true;13380 return true;
...@@ -13360,11 +13384,11 @@ static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCal...@@ -13360,11 +13384,11 @@ static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCal
13360 IrInstGen *args = instruction->args->child;13384 IrInstGen *args = instruction->args->child;
13361 IrInstGen **args_ptr = nullptr;13385 IrInstGen **args_ptr = nullptr;
13362 size_t args_len = 0;13386 size_t args_len = 0;
13363 if (!ir_extract_tuple_call_args(ira, &instruction->base.base, args, &args_ptr, &args_len)) {13387 if (!ir_extract_tuple_call_args(ira, instruction->base.scope, instruction->base.source_node, args, &args_ptr, &args_len)) {
13364 return ira->codegen->invalid_inst_gen;13388 return ira->codegen->invalid_inst_gen;
13365 }13389 }
1336613390
13367 IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options,13391 IrInstGen *result = ir_analyze_call_extra(ira, instruction->base.scope, instruction->base.source_node, instruction->options,
13368 instruction->fn_ref, args_ptr, args_len, instruction->result_loc);13392 instruction->fn_ref, args_ptr, args_len, instruction->result_loc);
13369 heap::c_allocator.deallocate(args_ptr, args_len);13393 heap::c_allocator.deallocate(args_ptr, args_len);
13370 return result;13394 return result;
...@@ -13374,11 +13398,11 @@ static IrInstGen *ir_analyze_instruction_async_call_extra(IrAnalyze *ira, IrInst...@@ -13374,11 +13398,11 @@ static IrInstGen *ir_analyze_instruction_async_call_extra(IrAnalyze *ira, IrInst
13374 IrInstGen *args = instruction->args->child;13398 IrInstGen *args = instruction->args->child;
13375 IrInstGen **args_ptr = nullptr;13399 IrInstGen **args_ptr = nullptr;
13376 size_t args_len = 0;13400 size_t args_len = 0;
13377 if (!ir_extract_tuple_call_args(ira, &instruction->base.base, args, &args_ptr, &args_len)) {13401 if (!ir_extract_tuple_call_args(ira, instruction->base.scope, instruction->base.source_node, args, &args_ptr, &args_len)) {
13378 return ira->codegen->invalid_inst_gen;13402 return ira->codegen->invalid_inst_gen;
13379 }13403 }
1338013404
13381 IrInstGen *result = ir_analyze_async_call_extra(ira, &instruction->base.base, instruction->modifier,13405 IrInstGen *result = ir_analyze_async_call_extra(ira, instruction->base.scope, instruction->base.source_node, instruction->modifier,
13382 instruction->fn_ref, instruction->ret_ptr, instruction->new_stack, args_ptr, args_len, instruction->result_loc);13406 instruction->fn_ref, instruction->ret_ptr, instruction->new_stack, args_ptr, args_len, instruction->result_loc);
13383 heap::c_allocator.deallocate(args_ptr, args_len);13407 heap::c_allocator.deallocate(args_ptr, args_len);
13384 return result;13408 return result;
...@@ -13392,7 +13416,7 @@ static IrInstGen *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstSrcCall...@@ -13392,7 +13416,7 @@ static IrInstGen *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstSrcCall
13392 return ira->codegen->invalid_inst_gen;13416 return ira->codegen->invalid_inst_gen;
13393 }13417 }
1339413418
13395 IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options,13419 IrInstGen *result = ir_analyze_call_extra(ira, instruction->base.scope, instruction->base.source_node, instruction->options,
13396 instruction->fn_ref, args_ptr, instruction->args_len, instruction->result_loc);13420 instruction->fn_ref, args_ptr, instruction->args_len, instruction->result_loc);
13397 heap::c_allocator.deallocate(args_ptr, instruction->args_len);13421 heap::c_allocator.deallocate(args_ptr, instruction->args_len);
13398 return result;13422 return result;
...@@ -13404,7 +13428,7 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal...@@ -13404,7 +13428,7 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal
13404 return ira->codegen->invalid_inst_gen;13428 return ira->codegen->invalid_inst_gen;
1340513429
13406 bool is_comptime = (call_instruction->modifier == CallModifierCompileTime) ||13430 bool is_comptime = (call_instruction->modifier == CallModifierCompileTime) ||
13407 ir_should_inline(ira->zir, call_instruction->base.base.scope);13431 ir_should_inline(ira->zir, call_instruction->base.scope);
13408 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;13432 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;
1340913433
13410 if (is_comptime || instr_is_comptime(fn_ref)) {13434 if (is_comptime || instr_is_comptime(fn_ref)) {
...@@ -13412,9 +13436,9 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal...@@ -13412,9 +13436,9 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal
13412 ZigType *ty = ir_resolve_type(ira, fn_ref);13436 ZigType *ty = ir_resolve_type(ira, fn_ref);
13413 if (ty == nullptr)13437 if (ty == nullptr)
13414 return ira->codegen->invalid_inst_gen;13438 return ira->codegen->invalid_inst_gen;
13415 ErrorMsg *msg = ir_add_error(ira, &fn_ref->base,13439 ErrorMsg *msg = ir_add_error(ira, fn_ref,
13416 buf_sprintf("type '%s' not a function", buf_ptr(&ty->name)));13440 buf_sprintf("type '%s' not a function", buf_ptr(&ty->name)));
13417 add_error_note(ira->codegen, msg, call_instruction->base.base.source_node,13441 add_error_note(ira->codegen, msg, call_instruction->base.source_node,
13418 buf_sprintf("use @as builtin for type coercion"));13442 buf_sprintf("use @as builtin for type coercion"));
13419 return ira->codegen->invalid_inst_gen;13443 return ira->codegen->invalid_inst_gen;
13420 } else if (fn_ref->value->type->id == ZigTypeIdFn) {13444 } else if (fn_ref->value->type->id == ZigTypeIdFn) {
...@@ -13427,12 +13451,12 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal...@@ -13427,12 +13451,12 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal
13427 assert(fn_ref->value->special == ConstValSpecialStatic);13451 assert(fn_ref->value->special == ConstValSpecialStatic);
13428 ZigFn *fn_table_entry = fn_ref->value->data.x_bound_fn.fn;13452 ZigFn *fn_table_entry = fn_ref->value->data.x_bound_fn.fn;
13429 IrInstGen *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;13453 IrInstGen *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;
13430 IrInst *first_arg_ptr_src = fn_ref->value->data.x_bound_fn.first_arg_src;13454 AstNode *first_arg_ptr_src = fn_ref->value->data.x_bound_fn.first_arg_src;
13431 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;13455 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;
13432 return ir_analyze_fn_call_src(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,13456 return ir_analyze_fn_call_src(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
13433 fn_ref, first_arg_ptr, first_arg_ptr_src, modifier);13457 fn_ref, first_arg_ptr, first_arg_ptr_src, modifier);
13434 } else {13458 } else {
13435 ir_add_error(ira, &fn_ref->base,13459 ir_add_error(ira, fn_ref,
13436 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));13460 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));
13437 return ira->codegen->invalid_inst_gen;13461 return ira->codegen->invalid_inst_gen;
13438 }13462 }
...@@ -13442,7 +13466,7 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal...@@ -13442,7 +13466,7 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal
13442 return ir_analyze_fn_call_src(ira, call_instruction, nullptr, fn_ref->value->type,13466 return ir_analyze_fn_call_src(ira, call_instruction, nullptr, fn_ref->value->type,
13443 fn_ref, nullptr, nullptr, modifier);13467 fn_ref, nullptr, nullptr, modifier);
13444 } else {13468 } else {
13445 ir_add_error(ira, &fn_ref->base,13469 ir_add_error(ira, fn_ref,
13446 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));13470 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));
13447 return ira->codegen->invalid_inst_gen;13471 return ira->codegen->invalid_inst_gen;
13448 }13472 }
...@@ -13561,7 +13585,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source...@@ -13561,7 +13585,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
13561}13585}
1356213586
13563static IrInstGen *ir_analyze_optional_type(IrAnalyze *ira, IrInstSrcUnOp *instruction) {13587static IrInstGen *ir_analyze_optional_type(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
13564 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);13588 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_type);
13565 result->value->special = ConstValSpecialLazy;13589 result->value->special = ConstValSpecialLazy;
1356613590
13567 LazyValueOptType *lazy_opt_type = heap::c_allocator.create<LazyValueOptType>();13591 LazyValueOptType *lazy_opt_type = heap::c_allocator.create<LazyValueOptType>();
...@@ -13576,7 +13600,7 @@ static IrInstGen *ir_analyze_optional_type(IrAnalyze *ira, IrInstSrcUnOp *instru...@@ -13576,7 +13600,7 @@ static IrInstGen *ir_analyze_optional_type(IrAnalyze *ira, IrInstSrcUnOp *instru
13576 return result;13600 return result;
13577}13601}
1357813602
13579static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInst* source_instr, ZigType *scalar_type,13603static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *scalar_type,
13580 ZigValue *operand_val, ZigValue *scalar_out_val, bool is_wrap_op)13604 ZigValue *operand_val, ZigValue *scalar_out_val, bool is_wrap_op)
13581{13605{
13582 bool is_float = (scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat);13606 bool is_float = (scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat);
...@@ -13586,7 +13610,7 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInst* source_instr, Z...@@ -13586,7 +13610,7 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInst* source_instr, Z
1358613610
13587 if (!ok_type) {13611 if (!ok_type) {
13588 const char *fmt = is_wrap_op ? "invalid wrapping negation type: '%s'" : "invalid negation type: '%s'";13612 const char *fmt = is_wrap_op ? "invalid wrapping negation type: '%s'" : "invalid negation type: '%s'";
13589 return ir_add_error(ira, source_instr, buf_sprintf(fmt, buf_ptr(&scalar_type->name)));13613 return ir_add_error_node(ira, source_node, buf_sprintf(fmt, buf_ptr(&scalar_type->name)));
13590 }13614 }
1359113615
13592 if (is_float) {13616 if (is_float) {
...@@ -13606,7 +13630,7 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInst* source_instr, Z...@@ -13606,7 +13630,7 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInst* source_instr, Z
13606 }13630 }
1360713631
13608 if (!bigint_fits_in_bits(&scalar_out_val->data.x_bigint, scalar_type->data.integral.bit_count, true)) {13632 if (!bigint_fits_in_bits(&scalar_out_val->data.x_bigint, scalar_type->data.integral.bit_count, true)) {
13609 return ir_add_error(ira, source_instr, buf_sprintf("negation caused overflow"));13633 return ir_add_error_node(ira, source_node, buf_sprintf("negation caused overflow"));
13610 }13634 }
13611 return nullptr;13635 return nullptr;
13612}13636}
...@@ -13632,7 +13656,7 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction...@@ -13632,7 +13656,7 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction
13632 break;13656 break;
13633 ZIG_FALLTHROUGH;13657 ZIG_FALLTHROUGH;
13634 default:13658 default:
13635 ir_add_error(ira, &instruction->base.base,13659 ir_add_error_node(ira, instruction->base.source_node,
13636 buf_sprintf("negation of type '%s'", buf_ptr(&scalar_type->name)));13660 buf_sprintf("negation of type '%s'", buf_ptr(&scalar_type->name)));
13637 return ira->codegen->invalid_inst_gen;13661 return ira->codegen->invalid_inst_gen;
13638 }13662 }
...@@ -13642,7 +13666,7 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction...@@ -13642,7 +13666,7 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction
13642 if (!operand_val)13666 if (!operand_val)
13643 return ira->codegen->invalid_inst_gen;13667 return ira->codegen->invalid_inst_gen;
1364413668
13645 IrInstGen *result_instruction = ir_const(ira, &instruction->base.base, expr_type);13669 IrInstGen *result_instruction = ir_const(ira, instruction->base.scope, instruction->base.source_node, expr_type);
13646 ZigValue *out_val = result_instruction->value;13670 ZigValue *out_val = result_instruction->value;
13647 if (expr_type->id == ZigTypeIdVector) {13671 if (expr_type->id == ZigTypeIdVector) {
13648 expand_undef_array(ira->codegen, operand_val);13672 expand_undef_array(ira->codegen, operand_val);
...@@ -13654,10 +13678,10 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction...@@ -13654,10 +13678,10 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction
13654 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];13678 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];
13655 assert(scalar_operand_val->type == scalar_type);13679 assert(scalar_operand_val->type == scalar_type);
13656 assert(scalar_out_val->type == scalar_type);13680 assert(scalar_out_val->type == scalar_type);
13657 ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base.base, scalar_type,13681 ErrorMsg *msg = ir_eval_negation_scalar(ira, instruction->base.scope, instruction->base.source_node, scalar_type,
13658 scalar_operand_val, scalar_out_val, is_wrap_op);13682 scalar_operand_val, scalar_out_val, is_wrap_op);
13659 if (msg != nullptr) {13683 if (msg != nullptr) {
13660 add_error_note(ira->codegen, msg, instruction->base.base.source_node,13684 add_error_note(ira->codegen, msg, instruction->base.source_node,
13661 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));13685 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
13662 return ira->codegen->invalid_inst_gen;13686 return ira->codegen->invalid_inst_gen;
13663 }13687 }
...@@ -13665,7 +13689,7 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction...@@ -13665,7 +13689,7 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction
13665 out_val->type = expr_type;13689 out_val->type = expr_type;
13666 out_val->special = ConstValSpecialStatic;13690 out_val->special = ConstValSpecialStatic;
13667 } else {13691 } else {
13668 if (ir_eval_negation_scalar(ira, &instruction->base.base, scalar_type, operand_val, out_val,13692 if (ir_eval_negation_scalar(ira, instruction->base.scope, instruction->base.source_node, scalar_type, operand_val, out_val,
13669 is_wrap_op) != nullptr)13693 is_wrap_op) != nullptr)
13670 {13694 {
13671 return ira->codegen->invalid_inst_gen;13695 return ira->codegen->invalid_inst_gen;
...@@ -13674,7 +13698,7 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction...@@ -13674,7 +13698,7 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction
13674 return result_instruction;13698 return result_instruction;
13675 }13699 }
1367613700
13677 return ir_build_negation(ira, &instruction->base.base, value, expr_type, is_wrap_op);13701 return ir_build_negation(ira, instruction->base.scope, instruction->base.source_node, value, expr_type, is_wrap_op);
13678}13702}
1367913703
13680static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction) {13704static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
...@@ -13687,7 +13711,7 @@ static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction)...@@ -13687,7 +13711,7 @@ static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction)
13687 expr_type->data.vector.elem_type : expr_type;13711 expr_type->data.vector.elem_type : expr_type;
1368813712
13689 if (scalar_type->id != ZigTypeIdInt) {13713 if (scalar_type->id != ZigTypeIdInt) {
13690 ir_add_error(ira, &instruction->base.base,13714 ir_add_error_node(ira, instruction->base.source_node,
13691 buf_sprintf("unable to perform binary not operation on type '%s'", buf_ptr(&expr_type->name)));13715 buf_sprintf("unable to perform binary not operation on type '%s'", buf_ptr(&expr_type->name)));
13692 return ira->codegen->invalid_inst_gen;13716 return ira->codegen->invalid_inst_gen;
13693 }13717 }
...@@ -13697,7 +13721,7 @@ static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction)...@@ -13697,7 +13721,7 @@ static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction)
13697 if (expr_val == nullptr)13721 if (expr_val == nullptr)
13698 return ira->codegen->invalid_inst_gen;13722 return ira->codegen->invalid_inst_gen;
1369913723
13700 IrInstGen *result = ir_const(ira, &instruction->base.base, expr_type);13724 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, expr_type);
1370113725
13702 if (expr_type->id == ZigTypeIdVector) {13726 if (expr_type->id == ZigTypeIdVector) {
13703 expand_undef_array(ira->codegen, expr_val);13727 expand_undef_array(ira->codegen, expr_val);
...@@ -13721,7 +13745,7 @@ static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction)...@@ -13721,7 +13745,7 @@ static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction)
13721 return result;13745 return result;
13722 }13746 }
1372313747
13724 return ir_build_binary_not(ira, &instruction->base.base, value, expr_type);13748 return ir_build_binary_not(ira, instruction->base.scope, instruction->base.source_node, value, expr_type);
13725}13749}
1372613750
13727static IrInstGen *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstSrcUnOp *instruction) {13751static IrInstGen *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
...@@ -13740,19 +13764,20 @@ static IrInstGen *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstSrcUnOp *in...@@ -13740,19 +13764,20 @@ static IrInstGen *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstSrcUnOp *in
13740 return ira->codegen->invalid_inst_gen;13764 return ira->codegen->invalid_inst_gen;
13741 ZigType *ptr_type = ptr->value->type;13765 ZigType *ptr_type = ptr->value->type;
13742 if (ptr_type->id == ZigTypeIdPointer && ptr_type->data.pointer.ptr_len == PtrLenUnknown) {13766 if (ptr_type->id == ZigTypeIdPointer && ptr_type->data.pointer.ptr_len == PtrLenUnknown) {
13743 ir_add_error_node(ira, instruction->base.base.source_node,13767 ir_add_error_node(ira, instruction->base.source_node,
13744 buf_sprintf("index syntax required for unknown-length pointer type '%s'",13768 buf_sprintf("index syntax required for unknown-length pointer type '%s'",
13745 buf_ptr(&ptr_type->name)));13769 buf_ptr(&ptr_type->name)));
13746 return ira->codegen->invalid_inst_gen;13770 return ira->codegen->invalid_inst_gen;
13747 }13771 }
1374813772
13749 IrInstGen *result = ir_get_deref(ira, &instruction->base.base, ptr, instruction->result_loc);13773 IrInstGen *result = ir_get_deref(ira, instruction->base.scope,
13774 instruction->base.source_node, ptr, instruction->result_loc);
13750 if (type_is_invalid(result->value->type))13775 if (type_is_invalid(result->value->type))
13751 return ira->codegen->invalid_inst_gen;13776 return ira->codegen->invalid_inst_gen;
1375213777
13753 // If the result needs to be an lvalue, type check it13778 // If the result needs to be an lvalue, type check it
13754 if (instruction->lval != LValNone && result->value->type->id != ZigTypeIdPointer) {13779 if (instruction->lval != LValNone && result->value->type->id != ZigTypeIdPointer) {
13755 ir_add_error(ira, &instruction->base.base,13780 ir_add_error_node(ira, instruction->base.source_node,
13756 buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value->type->name)));13781 buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value->type->name)));
13757 return ira->codegen->invalid_inst_gen;13782 return ira->codegen->invalid_inst_gen;
13758 }13783 }
...@@ -13786,15 +13811,15 @@ static IrInstGen *ir_analyze_instruction_br(IrAnalyze *ira, IrInstSrcBr *br_inst...@@ -13786,15 +13811,15 @@ static IrInstGen *ir_analyze_instruction_br(IrAnalyze *ira, IrInstSrcBr *br_inst
13786 return ir_unreach_error(ira);13811 return ir_unreach_error(ira);
1378713812
13788 if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr))13813 if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr))
13789 return ir_inline_bb(ira, &br_instruction->base.base, old_dest_block);13814 return ir_inline_bb(ira, br_instruction->base.source_node, old_dest_block);
1379013815
13791 IrBasicBlockGen *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base.base);13816 IrBasicBlockGen *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base);
13792 if (new_bb == nullptr)13817 if (new_bb == nullptr)
13793 return ir_unreach_error(ira);13818 return ir_unreach_error(ira);
1379413819
13795 ir_push_resume_block(ira, old_dest_block);13820 ir_push_resume_block(ira, old_dest_block);
1379613821
13797 IrInstGen *result = ir_build_br_gen(ira, &br_instruction->base.base, new_bb);13822 IrInstGen *result = ir_build_br_gen(ira, br_instruction->base.scope, br_instruction->base.source_node, new_bb);
13798 return ir_finish_anal(ira, result);13823 return ir_finish_anal(ira, result);
13799}13824}
1380013825
...@@ -13821,44 +13846,48 @@ static IrInstGen *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstSrcCondBr...@@ -13821,44 +13846,48 @@ static IrInstGen *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstSrcCondBr
13821 cond_br_instruction->then_block : cond_br_instruction->else_block;13846 cond_br_instruction->then_block : cond_br_instruction->else_block;
1382213847
13823 if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr))13848 if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr))
13824 return ir_inline_bb(ira, &cond_br_instruction->base.base, old_dest_block);13849 return ir_inline_bb(ira, cond_br_instruction->base.source_node, old_dest_block);
1382513850
13826 IrBasicBlockGen *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base.base);13851 IrBasicBlockGen *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base);
13827 if (new_dest_block == nullptr)13852 if (new_dest_block == nullptr)
13828 return ir_unreach_error(ira);13853 return ir_unreach_error(ira);
1382913854
13830 ir_push_resume_block(ira, old_dest_block);13855 ir_push_resume_block(ira, old_dest_block);
1383113856
13832 IrInstGen *result = ir_build_br_gen(ira, &cond_br_instruction->base.base, new_dest_block);13857 IrInstGen *result = ir_build_br_gen(ira, cond_br_instruction->base.scope,
13858 cond_br_instruction->base.source_node, new_dest_block);
13833 return ir_finish_anal(ira, result);13859 return ir_finish_anal(ira, result);
13834 }13860 }
1383513861
13836 assert(cond_br_instruction->then_block != cond_br_instruction->else_block);13862 assert(cond_br_instruction->then_block != cond_br_instruction->else_block);
13837 IrBasicBlockGen *new_then_block = ir_get_new_bb_runtime(ira, cond_br_instruction->then_block, &cond_br_instruction->base.base);13863 IrBasicBlockGen *new_then_block = ir_get_new_bb_runtime(ira, cond_br_instruction->then_block, &cond_br_instruction->base);
13838 if (new_then_block == nullptr)13864 if (new_then_block == nullptr)
13839 return ir_unreach_error(ira);13865 return ir_unreach_error(ira);
1384013866
13841 IrBasicBlockGen *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base.base);13867 IrBasicBlockGen *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base);
13842 if (new_else_block == nullptr)13868 if (new_else_block == nullptr)
13843 return ir_unreach_error(ira);13869 return ir_unreach_error(ira);
1384413870
13845 ir_push_resume_block(ira, cond_br_instruction->else_block);13871 ir_push_resume_block(ira, cond_br_instruction->else_block);
13846 ir_push_resume_block(ira, cond_br_instruction->then_block);13872 ir_push_resume_block(ira, cond_br_instruction->then_block);
1384713873
13848 IrInstGen *result = ir_build_cond_br_gen(ira, &cond_br_instruction->base.base,13874 IrInstGen *result = ir_build_cond_br_gen(ira, cond_br_instruction->base.scope,
13849 casted_condition, new_then_block, new_else_block);13875 cond_br_instruction->base.source_node, casted_condition, new_then_block,
13876 new_else_block);
13850 return ir_finish_anal(ira, result);13877 return ir_finish_anal(ira, result);
13851}13878}
1385213879
13853static IrInstGen *ir_analyze_instruction_unreachable(IrAnalyze *ira,13880static IrInstGen *ir_analyze_instruction_unreachable(IrAnalyze *ira,
13854 IrInstSrcUnreachable *unreachable_instruction)13881 IrInstSrcUnreachable *unreachable_instruction)
13855{13882{
13856 if (ir_should_inline(ira->zir, unreachable_instruction->base.base.scope)) {13883 if (ir_should_inline(ira->zir, unreachable_instruction->base.scope)) {
13857 ir_add_error(ira, &unreachable_instruction->base.base, buf_sprintf("reached unreachable code"));13884 ir_add_error_node(ira, unreachable_instruction->base.source_node,
13885 buf_sprintf("reached unreachable code"));
13858 return ir_unreach_error(ira);13886 return ir_unreach_error(ira);
13859 }13887 }
1386013888
13861 IrInstGen *result = ir_build_unreachable_gen(ira, &unreachable_instruction->base.base);13889 IrInstGen *result = ir_build_unreachable_gen(ira, unreachable_instruction->base.scope,
13890 unreachable_instruction->base.source_node);
13862 return ir_finish_anal(ira, result);13891 return ir_finish_anal(ira, result);
13863}13892}
1386413893
...@@ -13876,7 +13905,8 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i...@@ -13876,7 +13905,8 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
13876 return ira->codegen->invalid_inst_gen;13905 return ira->codegen->invalid_inst_gen;
1387713906
13878 if (value->value->special != ConstValSpecialRuntime) {13907 if (value->value->special != ConstValSpecialRuntime) {
13879 IrInstGen *result = ir_const(ira, &phi_instruction->base.base, nullptr);13908 IrInstGen *result = ir_const(ira, phi_instruction->base.scope,
13909 phi_instruction->base.source_node, nullptr);
13880 copy_const_val(ira->codegen, result->value, value->value);13910 copy_const_val(ira->codegen, result->value, value->value);
13881 return result;13911 return result;
13882 } else {13912 } else {
...@@ -13899,9 +13929,10 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i...@@ -13899,9 +13929,10 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
13899 if (gen_instruction == nullptr) {13929 if (gen_instruction == nullptr) {
13900 // unreachable instructions will cause implicit_elem_type to be null13930 // unreachable instructions will cause implicit_elem_type to be null
13901 if (this_peer->base.implicit_elem_type == nullptr) {13931 if (this_peer->base.implicit_elem_type == nullptr) {
13902 instructions[i] = ir_const_unreachable(ira, &this_peer->base.source_instruction->base);13932 instructions[i] = ir_const_unreachable(ira, this_peer->base.source_instruction->scope, this_peer->base.source_instruction->source_node);
13903 } else {13933 } else {
13904 instructions[i] = ir_const(ira, &this_peer->base.source_instruction->base,13934 instructions[i] = ir_const(ira, this_peer->base.source_instruction->scope,
13935 this_peer->base.source_instruction->source_node,
13905 this_peer->base.implicit_elem_type);13936 this_peer->base.implicit_elem_type);
13906 instructions[i]->value->special = ConstValSpecialRuntime;13937 instructions[i]->value->special = ConstValSpecialRuntime;
13907 }13938 }
...@@ -13910,18 +13941,19 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i...@@ -13910,18 +13941,19 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
13910 }13941 }
1391113942
13912 }13943 }
13913 ZigType *expected_type = ir_result_loc_expected_type(ira, &phi_instruction->base.base, peer_parent->parent);13944 ZigType *expected_type = ir_result_loc_expected_type(ira, peer_parent->parent);
13914 peer_parent->resolved_type = ir_resolve_peer_types(ira,13945 peer_parent->resolved_type = ir_resolve_peer_types(ira,
13915 peer_parent->base.source_instruction->base.source_node, expected_type, instructions,13946 peer_parent->base.source_instruction->source_node, expected_type, instructions,
13916 peer_parent->peers.length);13947 peer_parent->peers.length);
13917 if (type_is_invalid(peer_parent->resolved_type))13948 if (type_is_invalid(peer_parent->resolved_type))
13918 return ira->codegen->invalid_inst_gen;13949 return ira->codegen->invalid_inst_gen;
1391913950
13920 // the logic below assumes there are no instructions in the new current basic block yet13951 // the logic below assumes there are no instructions in the new current basic block yet
13921 ir_assert(ira->new_irb.current_basic_block->instruction_list.length == 0, &phi_instruction->base.base);13952 src_assert(ira->new_irb.current_basic_block->instruction_list.length == 0,
13953 phi_instruction->base.source_node);
1392213954
13923 // In case resolving the parent activates a suspend, do it now13955 // In case resolving the parent activates a suspend, do it now
13924 IrInstGen *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base.base, peer_parent->parent,13956 IrInstGen *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent,
13925 peer_parent->resolved_type, nullptr, false, true);13957 peer_parent->resolved_type, nullptr, false, true);
13926 if (parent_result_loc != nullptr &&13958 if (parent_result_loc != nullptr &&
13927 (type_is_invalid(parent_result_loc->value->type) || parent_result_loc->value->type->id == ZigTypeIdUnreachable))13959 (type_is_invalid(parent_result_loc->value->type) || parent_result_loc->value->type->id == ZigTypeIdUnreachable))
...@@ -13937,7 +13969,8 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i...@@ -13937,7 +13969,8 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
13937 if (instrs_to_move.length != 0) {13969 if (instrs_to_move.length != 0) {
13938 IrBasicBlockGen *predecessor = peer_parent->base.source_instruction->child->owner_bb;13970 IrBasicBlockGen *predecessor = peer_parent->base.source_instruction->child->owner_bb;
13939 IrInstGen *branch_instruction = predecessor->instruction_list.pop();13971 IrInstGen *branch_instruction = predecessor->instruction_list.pop();
13940 ir_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable, &phi_instruction->base.base);13972 src_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable,
13973 phi_instruction->base.source_node);
13941 while (instrs_to_move.length != 0) {13974 while (instrs_to_move.length != 0) {
13942 predecessor->instruction_list.append(instrs_to_move.pop());13975 predecessor->instruction_list.append(instrs_to_move.pop());
13943 }13976 }
...@@ -13947,7 +13980,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i...@@ -13947,7 +13980,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
13947 }13980 }
1394813981
13949 IrSuspendPosition suspend_pos;13982 IrSuspendPosition suspend_pos;
13950 ira_suspend(ira, &phi_instruction->base.base, nullptr, &suspend_pos);13983 ira_suspend(ira, &phi_instruction->base, nullptr, &suspend_pos);
13951 ir_push_resume(ira, suspend_pos);13984 ir_push_resume(ira, suspend_pos);
1395213985
13953 for (size_t i = 0; i < peer_parent->peers.length; i += 1) {13986 for (size_t i = 0; i < peer_parent->peers.length; i += 1) {
...@@ -13988,7 +14021,8 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i...@@ -13988,7 +14021,8 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
13988 }14021 }
1398914022
13990 if (new_incoming_blocks.length == 0) {14023 if (new_incoming_blocks.length == 0) {
13991 IrInstGen *result = ir_build_unreachable_gen(ira, &phi_instruction->base.base);14024 IrInstGen *result = ir_build_unreachable_gen(ira, phi_instruction->base.scope,
14025 phi_instruction->base.source_node);
13992 return ir_finish_anal(ira, result);14026 return ir_finish_anal(ira, result);
13993 }14027 }
1399414028
...@@ -14011,7 +14045,8 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i...@@ -14011,7 +14045,8 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
14011 resolved_type = ir_resolve_type(ira, peer_parent->parent->source_instruction->child);14045 resolved_type = ir_resolve_type(ira, peer_parent->parent->source_instruction->child);
14012 } else if (peer_parent->parent->resolved_loc) {14046 } else if (peer_parent->parent->resolved_loc) {
14013 ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value->type;14047 ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value->type;
14014 ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base.base);14048 src_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer,
14049 phi_instruction->base.source_node);
14015 resolved_type = resolved_loc_ptr_type->data.pointer.child_type;14050 resolved_type = resolved_loc_ptr_type->data.pointer.child_type;
14016 }14051 }
1401714052
...@@ -14021,7 +14056,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i...@@ -14021,7 +14056,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
14021 }14056 }
1402214057
14023 if (resolved_type == nullptr) {14058 if (resolved_type == nullptr) {
14024 resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.base.source_node, nullptr,14059 resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr,
14025 new_incoming_values.items, new_incoming_values.length);14060 new_incoming_values.items, new_incoming_values.length);
14026 if (type_is_invalid(resolved_type))14061 if (type_is_invalid(resolved_type))
14027 return ira->codegen->invalid_inst_gen;14062 return ira->codegen->invalid_inst_gen;
...@@ -14031,7 +14066,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i...@@ -14031,7 +14066,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
14031 case OnePossibleValueInvalid:14066 case OnePossibleValueInvalid:
14032 return ira->codegen->invalid_inst_gen;14067 return ira->codegen->invalid_inst_gen;
14033 case OnePossibleValueYes:14068 case OnePossibleValueYes:
14034 return ir_const_move(ira, &phi_instruction->base.base,14069 return ir_const_move(ira, phi_instruction->base.scope, phi_instruction->base.source_node,
14035 get_the_one_possible_value(ira->codegen, resolved_type));14070 get_the_one_possible_value(ira->codegen, resolved_type));
14036 case OnePossibleValueNo:14071 case OnePossibleValueNo:
14037 break;14072 break;
...@@ -14041,7 +14076,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i...@@ -14041,7 +14076,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
14041 case ReqCompTimeInvalid:14076 case ReqCompTimeInvalid:
14042 return ira->codegen->invalid_inst_gen;14077 return ira->codegen->invalid_inst_gen;
14043 case ReqCompTimeYes:14078 case ReqCompTimeYes:
14044 ir_add_error(ira, &phi_instruction->base.base,14079 ir_add_error_node(ira, phi_instruction->base.source_node,
14045 buf_sprintf("values of type '%s' must be comptime known", buf_ptr(&resolved_type->name)));14080 buf_sprintf("values of type '%s' must be comptime known", buf_ptr(&resolved_type->name)));
14046 return ira->codegen->invalid_inst_gen;14081 return ira->codegen->invalid_inst_gen;
14047 case ReqCompTimeNo:14082 case ReqCompTimeNo:
...@@ -14057,7 +14092,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i...@@ -14057,7 +14092,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
14057 for (size_t i = 0; i < new_incoming_values.length; i += 1) {14092 for (size_t i = 0; i < new_incoming_values.length; i += 1) {
14058 IrInstGen *new_value = new_incoming_values.at(i);14093 IrInstGen *new_value = new_incoming_values.at(i);
14059 IrBasicBlockGen *predecessor = new_incoming_blocks.at(i);14094 IrBasicBlockGen *predecessor = new_incoming_blocks.at(i);
14060 ir_assert(predecessor->instruction_list.length != 0, &phi_instruction->base.base);14095 src_assert(predecessor->instruction_list.length != 0, phi_instruction->base.source_node);
14061 IrInstGen *branch_instruction = predecessor->instruction_list.pop();14096 IrInstGen *branch_instruction = predecessor->instruction_list.pop();
14062 ir_set_cursor_at_end_gen(&ira->new_irb, predecessor);14097 ir_set_cursor_at_end_gen(&ira->new_irb, predecessor);
14063 IrInstGen *casted_value = ir_implicit_cast(ira, new_value, resolved_type);14098 IrInstGen *casted_value = ir_implicit_cast(ira, new_value, resolved_type);
...@@ -14075,8 +14110,9 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i...@@ -14075,8 +14110,9 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
14075 }14110 }
14076 ir_set_cursor_at_end_gen(&ira->new_irb, cur_bb);14111 ir_set_cursor_at_end_gen(&ira->new_irb, cur_bb);
1407714112
14078 IrInstGen *result = ir_build_phi_gen(ira, &phi_instruction->base.base,14113 IrInstGen *result = ir_build_phi_gen(ira, phi_instruction->base.scope,
14079 new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items, resolved_type);14114 phi_instruction->base.source_node, new_incoming_blocks.length,
14115 new_incoming_blocks.items, new_incoming_values.items, resolved_type);
1408014116
14081 if (all_stack_ptrs) {14117 if (all_stack_ptrs) {
14082 assert(result->value->special == ConstValSpecialRuntime);14118 assert(result->value->special == ConstValSpecialRuntime);
...@@ -14088,9 +14124,9 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i...@@ -14088,9 +14124,9 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
1408814124
14089static IrInstGen *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstSrcVarPtr *instruction) {14125static IrInstGen *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstSrcVarPtr *instruction) {
14090 ZigVar *var = instruction->var;14126 ZigVar *var = instruction->var;
14091 IrInstGen *result = ir_get_var_ptr(ira, &instruction->base.base, var);14127 IrInstGen *result = ir_get_var_ptr(ira, instruction->base.scope, instruction->base.source_node, var);
14092 if (instruction->crossed_fndef_scope != nullptr && !instr_is_comptime(result)) {14128 if (instruction->crossed_fndef_scope != nullptr && !instr_is_comptime(result)) {
14093 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,14129 ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node,
14094 buf_sprintf("'%s' not accessible from inner function", var->name));14130 buf_sprintf("'%s' not accessible from inner function", var->name));
14095 add_error_note(ira->codegen, msg, instruction->crossed_fndef_scope->base.source_node,14131 add_error_note(ira->codegen, msg, instruction->crossed_fndef_scope->base.source_node,
14096 buf_sprintf("crossed function definition here"));14132 buf_sprintf("crossed function definition here"));
...@@ -14244,8 +14280,8 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP...@@ -14244,8 +14280,8 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
14244 array_type->data.pointer.ptr_len == PtrLenSingle &&14280 array_type->data.pointer.ptr_len == PtrLenSingle &&
14245 array_type->data.pointer.child_type->id == ZigTypeIdArray)14281 array_type->data.pointer.child_type->id == ZigTypeIdArray)
14246 {14282 {
14247 IrInstGen *ptr_value = ir_get_deref(ira, &elem_ptr_instruction->base.base,14283 IrInstGen *ptr_value = ir_get_deref(ira, elem_ptr_instruction->base.scope,
14248 array_ptr, nullptr);14284 elem_ptr_instruction->base.source_node, array_ptr, nullptr);
14249 if (type_is_invalid(ptr_value->value->type))14285 if (type_is_invalid(ptr_value->value->type))
14250 return ira->codegen->invalid_inst_gen;14286 return ira->codegen->invalid_inst_gen;
1425114287
...@@ -14257,7 +14293,8 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP...@@ -14257,7 +14293,8 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
1425714293
14258 if (array_type->id == ZigTypeIdArray) {14294 if (array_type->id == ZigTypeIdArray) {
14259 if(array_type->data.array.len == 0 && array_type->data.array.sentinel == nullptr){14295 if(array_type->data.array.len == 0 && array_type->data.array.sentinel == nullptr){
14260 ir_add_error(ira, &elem_ptr_instruction->base.base, buf_sprintf("accessing a zero length array is not allowed"));14296 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
14297 buf_sprintf("accessing a zero length array is not allowed"));
14261 return ira->codegen->invalid_inst_gen;14298 return ira->codegen->invalid_inst_gen;
14262 }14299 }
1426314300
...@@ -14282,7 +14319,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP...@@ -14282,7 +14319,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
14282 }14319 }
14283 } else if (array_type->id == ZigTypeIdPointer) {14320 } else if (array_type->id == ZigTypeIdPointer) {
14284 if (array_type->data.pointer.ptr_len == PtrLenSingle) {14321 if (array_type->data.pointer.ptr_len == PtrLenSingle) {
14285 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,14322 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
14286 buf_sprintf("index of single-item pointer"));14323 buf_sprintf("index of single-item pointer"));
14287 return ira->codegen->invalid_inst_gen;14324 return ira->codegen->invalid_inst_gen;
14288 }14325 }
...@@ -14301,27 +14338,27 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP...@@ -14301,27 +14338,27 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
14301 IrInstGen *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);14338 IrInstGen *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);
14302 if (type_is_invalid(casted_elem_index->value->type))14339 if (type_is_invalid(casted_elem_index->value->type))
14303 return ira->codegen->invalid_inst_gen;14340 return ira->codegen->invalid_inst_gen;
14304 ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base.base);14341 src_assert(instr_is_comptime(casted_elem_index), elem_ptr_instruction->base.source_node);
14305 Buf *field_name = buf_alloc();14342 Buf *field_name = buf_alloc();
14306 bigint_append_buf(field_name, &casted_elem_index->value->data.x_bigint, 10);14343 bigint_append_buf(field_name, &casted_elem_index->value->data.x_bigint, 10);
14307 return ir_analyze_inferred_field_ptr(ira, field_name, &elem_ptr_instruction->base.base,14344 return ir_analyze_inferred_field_ptr(ira, field_name, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node,
14308 array_ptr, array_type);14345 array_ptr, array_type);
14309 } else if (is_tuple(array_type)) {14346 } else if (is_tuple(array_type)) {
14310 uint64_t elem_index_scalar;14347 uint64_t elem_index_scalar;
14311 if (!ir_resolve_usize(ira, elem_index, &elem_index_scalar))14348 if (!ir_resolve_usize(ira, elem_index, &elem_index_scalar))
14312 return ira->codegen->invalid_inst_gen;14349 return ira->codegen->invalid_inst_gen;
14313 if (elem_index_scalar >= array_type->data.structure.src_field_count) {14350 if (elem_index_scalar >= array_type->data.structure.src_field_count) {
14314 ir_add_error(ira, &elem_ptr_instruction->base.base, buf_sprintf(14351 ir_add_error_node(ira, elem_ptr_instruction->base.source_node, buf_sprintf(
14315 "field index %" ZIG_PRI_u64 " outside tuple '%s' which has %" PRIu32 " fields",14352 "field index %" ZIG_PRI_u64 " outside tuple '%s' which has %" PRIu32 " fields",
14316 elem_index_scalar, buf_ptr(&array_type->name),14353 elem_index_scalar, buf_ptr(&array_type->name),
14317 array_type->data.structure.src_field_count));14354 array_type->data.structure.src_field_count));
14318 return ira->codegen->invalid_inst_gen;14355 return ira->codegen->invalid_inst_gen;
14319 }14356 }
14320 TypeStructField *field = array_type->data.structure.fields[elem_index_scalar];14357 TypeStructField *field = array_type->data.structure.fields[elem_index_scalar];
14321 return ir_analyze_struct_field_ptr(ira, &elem_ptr_instruction->base.base, field, array_ptr,14358 return ir_analyze_struct_field_ptr(ira, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node, field, array_ptr,
14322 array_type, false);14359 array_type, false);
14323 } else {14360 } else {
14324 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,14361 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
14325 buf_sprintf("array access of non-array type '%s'", buf_ptr(&array_type->name)));14362 buf_sprintf("array access of non-array type '%s'", buf_ptr(&array_type->name)));
14326 return ira->codegen->invalid_inst_gen;14363 return ira->codegen->invalid_inst_gen;
14327 }14364 }
...@@ -14342,7 +14379,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP...@@ -14342,7 +14379,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
14342 uint64_t array_len = array_type->data.array.len +14379 uint64_t array_len = array_type->data.array.len +
14343 (array_type->data.array.sentinel != nullptr);14380 (array_type->data.array.sentinel != nullptr);
14344 if (index >= array_len) {14381 if (index >= array_len) {
14345 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,14382 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
14346 buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64,14383 buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64,
14347 index, array_len));14384 index, array_len));
14348 return ira->codegen->invalid_inst_gen;14385 return ira->codegen->invalid_inst_gen;
...@@ -14351,7 +14388,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP...@@ -14351,7 +14388,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
14351 } else if (array_type->id == ZigTypeIdVector) {14388 } else if (array_type->id == ZigTypeIdVector) {
14352 uint64_t vector_len = array_type->data.vector.len;14389 uint64_t vector_len = array_type->data.vector.len;
14353 if (index >= vector_len) {14390 if (index >= vector_len) {
14354 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,14391 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
14355 buf_sprintf("index %" ZIG_PRI_u64 " outside vector of size %" ZIG_PRI_u64,14392 buf_sprintf("index %" ZIG_PRI_u64 " outside vector of size %" ZIG_PRI_u64,
14356 index, vector_len));14393 index, vector_len));
14357 return ira->codegen->invalid_inst_gen;14394 return ira->codegen->invalid_inst_gen;
...@@ -14385,13 +14422,13 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP...@@ -14385,13 +14422,13 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
14385 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || array_type->id == ZigTypeIdArray))14422 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || array_type->id == ZigTypeIdArray))
14386 {14423 {
14387 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,14424 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
14388 elem_ptr_instruction->base.base.source_node, orig_array_ptr_val, UndefBad)))14425 elem_ptr_instruction->base.source_node, orig_array_ptr_val, UndefBad)))
14389 {14426 {
14390 return ira->codegen->invalid_inst_gen;14427 return ira->codegen->invalid_inst_gen;
14391 }14428 }
1439214429
14393 ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,14430 ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,
14394 elem_ptr_instruction->base.base.source_node);14431 elem_ptr_instruction->base.source_node);
14395 if (array_ptr_val == nullptr)14432 if (array_ptr_val == nullptr)
14396 return ira->codegen->invalid_inst_gen;14433 return ira->codegen->invalid_inst_gen;
1439714434
...@@ -14411,7 +14448,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP...@@ -14411,7 +14448,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
14411 elem_val->parent.data.p_array.elem_index = i;14448 elem_val->parent.data.p_array.elem_index = i;
14412 }14449 }
14413 } else if (is_slice(array_type)) {14450 } else if (is_slice(array_type)) {
14414 ir_assert(array_ptr->value->type->id == ZigTypeIdPointer, &elem_ptr_instruction->base.base);14451 src_assert(array_ptr->value->type->id == ZigTypeIdPointer, elem_ptr_instruction->base.source_node);
14415 ZigType *actual_array_type = array_ptr->value->type->data.pointer.child_type;14452 ZigType *actual_array_type = array_ptr->value->type->data.pointer.child_type;
1441614453
14417 if (type_is_invalid(actual_array_type))14454 if (type_is_invalid(actual_array_type))
...@@ -14454,12 +14491,12 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP...@@ -14454,12 +14491,12 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
14454 array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr))14491 array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr))
14455 {14492 {
14456 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,14493 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
14457 elem_ptr_instruction->base.base.source_node, array_ptr_val, UndefOk)))14494 elem_ptr_instruction->base.source_node, array_ptr_val, UndefOk)))
14458 {14495 {
14459 return ira->codegen->invalid_inst_gen;14496 return ira->codegen->invalid_inst_gen;
14460 }14497 }
14461 if (array_type->id == ZigTypeIdPointer) {14498 if (array_type->id == ZigTypeIdPointer) {
14462 IrInstGen *result = ir_const(ira, &elem_ptr_instruction->base.base, return_type);14499 IrInstGen *result = ir_const(ira, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node, return_type);
14463 ZigValue *out_val = result->value;14500 ZigValue *out_val = result->value;
14464 out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;14501 out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;
14465 size_t new_index;14502 size_t new_index;
...@@ -14529,7 +14566,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP...@@ -14529,7 +14566,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
14529 zig_panic("TODO elem ptr on a null pointer");14566 zig_panic("TODO elem ptr on a null pointer");
14530 }14567 }
14531 if (new_index >= mem_size) {14568 if (new_index >= mem_size) {
14532 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,14569 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
14533 buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size));14570 buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size));
14534 return ira->codegen->invalid_inst_gen;14571 return ira->codegen->invalid_inst_gen;
14535 }14572 }
...@@ -14538,21 +14575,22 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP...@@ -14538,21 +14575,22 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
14538 expand_undef_struct(ira->codegen, array_ptr_val);14575 expand_undef_struct(ira->codegen, array_ptr_val);
1453914576
14540 ZigValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index];14577 ZigValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index];
14541 ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base.base);14578 src_assert(ptr_field != nullptr, elem_ptr_instruction->base.source_node);
14542 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {14579 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
14543 return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope,14580 return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.scope,
14544 elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, false,14581 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false,
14545 return_type);14582 return_type);
14546 }14583 }
14547 ZigValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index];14584 ZigValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index];
14548 IrInstGen *result = ir_const(ira, &elem_ptr_instruction->base.base, return_type);14585 IrInstGen *result = ir_const(ira, elem_ptr_instruction->base.scope,
14586 elem_ptr_instruction->base.source_node, return_type);
14549 ZigValue *out_val = result->value;14587 ZigValue *out_val = result->value;
14550 ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry;14588 ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry;
14551 uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint);14589 uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint);
14552 uint64_t full_slice_len = slice_len +14590 uint64_t full_slice_len = slice_len +
14553 ((slice_ptr_type->data.pointer.sentinel != nullptr) ? 1 : 0);14591 ((slice_ptr_type->data.pointer.sentinel != nullptr) ? 1 : 0);
14554 if (index >= full_slice_len) {14592 if (index >= full_slice_len) {
14555 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,14593 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
14556 buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64,14594 buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64,
14557 index, slice_len));14595 index, slice_len));
14558 return ira->codegen->invalid_inst_gen;14596 return ira->codegen->invalid_inst_gen;
...@@ -14575,7 +14613,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP...@@ -14575,7 +14613,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
14575 ConstArraySpecialBuf)14613 ConstArraySpecialBuf)
14576 {14614 {
14577 if (new_index >= ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len) {14615 if (new_index >= ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len) {
14578 ir_add_error(ira, &elem_ptr_instruction->base.base, buf_sprintf("out of bounds slice"));14616 ir_add_error_node(ira, elem_ptr_instruction->base.source_node, buf_sprintf("out of bounds slice"));
14579 return ira->codegen->invalid_inst_gen;14617 return ira->codegen->invalid_inst_gen;
14580 }14618 }
14581 }14619 }
...@@ -14606,12 +14644,12 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP...@@ -14606,12 +14644,12 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
1460614644
14607 IrInstGen *result;14645 IrInstGen *result;
14608 if (orig_array_ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {14646 if (orig_array_ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
14609 result = ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope,14647 result = ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.scope,
14610 elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index,14648 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index,
14611 false, return_type);14649 false, return_type);
14612 result->value->special = ConstValSpecialStatic;14650 result->value->special = ConstValSpecialStatic;
14613 } else {14651 } else {
14614 result = ir_const(ira, &elem_ptr_instruction->base.base, return_type);14652 result = ir_const(ira, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node, return_type);
14615 }14653 }
14616 ZigValue *out_val = result->value;14654 ZigValue *out_val = result->value;
14617 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;14655 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
...@@ -14637,7 +14675,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP...@@ -14637,7 +14675,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
14637 // runtime known element index14675 // runtime known element index
14638 switch (type_requires_comptime(ira->codegen, return_type)) {14676 switch (type_requires_comptime(ira->codegen, return_type)) {
14639 case ReqCompTimeYes:14677 case ReqCompTimeYes:
14640 ir_add_error(ira, &elem_index->base,14678 ir_add_error(ira, elem_index,
14641 buf_sprintf("values of type '%s' must be comptime known, but index value is runtime known",14679 buf_sprintf("values of type '%s' must be comptime known, but index value is runtime known",
14642 buf_ptr(&return_type->data.pointer.child_type->name)));14680 buf_ptr(&return_type->data.pointer.child_type->name)));
14643 return ira->codegen->invalid_inst_gen;14681 return ira->codegen->invalid_inst_gen;
...@@ -14667,13 +14705,13 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP...@@ -14667,13 +14705,13 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
14667 }14705 }
14668 }14706 }
1466914707
14670 return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope,14708 return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.scope,
14671 elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, safety_check_on, return_type);14709 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, safety_check_on, return_type);
14672}14710}
1467314711
14674static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,14712static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
14675 ZigType *bare_struct_type, Buf *field_name, IrInst* source_instr,14713 ZigType *bare_struct_type, Buf *field_name, Scope *scope, AstNode *source_node,
14676 IrInstGen *container_ptr, IrInst *container_ptr_src, ZigType *container_type)14714 IrInstGen *container_ptr, AstNode *container_ptr_src, ZigType *container_type)
14677{14715{
14678 if (!is_slice(bare_struct_type)) {14716 if (!is_slice(bare_struct_type)) {
14679 ScopeDecls *container_scope = get_container_scope(bare_struct_type);14717 ScopeDecls *container_scope = get_container_scope(bare_struct_type);
...@@ -14681,16 +14719,16 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -14681,16 +14719,16 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
14681 auto tld = find_container_decl(ira->codegen, container_scope, field_name);14719 auto tld = find_container_decl(ira->codegen, container_scope, field_name);
14682 if (tld) {14720 if (tld) {
14683 if (tld->id == TldIdFn) {14721 if (tld->id == TldIdFn) {
14684 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);14722 resolve_top_level_decl(ira->codegen, tld, source_node, false);
14685 if (tld->resolution == TldResolutionInvalid)14723 if (tld->resolution == TldResolutionInvalid)
14686 return ira->codegen->invalid_inst_gen;14724 return ira->codegen->invalid_inst_gen;
14687 if (tld->resolution == TldResolutionResolving)14725 if (tld->resolution == TldResolutionResolving)
14688 return ir_error_dependency_loop(ira, source_instr);14726 return ir_error_dependency_loop(ira, source_node);
1468914727
14690 if (tld->visib_mod == VisibModPrivate &&14728 if (tld->visib_mod == VisibModPrivate &&
14691 tld->import != get_scope_import(source_instr->scope))14729 tld->import != get_scope_import(scope))
14692 {14730 {
14693 ErrorMsg *msg = ir_add_error(ira, source_instr,14731 ErrorMsg *msg = ir_add_error_node(ira, source_node,
14694 buf_sprintf("'%s' is private", buf_ptr(field_name)));14732 buf_sprintf("'%s' is private", buf_ptr(field_name)));
14695 add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));14733 add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));
14696 return ira->codegen->invalid_inst_gen;14734 return ira->codegen->invalid_inst_gen;
...@@ -14703,15 +14741,15 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -14703,15 +14741,15 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
14703 if (type_is_invalid(fn_entry->type_entry))14741 if (type_is_invalid(fn_entry->type_entry))
14704 return ira->codegen->invalid_inst_gen;14742 return ira->codegen->invalid_inst_gen;
1470514743
14706 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn_entry, container_ptr,14744 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, scope, source_node, fn_entry, container_ptr,
14707 container_ptr_src);14745 container_ptr_src);
14708 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);14746 return ir_get_ref(ira, scope, source_node, bound_fn_value, true, false);
14709 } else if (tld->id == TldIdVar) {14747 } else if (tld->id == TldIdVar) {
14710 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);14748 resolve_top_level_decl(ira->codegen, tld, source_node, false);
14711 if (tld->resolution == TldResolutionInvalid)14749 if (tld->resolution == TldResolutionInvalid)
14712 return ira->codegen->invalid_inst_gen;14750 return ira->codegen->invalid_inst_gen;
14713 if (tld->resolution == TldResolutionResolving)14751 if (tld->resolution == TldResolutionResolving)
14714 return ir_error_dependency_loop(ira, source_instr);14752 return ir_error_dependency_loop(ira, source_node);
1471514753
14716 TldVar *tld_var = (TldVar *)tld;14754 TldVar *tld_var = (TldVar *)tld;
14717 ZigVar *var = tld_var->var;14755 ZigVar *var = tld_var->var;
...@@ -14721,11 +14759,11 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -14721,11 +14759,11 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
14721 return ira->codegen->invalid_inst_gen;14759 return ira->codegen->invalid_inst_gen;
1472214760
14723 if (var->const_value->type->id == ZigTypeIdFn) {14761 if (var->const_value->type->id == ZigTypeIdFn) {
14724 ir_assert(var->const_value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr);14762 src_assert(var->const_value->data.x_ptr.special == ConstPtrSpecialFunction, source_node);
14725 ZigFn *fn = var->const_value->data.x_ptr.data.fn.fn_entry;14763 ZigFn *fn = var->const_value->data.x_ptr.data.fn.fn_entry;
14726 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn, container_ptr,14764 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, scope, source_node, fn, container_ptr,
14727 container_ptr_src);14765 container_ptr_src);
14728 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);14766 return ir_get_ref(ira, scope, source_node, bound_fn_value, true, false);
14729 }14767 }
14730 }14768 }
14731 }14769 }
...@@ -14744,7 +14782,7 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -14744,7 +14782,7 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
14744 } else {14782 } else {
14745 prefix_name = "";14783 prefix_name = "";
14746 }14784 }
14747 ir_add_error_node(ira, source_instr->source_node,14785 ir_add_error_node(ira, source_node,
14748 buf_sprintf("no member named '%s' in %s'%s'", buf_ptr(field_name), prefix_name, buf_ptr(&bare_struct_type->name)));14786 buf_sprintf("no member named '%s' in %s'%s'", buf_ptr(field_name), prefix_name, buf_ptr(&bare_struct_type->name)));
14749 return ira->codegen->invalid_inst_gen;14787 return ira->codegen->invalid_inst_gen;
14750}14788}
...@@ -14762,7 +14800,7 @@ static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, Ty...@@ -14762,7 +14800,7 @@ static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, Ty
14762 field->type_entry, nullptr, UndefOk);14800 field->type_entry, nullptr, UndefOk);
14763}14801}
1476414802
14765static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_instr,14803static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node,
14766 TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing)14804 TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing)
14767{14805{
14768 Error err;14806 Error err;
...@@ -14770,21 +14808,21 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins...@@ -14770,21 +14808,21 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins
14770 if (field_type == nullptr)14808 if (field_type == nullptr)
14771 return ira->codegen->invalid_inst_gen;14809 return ira->codegen->invalid_inst_gen;
14772 if (field->is_comptime) {14810 if (field->is_comptime) {
14773 IrInstGen *elem = ir_const(ira, source_instr, field_type);14811 IrInstGen *elem = ir_const(ira, scope, source_node, field_type);
14774 memoize_field_init_val(ira->codegen, struct_type, field);14812 memoize_field_init_val(ira->codegen, struct_type, field);
14775 if(field->init_val != nullptr && type_is_invalid(field->init_val->type)){14813 if(field->init_val != nullptr && type_is_invalid(field->init_val->type)){
14776 return ira->codegen->invalid_inst_gen;14814 return ira->codegen->invalid_inst_gen;
14777 }14815 }
14778 copy_const_val(ira->codegen, elem->value, field->init_val);14816 copy_const_val(ira->codegen, elem->value, field->init_val);
14779 return ir_get_ref2(ira, source_instr, elem, field_type, true, false);14817 return ir_get_ref2(ira, scope, source_node, elem, field_type, true, false);
14780 }14818 }
14781 switch (type_has_one_possible_value(ira->codegen, field_type)) {14819 switch (type_has_one_possible_value(ira->codegen, field_type)) {
14782 case OnePossibleValueInvalid:14820 case OnePossibleValueInvalid:
14783 return ira->codegen->invalid_inst_gen;14821 return ira->codegen->invalid_inst_gen;
14784 case OnePossibleValueYes: {14822 case OnePossibleValueYes: {
14785 IrInstGen *elem = ir_const_move(ira, source_instr,14823 IrInstGen *elem = ir_const_move(ira, scope, source_node,
14786 get_the_one_possible_value(ira->codegen, field_type));14824 get_the_one_possible_value(ira->codegen, field_type));
14787 return ir_get_ref(ira, source_instr, elem,14825 return ir_get_ref(ira, scope, source_node, elem,
14788 struct_ptr->value->type->data.pointer.is_const,14826 struct_ptr->value->type->data.pointer.is_const,
14789 struct_ptr->value->type->data.pointer.is_volatile);14827 struct_ptr->value->type->data.pointer.is_volatile);
14790 }14828 }
...@@ -14819,7 +14857,7 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins...@@ -14819,7 +14857,7 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins
14819 return ira->codegen->invalid_inst_gen;14857 return ira->codegen->invalid_inst_gen;
1482014858
14821 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {14859 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
14822 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);14860 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_node);
14823 if (struct_val == nullptr)14861 if (struct_val == nullptr)
14824 return ira->codegen->invalid_inst_gen;14862 return ira->codegen->invalid_inst_gen;
14825 if (type_is_invalid(struct_val->type))14863 if (type_is_invalid(struct_val->type))
...@@ -14827,7 +14865,7 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins...@@ -14827,7 +14865,7 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins
1482714865
14828 // This to allow lazy values to be resolved.14866 // This to allow lazy values to be resolved.
14829 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,14867 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
14830 source_instr->source_node, struct_val, UndefOk)))14868 source_node, struct_val, UndefOk)))
14831 {14869 {
14832 return ira->codegen->invalid_inst_gen;14870 return ira->codegen->invalid_inst_gen;
14833 }14871 }
...@@ -14846,10 +14884,10 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins...@@ -14846,10 +14884,10 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins
14846 }14884 }
14847 IrInstGen *result;14885 IrInstGen *result;
14848 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {14886 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
14849 result = ir_build_struct_field_ptr(ira, source_instr, struct_ptr, field, ptr_type);14887 result = ir_build_struct_field_ptr(ira, scope, source_node, struct_ptr, field, ptr_type);
14850 result->value->special = ConstValSpecialStatic;14888 result->value->special = ConstValSpecialStatic;
14851 } else {14889 } else {
14852 result = ir_const(ira, source_instr, ptr_type);14890 result = ir_const(ira, scope, source_node, ptr_type);
14853 }14891 }
14854 ZigValue *const_val = result->value;14892 ZigValue *const_val = result->value;
14855 const_val->data.x_ptr.special = ConstPtrSpecialBaseStruct;14893 const_val->data.x_ptr.special = ConstPtrSpecialBaseStruct;
...@@ -14859,11 +14897,11 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins...@@ -14859,11 +14897,11 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins
14859 return result;14897 return result;
14860 }14898 }
14861 }14899 }
14862 return ir_build_struct_field_ptr(ira, source_instr, struct_ptr, field, ptr_type);14900 return ir_build_struct_field_ptr(ira, scope, source_node, struct_ptr, field, ptr_type);
14863}14901}
1486414902
14865static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,14903static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
14866 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type)14904 Scope *scope, AstNode *source_node, IrInstGen *container_ptr, ZigType *container_type)
14867{14905{
14868 // The type of the field is not available until a store using this pointer happens.14906 // The type of the field is not available until a store using this pointer happens.
14869 // So, here we create a special pointer type which has the inferred struct type and14907 // So, here we create a special pointer type which has the inferred struct type and
...@@ -14872,7 +14910,7 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,...@@ -14872,7 +14910,7 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
14872 // struct.14910 // struct.
1487314911
14874 ZigType *container_ptr_type = container_ptr->value->type;14912 ZigType *container_ptr_type = container_ptr->value->type;
14875 ir_assert(container_ptr_type->id == ZigTypeIdPointer, source_instr);14913 src_assert(container_ptr_type->id == ZigTypeIdPointer, source_node);
1487614914
14877 InferredStructField *inferred_struct_field = heap::c_allocator.create<InferredStructField>();14915 InferredStructField *inferred_struct_field = heap::c_allocator.create<InferredStructField>();
14878 inferred_struct_field->inferred_struct_type = container_type;14916 inferred_struct_field->inferred_struct_type = container_type;
...@@ -14890,20 +14928,20 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,...@@ -14890,20 +14928,20 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
1489014928
14891 IrInstGen *result;14929 IrInstGen *result;
14892 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {14930 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
14893 result = ir_build_cast(ira, source_instr, container_ptr_type, container_ptr, CastOpNoop);14931 result = ir_build_cast(ira, scope, source_node, container_ptr_type, container_ptr, CastOpNoop);
14894 } else {14932 } else {
14895 result = ir_const(ira, source_instr, field_ptr_type);14933 result = ir_const(ira, scope, source_node, field_ptr_type);
14896 }14934 }
14897 copy_const_val(ira->codegen, result->value, ptr_val);14935 copy_const_val(ira->codegen, result->value, ptr_val);
14898 result->value->type = field_ptr_type;14936 result->value->type = field_ptr_type;
14899 return result;14937 return result;
14900 }14938 }
1490114939
14902 return ir_build_cast(ira, source_instr, field_ptr_type, container_ptr, CastOpNoop);14940 return ir_build_cast(ira, scope, source_node, field_ptr_type, container_ptr, CastOpNoop);
14903}14941}
1490414942
14905static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,14943static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
14906 IrInst* source_instr, IrInstGen *container_ptr, IrInst *container_ptr_src,14944 Scope *scope, AstNode *source_node, IrInstGen *container_ptr, AstNode *container_ptr_src,
14907 ZigType *container_type, bool initializing)14945 ZigType *container_type, bool initializing)
14908{14946{
14909 Error err;14947 Error err;
...@@ -14913,13 +14951,13 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name...@@ -14913,13 +14951,13 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
14913 if (initializing && bare_type->id == ZigTypeIdStruct &&14951 if (initializing && bare_type->id == ZigTypeIdStruct &&
14914 bare_type->data.structure.resolve_status == ResolveStatusBeingInferred)14952 bare_type->data.structure.resolve_status == ResolveStatusBeingInferred)
14915 {14953 {
14916 return ir_analyze_inferred_field_ptr(ira, field_name, source_instr, container_ptr, bare_type);14954 return ir_analyze_inferred_field_ptr(ira, field_name, scope, source_node, container_ptr, bare_type);
14917 }14955 }
1491814956
14919 // Tracks wether we should return an undefined value of the correct type.14957 // Tracks wether we should return an undefined value of the correct type.
14920 // We do this if the container pointer is undefined and we are in a TypeOf call.14958 // We do this if the container pointer is undefined and we are in a TypeOf call.
14921 bool return_undef = container_ptr->value->special == ConstValSpecialUndef && \14959 bool return_undef = container_ptr->value->special == ConstValSpecialUndef && \
14922 get_scope_typeof(source_instr->scope) != nullptr;14960 get_scope_typeof(scope) != nullptr;
1492314961
14924 if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown)))14962 if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown)))
14925 return ira->codegen->invalid_inst_gen;14963 return ira->codegen->invalid_inst_gen;
...@@ -14931,19 +14969,19 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name...@@ -14931,19 +14969,19 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
14931 if (return_undef) {14969 if (return_undef) {
14932 ZigType *field_ptr_type = get_pointer_to_type(ira->codegen, resolve_struct_field_type(ira->codegen, field),14970 ZigType *field_ptr_type = get_pointer_to_type(ira->codegen, resolve_struct_field_type(ira->codegen, field),
14933 container_ptr->value->type->data.pointer.is_const);14971 container_ptr->value->type->data.pointer.is_const);
14934 return ir_const_undef(ira, source_instr, field_ptr_type);14972 return ir_const_undef(ira, scope, source_node, field_ptr_type);
14935 }14973 }
1493614974
14937 return ir_analyze_struct_field_ptr(ira, source_instr, field, container_ptr, bare_type, initializing);14975 return ir_analyze_struct_field_ptr(ira, scope, source_node, field, container_ptr, bare_type, initializing);
14938 } else {14976 } else {
14939 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,14977 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
14940 source_instr, container_ptr, container_ptr_src, container_type);14978 scope, source_node, container_ptr, container_ptr_src, container_type);
14941 }14979 }
14942 }14980 }
1494314981
14944 if (bare_type->id == ZigTypeIdEnum || bare_type->id == ZigTypeIdOpaque) {14982 if (bare_type->id == ZigTypeIdEnum || bare_type->id == ZigTypeIdOpaque) {
14945 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,14983 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
14946 source_instr, container_ptr, container_ptr_src, container_type);14984 scope, source_node, container_ptr, container_ptr_src, container_type);
14947 }14985 }
1494814986
14949 if (bare_type->id == ZigTypeIdUnion) {14987 if (bare_type->id == ZigTypeIdUnion) {
...@@ -14953,7 +14991,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name...@@ -14953,7 +14991,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
14953 TypeUnionField *field = find_union_type_field(bare_type, field_name);14991 TypeUnionField *field = find_union_type_field(bare_type, field_name);
14954 if (field == nullptr) {14992 if (field == nullptr) {
14955 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,14993 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
14956 source_instr, container_ptr, container_ptr_src, container_type);14994 scope, source_node, container_ptr, container_ptr_src, container_type);
14957 }14995 }
1495814996
14959 ZigType *field_type = resolve_union_field_type(ira->codegen, field);14997 ZigType *field_type = resolve_union_field_type(ira->codegen, field);
...@@ -14969,7 +15007,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name...@@ -14969,7 +15007,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
1496915007
14970 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&15008 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
14971 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {15009 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
14972 ZigValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);15010 ZigValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_node);
14973 if (union_val == nullptr)15011 if (union_val == nullptr)
14974 return ira->codegen->invalid_inst_gen;15012 return ira->codegen->invalid_inst_gen;
14975 if (type_is_invalid(union_val->type))15013 if (type_is_invalid(union_val->type))
...@@ -14980,7 +15018,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name...@@ -14980,7 +15018,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
14980 // its payload slot is UB.15018 // its payload slot is UB.
14981 const UndefAllowed allow_undef = initializing ? UndefOk : UndefBad;15019 const UndefAllowed allow_undef = initializing ? UndefOk : UndefBad;
14982 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,15020 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
14983 source_instr->source_node, union_val, allow_undef)))15021 source_node, union_val, allow_undef)))
14984 {15022 {
14985 return ira->codegen->invalid_inst_gen;15023 return ira->codegen->invalid_inst_gen;
14986 }15024 }
...@@ -15001,7 +15039,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name...@@ -15001,7 +15039,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
15001 zig_unreachable();15039 zig_unreachable();
1500215040
15003 if (field != actual_field) {15041 if (field != actual_field) {
15004 ir_add_error_node(ira, source_instr->source_node,15042 ir_add_error_node(ira, source_node,
15005 buf_sprintf("accessing union field '%s' while field '%s' is set", buf_ptr(field_name),15043 buf_sprintf("accessing union field '%s' while field '%s' is set", buf_ptr(field_name),
15006 buf_ptr(actual_field->name)));15044 buf_ptr(actual_field->name)));
15007 return ira->codegen->invalid_inst_gen;15045 return ira->codegen->invalid_inst_gen;
...@@ -15013,11 +15051,11 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name...@@ -15013,11 +15051,11 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
1501315051
15014 IrInstGen *result;15052 IrInstGen *result;
15015 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {15053 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
15016 result = ir_build_union_field_ptr(ira, source_instr, container_ptr, field, true,15054 result = ir_build_union_field_ptr(ira, scope, source_node, container_ptr, field, true,
15017 initializing, ptr_type);15055 initializing, ptr_type);
15018 result->value->special = ConstValSpecialStatic;15056 result->value->special = ConstValSpecialStatic;
15019 } else {15057 } else {
15020 result = ir_const(ira, source_instr, ptr_type);15058 result = ir_const(ira, scope, source_node, ptr_type);
15021 }15059 }
15022 ZigValue *const_val = result->value;15060 ZigValue *const_val = result->value;
15023 const_val->data.x_ptr.special = ConstPtrSpecialRef;15061 const_val->data.x_ptr.special = ConstPtrSpecialRef;
...@@ -15027,7 +15065,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name...@@ -15027,7 +15065,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
15027 }15065 }
15028 }15066 }
1502915067
15030 return ir_build_union_field_ptr(ira, source_instr, container_ptr, field, true, initializing, ptr_type);15068 return ir_build_union_field_ptr(ira, scope, source_node, container_ptr, field, true, initializing, ptr_type);
15031 }15069 }
1503215070
15033 zig_unreachable();15071 zig_unreachable();
...@@ -15042,18 +15080,18 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,...@@ -15042,18 +15080,18 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,
15042 }15080 }
15043}15081}
1504415082
15045static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst* source_instr) {15083static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, AstNode* source_node) {
15046 ir_add_error(ira, source_instr, buf_sprintf("dependency loop detected"));15084 ir_add_error_node(ira, source_node, buf_sprintf("dependency loop detected"));
15047 return ira->codegen->invalid_inst_gen;15085 return ira->codegen->invalid_inst_gen;
15048}15086}
1504915087
15050static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction, Tld *tld) {15088static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, Scope *scope, AstNode *source_node, Tld *tld) {
15051 resolve_top_level_decl(ira->codegen, tld, source_instruction->source_node, true);15089 resolve_top_level_decl(ira->codegen, tld, source_node, true);
15052 if (tld->resolution == TldResolutionInvalid) {15090 if (tld->resolution == TldResolutionInvalid) {
15053 return ira->codegen->invalid_inst_gen;15091 return ira->codegen->invalid_inst_gen;
15054 }15092 }
15055 if (tld->resolution == TldResolutionResolving)15093 if (tld->resolution == TldResolutionResolving)
15056 return ir_error_dependency_loop(ira, source_instruction);15094 return ir_error_dependency_loop(ira, source_node);
1505715095
15058 switch (tld->id) {15096 switch (tld->id) {
15059 case TldIdContainer:15097 case TldIdContainer:
...@@ -15067,10 +15105,10 @@ static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction...@@ -15067,10 +15105,10 @@ static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction
1506715105
15068 if (tld_var->extern_lib_name != nullptr) {15106 if (tld_var->extern_lib_name != nullptr) {
15069 add_link_lib_symbol(ira, tld_var->extern_lib_name, buf_create_from_str(var->name),15107 add_link_lib_symbol(ira, tld_var->extern_lib_name, buf_create_from_str(var->name),
15070 source_instruction->source_node);15108 source_node);
15071 }15109 }
1507215110
15073 return ir_get_var_ptr(ira, source_instruction, var);15111 return ir_get_var_ptr(ira, scope, source_node, var);
15074 }15112 }
15075 case TldIdFn: {15113 case TldIdFn: {
15076 TldFn *tld_fn = (TldFn *)tld;15114 TldFn *tld_fn = (TldFn *)tld;
...@@ -15081,11 +15119,11 @@ static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction...@@ -15081,11 +15119,11 @@ static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction
15081 return ira->codegen->invalid_inst_gen;15119 return ira->codegen->invalid_inst_gen;
1508215120
15083 if (tld_fn->extern_lib_name != nullptr) {15121 if (tld_fn->extern_lib_name != nullptr) {
15084 add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_instruction->source_node);15122 add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_node);
15085 }15123 }
1508615124
15087 IrInstGen *fn_inst = ir_const_fn(ira, source_instruction, fn_entry);15125 IrInstGen *fn_inst = ir_const_fn(ira, scope, source_node, fn_entry);
15088 return ir_get_ref(ira, source_instruction, fn_inst, true, false);15126 return ir_get_ref(ira, scope, source_node, fn_inst, true, false);
15089 }15127 }
15090 }15128 }
15091 zig_unreachable();15129 zig_unreachable();
...@@ -15119,27 +15157,30 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel...@@ -15119,27 +15157,30 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
15119 }15157 }
1512015158
1512115159
15122 AstNode *source_node = field_ptr_instruction->base.base.source_node;15160 AstNode *source_node = field_ptr_instruction->base.source_node;
1512315161
15124 if (type_is_invalid(container_type)) {15162 if (type_is_invalid(container_type)) {
15125 return ira->codegen->invalid_inst_gen;15163 return ira->codegen->invalid_inst_gen;
15126 } else if (is_tuple(container_type) && !field_ptr_instruction->initializing && buf_eql_str(field_name, "len")) {15164 } else if (is_tuple(container_type) && !field_ptr_instruction->initializing && buf_eql_str(field_name, "len")) {
15127 IrInstGen *len_inst = ir_const_unsigned(ira, &field_ptr_instruction->base.base,15165 IrInstGen *len_inst = ir_const_unsigned(ira, field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node,
15128 container_type->data.structure.src_field_count);15166 container_type->data.structure.src_field_count);
15129 return ir_get_ref(ira, &field_ptr_instruction->base.base, len_inst, true, false);15167 return ir_get_ref(ira, field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node, len_inst, true, false);
15130 } else if (is_slice(container_type) || is_container_ref(container_type)) {15168 } else if (is_slice(container_type) || is_container_ref(container_type)) {
15131 assert(container_ptr->value->type->id == ZigTypeIdPointer);15169 assert(container_ptr->value->type->id == ZigTypeIdPointer);
15132 if (container_type->id == ZigTypeIdPointer) {15170 if (container_type->id == ZigTypeIdPointer) {
15133 ZigType *bare_type = container_ref_type(container_type);15171 ZigType *bare_type = container_ref_type(container_type);
15134 IrInstGen *container_child = ir_get_deref(ira, &field_ptr_instruction->base.base, container_ptr, nullptr);15172 IrInstGen *container_child = ir_get_deref(ira, field_ptr_instruction->base.scope,
15135 IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base,15173 field_ptr_instruction->base.source_node, container_ptr, nullptr);
15136 container_child, &field_ptr_instruction->container_ptr->base, bare_type,15174 IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name,
15175 field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node,
15176 container_child, field_ptr_instruction->container_ptr->source_node, bare_type,
15137 field_ptr_instruction->initializing);15177 field_ptr_instruction->initializing);
15138 return result;15178 return result;
15139 } else {15179 } else {
15140 IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base,15180 IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name,
15141 container_ptr, &field_ptr_instruction->container_ptr->base, container_type,15181 field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node,
15142 field_ptr_instruction->initializing);15182 container_ptr, field_ptr_instruction->container_ptr->source_node,
15183 container_type, field_ptr_instruction->initializing);
15143 return result;15184 return result;
15144 }15185 }
15145 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {15186 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {
...@@ -15154,7 +15195,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel...@@ -15154,7 +15195,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
15154 ZigType *usize = ira->codegen->builtin_types.entry_usize;15195 ZigType *usize = ira->codegen->builtin_types.entry_usize;
15155 bool ptr_is_const = true;15196 bool ptr_is_const = true;
15156 bool ptr_is_volatile = false;15197 bool ptr_is_volatile = false;
15157 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, len_val,15198 return ir_get_const_ptr(ira, field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node, len_val,
15158 usize, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);15199 usize, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
15159 } else {15200 } else {
15160 ir_add_error_node(ira, source_node,15201 ir_add_error_node(ira, source_node,
...@@ -15172,7 +15213,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel...@@ -15172,7 +15213,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
15172 if (child_val == nullptr)15213 if (child_val == nullptr)
15173 return ira->codegen->invalid_inst_gen;15214 return ira->codegen->invalid_inst_gen;
15174 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,15215 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
15175 field_ptr_instruction->base.base.source_node, child_val, UndefBad)))15216 field_ptr_instruction->base.source_node, child_val, UndefBad)))
15176 {15217 {
15177 return ira->codegen->invalid_inst_gen;15218 return ira->codegen->invalid_inst_gen;
15178 }15219 }
...@@ -15189,7 +15230,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel...@@ -15189,7 +15230,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
15189 if (field) {15230 if (field) {
15190 bool ptr_is_const = true;15231 bool ptr_is_const = true;
15191 bool ptr_is_volatile = false;15232 bool ptr_is_volatile = false;
15192 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,15233 return ir_get_const_ptr(ira, field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node,
15193 create_const_enum(ira->codegen, child_type, &field->value), child_type,15234 create_const_enum(ira->codegen, child_type, &field->value), child_type,
15194 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);15235 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
15195 }15236 }
...@@ -15198,14 +15239,14 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel...@@ -15198,14 +15239,14 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
15198 Tld *tld = find_container_decl(ira->codegen, container_scope, field_name);15239 Tld *tld = find_container_decl(ira->codegen, container_scope, field_name);
15199 if (tld) {15240 if (tld) {
15200 if (tld->visib_mod == VisibModPrivate &&15241 if (tld->visib_mod == VisibModPrivate &&
15201 tld->import != get_scope_import(field_ptr_instruction->base.base.scope))15242 tld->import != get_scope_import(field_ptr_instruction->base.scope))
15202 {15243 {
15203 ErrorMsg *msg = ir_add_error(ira, &field_ptr_instruction->base.base,15244 ErrorMsg *msg = ir_add_error_node(ira, field_ptr_instruction->base.source_node,
15204 buf_sprintf("'%s' is private", buf_ptr(field_name)));15245 buf_sprintf("'%s' is private", buf_ptr(field_name)));
15205 add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));15246 add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));
15206 return ira->codegen->invalid_inst_gen;15247 return ira->codegen->invalid_inst_gen;
15207 }15248 }
15208 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base.base, tld);15249 return ir_analyze_decl_ref(ira, field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node, tld);
15209 }15250 }
15210 if (child_type->id == ZigTypeIdUnion &&15251 if (child_type->id == ZigTypeIdUnion &&
15211 (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr ||15252 (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr ||
...@@ -15218,14 +15259,14 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel...@@ -15218,14 +15259,14 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
15218 ZigType *enum_type = child_type->data.unionation.tag_type;15259 ZigType *enum_type = child_type->data.unionation.tag_type;
15219 bool ptr_is_const = true;15260 bool ptr_is_const = true;
15220 bool ptr_is_volatile = false;15261 bool ptr_is_volatile = false;
15221 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,15262 return ir_get_const_ptr(ira, field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node,
15222 create_const_enum(ira->codegen, enum_type, &field->enum_field->value), enum_type,15263 create_const_enum(ira->codegen, enum_type, &field->enum_field->value), enum_type,
15223 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);15264 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
15224 }15265 }
15225 }15266 }
15226 const char *container_name = (child_type == ira->codegen->root_import) ?15267 const char *container_name = (child_type == ira->codegen->root_import) ?
15227 "root source file" : buf_ptr(buf_sprintf("container '%s'", buf_ptr(&child_type->name)));15268 "root source file" : buf_ptr(buf_sprintf("container '%s'", buf_ptr(&child_type->name)));
15228 ir_add_error(ira, &field_ptr_instruction->base.base,15269 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
15229 buf_sprintf("%s has no member called '%s'",15270 buf_sprintf("%s has no member called '%s'",
15230 container_name, buf_ptr(field_name)));15271 container_name, buf_ptr(field_name)));
15231 return ira->codegen->invalid_inst_gen;15272 return ira->codegen->invalid_inst_gen;
...@@ -15238,7 +15279,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel...@@ -15238,7 +15279,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
15238 err_entry = existing_entry->value;15279 err_entry = existing_entry->value;
15239 } else {15280 } else {
15240 err_entry = heap::c_allocator.create<ErrorTableEntry>();15281 err_entry = heap::c_allocator.create<ErrorTableEntry>();
15241 err_entry->decl_node = field_ptr_instruction->base.base.source_node;15282 err_entry->decl_node = field_ptr_instruction->base.source_node;
15242 buf_init_from_buf(&err_entry->name, field_name);15283 buf_init_from_buf(&err_entry->name, field_name);
15243 size_t error_value_count = ira->codegen->errors_by_index.length;15284 size_t error_value_count = ira->codegen->errors_by_index.length;
15244 assert((uint32_t)error_value_count < (((uint32_t)1) << (uint32_t)ira->codegen->err_tag_type->data.integral.bit_count));15285 assert((uint32_t)error_value_count < (((uint32_t)1) << (uint32_t)ira->codegen->err_tag_type->data.integral.bit_count));
...@@ -15248,17 +15289,17 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel...@@ -15248,17 +15289,17 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
15248 }15289 }
15249 if (err_entry->set_with_only_this_in_it == nullptr) {15290 if (err_entry->set_with_only_this_in_it == nullptr) {
15250 err_entry->set_with_only_this_in_it = make_err_set_with_one_item(ira->codegen,15291 err_entry->set_with_only_this_in_it = make_err_set_with_one_item(ira->codegen,
15251 field_ptr_instruction->base.base.scope, field_ptr_instruction->base.base.source_node,15292 field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node,
15252 err_entry);15293 err_entry);
15253 }15294 }
15254 err_set_type = err_entry->set_with_only_this_in_it;15295 err_set_type = err_entry->set_with_only_this_in_it;
15255 } else {15296 } else {
15256 if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.base.source_node)) {15297 if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.source_node)) {
15257 return ira->codegen->invalid_inst_gen;15298 return ira->codegen->invalid_inst_gen;
15258 }15299 }
15259 err_entry = find_err_table_entry(child_type, field_name);15300 err_entry = find_err_table_entry(child_type, field_name);
15260 if (err_entry == nullptr) {15301 if (err_entry == nullptr) {
15261 ir_add_error(ira, &field_ptr_instruction->base.base,15302 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
15262 buf_sprintf("no error named '%s' in '%s'", buf_ptr(field_name), buf_ptr(&child_type->name)));15303 buf_sprintf("no error named '%s' in '%s'", buf_ptr(field_name), buf_ptr(&child_type->name)));
15263 return ira->codegen->invalid_inst_gen;15304 return ira->codegen->invalid_inst_gen;
15264 }15305 }
...@@ -15271,19 +15312,20 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel...@@ -15271,19 +15312,20 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
1527115312
15272 bool ptr_is_const = true;15313 bool ptr_is_const = true;
15273 bool ptr_is_volatile = false;15314 bool ptr_is_volatile = false;
15274 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, const_val,15315 return ir_get_const_ptr(ira, field_ptr_instruction->base.scope,
15316 field_ptr_instruction->base.source_node, const_val,
15275 err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);15317 err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
15276 } else {15318 } else {
15277 ir_add_error(ira, &field_ptr_instruction->base.base,15319 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
15278 buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));15320 buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));
15279 return ira->codegen->invalid_inst_gen;15321 return ira->codegen->invalid_inst_gen;
15280 }15322 }
15281 } else if (field_ptr_instruction->initializing) {15323 } else if (field_ptr_instruction->initializing) {
15282 ir_add_error(ira, &field_ptr_instruction->base.base,15324 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
15283 buf_sprintf("type '%s' does not support struct initialization syntax", buf_ptr(&container_type->name)));15325 buf_sprintf("type '%s' does not support struct initialization syntax", buf_ptr(&container_type->name)));
15284 return ira->codegen->invalid_inst_gen;15326 return ira->codegen->invalid_inst_gen;
15285 } else {15327 } else {
15286 ir_add_error_node(ira, field_ptr_instruction->base.base.source_node,15328 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
15287 buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));15329 buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));
15288 return ira->codegen->invalid_inst_gen;15330 return ira->codegen->invalid_inst_gen;
15289 }15331 }
...@@ -15298,14 +15340,14 @@ static IrInstGen *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstSrcStor...@@ -15298,14 +15340,14 @@ static IrInstGen *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstSrcStor
15298 if (type_is_invalid(value->value->type))15340 if (type_is_invalid(value->value->type))
15299 return ira->codegen->invalid_inst_gen;15341 return ira->codegen->invalid_inst_gen;
1530015342
15301 return ir_analyze_store_ptr(ira, &instruction->base.base, ptr, value, instruction->allow_write_through_const);15343 return ir_analyze_store_ptr(ira, instruction->base.scope, instruction->base.source_node, ptr, value, instruction->allow_write_through_const);
15302}15344}
1530315345
15304static IrInstGen *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstSrcLoadPtr *instruction) {15346static IrInstGen *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstSrcLoadPtr *instruction) {
15305 IrInstGen *ptr = instruction->ptr->child;15347 IrInstGen *ptr = instruction->ptr->child;
15306 if (type_is_invalid(ptr->value->type))15348 if (type_is_invalid(ptr->value->type))
15307 return ira->codegen->invalid_inst_gen;15349 return ira->codegen->invalid_inst_gen;
15308 return ir_get_deref(ira, &instruction->base.base, ptr, nullptr);15350 return ir_get_deref(ira, instruction->base.scope, instruction->base.source_node, ptr, nullptr);
15309}15351}
1531015352
15311static IrInstGen *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstSrcTypeOf *typeof_instruction) {15353static IrInstGen *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstSrcTypeOf *typeof_instruction) {
...@@ -15325,7 +15367,7 @@ static IrInstGen *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstSrcTypeOf...@@ -15325,7 +15367,7 @@ static IrInstGen *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstSrcTypeOf
15325 args[i] = value;15367 args[i] = value;
15326 }15368 }
1532715369
15328 type_entry = ir_resolve_peer_types(ira, typeof_instruction->base.base.source_node,15370 type_entry = ir_resolve_peer_types(ira, typeof_instruction->base.source_node,
15329 nullptr, args, value_count);15371 nullptr, args, value_count);
1533015372
15331 heap::c_allocator.deallocate(args, value_count);15373 heap::c_allocator.deallocate(args, value_count);
...@@ -15334,13 +15376,13 @@ static IrInstGen *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstSrcTypeOf...@@ -15334,13 +15376,13 @@ static IrInstGen *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstSrcTypeOf
15334 if (type_is_invalid(type_entry))15376 if (type_is_invalid(type_entry))
15335 return ira->codegen->invalid_inst_gen;15377 return ira->codegen->invalid_inst_gen;
1533615378
15337 return ir_const_type(ira, &typeof_instruction->base.base, type_entry);15379 return ir_const_type(ira, typeof_instruction->base.scope, typeof_instruction->base.source_node, type_entry);
15338}15380}
1533915381
15340static IrInstGen *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstSrcSetCold *instruction) {15382static IrInstGen *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstSrcSetCold *instruction) {
15341 if (ira->new_irb.exec->is_inline) {15383 if (ira->new_irb.exec->is_inline) {
15342 // ignore setCold when running functions at compile time15384 // ignore setCold when running functions at compile time
15343 return ir_const_void(ira, &instruction->base.base);15385 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
15344 }15386 }
1534515387
15346 IrInstGen *is_cold_value = instruction->is_cold->child;15388 IrInstGen *is_cold_value = instruction->is_cold->child;
...@@ -15348,22 +15390,22 @@ static IrInstGen *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstSrcSetCo...@@ -15348,22 +15390,22 @@ static IrInstGen *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstSrcSetCo
15348 if (!ir_resolve_bool(ira, is_cold_value, &want_cold))15390 if (!ir_resolve_bool(ira, is_cold_value, &want_cold))
15349 return ira->codegen->invalid_inst_gen;15391 return ira->codegen->invalid_inst_gen;
1535015392
15351 ZigFn *fn_entry = scope_fn_entry(instruction->base.base.scope);15393 ZigFn *fn_entry = scope_fn_entry(instruction->base.scope);
15352 if (fn_entry == nullptr) {15394 if (fn_entry == nullptr) {
15353 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setCold outside function"));15395 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("@setCold outside function"));
15354 return ira->codegen->invalid_inst_gen;15396 return ira->codegen->invalid_inst_gen;
15355 }15397 }
1535615398
15357 if (fn_entry->set_cold_node != nullptr) {15399 if (fn_entry->set_cold_node != nullptr) {
15358 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, buf_sprintf("cold set twice in same function"));15400 ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("cold set twice in same function"));
15359 add_error_note(ira->codegen, msg, fn_entry->set_cold_node, buf_sprintf("first set here"));15401 add_error_note(ira->codegen, msg, fn_entry->set_cold_node, buf_sprintf("first set here"));
15360 return ira->codegen->invalid_inst_gen;15402 return ira->codegen->invalid_inst_gen;
15361 }15403 }
1536215404
15363 fn_entry->set_cold_node = instruction->base.base.source_node;15405 fn_entry->set_cold_node = instruction->base.source_node;
15364 fn_entry->is_cold = want_cold;15406 fn_entry->is_cold = want_cold;
1536515407
15366 return ir_const_void(ira, &instruction->base.base);15408 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
15367}15409}
1536815410
15369static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,15411static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
...@@ -15371,13 +15413,14 @@ static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,...@@ -15371,13 +15413,14 @@ static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
15371{15413{
15372 if (ira->new_irb.exec->is_inline) {15414 if (ira->new_irb.exec->is_inline) {
15373 // ignore setRuntimeSafety when running functions at compile time15415 // ignore setRuntimeSafety when running functions at compile time
15374 return ir_const_void(ira, &set_runtime_safety_instruction->base.base);15416 return ir_const_void(ira, set_runtime_safety_instruction->base.scope,
15417 set_runtime_safety_instruction->base.source_node);
15375 }15418 }
1537615419
15377 bool *safety_off_ptr;15420 bool *safety_off_ptr;
15378 AstNode **safety_set_node_ptr;15421 AstNode **safety_set_node_ptr;
1537915422
15380 Scope *scope = set_runtime_safety_instruction->base.base.scope;15423 Scope *scope = set_runtime_safety_instruction->base.scope;
15381 while (scope != nullptr) {15424 while (scope != nullptr) {
15382 if (scope->id == ScopeIdBlock) {15425 if (scope->id == ScopeIdBlock) {
15383 ScopeBlock *block_scope = (ScopeBlock *)scope;15426 ScopeBlock *block_scope = (ScopeBlock *)scope;
...@@ -15408,7 +15451,7 @@ static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,...@@ -15408,7 +15451,7 @@ static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
15408 if (!ir_resolve_bool(ira, safety_on_value, &want_runtime_safety))15451 if (!ir_resolve_bool(ira, safety_on_value, &want_runtime_safety))
15409 return ira->codegen->invalid_inst_gen;15452 return ira->codegen->invalid_inst_gen;
1541015453
15411 AstNode *source_node = set_runtime_safety_instruction->base.base.source_node;15454 AstNode *source_node = set_runtime_safety_instruction->base.source_node;
15412 if (*safety_set_node_ptr) {15455 if (*safety_set_node_ptr) {
15413 ErrorMsg *msg = ir_add_error_node(ira, source_node,15456 ErrorMsg *msg = ir_add_error_node(ira, source_node,
15414 buf_sprintf("runtime safety set twice for same scope"));15457 buf_sprintf("runtime safety set twice for same scope"));
...@@ -15418,7 +15461,8 @@ static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,...@@ -15418,7 +15461,8 @@ static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
15418 *safety_set_node_ptr = source_node;15461 *safety_set_node_ptr = source_node;
15419 *safety_off_ptr = !want_runtime_safety;15462 *safety_off_ptr = !want_runtime_safety;
1542015463
15421 return ir_const_void(ira, &set_runtime_safety_instruction->base.base);15464 return ir_const_void(ira, set_runtime_safety_instruction->base.scope,
15465 set_runtime_safety_instruction->base.source_node);
15422}15466}
1542315467
15424static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,15468static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
...@@ -15426,13 +15470,13 @@ static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,...@@ -15426,13 +15470,13 @@ static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
15426{15470{
15427 if (ira->new_irb.exec->is_inline) {15471 if (ira->new_irb.exec->is_inline) {
15428 // ignore setFloatMode when running functions at compile time15472 // ignore setFloatMode when running functions at compile time
15429 return ir_const_void(ira, &instruction->base.base);15473 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
15430 }15474 }
1543115475
15432 bool *fast_math_on_ptr;15476 bool *fast_math_on_ptr;
15433 AstNode **fast_math_set_node_ptr;15477 AstNode **fast_math_set_node_ptr;
1543415478
15435 Scope *scope = instruction->base.base.scope;15479 Scope *scope = instruction->base.scope;
15436 while (scope != nullptr) {15480 while (scope != nullptr) {
15437 if (scope->id == ScopeIdBlock) {15481 if (scope->id == ScopeIdBlock) {
15438 ScopeBlock *block_scope = (ScopeBlock *)scope;15482 ScopeBlock *block_scope = (ScopeBlock *)scope;
...@@ -15463,7 +15507,7 @@ static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,...@@ -15463,7 +15507,7 @@ static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
15463 if (!ir_resolve_float_mode(ira, float_mode_value, &float_mode_scalar))15507 if (!ir_resolve_float_mode(ira, float_mode_value, &float_mode_scalar))
15464 return ira->codegen->invalid_inst_gen;15508 return ira->codegen->invalid_inst_gen;
1546515509
15466 AstNode *source_node = instruction->base.base.source_node;15510 AstNode *source_node = instruction->base.source_node;
15467 if (*fast_math_set_node_ptr) {15511 if (*fast_math_set_node_ptr) {
15468 ErrorMsg *msg = ir_add_error_node(ira, source_node,15512 ErrorMsg *msg = ir_add_error_node(ira, source_node,
15469 buf_sprintf("float mode set twice for same scope"));15513 buf_sprintf("float mode set twice for same scope"));
...@@ -15473,7 +15517,7 @@ static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,...@@ -15473,7 +15517,7 @@ static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
15473 *fast_math_set_node_ptr = source_node;15517 *fast_math_set_node_ptr = source_node;
15474 *fast_math_on_ptr = (float_mode_scalar == FloatModeOptimized);15518 *fast_math_on_ptr = (float_mode_scalar == FloatModeOptimized);
1547515519
15476 return ir_const_void(ira, &instruction->base.base);15520 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
15477}15521}
1547815522
15479static IrInstGen *ir_analyze_instruction_any_frame_type(IrAnalyze *ira, IrInstSrcAnyFrameType *instruction) {15523static IrInstGen *ir_analyze_instruction_any_frame_type(IrAnalyze *ira, IrInstSrcAnyFrameType *instruction) {
...@@ -15485,11 +15529,12 @@ static IrInstGen *ir_analyze_instruction_any_frame_type(IrAnalyze *ira, IrInstSr...@@ -15485,11 +15529,12 @@ static IrInstGen *ir_analyze_instruction_any_frame_type(IrAnalyze *ira, IrInstSr
15485 }15529 }
1548615530
15487 ZigType *any_frame_type = get_any_frame_type(ira->codegen, payload_type);15531 ZigType *any_frame_type = get_any_frame_type(ira->codegen, payload_type);
15488 return ir_const_type(ira, &instruction->base.base, any_frame_type);15532 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, any_frame_type);
15489}15533}
1549015534
15491static IrInstGen *ir_analyze_instruction_slice_type(IrAnalyze *ira, IrInstSrcSliceType *slice_type_instruction) {15535static IrInstGen *ir_analyze_instruction_slice_type(IrAnalyze *ira, IrInstSrcSliceType *slice_type_instruction) {
15492 IrInstGen *result = ir_const(ira, &slice_type_instruction->base.base, ira->codegen->builtin_types.entry_type);15536 IrInstGen *result = ir_const(ira, slice_type_instruction->base.scope,
15537 slice_type_instruction->base.source_node, ira->codegen->builtin_types.entry_type);
15493 result->value->special = ConstValSpecialLazy;15538 result->value->special = ConstValSpecialLazy;
1549415539
15495 LazyValueSliceType *lazy_slice_type = heap::c_allocator.create<LazyValueSliceType>();15540 LazyValueSliceType *lazy_slice_type = heap::c_allocator.create<LazyValueSliceType>();
...@@ -15542,10 +15587,10 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_...@@ -15542,10 +15587,10 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_
15542static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_instruction) {15587static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_instruction) {
15543 Error err;15588 Error err;
1554415589
15545 assert(asm_instruction->base.base.source_node->type == NodeTypeAsmExpr);15590 assert(asm_instruction->base.source_node->type == NodeTypeAsmExpr);
1554615591
15547 AstNode *node = asm_instruction->base.base.source_node;15592 AstNode *node = asm_instruction->base.source_node;
15548 AstNodeAsmExpr *asm_expr = &asm_instruction->base.base.source_node->data.asm_expr;15593 AstNodeAsmExpr *asm_expr = &asm_instruction->base.source_node->data.asm_expr;
1554915594
15550 Buf *template_buf = ir_resolve_str(ira, asm_instruction->asm_template->child);15595 Buf *template_buf = ir_resolve_str(ira, asm_instruction->asm_template->child);
15551 if (template_buf == nullptr)15596 if (template_buf == nullptr)
...@@ -15555,10 +15600,10 @@ static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_i...@@ -15555,10 +15600,10 @@ static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_i
15555 buf_append_char(&ira->codegen->global_asm, '\n');15600 buf_append_char(&ira->codegen->global_asm, '\n');
15556 buf_append_buf(&ira->codegen->global_asm, template_buf);15601 buf_append_buf(&ira->codegen->global_asm, template_buf);
1555715602
15558 return ir_const_void(ira, &asm_instruction->base.base);15603 return ir_const_void(ira, asm_instruction->base.scope, asm_instruction->base.source_node);
15559 }15604 }
1556015605
15561 if (!ir_emit_global_runtime_side_effect(ira, &asm_instruction->base.base))15606 if (!ir_emit_global_runtime_side_effect(ira, &asm_instruction->base))
15562 return ira->codegen->invalid_inst_gen;15607 return ira->codegen->invalid_inst_gen;
1556315608
15564 ZigList<AsmToken> tok_list = {};15609 ZigList<AsmToken> tok_list = {};
...@@ -15606,7 +15651,7 @@ static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_i...@@ -15606,7 +15651,7 @@ static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_i
15606 if (instr_is_comptime(input_value) &&15651 if (instr_is_comptime(input_value) &&
15607 (input_value->value->type->id == ZigTypeIdComptimeInt ||15652 (input_value->value->type->id == ZigTypeIdComptimeInt ||
15608 input_value->value->type->id == ZigTypeIdComptimeFloat)) {15653 input_value->value->type->id == ZigTypeIdComptimeFloat)) {
15609 ir_add_error(ira, &input_value->base,15654 ir_add_error(ira, input_value,
15610 buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value->type->name)));15655 buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value->type->name)));
15611 return ira->codegen->invalid_inst_gen;15656 return ira->codegen->invalid_inst_gen;
15612 }15657 }
...@@ -15614,14 +15659,15 @@ static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_i...@@ -15614,14 +15659,15 @@ static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_i
15614 input_list[i] = input_value;15659 input_list[i] = input_value;
15615 }15660 }
1561615661
15617 return ir_build_asm_gen(ira, &asm_instruction->base.base,15662 return ir_build_asm_gen(ira, asm_instruction->base.scope, asm_instruction->base.source_node,
15618 template_buf, tok_list.items, tok_list.length,15663 template_buf, tok_list.items, tok_list.length,
15619 input_list, output_types, asm_instruction->output_vars, asm_instruction->return_count,15664 input_list, output_types, asm_instruction->output_vars, asm_instruction->return_count,
15620 asm_instruction->has_side_effects, return_type);15665 asm_instruction->has_side_effects, return_type);
15621}15666}
1562215667
15623static IrInstGen *ir_analyze_instruction_array_type(IrAnalyze *ira, IrInstSrcArrayType *array_type_instruction) {15668static IrInstGen *ir_analyze_instruction_array_type(IrAnalyze *ira, IrInstSrcArrayType *array_type_instruction) {
15624 IrInstGen *result = ir_const(ira, &array_type_instruction->base.base, ira->codegen->builtin_types.entry_type);15669 IrInstGen *result = ir_const(ira, array_type_instruction->base.scope,
15670 array_type_instruction->base.source_node, ira->codegen->builtin_types.entry_type);
15625 result->value->special = ConstValSpecialLazy;15671 result->value->special = ConstValSpecialLazy;
1562615672
15627 LazyValueArrayType *lazy_array_type = heap::c_allocator.create<LazyValueArrayType>();15673 LazyValueArrayType *lazy_array_type = heap::c_allocator.create<LazyValueArrayType>();
...@@ -15646,7 +15692,7 @@ static IrInstGen *ir_analyze_instruction_array_type(IrAnalyze *ira, IrInstSrcArr...@@ -15646,7 +15692,7 @@ static IrInstGen *ir_analyze_instruction_array_type(IrAnalyze *ira, IrInstSrcArr
15646}15692}
1564715693
15648static IrInstGen *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstSrcSizeOf *instruction) {15694static IrInstGen *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstSrcSizeOf *instruction) {
15649 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);15695 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int);
15650 result->value->special = ConstValSpecialLazy;15696 result->value->special = ConstValSpecialLazy;
1565115697
15652 LazyValueSizeOf *lazy_size_of = heap::c_allocator.create<LazyValueSizeOf>();15698 LazyValueSizeOf *lazy_size_of = heap::c_allocator.create<LazyValueSizeOf>();
...@@ -15662,7 +15708,7 @@ static IrInstGen *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstSrcSizeOf...@@ -15662,7 +15708,7 @@ static IrInstGen *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstSrcSizeOf
15662 return result;15708 return result;
15663}15709}
1566415710
15665static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value) {15711static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value) {
15666 ZigType *type_entry = value->value->type;15712 ZigType *type_entry = value->value->type;
1566715713
15668 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) {15714 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) {
...@@ -15671,30 +15717,30 @@ static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst,...@@ -15671,30 +15717,30 @@ static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst,
15671 if (c_ptr_val == nullptr)15717 if (c_ptr_val == nullptr)
15672 return ira->codegen->invalid_inst_gen;15718 return ira->codegen->invalid_inst_gen;
15673 if (c_ptr_val->special == ConstValSpecialUndef)15719 if (c_ptr_val->special == ConstValSpecialUndef)
15674 return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool);15720 return ir_const_undef(ira, scope, source_node, ira->codegen->builtin_types.entry_bool);
15675 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||15721 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||
15676 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&15722 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
15677 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);15723 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);
15678 return ir_const_bool(ira, source_inst, !is_null);15724 return ir_const_bool(ira, scope, source_node, !is_null);
15679 }15725 }
1568015726
15681 return ir_build_test_non_null_gen(ira, source_inst, value);15727 return ir_build_test_non_null_gen(ira, scope, source_node, value);
15682 } else if (type_entry->id == ZigTypeIdOptional) {15728 } else if (type_entry->id == ZigTypeIdOptional) {
15683 if (instr_is_comptime(value)) {15729 if (instr_is_comptime(value)) {
15684 ZigValue *maybe_val = ir_resolve_const(ira, value, UndefOk);15730 ZigValue *maybe_val = ir_resolve_const(ira, value, UndefOk);
15685 if (maybe_val == nullptr)15731 if (maybe_val == nullptr)
15686 return ira->codegen->invalid_inst_gen;15732 return ira->codegen->invalid_inst_gen;
15687 if (maybe_val->special == ConstValSpecialUndef)15733 if (maybe_val->special == ConstValSpecialUndef)
15688 return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool);15734 return ir_const_undef(ira, scope, source_node, ira->codegen->builtin_types.entry_bool);
1568915735
15690 return ir_const_bool(ira, source_inst, !optional_value_is_null(maybe_val));15736 return ir_const_bool(ira, scope, source_node, !optional_value_is_null(maybe_val));
15691 }15737 }
1569215738
15693 return ir_build_test_non_null_gen(ira, source_inst, value);15739 return ir_build_test_non_null_gen(ira, scope, source_node, value);
15694 } else if (type_entry->id == ZigTypeIdNull) {15740 } else if (type_entry->id == ZigTypeIdNull) {
15695 return ir_const_bool(ira, source_inst, false);15741 return ir_const_bool(ira, scope, source_node, false);
15696 } else {15742 } else {
15697 return ir_const_bool(ira, source_inst, true);15743 return ir_const_bool(ira, scope, source_node, true);
15698 }15744 }
15699}15745}
1570015746
...@@ -15703,10 +15749,10 @@ static IrInstGen *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstSrc...@@ -15703,10 +15749,10 @@ static IrInstGen *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstSrc
15703 if (type_is_invalid(value->value->type))15749 if (type_is_invalid(value->value->type))
15704 return ira->codegen->invalid_inst_gen;15750 return ira->codegen->invalid_inst_gen;
1570515751
15706 return ir_analyze_test_non_null(ira, &instruction->base.base, value);15752 return ir_analyze_test_non_null(ira, instruction->base.scope, instruction->base.source_node, value);
15707}15753}
1570815754
15709static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr,15755static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, Scope *scope, AstNode *source_node,
15710 IrInstGen *base_ptr, bool safety_check_on, bool initializing)15756 IrInstGen *base_ptr, bool safety_check_on, bool initializing)
15711{15757{
15712 Error err;15758 Error err;
...@@ -15721,14 +15767,14 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou...@@ -15721,14 +15767,14 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou
15721 if (!val)15767 if (!val)
15722 return ira->codegen->invalid_inst_gen;15768 return ira->codegen->invalid_inst_gen;
15723 if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {15769 if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
15724 ZigValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);15770 ZigValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_node);
15725 if (c_ptr_val == nullptr)15771 if (c_ptr_val == nullptr)
15726 return ira->codegen->invalid_inst_gen;15772 return ira->codegen->invalid_inst_gen;
15727 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||15773 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||
15728 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&15774 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
15729 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);15775 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);
15730 if (is_null) {15776 if (is_null) {
15731 ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null"));15777 ir_add_error_node(ira, source_node, buf_sprintf("unable to unwrap null"));
15732 return ira->codegen->invalid_inst_gen;15778 return ira->codegen->invalid_inst_gen;
15733 }15779 }
15734 return base_ptr;15780 return base_ptr;
...@@ -15736,13 +15782,13 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou...@@ -15736,13 +15782,13 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou
15736 }15782 }
15737 if (!safety_check_on)15783 if (!safety_check_on)
15738 return base_ptr;15784 return base_ptr;
15739 IrInstGen *c_ptr_val = ir_get_deref(ira, source_instr, base_ptr, nullptr);15785 IrInstGen *c_ptr_val = ir_get_deref(ira, scope, source_node, base_ptr, nullptr);
15740 ir_build_assert_non_null(ira, source_instr, c_ptr_val);15786 ir_build_assert_non_null(ira, scope, source_node, c_ptr_val);
15741 return base_ptr;15787 return base_ptr;
15742 }15788 }
1574315789
15744 if (type_entry->id != ZigTypeIdOptional) {15790 if (type_entry->id != ZigTypeIdOptional) {
15745 ir_add_error(ira, &base_ptr->base,15791 ir_add_error(ira, base_ptr,
15746 buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name)));15792 buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name)));
15747 return ira->codegen->invalid_inst_gen;15793 return ira->codegen->invalid_inst_gen;
15748 }15794 }
...@@ -15759,7 +15805,7 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou...@@ -15759,7 +15805,7 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou
15759 if (ptr_val == nullptr)15805 if (ptr_val == nullptr)
15760 return ira->codegen->invalid_inst_gen;15806 return ira->codegen->invalid_inst_gen;
15761 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {15807 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
15762 ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);15808 ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_node);
15763 if (optional_val == nullptr)15809 if (optional_val == nullptr)
15764 return ira->codegen->invalid_inst_gen;15810 return ira->codegen->invalid_inst_gen;
1576515811
...@@ -15787,21 +15833,21 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou...@@ -15787,21 +15833,21 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou
15787 }15833 }
15788 } else {15834 } else {
15789 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,15835 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
15790 source_instr->source_node, optional_val, UndefBad)))15836 source_node, optional_val, UndefBad)))
15791 return ira->codegen->invalid_inst_gen;15837 return ira->codegen->invalid_inst_gen;
15792 if (optional_value_is_null(optional_val)) {15838 if (optional_value_is_null(optional_val)) {
15793 ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null"));15839 ir_add_error_node(ira, source_node, buf_sprintf("unable to unwrap null"));
15794 return ira->codegen->invalid_inst_gen;15840 return ira->codegen->invalid_inst_gen;
15795 }15841 }
15796 }15842 }
1579715843
15798 IrInstGen *result;15844 IrInstGen *result;
15799 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {15845 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
15800 result = ir_build_optional_unwrap_ptr_gen(ira, source_instr, base_ptr, false,15846 result = ir_build_optional_unwrap_ptr_gen(ira, scope, source_node, base_ptr, false,
15801 initializing, result_type);15847 initializing, result_type);
15802 result->value->special = ConstValSpecialStatic;15848 result->value->special = ConstValSpecialStatic;
15803 } else {15849 } else {
15804 result = ir_const(ira, source_instr, result_type);15850 result = ir_const(ira, scope, source_node, result_type);
15805 }15851 }
15806 ZigValue *result_val = result->value;15852 ZigValue *result_val = result->value;
15807 result_val->data.x_ptr.special = ConstPtrSpecialRef;15853 result_val->data.x_ptr.special = ConstPtrSpecialRef;
...@@ -15826,7 +15872,7 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou...@@ -15826,7 +15872,7 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou
15826 }15872 }
15827 }15873 }
1582815874
15829 return ir_build_optional_unwrap_ptr_gen(ira, source_instr, base_ptr, safety_check_on,15875 return ir_build_optional_unwrap_ptr_gen(ira, scope, source_node, base_ptr, safety_check_on,
15830 initializing, result_type);15876 initializing, result_type);
15831}15877}
1583215878
...@@ -15837,7 +15883,7 @@ static IrInstGen *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira,...@@ -15837,7 +15883,7 @@ static IrInstGen *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira,
15837 if (type_is_invalid(base_ptr->value->type))15883 if (type_is_invalid(base_ptr->value->type))
15838 return ira->codegen->invalid_inst_gen;15884 return ira->codegen->invalid_inst_gen;
1583915885
15840 return ir_analyze_unwrap_optional_payload(ira, &instruction->base.base, base_ptr,15886 return ir_analyze_unwrap_optional_payload(ira, instruction->base.scope, instruction->base.source_node, base_ptr,
15841 instruction->safety_check_on, false);15887 instruction->safety_check_on, false);
15842}15888}
1584315889
...@@ -15851,20 +15897,20 @@ static IrInstGen *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstSrcCtz *instr...@@ -15851,20 +15897,20 @@ static IrInstGen *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstSrcCtz *instr
15851 return ira->codegen->invalid_inst_gen;15897 return ira->codegen->invalid_inst_gen;
1585215898
15853 if (int_type->data.integral.bit_count == 0)15899 if (int_type->data.integral.bit_count == 0)
15854 return ir_const_unsigned(ira, &instruction->base.base, 0);15900 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, 0);
1585515901
15856 if (instr_is_comptime(op)) {15902 if (instr_is_comptime(op)) {
15857 ZigValue *val = ir_resolve_const(ira, op, UndefOk);15903 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
15858 if (val == nullptr)15904 if (val == nullptr)
15859 return ira->codegen->invalid_inst_gen;15905 return ira->codegen->invalid_inst_gen;
15860 if (val->special == ConstValSpecialUndef)15906 if (val->special == ConstValSpecialUndef)
15861 return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);15907 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int);
15862 size_t result_usize = bigint_ctz(&op->value->data.x_bigint, int_type->data.integral.bit_count);15908 size_t result_usize = bigint_ctz(&op->value->data.x_bigint, int_type->data.integral.bit_count);
15863 return ir_const_unsigned(ira, &instruction->base.base, result_usize);15909 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, result_usize);
15864 }15910 }
1586515911
15866 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);15912 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
15867 return ir_build_ctz_gen(ira, &instruction->base.base, return_type, op);15913 return ir_build_ctz_gen(ira, instruction->base.scope, instruction->base.source_node, return_type, op);
15868}15914}
1586915915
15870static IrInstGen *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstSrcClz *instruction) {15916static IrInstGen *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstSrcClz *instruction) {
...@@ -15877,20 +15923,20 @@ static IrInstGen *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstSrcClz *instr...@@ -15877,20 +15923,20 @@ static IrInstGen *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstSrcClz *instr
15877 return ira->codegen->invalid_inst_gen;15923 return ira->codegen->invalid_inst_gen;
1587815924
15879 if (int_type->data.integral.bit_count == 0)15925 if (int_type->data.integral.bit_count == 0)
15880 return ir_const_unsigned(ira, &instruction->base.base, 0);15926 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, 0);
1588115927
15882 if (instr_is_comptime(op)) {15928 if (instr_is_comptime(op)) {
15883 ZigValue *val = ir_resolve_const(ira, op, UndefOk);15929 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
15884 if (val == nullptr)15930 if (val == nullptr)
15885 return ira->codegen->invalid_inst_gen;15931 return ira->codegen->invalid_inst_gen;
15886 if (val->special == ConstValSpecialUndef)15932 if (val->special == ConstValSpecialUndef)
15887 return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);15933 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int);
15888 size_t result_usize = bigint_clz(&op->value->data.x_bigint, int_type->data.integral.bit_count);15934 size_t result_usize = bigint_clz(&op->value->data.x_bigint, int_type->data.integral.bit_count);
15889 return ir_const_unsigned(ira, &instruction->base.base, result_usize);15935 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, result_usize);
15890 }15936 }
1589115937
15892 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);15938 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
15893 return ir_build_clz_gen(ira, &instruction->base.base, return_type, op);15939 return ir_build_clz_gen(ira, instruction->base.scope, instruction->base.source_node, return_type, op);
15894}15940}
1589515941
15896static IrInstGen *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstSrcPopCount *instruction) {15942static IrInstGen *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstSrcPopCount *instruction) {
...@@ -15903,38 +15949,38 @@ static IrInstGen *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstSrcPopC...@@ -15903,38 +15949,38 @@ static IrInstGen *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstSrcPopC
15903 return ira->codegen->invalid_inst_gen;15949 return ira->codegen->invalid_inst_gen;
1590415950
15905 if (int_type->data.integral.bit_count == 0)15951 if (int_type->data.integral.bit_count == 0)
15906 return ir_const_unsigned(ira, &instruction->base.base, 0);15952 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, 0);
1590715953
15908 if (instr_is_comptime(op)) {15954 if (instr_is_comptime(op)) {
15909 ZigValue *val = ir_resolve_const(ira, op, UndefOk);15955 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
15910 if (val == nullptr)15956 if (val == nullptr)
15911 return ira->codegen->invalid_inst_gen;15957 return ira->codegen->invalid_inst_gen;
15912 if (val->special == ConstValSpecialUndef)15958 if (val->special == ConstValSpecialUndef)
15913 return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);15959 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int);
1591415960
15915 if (bigint_cmp_zero(&val->data.x_bigint) != CmpLT) {15961 if (bigint_cmp_zero(&val->data.x_bigint) != CmpLT) {
15916 size_t result = bigint_popcount_unsigned(&val->data.x_bigint);15962 size_t result = bigint_popcount_unsigned(&val->data.x_bigint);
15917 return ir_const_unsigned(ira, &instruction->base.base, result);15963 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, result);
15918 }15964 }
15919 size_t result = bigint_popcount_signed(&val->data.x_bigint, int_type->data.integral.bit_count);15965 size_t result = bigint_popcount_signed(&val->data.x_bigint, int_type->data.integral.bit_count);
15920 return ir_const_unsigned(ira, &instruction->base.base, result);15966 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, result);
15921 }15967 }
1592215968
15923 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);15969 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
15924 return ir_build_pop_count_gen(ira, &instruction->base.base, return_type, op);15970 return ir_build_pop_count_gen(ira, instruction->base.scope, instruction->base.source_node, return_type, op);
15925}15971}
1592615972
15927static IrInstGen *ir_analyze_union_tag(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value) {15973static IrInstGen *ir_analyze_union_tag(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value) {
15928 if (type_is_invalid(value->value->type))15974 if (type_is_invalid(value->value->type))
15929 return ira->codegen->invalid_inst_gen;15975 return ira->codegen->invalid_inst_gen;
1593015976
15931 if (value->value->type->id != ZigTypeIdUnion) {15977 if (value->value->type->id != ZigTypeIdUnion) {
15932 ir_add_error(ira, &value->base,15978 ir_add_error(ira, value,
15933 buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value->type->name)));15979 buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value->type->name)));
15934 return ira->codegen->invalid_inst_gen;15980 return ira->codegen->invalid_inst_gen;
15935 }15981 }
15936 if (!value->value->type->data.unionation.have_explicit_tag_type) {15982 if (!value->value->type->data.unionation.have_explicit_tag_type) {
15937 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union has no associated enum"));15983 ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("union has no associated enum"));
15938 if (value->value->type->data.unionation.decl_node != nullptr) {15984 if (value->value->type->data.unionation.decl_node != nullptr) {
15939 add_error_note(ira->codegen, msg, value->value->type->data.unionation.decl_node,15985 add_error_note(ira->codegen, msg, value->value->type->data.unionation.decl_node,
15940 buf_sprintf("declared here"));15986 buf_sprintf("declared here"));
...@@ -15951,14 +15997,14 @@ static IrInstGen *ir_analyze_union_tag(IrAnalyze *ira, IrInst* source_instr, IrI...@@ -15951,14 +15997,14 @@ static IrInstGen *ir_analyze_union_tag(IrAnalyze *ira, IrInst* source_instr, IrI
15951 return ira->codegen->invalid_inst_gen;15997 return ira->codegen->invalid_inst_gen;
1595215998
15953 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,15999 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
15954 source_instr->scope, source_instr->source_node);16000 scope, source_node);
15955 const_instruction->base.value->type = tag_type;16001 const_instruction->base.value->type = tag_type;
15956 const_instruction->base.value->special = ConstValSpecialStatic;16002 const_instruction->base.value->special = ConstValSpecialStatic;
15957 bigint_init_bigint(&const_instruction->base.value->data.x_enum_tag, &val->data.x_union.tag);16003 bigint_init_bigint(&const_instruction->base.value->data.x_enum_tag, &val->data.x_union.tag);
15958 return &const_instruction->base;16004 return &const_instruction->base;
15959 }16005 }
1596016006
15961 return ir_build_union_tag(ira, source_instr, value, tag_type);16007 return ir_build_union_tag(ira, scope, source_node, value, tag_type);
15962}16008}
1596316009
15964static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,16010static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,
...@@ -16008,10 +16054,11 @@ static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -16008,10 +16054,11 @@ static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,
16008 }16054 }
1600916055
16010 if (is_comptime || old_dest_block->ref_count == 1) {16056 if (is_comptime || old_dest_block->ref_count == 1) {
16011 return ir_inline_bb(ira, &switch_br_instruction->base.base, old_dest_block);16057 return ir_inline_bb(ira, switch_br_instruction->base.source_node, old_dest_block);
16012 } else {16058 } else {
16013 IrBasicBlockGen *new_dest_block = ir_get_new_bb(ira, old_dest_block, &switch_br_instruction->base.base);16059 IrBasicBlockGen *new_dest_block = ir_get_new_bb(ira, old_dest_block, &switch_br_instruction->base);
16014 IrInstGen *result = ir_build_br_gen(ira, &switch_br_instruction->base.base, new_dest_block);16060 IrInstGen *result = ir_build_br_gen(ira, switch_br_instruction->base.scope,
16061 switch_br_instruction->base.source_node, new_dest_block);
16015 return ir_finish_anal(ira, result);16062 return ir_finish_anal(ira, result);
16016 }16063 }
16017 }16064 }
...@@ -16020,7 +16067,7 @@ static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -16020,7 +16067,7 @@ static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,
16020 for (size_t i = 0; i < case_count; i += 1) {16067 for (size_t i = 0; i < case_count; i += 1) {
16021 IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i];16068 IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i];
16022 IrInstGenSwitchBrCase *new_case = &cases[i];16069 IrInstGenSwitchBrCase *new_case = &cases[i];
16023 new_case->block = ir_get_new_bb(ira, old_case->block, &switch_br_instruction->base.base);16070 new_case->block = ir_get_new_bb(ira, old_case->block, &switch_br_instruction->base);
16024 new_case->value = ira->codegen->invalid_inst_gen;16071 new_case->value = ira->codegen->invalid_inst_gen;
1602516072
16026 // Calling ir_get_new_bb set the ref_instruction on the new basic block.16073 // Calling ir_get_new_bb set the ref_instruction on the new basic block.
...@@ -16048,12 +16095,12 @@ static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -16048,12 +16095,12 @@ static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,
16048 IrInstGenSwitchBrCase *new_case = &cases[i];16095 IrInstGenSwitchBrCase *new_case = &cases[i];
16049 if (type_is_invalid(new_case->value->value->type))16096 if (type_is_invalid(new_case->value->value->type))
16050 return ir_unreach_error(ira);16097 return ir_unreach_error(ira);
16051 new_case->block->ref_instruction = &switch_br_instruction->base.base;16098 new_case->block->ref_instruction = &switch_br_instruction->base;
16052 }16099 }
1605316100
16054 IrBasicBlockGen *new_else_block = ir_get_new_bb(ira, switch_br_instruction->else_block, &switch_br_instruction->base.base);16101 IrBasicBlockGen *new_else_block = ir_get_new_bb(ira, switch_br_instruction->else_block, &switch_br_instruction->base);
16055 IrInstGenSwitchBr *switch_br = ir_build_switch_br_gen(ira, &switch_br_instruction->base.base,16102 IrInstGenSwitchBr *switch_br = ir_build_switch_br_gen(ira, switch_br_instruction->base.scope,
16056 target_value, new_else_block, case_count, cases);16103 switch_br_instruction->base.source_node, target_value, new_else_block, case_count, cases);
16057 return ir_finish_anal(ira, &switch_br->base);16104 return ir_finish_anal(ira, &switch_br->base);
16058}16105}
1605916106
...@@ -16069,13 +16116,14 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -16069,13 +16116,14 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,
16069 assert(instr_is_comptime(target_value_ptr));16116 assert(instr_is_comptime(target_value_ptr));
16070 ZigType *ptr_type = target_value_ptr->value->data.x_type;16117 ZigType *ptr_type = target_value_ptr->value->data.x_type;
16071 assert(ptr_type->id == ZigTypeIdPointer);16118 assert(ptr_type->id == ZigTypeIdPointer);
16072 return ir_const_type(ira, &switch_target_instruction->base.base, ptr_type->data.pointer.child_type);16119 return ir_const_type(ira, switch_target_instruction->base.scope,
16120 switch_target_instruction->base.source_node, ptr_type->data.pointer.child_type);
16073 }16121 }
1607416122
16075 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;16123 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;
16076 ZigValue *pointee_val = nullptr;16124 ZigValue *pointee_val = nullptr;
16077 if (instr_is_comptime(target_value_ptr) && target_value_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {16125 if (instr_is_comptime(target_value_ptr) && target_value_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
16078 pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->base.source_node);16126 pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->source_node);
16079 if (pointee_val == nullptr)16127 if (pointee_val == nullptr)
16080 return ira->codegen->invalid_inst_gen;16128 return ira->codegen->invalid_inst_gen;
1608116129
...@@ -16100,13 +16148,15 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -16100,13 +16148,15 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,
16100 case ZigTypeIdFn:16148 case ZigTypeIdFn:
16101 case ZigTypeIdErrorSet: {16149 case ZigTypeIdErrorSet: {
16102 if (pointee_val) {16150 if (pointee_val) {
16103 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, nullptr);16151 IrInstGen *result = ir_const(ira, switch_target_instruction->base.scope,
16152 switch_target_instruction->base.source_node, nullptr);
16104 copy_const_val(ira->codegen, result->value, pointee_val);16153 copy_const_val(ira->codegen, result->value, pointee_val);
16105 result->value->type = target_type;16154 result->value->type = target_type;
16106 return result;16155 return result;
16107 }16156 }
1610816157
16109 IrInstGen *result = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr);16158 IrInstGen *result = ir_get_deref(ira, switch_target_instruction->base.scope,
16159 switch_target_instruction->base.source_node, target_value_ptr, nullptr);
16110 result->value->type = target_type;16160 result->value->type = target_type;
16111 return result;16161 return result;
16112 }16162 }
...@@ -16115,7 +16165,7 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -16115,7 +16165,7 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,
16115 if (!decl_node->data.container_decl.auto_enum &&16165 if (!decl_node->data.container_decl.auto_enum &&
16116 decl_node->data.container_decl.init_arg_expr == nullptr)16166 decl_node->data.container_decl.init_arg_expr == nullptr)
16117 {16167 {
16118 ErrorMsg *msg = ir_add_error(ira, &target_value_ptr->base,16168 ErrorMsg *msg = ir_add_error(ira, target_value_ptr,
16119 buf_sprintf("switch on union which has no attached enum"));16169 buf_sprintf("switch on union which has no attached enum"));
16120 add_error_note(ira->codegen, msg, decl_node,16170 add_error_note(ira->codegen, msg, decl_node,
16121 buf_sprintf("consider 'union(enum)' here"));16171 buf_sprintf("consider 'union(enum)' here"));
...@@ -16125,22 +16175,23 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -16125,22 +16175,23 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,
16125 assert(tag_type != nullptr);16175 assert(tag_type != nullptr);
16126 assert(tag_type->id == ZigTypeIdEnum);16176 assert(tag_type->id == ZigTypeIdEnum);
16127 if (pointee_val) {16177 if (pointee_val) {
16128 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, tag_type);16178 IrInstGen *result = ir_const(ira, switch_target_instruction->base.scope, switch_target_instruction->base.source_node, tag_type);
16129 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_union.tag);16179 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_union.tag);
16130 return result;16180 return result;
16131 }16181 }
1613216182
16133 if (can_fold_enum_type(tag_type)) {16183 if (can_fold_enum_type(tag_type)) {
16134 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, tag_type);16184 IrInstGen *result = ir_const(ira, switch_target_instruction->base.scope, switch_target_instruction->base.source_node, tag_type);
16135 TypeEnumField *only_field = &tag_type->data.enumeration.fields[0];16185 TypeEnumField *only_field = &tag_type->data.enumeration.fields[0];
16136 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);16186 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);
16137 return result;16187 return result;
16138 }16188 }
1613916189
16140 IrInstGen *union_value = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr);16190 IrInstGen *union_value = ir_get_deref(ira, switch_target_instruction->base.scope,
16191 switch_target_instruction->base.source_node, target_value_ptr, nullptr);
16141 union_value->value->type = target_type;16192 union_value->value->type = target_type;
1614216193
16143 return ir_build_union_tag(ira, &switch_target_instruction->base.base, union_value, tag_type);16194 return ir_build_union_tag(ira, switch_target_instruction->base.scope, switch_target_instruction->base.source_node, union_value, tag_type);
16144 }16195 }
16145 case ZigTypeIdEnum: {16196 case ZigTypeIdEnum: {
16146 if ((err = type_resolve(ira->codegen, target_type, ResolveStatusZeroBitsKnown)))16197 if ((err = type_resolve(ira->codegen, target_type, ResolveStatusZeroBitsKnown)))
...@@ -16148,18 +16199,19 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -16148,18 +16199,19 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1614816199
16149 if (can_fold_enum_type(target_type)) {16200 if (can_fold_enum_type(target_type)) {
16150 TypeEnumField *only_field = &target_type->data.enumeration.fields[0];16201 TypeEnumField *only_field = &target_type->data.enumeration.fields[0];
16151 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, target_type);16202 IrInstGen *result = ir_const(ira, switch_target_instruction->base.scope, switch_target_instruction->base.source_node, target_type);
16152 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);16203 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);
16153 return result;16204 return result;
16154 }16205 }
1615516206
16156 if (pointee_val) {16207 if (pointee_val) {
16157 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, target_type);16208 IrInstGen *result = ir_const(ira, switch_target_instruction->base.scope, switch_target_instruction->base.source_node, target_type);
16158 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_enum_tag);16209 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_enum_tag);
16159 return result;16210 return result;
16160 }16211 }
1616116212
16162 IrInstGen *enum_value = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr);16213 IrInstGen *enum_value = ir_get_deref(ira, switch_target_instruction->base.scope,
16214 switch_target_instruction->base.source_node, target_value_ptr, nullptr);
16163 enum_value->value->type = target_type;16215 enum_value->value->type = target_type;
16164 return enum_value;16216 return enum_value;
16165 }16217 }
...@@ -16175,7 +16227,7 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -16175,7 +16227,7 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,
16175 case ZigTypeIdVector:16227 case ZigTypeIdVector:
16176 case ZigTypeIdFnFrame:16228 case ZigTypeIdFnFrame:
16177 case ZigTypeIdAnyFrame:16229 case ZigTypeIdAnyFrame:
16178 ir_add_error(ira, &switch_target_instruction->base.base,16230 ir_add_error_node(ira, switch_target_instruction->base.source_node,
16179 buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name)));16231 buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name)));
16180 return ira->codegen->invalid_inst_gen;16232 return ira->codegen->invalid_inst_gen;
16181 }16233 }
...@@ -16228,12 +16280,12 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi...@@ -16228,12 +16280,12 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi
16228 ZigType *payload_type = payload_field->type_entry;16280 ZigType *payload_type = payload_field->type_entry;
16229 if (first_field->type_entry != payload_type) {16281 if (first_field->type_entry != payload_type) {
16230 if (invalid_payload_msg == nullptr) {16282 if (invalid_payload_msg == nullptr) {
16231 invalid_payload_msg = ir_add_error(ira, &instruction->base.base,16283 invalid_payload_msg = ir_add_error_node(ira, instruction->base.source_node,
16232 buf_sprintf("capture group with incompatible types"));16284 buf_sprintf("capture group with incompatible types"));
16233 add_error_note(ira->codegen, invalid_payload_msg, first_prong_value->base.source_node,16285 add_error_note(ira->codegen, invalid_payload_msg, first_prong_value->source_node,
16234 buf_sprintf("type '%s' here", buf_ptr(&first_field->type_entry->name)));16286 buf_sprintf("type '%s' here", buf_ptr(&first_field->type_entry->name)));
16235 }16287 }
16236 add_error_note(ira->codegen, invalid_payload_msg, this_prong_inst->base.source_node,16288 add_error_note(ira->codegen, invalid_payload_msg, this_prong_inst->source_node,
16237 buf_sprintf("type '%s' here", buf_ptr(&payload_field->type_entry->name)));16289 buf_sprintf("type '%s' here", buf_ptr(&payload_field->type_entry->name)));
16238 }16290 }
16239 }16291 }
...@@ -16247,11 +16299,11 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi...@@ -16247,11 +16299,11 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi
16247 if (!target_value_ptr)16299 if (!target_value_ptr)
16248 return ira->codegen->invalid_inst_gen;16300 return ira->codegen->invalid_inst_gen;
1624916301
16250 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.base.source_node);16302 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.source_node);
16251 if (pointee_val == nullptr)16303 if (pointee_val == nullptr)
16252 return ira->codegen->invalid_inst_gen;16304 return ira->codegen->invalid_inst_gen;
1625316305
16254 IrInstGen *result = ir_const(ira, &instruction->base.base,16306 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node,
16255 get_pointer_to_type(ira->codegen, first_field->type_entry,16307 get_pointer_to_type(ira->codegen, first_field->type_entry,
16256 target_val_ptr->type->data.pointer.is_const));16308 target_val_ptr->type->data.pointer.is_const));
16257 ZigValue *out_val = result->value;16309 ZigValue *out_val = result->value;
...@@ -16263,7 +16315,7 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi...@@ -16263,7 +16315,7 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi
1626316315
16264 ZigType *result_type = get_pointer_to_type(ira->codegen, first_field->type_entry,16316 ZigType *result_type = get_pointer_to_type(ira->codegen, first_field->type_entry,
16265 target_value_ptr->value->type->data.pointer.is_const);16317 target_value_ptr->value->type->data.pointer.is_const);
16266 return ir_build_union_field_ptr(ira, &instruction->base.base, target_value_ptr, first_field,16318 return ir_build_union_field_ptr(ira, instruction->base.scope, instruction->base.source_node, target_value_ptr, first_field,
16267 false, false, result_type);16319 false, false, result_type);
16268 } else if (target_type->id == ZigTypeIdErrorSet) {16320 } else if (target_type->id == ZigTypeIdErrorSet) {
16269 // construct an error set from the prong values16321 // construct an error set from the prong values
...@@ -16293,12 +16345,13 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi...@@ -16293,12 +16345,13 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi
16293 ref_type->data.pointer.explicit_alignment,16345 ref_type->data.pointer.explicit_alignment,
16294 ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes,16346 ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes,
16295 ref_type->data.pointer.allow_zero);16347 ref_type->data.pointer.allow_zero);
16296 return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr,16348 return ir_analyze_ptr_cast(ira, instruction->base.scope, instruction->base.source_node,
16297 &instruction->target_value_ptr->base, new_target_value_ptr_type, &instruction->base.base, false, false);16349 target_value_ptr, instruction->target_value_ptr->source_node,
16350 new_target_value_ptr_type, instruction->base.source_node, false, false);
16298 } else if (instruction->prongs_len > 1) {16351 } else if (instruction->prongs_len > 1) {
16299 return target_value_ptr;16352 return target_value_ptr;
16300 } else {16353 } else {
16301 ir_add_error(ira, &instruction->base.base,16354 ir_add_error_node(ira, instruction->base.source_node,
16302 buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name)));16355 buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name)));
16303 return ira->codegen->invalid_inst_gen;16356 return ira->codegen->invalid_inst_gen;
16304 }16357 }
...@@ -16316,7 +16369,7 @@ static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,...@@ -16316,7 +16369,7 @@ static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
16316 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;16369 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;
16317 if (target_type->id == ZigTypeIdErrorSet) {16370 if (target_type->id == ZigTypeIdErrorSet) {
16318 // make a new set that has the other cases removed16371 // make a new set that has the other cases removed
16319 if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.base.source_node)) {16372 if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.source_node)) {
16320 return ira->codegen->invalid_inst_gen;16373 return ira->codegen->invalid_inst_gen;
16321 }16374 }
16322 if (type_is_global_error_set(target_type)) {16375 if (type_is_global_error_set(target_type)) {
...@@ -16378,8 +16431,9 @@ static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,...@@ -16378,8 +16431,9 @@ static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
16378 ref_type->data.pointer.explicit_alignment,16431 ref_type->data.pointer.explicit_alignment,
16379 ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes,16432 ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes,
16380 ref_type->data.pointer.allow_zero);16433 ref_type->data.pointer.allow_zero);
16381 return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr,16434 return ir_analyze_ptr_cast(ira, instruction->base.scope, instruction->base.source_node,
16382 &instruction->target_value_ptr->base, new_target_value_ptr_type, &instruction->base.base, false, false);16435 target_value_ptr, instruction->target_value_ptr->source_node,
16436 new_target_value_ptr_type, instruction->base.source_node, false, false);
16383 }16437 }
1638416438
16385 return target_value_ptr;16439 return target_value_ptr;
...@@ -16393,7 +16447,7 @@ static IrInstGen *ir_analyze_instruction_import(IrAnalyze *ira, IrInstSrcImport...@@ -16393,7 +16447,7 @@ static IrInstGen *ir_analyze_instruction_import(IrAnalyze *ira, IrInstSrcImport
16393 if (!import_target_str)16447 if (!import_target_str)
16394 return ira->codegen->invalid_inst_gen;16448 return ira->codegen->invalid_inst_gen;
1639516449
16396 AstNode *source_node = import_instruction->base.base.source_node;16450 AstNode *source_node = import_instruction->base.source_node;
16397 ZigType *import = source_node->owner;16451 ZigType *import = source_node->owner;
1639816452
16399 ZigType *target_import;16453 ZigType *target_import;
...@@ -16418,7 +16472,7 @@ static IrInstGen *ir_analyze_instruction_import(IrAnalyze *ira, IrInstSrcImport...@@ -16418,7 +16472,7 @@ static IrInstGen *ir_analyze_instruction_import(IrAnalyze *ira, IrInstSrcImport
16418 }16472 }
16419 }16473 }
1642016474
16421 return ir_const_type(ira, &import_instruction->base.base, target_import);16475 return ir_const_type(ira, import_instruction->base.scope, import_instruction->base.source_node, target_import);
16422}16476}
1642316477
16424static IrInstGen *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstSrcRef *ref_instruction) {16478static IrInstGen *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstSrcRef *ref_instruction) {
...@@ -16434,10 +16488,10 @@ static IrInstGen *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstSrcRef *ref_i...@@ -16434,10 +16488,10 @@ static IrInstGen *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstSrcRef *ref_i
16434 is_const = true;16488 is_const = true;
16435 }16489 }
1643616490
16437 return ir_get_ref(ira, &ref_instruction->base.base, value, is_const, is_volatile);16491 return ir_get_ref(ira, ref_instruction->base.scope, ref_instruction->base.source_node, value, is_const, is_volatile);
16438}16492}
1643916493
16440static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, IrInst* source_instruction,16494static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, Scope *scope, AstNode *source_node,
16441 AstNode *field_source_node, ZigType *union_type, Buf *field_name, IrInstGen *field_result_loc,16495 AstNode *field_source_node, ZigType *union_type, Buf *field_name, IrInstGen *field_result_loc,
16442 IrInstGen *result_loc)16496 IrInstGen *result_loc)
16443{16497{
...@@ -16468,26 +16522,26 @@ static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, IrInst* source_instructi...@@ -16468,26 +16522,26 @@ static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, IrInst* source_instructi
16468 }16522 }
16469 }16523 }
1647016524
16471 bool is_comptime = ir_should_inline(ira->zir, source_instruction->scope)16525 bool is_comptime = ir_should_inline(ira->zir, scope)
16472 || type_requires_comptime(ira->codegen, union_type) == ReqCompTimeYes;16526 || type_requires_comptime(ira->codegen, union_type) == ReqCompTimeYes;
1647316527
16474 IrInstGen *result = ir_get_deref(ira, source_instruction, result_loc, nullptr);16528 IrInstGen *result = ir_get_deref(ira, scope, source_node, result_loc, nullptr);
16475 if (is_comptime && !instr_is_comptime(result)) {16529 if (is_comptime && !instr_is_comptime(result)) {
16476 ir_add_error(ira, &field_result_loc->base,16530 ir_add_error(ira, field_result_loc,
16477 buf_sprintf("unable to evaluate constant expression"));16531 buf_sprintf("unable to evaluate constant expression"));
16478 return ira->codegen->invalid_inst_gen;16532 return ira->codegen->invalid_inst_gen;
16479 }16533 }
16480 return result;16534 return result;
16481}16535}
1648216536
16483static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *source_instr,16537static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, Scope *scope, AstNode *source_node,
16484 ZigType *container_type, size_t instr_field_count, IrInstSrcContainerInitFieldsField *fields,16538 ZigType *container_type, size_t instr_field_count, IrInstSrcContainerInitFieldsField *fields,
16485 IrInstGen *result_loc)16539 IrInstGen *result_loc)
16486{16540{
16487 Error err;16541 Error err;
16488 if (container_type->id == ZigTypeIdUnion) {16542 if (container_type->id == ZigTypeIdUnion) {
16489 if (instr_field_count != 1) {16543 if (instr_field_count != 1) {
16490 ir_add_error(ira, source_instr,16544 ir_add_error_node(ira, source_node,
16491 buf_sprintf("union initialization expects exactly one field"));16545 buf_sprintf("union initialization expects exactly one field"));
16492 return ira->codegen->invalid_inst_gen;16546 return ira->codegen->invalid_inst_gen;
16493 }16547 }
...@@ -16496,11 +16550,11 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc...@@ -16496,11 +16550,11 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
16496 if (type_is_invalid(field_result_loc->value->type))16550 if (type_is_invalid(field_result_loc->value->type))
16497 return ira->codegen->invalid_inst_gen;16551 return ira->codegen->invalid_inst_gen;
1649816552
16499 return ir_analyze_union_init(ira, source_instr, field->source_node, container_type, field->name,16553 return ir_analyze_union_init(ira, scope, source_node, field->source_node, container_type, field->name,
16500 field_result_loc, result_loc);16554 field_result_loc, result_loc);
16501 }16555 }
16502 if (container_type->id != ZigTypeIdStruct || is_slice(container_type)) {16556 if (container_type->id != ZigTypeIdStruct || is_slice(container_type)) {
16503 ir_add_error(ira, source_instr,16557 ir_add_error_node(ira, source_node,
16504 buf_sprintf("type '%s' does not support struct initialization syntax",16558 buf_sprintf("type '%s' does not support struct initialization syntax",
16505 buf_ptr(&container_type->name)));16559 buf_ptr(&container_type->name)));
16506 return ira->codegen->invalid_inst_gen;16560 return ira->codegen->invalid_inst_gen;
...@@ -16521,7 +16575,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc...@@ -16521,7 +16575,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
16521 AstNode **field_assign_nodes = heap::c_allocator.allocate<AstNode *>(actual_field_count);16575 AstNode **field_assign_nodes = heap::c_allocator.allocate<AstNode *>(actual_field_count);
16522 ZigList<IrInstGen *> const_ptrs = {};16576 ZigList<IrInstGen *> const_ptrs = {};
1652316577
16524 bool is_comptime = ir_should_inline(ira->zir, source_instr->scope)16578 bool is_comptime = ir_should_inline(ira->zir, scope)
16525 || type_requires_comptime(ira->codegen, container_type) == ReqCompTimeYes;16579 || type_requires_comptime(ira->codegen, container_type) == ReqCompTimeYes;
1652616580
1652716581
...@@ -16580,7 +16634,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc...@@ -16580,7 +16634,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
16580 TypeStructField *field = container_type->data.structure.fields[i];16634 TypeStructField *field = container_type->data.structure.fields[i];
16581 memoize_field_init_val(ira->codegen, container_type, field);16635 memoize_field_init_val(ira->codegen, container_type, field);
16582 if (field->init_val == nullptr) {16636 if (field->init_val == nullptr) {
16583 ir_add_error(ira, source_instr,16637 ir_add_error_node(ira, source_node,
16584 buf_sprintf("missing field: '%s'", buf_ptr(field->name)));16638 buf_sprintf("missing field: '%s'", buf_ptr(field->name)));
16585 any_missing = true;16639 any_missing = true;
16586 continue;16640 continue;
...@@ -16588,12 +16642,12 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc...@@ -16588,12 +16642,12 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
16588 if (type_is_invalid(field->init_val->type))16642 if (type_is_invalid(field->init_val->type))
16589 return ira->codegen->invalid_inst_gen;16643 return ira->codegen->invalid_inst_gen;
1659016644
16591 IrInstGen *runtime_inst = ir_const(ira, source_instr, field->init_val->type);16645 IrInstGen *runtime_inst = ir_const(ira, scope, source_node, field->init_val->type);
16592 copy_const_val(ira->codegen, runtime_inst->value, field->init_val);16646 copy_const_val(ira->codegen, runtime_inst->value, field->init_val);
1659316647
16594 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, result_loc,16648 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, field, result_loc,
16595 container_type, true);16649 container_type, true);
16596 ir_analyze_store_ptr(ira, source_instr, field_ptr, runtime_inst, false);16650 ir_analyze_store_ptr(ira, scope, source_node, field_ptr, runtime_inst, false);
16597 if (instr_is_comptime(field_ptr) && field_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {16651 if (instr_is_comptime(field_ptr) && field_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
16598 const_ptrs.append(field_ptr);16652 const_ptrs.append(field_ptr);
16599 } else {16653 } else {
...@@ -16609,18 +16663,20 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc...@@ -16609,18 +16663,20 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
16609 result_loc->value->special = ConstValSpecialRuntime;16663 result_loc->value->special = ConstValSpecialRuntime;
16610 for (size_t i = 0; i < const_ptrs.length; i += 1) {16664 for (size_t i = 0; i < const_ptrs.length; i += 1) {
16611 IrInstGen *field_result_loc = const_ptrs.at(i);16665 IrInstGen *field_result_loc = const_ptrs.at(i);
16612 IrInstGen *deref = ir_get_deref(ira, &field_result_loc->base, field_result_loc, nullptr);16666 IrInstGen *deref = ir_get_deref(ira, field_result_loc->scope,
16667 field_result_loc->source_node, field_result_loc, nullptr);
16613 field_result_loc->value->special = ConstValSpecialRuntime;16668 field_result_loc->value->special = ConstValSpecialRuntime;
16614 ir_analyze_store_ptr(ira, &field_result_loc->base, field_result_loc, deref, false);16669 ir_analyze_store_ptr(ira, field_result_loc->scope, field_result_loc->source_node,
16670 field_result_loc, deref, false);
16615 }16671 }
16616 }16672 }
16617 }16673 }
1661816674
16619 const_ptrs.deinit();16675 const_ptrs.deinit();
16620 IrInstGen *result = ir_get_deref(ira, source_instr, result_loc, nullptr);16676 IrInstGen *result = ir_get_deref(ira, scope, source_node, result_loc, nullptr);
1662116677
16622 if (is_comptime && !instr_is_comptime(result)) {16678 if (is_comptime && !instr_is_comptime(result)) {
16623 ir_add_error_node(ira, first_non_const_instruction->base.source_node,16679 ir_add_error_node(ira, first_non_const_instruction->source_node,
16624 buf_sprintf("unable to evaluate constant expression"));16680 buf_sprintf("unable to evaluate constant expression"));
16625 return ira->codegen->invalid_inst_gen;16681 return ira->codegen->invalid_inst_gen;
16626 }16682 }
...@@ -16631,14 +16687,14 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc...@@ -16631,14 +16687,14 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
16631static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,16687static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
16632 IrInstSrcContainerInitList *instruction)16688 IrInstSrcContainerInitList *instruction)
16633{16689{
16634 ir_assert(instruction->result_loc != nullptr, &instruction->base.base);16690 src_assert(instruction->result_loc != nullptr, instruction->base.source_node);
16635 IrInstGen *result_loc = instruction->result_loc->child;16691 IrInstGen *result_loc = instruction->result_loc->child;
16636 if (type_is_invalid(result_loc->value->type))16692 if (type_is_invalid(result_loc->value->type))
16637 return result_loc;16693 return result_loc;
1663816694
16639 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base);16695 src_assert(result_loc->value->type->id == ZigTypeIdPointer, instruction->base.source_node);
16640 if (result_loc->value->type->data.pointer.is_const) {16696 if (result_loc->value->type->data.pointer.is_const) {
16641 ir_add_error(ira, &instruction->base.base, buf_sprintf("cannot assign to constant"));16697 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("cannot assign to constant"));
16642 return ira->codegen->invalid_inst_gen;16698 return ira->codegen->invalid_inst_gen;
16643 }16699 }
1664416700
...@@ -16654,19 +16710,19 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -16654,19 +16710,19 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
1665416710
16655 if (container_type->id == ZigTypeIdVoid) {16711 if (container_type->id == ZigTypeIdVoid) {
16656 if (elem_count != 0) {16712 if (elem_count != 0) {
16657 ir_add_error_node(ira, instruction->base.base.source_node,16713 ir_add_error_node(ira, instruction->base.source_node,
16658 buf_sprintf("void expression expects no arguments"));16714 buf_sprintf("void expression expects no arguments"));
16659 return ira->codegen->invalid_inst_gen;16715 return ira->codegen->invalid_inst_gen;
16660 }16716 }
16661 return ir_const_void(ira, &instruction->base.base);16717 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
16662 }16718 }
1666316719
16664 if (container_type->id == ZigTypeIdStruct && elem_count == 0) {16720 if (container_type->id == ZigTypeIdStruct && elem_count == 0) {
16665 ir_assert(instruction->result_loc != nullptr, &instruction->base.base);16721 src_assert(instruction->result_loc != nullptr, instruction->base.source_node);
16666 IrInstGen *result_loc = instruction->result_loc->child;16722 IrInstGen *result_loc = instruction->result_loc->child;
16667 if (type_is_invalid(result_loc->value->type))16723 if (type_is_invalid(result_loc->value->type))
16668 return result_loc;16724 return result_loc;
16669 return ir_analyze_container_init_fields(ira, &instruction->base.base, container_type, 0, nullptr, result_loc);16725 return ir_analyze_container_init_fields(ira, instruction->base.scope, instruction->base.source_node, container_type, 0, nullptr, result_loc);
16670 }16726 }
1667116727
16672 if (container_type->id == ZigTypeIdArray) {16728 if (container_type->id == ZigTypeIdArray) {
...@@ -16674,7 +16730,7 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -16674,7 +16730,7 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
16674 if (container_type->data.array.len != elem_count) {16730 if (container_type->data.array.len != elem_count) {
16675 ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count, nullptr);16731 ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count, nullptr);
1667616732
16677 ir_add_error(ira, &instruction->base.base,16733 ir_add_error_node(ira, instruction->base.source_node,
16678 buf_sprintf("expected %s literal, found %s literal",16734 buf_sprintf("expected %s literal, found %s literal",
16679 buf_ptr(&container_type->name), buf_ptr(&literal_type->name)));16735 buf_ptr(&container_type->name), buf_ptr(&literal_type->name)));
16680 return ira->codegen->invalid_inst_gen;16736 return ira->codegen->invalid_inst_gen;
...@@ -16687,7 +16743,7 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -16687,7 +16743,7 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
16687 } else if (container_type->id == ZigTypeIdVector || is_tuple(container_type)) {16743 } else if (container_type->id == ZigTypeIdVector || is_tuple(container_type)) {
16688 // OK16744 // OK
16689 } else {16745 } else {
16690 ir_add_error(ira, &instruction->base.base,16746 ir_add_error_node(ira, instruction->base.source_node,
16691 buf_sprintf("type '%s' does not support array initialization",16747 buf_sprintf("type '%s' does not support array initialization",
16692 buf_ptr(&container_type->name)));16748 buf_ptr(&container_type->name)));
16693 return ira->codegen->invalid_inst_gen;16749 return ira->codegen->invalid_inst_gen;
...@@ -16697,7 +16753,7 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -16697,7 +16753,7 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
16697 case OnePossibleValueInvalid:16753 case OnePossibleValueInvalid:
16698 return ira->codegen->invalid_inst_gen;16754 return ira->codegen->invalid_inst_gen;
16699 case OnePossibleValueYes:16755 case OnePossibleValueYes:
16700 return ir_const_move(ira, &instruction->base.base,16756 return ir_const_move(ira, instruction->base.scope, instruction->base.source_node,
16701 get_the_one_possible_value(ira->codegen, container_type));16757 get_the_one_possible_value(ira->codegen, container_type));
16702 case OnePossibleValueNo:16758 case OnePossibleValueNo:
16703 break;16759 break;
...@@ -16708,7 +16764,7 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -16708,7 +16764,7 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
16708 case ReqCompTimeInvalid:16764 case ReqCompTimeInvalid:
16709 return ira->codegen->invalid_inst_gen;16765 return ira->codegen->invalid_inst_gen;
16710 case ReqCompTimeNo:16766 case ReqCompTimeNo:
16711 is_comptime = ir_should_inline(ira->zir, instruction->base.base.scope);16767 is_comptime = ir_should_inline(ira->zir, instruction->base.scope);
16712 break;16768 break;
16713 case ReqCompTimeYes:16769 case ReqCompTimeYes:
16714 is_comptime = true;16770 is_comptime = true;
...@@ -16752,32 +16808,35 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -16752,32 +16808,35 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
16752 // This field will be generated comptime; no need to do this.16808 // This field will be generated comptime; no need to do this.
16753 continue;16809 continue;
16754 }16810 }
16755 IrInstGen *deref = ir_get_deref(ira, &elem_result_loc->base, elem_result_loc, nullptr);16811 IrInstGen *deref = ir_get_deref(ira, elem_result_loc->scope,
16812 elem_result_loc->source_node, elem_result_loc, nullptr);
16756 elem_result_loc->value->special = ConstValSpecialRuntime;16813 elem_result_loc->value->special = ConstValSpecialRuntime;
16757 ir_analyze_store_ptr(ira, &elem_result_loc->base, elem_result_loc, deref, false);16814 ir_analyze_store_ptr(ira, elem_result_loc->scope, elem_result_loc->source_node,
16815 elem_result_loc, deref, false);
16758 }16816 }
16759 }16817 }
16760 }16818 }
1676116819
16762 const_ptrs.deinit();16820 const_ptrs.deinit();
1676316821
16764 IrInstGen *result = ir_get_deref(ira, &instruction->base.base, result_loc, nullptr);16822 IrInstGen *result = ir_get_deref(ira, instruction->base.scope, instruction->base.source_node,
16823 result_loc, nullptr);
16765 // If the result is a tuple, we are allowed to return a struct that uses ConstValSpecialRuntime fields at comptime.16824 // If the result is a tuple, we are allowed to return a struct that uses ConstValSpecialRuntime fields at comptime.
16766 if (instr_is_comptime(result) || is_tuple(container_type))16825 if (instr_is_comptime(result) || is_tuple(container_type))
16767 return result;16826 return result;
1676816827
16769 if (is_comptime) {16828 if (is_comptime) {
16770 ir_add_error(ira, &first_non_const_instruction->base,16829 ir_add_error(ira, first_non_const_instruction,
16771 buf_sprintf("unable to evaluate constant expression"));16830 buf_sprintf("unable to evaluate constant expression"));
16772 return ira->codegen->invalid_inst_gen;16831 return ira->codegen->invalid_inst_gen;
16773 }16832 }
1677416833
16775 ZigType *result_elem_type = result_loc->value->type->data.pointer.child_type;16834 ZigType *result_elem_type = result_loc->value->type->data.pointer.child_type;
16776 if (is_slice(result_elem_type)) {16835 if (is_slice(result_elem_type)) {
16777 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,16836 ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node,
16778 buf_sprintf("runtime-initialized array cannot be casted to slice type '%s'",16837 buf_sprintf("runtime-initialized array cannot be casted to slice type '%s'",
16779 buf_ptr(&result_elem_type->name)));16838 buf_ptr(&result_elem_type->name)));
16780 add_error_note(ira->codegen, msg, first_non_const_instruction->base.source_node,16839 add_error_note(ira->codegen, msg, first_non_const_instruction->source_node,
16781 buf_sprintf("this value is not comptime-known"));16840 buf_sprintf("this value is not comptime-known"));
16782 return ira->codegen->invalid_inst_gen;16841 return ira->codegen->invalid_inst_gen;
16783 }16842 }
...@@ -16787,20 +16846,20 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -16787,20 +16846,20 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
16787static IrInstGen *ir_analyze_instruction_container_init_fields(IrAnalyze *ira,16846static IrInstGen *ir_analyze_instruction_container_init_fields(IrAnalyze *ira,
16788 IrInstSrcContainerInitFields *instruction)16847 IrInstSrcContainerInitFields *instruction)
16789{16848{
16790 ir_assert(instruction->result_loc != nullptr, &instruction->base.base);16849 src_assert(instruction->result_loc != nullptr, instruction->base.source_node);
16791 IrInstGen *result_loc = instruction->result_loc->child;16850 IrInstGen *result_loc = instruction->result_loc->child;
16792 if (type_is_invalid(result_loc->value->type))16851 if (type_is_invalid(result_loc->value->type))
16793 return result_loc;16852 return result_loc;
1679416853
16795 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base);16854 src_assert(result_loc->value->type->id == ZigTypeIdPointer, instruction->base.source_node);
16796 if (result_loc->value->type->data.pointer.is_const) {16855 if (result_loc->value->type->data.pointer.is_const) {
16797 ir_add_error(ira, &instruction->base.base, buf_sprintf("cannot assign to constant"));16856 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("cannot assign to constant"));
16798 return ira->codegen->invalid_inst_gen;16857 return ira->codegen->invalid_inst_gen;
16799 }16858 }
1680016859
16801 ZigType *container_type = result_loc->value->type->data.pointer.child_type;16860 ZigType *container_type = result_loc->value->type->data.pointer.child_type;
1680216861
16803 return ir_analyze_container_init_fields(ira, &instruction->base.base, container_type,16862 return ir_analyze_container_init_fields(ira, instruction->base.scope, instruction->base.source_node, container_type,
16804 instruction->field_count, instruction->fields, result_loc);16863 instruction->field_count, instruction->fields, result_loc);
16805}16864}
1680616865
...@@ -16810,7 +16869,7 @@ static IrInstGen *ir_analyze_instruction_compile_err(IrAnalyze *ira, IrInstSrcCo...@@ -16810,7 +16869,7 @@ static IrInstGen *ir_analyze_instruction_compile_err(IrAnalyze *ira, IrInstSrcCo
16810 if (!msg_buf)16869 if (!msg_buf)
16811 return ira->codegen->invalid_inst_gen;16870 return ira->codegen->invalid_inst_gen;
1681216871
16813 ir_add_error(ira, &instruction->base.base, msg_buf);16872 ir_add_error_node(ira, instruction->base.source_node, msg_buf);
1681416873
16815 return ira->codegen->invalid_inst_gen;16874 return ira->codegen->invalid_inst_gen;
16816}16875}
...@@ -16825,7 +16884,7 @@ static IrInstGen *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstSrcCo...@@ -16825,7 +16884,7 @@ static IrInstGen *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstSrcCo
16825 buf_resize(&buf, 0);16884 buf_resize(&buf, 0);
16826 if (msg->value->special == ConstValSpecialLazy) {16885 if (msg->value->special == ConstValSpecialLazy) {
16827 // Resolve any lazy value that's passed, we need its value16886 // Resolve any lazy value that's passed, we need its value
16828 if (ir_resolve_lazy(ira->codegen, msg->base.source_node, msg->value))16887 if (ir_resolve_lazy(ira->codegen, msg->source_node, msg->value))
16829 return ira->codegen->invalid_inst_gen;16888 return ira->codegen->invalid_inst_gen;
16830 }16889 }
16831 render_const_value(ira->codegen, &buf, msg->value);16890 render_const_value(ira->codegen, &buf, msg->value);
...@@ -16834,15 +16893,15 @@ static IrInstGen *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstSrcCo...@@ -16834,15 +16893,15 @@ static IrInstGen *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstSrcCo
16834 }16893 }
16835 fprintf(stderr, "\n");16894 fprintf(stderr, "\n");
1683616895
16837 auto *expr = &instruction->base.base.source_node->data.fn_call_expr;16896 auto *expr = &instruction->base.source_node->data.fn_call_expr;
16838 if (!expr->seen) {16897 if (!expr->seen) {
16839 // Here we bypass higher level functions such as ir_add_error because we do not want16898 // Here we bypass higher level functions such as ir_add_error because we do not want
16840 // invalidate_exec to be called.16899 // invalidate_exec to be called.
16841 add_node_error(ira->codegen, instruction->base.base.source_node, buf_sprintf("found compile log statement"));16900 add_node_error(ira->codegen, instruction->base.source_node, buf_sprintf("found compile log statement"));
16842 }16901 }
16843 expr->seen = true;16902 expr->seen = true;
1684416903
16845 return ir_const_void(ira, &instruction->base.base);16904 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
16846}16905}
1684716906
16848static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrName *instruction) {16907static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrName *instruction) {
...@@ -16864,7 +16923,7 @@ static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrNa...@@ -16864,7 +16923,7 @@ static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrNa
16864 ira->codegen, &err->name,16923 ira->codegen, &err->name,
16865 ira->codegen->intern.for_zero_byte());16924 ira->codegen->intern.for_zero_byte());
16866 }16925 }
16867 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);16926 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr);
16868 result->value = err->cached_error_name_val;16927 result->value = err->cached_error_name_val;
16869 return result;16928 return result;
16870 }16929 }
...@@ -16875,7 +16934,7 @@ static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrNa...@@ -16875,7 +16934,7 @@ static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrNa
16875 true, false, PtrLenUnknown, 0, 0, 0, false,16934 true, false, PtrLenUnknown, 0, 0, 0, false,
16876 VECTOR_INDEX_NONE, nullptr, ira->codegen->intern.for_zero_byte());16935 VECTOR_INDEX_NONE, nullptr, ira->codegen->intern.for_zero_byte());
16877 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);16936 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);
16878 return ir_build_err_name_gen(ira, &instruction->base.base, value, str_type);16937 return ir_build_err_name_gen(ira, instruction->base.scope, instruction->base.source_node, value, str_type);
16879}16938}
1688016939
16881static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrcTagName *instruction) {16940static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrcTagName *instruction) {
...@@ -16887,7 +16946,7 @@ static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrc...@@ -16887,7 +16946,7 @@ static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrc
16887 ZigType *target_type = target->value->type;16946 ZigType *target_type = target->value->type;
1688816947
16889 if (target_type->id == ZigTypeIdEnumLiteral) {16948 if (target_type->id == ZigTypeIdEnumLiteral) {
16890 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);16949 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr);
16891 Buf *field_name = target->value->data.x_enum_literal;16950 Buf *field_name = target->value->data.x_enum_literal;
16892 result->value = create_sentineled_str_lit(16951 result->value = create_sentineled_str_lit(
16893 ira->codegen, field_name,16952 ira->codegen, field_name,
...@@ -16896,21 +16955,21 @@ static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrc...@@ -16896,21 +16955,21 @@ static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrc
16896 }16955 }
1689716956
16898 if (target_type->id == ZigTypeIdUnion) {16957 if (target_type->id == ZigTypeIdUnion) {
16899 target = ir_analyze_union_tag(ira, &instruction->base.base, target);16958 target = ir_analyze_union_tag(ira, instruction->base.scope, instruction->base.source_node, target);
16900 if (type_is_invalid(target->value->type))16959 if (type_is_invalid(target->value->type))
16901 return ira->codegen->invalid_inst_gen;16960 return ira->codegen->invalid_inst_gen;
16902 target_type = target->value->type;16961 target_type = target->value->type;
16903 }16962 }
1690416963
16905 if (target_type->id != ZigTypeIdEnum) {16964 if (target_type->id != ZigTypeIdEnum) {
16906 ir_add_error(ira, &target->base,16965 ir_add_error(ira, target,
16907 buf_sprintf("expected enum tag, found '%s'", buf_ptr(&target_type->name)));16966 buf_sprintf("expected enum tag, found '%s'", buf_ptr(&target_type->name)));
16908 return ira->codegen->invalid_inst_gen;16967 return ira->codegen->invalid_inst_gen;
16909 }16968 }
1691016969
16911 if (can_fold_enum_type(target_type)) {16970 if (can_fold_enum_type(target_type)) {
16912 TypeEnumField *only_field = &target_type->data.enumeration.fields[0];16971 TypeEnumField *only_field = &target_type->data.enumeration.fields[0];
16913 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);16972 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr);
16914 result->value = create_sentineled_str_lit(16973 result->value = create_sentineled_str_lit(
16915 ira->codegen, only_field->name,16974 ira->codegen, only_field->name,
16916 ira->codegen->intern.for_zero_byte());16975 ira->codegen->intern.for_zero_byte());
...@@ -16925,11 +16984,11 @@ static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrc...@@ -16925,11 +16984,11 @@ static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrc
16925 Buf *int_buf = buf_alloc();16984 Buf *int_buf = buf_alloc();
16926 bigint_append_buf(int_buf, &target->value->data.x_bigint, 10);16985 bigint_append_buf(int_buf, &target->value->data.x_bigint, 10);
1692716986
16928 ir_add_error(ira, &target->base,16987 ir_add_error(ira, target,
16929 buf_sprintf("no tag by value %s", buf_ptr(int_buf)));16988 buf_sprintf("no tag by value %s", buf_ptr(int_buf)));
16930 return ira->codegen->invalid_inst_gen;16989 return ira->codegen->invalid_inst_gen;
16931 }16990 }
16932 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);16991 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr);
16933 result->value = create_sentineled_str_lit(16992 result->value = create_sentineled_str_lit(
16934 ira->codegen, field->name,16993 ira->codegen, field->name,
16935 ira->codegen->intern.for_zero_byte());16994 ira->codegen->intern.for_zero_byte());
...@@ -16941,7 +17000,7 @@ static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrc...@@ -16941,7 +17000,7 @@ static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrc
16941 true, false, PtrLenUnknown, 0, 0, 0, false,17000 true, false, PtrLenUnknown, 0, 0, 0, false,
16942 VECTOR_INDEX_NONE, nullptr, ira->codegen->intern.for_zero_byte());17001 VECTOR_INDEX_NONE, nullptr, ira->codegen->intern.for_zero_byte());
16943 ZigType *result_type = get_slice_type(ira->codegen, u8_ptr_type);17002 ZigType *result_type = get_slice_type(ira->codegen, u8_ptr_type);
16944 return ir_build_tag_name_gen(ira, &instruction->base.base, target, result_type);17003 return ir_build_tag_name_gen(ira, instruction->base.scope, instruction->base.source_node, target, result_type);
16945}17004}
1694617005
16947static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,17006static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
...@@ -16963,7 +17022,7 @@ static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -16963,7 +17022,7 @@ static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
16963 return ira->codegen->invalid_inst_gen;17022 return ira->codegen->invalid_inst_gen;
1696417023
16965 if (container_type->id != ZigTypeIdStruct) {17024 if (container_type->id != ZigTypeIdStruct) {
16966 ir_add_error(ira, &type_value->base,17025 ir_add_error(ira, type_value,
16967 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));17026 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
16968 return ira->codegen->invalid_inst_gen;17027 return ira->codegen->invalid_inst_gen;
16969 }17028 }
...@@ -16973,14 +17032,14 @@ static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -16973,14 +17032,14 @@ static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
1697317032
16974 TypeStructField *field = find_struct_type_field(container_type, field_name);17033 TypeStructField *field = find_struct_type_field(container_type, field_name);
16975 if (field == nullptr) {17034 if (field == nullptr) {
16976 ir_add_error(ira, &field_name_value->base,17035 ir_add_error(ira, field_name_value,
16977 buf_sprintf("struct '%s' has no field '%s'",17036 buf_sprintf("struct '%s' has no field '%s'",
16978 buf_ptr(&container_type->name), buf_ptr(field_name)));17037 buf_ptr(&container_type->name), buf_ptr(field_name)));
16979 return ira->codegen->invalid_inst_gen;17038 return ira->codegen->invalid_inst_gen;
16980 }17039 }
1698117040
16982 if (field_ptr->value->type->id != ZigTypeIdPointer) {17041 if (field_ptr->value->type->id != ZigTypeIdPointer) {
16983 ir_add_error(ira, &field_ptr->base,17042 ir_add_error(ira, field_ptr,
16984 buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value->type->name)));17043 buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value->type->name)));
16985 return ira->codegen->invalid_inst_gen;17044 return ira->codegen->invalid_inst_gen;
16986 }17045 }
...@@ -17010,20 +17069,20 @@ static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -17010,20 +17069,20 @@ static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
17010 return ira->codegen->invalid_inst_gen;17069 return ira->codegen->invalid_inst_gen;
1701117070
17012 if (field_ptr_val->data.x_ptr.special != ConstPtrSpecialBaseStruct) {17071 if (field_ptr_val->data.x_ptr.special != ConstPtrSpecialBaseStruct) {
17013 ir_add_error(ira, &field_ptr->base, buf_sprintf("pointer value not based on parent struct"));17072 ir_add_error(ira, field_ptr, buf_sprintf("pointer value not based on parent struct"));
17014 return ira->codegen->invalid_inst_gen;17073 return ira->codegen->invalid_inst_gen;
17015 }17074 }
1701617075
17017 size_t ptr_field_index = field_ptr_val->data.x_ptr.data.base_struct.field_index;17076 size_t ptr_field_index = field_ptr_val->data.x_ptr.data.base_struct.field_index;
17018 if (ptr_field_index != field->src_index) {17077 if (ptr_field_index != field->src_index) {
17019 ir_add_error(ira, &instruction->base.base,17078 ir_add_error_node(ira, instruction->base.source_node,
17020 buf_sprintf("field '%s' has index %" ZIG_PRI_usize " but pointer value is index %" ZIG_PRI_usize " of struct '%s'",17079 buf_sprintf("field '%s' has index %" ZIG_PRI_usize " but pointer value is index %" ZIG_PRI_usize " of struct '%s'",
17021 buf_ptr(field->name), field->src_index,17080 buf_ptr(field->name), field->src_index,
17022 ptr_field_index, buf_ptr(&container_type->name)));17081 ptr_field_index, buf_ptr(&container_type->name)));
17023 return ira->codegen->invalid_inst_gen;17082 return ira->codegen->invalid_inst_gen;
17024 }17083 }
1702517084
17026 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);17085 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, result_type);
17027 ZigValue *out_val = result->value;17086 ZigValue *out_val = result->value;
17028 out_val->data.x_ptr.special = ConstPtrSpecialRef;17087 out_val->data.x_ptr.special = ConstPtrSpecialRef;
17029 out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val;17088 out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val;
...@@ -17031,7 +17090,7 @@ static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -17031,7 +17090,7 @@ static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
17031 return result;17090 return result;
17032 }17091 }
1703317092
17034 return ir_build_field_parent_ptr_gen(ira, &instruction->base.base, casted_field_ptr, field, result_type);17093 return ir_build_field_parent_ptr_gen(ira, instruction->base.scope, instruction->base.source_node, casted_field_ptr, field, result_type);
17035}17094}
1703617095
17037static TypeStructField *validate_host_int_byte_offset(IrAnalyze *ira,17096static TypeStructField *validate_host_int_byte_offset(IrAnalyze *ira,
...@@ -17052,21 +17111,21 @@ static TypeStructField *validate_host_int_byte_offset(IrAnalyze *ira,...@@ -17052,21 +17111,21 @@ static TypeStructField *validate_host_int_byte_offset(IrAnalyze *ira,
17052 return nullptr;17111 return nullptr;
1705317112
17054 if (container_type->id != ZigTypeIdStruct) {17113 if (container_type->id != ZigTypeIdStruct) {
17055 ir_add_error(ira, &type_value->base,17114 ir_add_error(ira, type_value,
17056 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));17115 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
17057 return nullptr;17116 return nullptr;
17058 }17117 }
1705917118
17060 TypeStructField *field = find_struct_type_field(container_type, field_name);17119 TypeStructField *field = find_struct_type_field(container_type, field_name);
17061 if (field == nullptr) {17120 if (field == nullptr) {
17062 ir_add_error(ira, &field_name_value->base,17121 ir_add_error(ira, field_name_value,
17063 buf_sprintf("struct '%s' has no field '%s'",17122 buf_sprintf("struct '%s' has no field '%s'",
17064 buf_ptr(&container_type->name), buf_ptr(field_name)));17123 buf_ptr(&container_type->name), buf_ptr(field_name)));
17065 return nullptr;17124 return nullptr;
17066 }17125 }
1706717126
17068 if (!type_has_bits(ira->codegen, field->type_entry)) {17127 if (!type_has_bits(ira->codegen, field->type_entry)) {
17069 ir_add_error(ira, &field_name_value->base,17128 ir_add_error(ira, field_name_value,
17070 buf_sprintf("zero-bit field '%s' in struct '%s' has no offset",17129 buf_sprintf("zero-bit field '%s' in struct '%s' has no offset",
17071 buf_ptr(field_name), buf_ptr(&container_type->name)));17130 buf_ptr(field_name), buf_ptr(&container_type->name)));
17072 return nullptr;17131 return nullptr;
...@@ -17088,7 +17147,7 @@ static IrInstGen *ir_analyze_instruction_offset_of(IrAnalyze *ira, IrInstSrcOffs...@@ -17088,7 +17147,7 @@ static IrInstGen *ir_analyze_instruction_offset_of(IrAnalyze *ira, IrInstSrcOffs
17088 return ira->codegen->invalid_inst_gen;17147 return ira->codegen->invalid_inst_gen;
1708917148
17090 size_t byte_offset = host_int_byte_offset + (field->bit_offset_in_host / 8);17149 size_t byte_offset = host_int_byte_offset + (field->bit_offset_in_host / 8);
17091 return ir_const_unsigned(ira, &instruction->base.base, byte_offset);17150 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, byte_offset);
17092}17151}
1709317152
17094static IrInstGen *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, IrInstSrcBitOffsetOf *instruction) {17153static IrInstGen *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, IrInstSrcBitOffsetOf *instruction) {
...@@ -17102,7 +17161,7 @@ static IrInstGen *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, IrInstSrc...@@ -17102,7 +17161,7 @@ static IrInstGen *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, IrInstSrc
17102 return ira->codegen->invalid_inst_gen;17161 return ira->codegen->invalid_inst_gen;
1710317162
17104 size_t bit_offset = host_int_byte_offset * 8 + field->bit_offset_in_host;17163 size_t bit_offset = host_int_byte_offset * 8 + field->bit_offset_in_host;
17105 return ir_const_unsigned(ira, &instruction->base.base, bit_offset);17164 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, bit_offset);
17106}17165}
1710717166
17108static void ensure_field_index(ZigType *type, const char *field_name, size_t index) {17167static void ensure_field_index(ZigType *type, const char *field_name, size_t index) {
...@@ -17150,7 +17209,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig...@@ -17150,7 +17209,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig
17150 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value);17209 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value);
17151}17210}
1715217211
17153static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigValue *out_val,17212static Error ir_make_type_info_decls(IrAnalyze *ira, AstNode *source_node, ZigValue *out_val,
17154 ScopeDecls *decls_scope, bool resolve_types)17213 ScopeDecls *decls_scope, bool resolve_types)
17155{17214{
17156 Error err;17215 Error err;
...@@ -17174,7 +17233,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa...@@ -17174,7 +17233,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
17174 out_val->data.x_lazy = &lazy_type_info_decls->base;17233 out_val->data.x_lazy = &lazy_type_info_decls->base;
17175 lazy_type_info_decls->base.id = LazyValueIdTypeInfoDecls;17234 lazy_type_info_decls->base.id = LazyValueIdTypeInfoDecls;
1717617235
17177 lazy_type_info_decls->source_instr = source_instr;17236 lazy_type_info_decls->source_node = source_node;
17178 lazy_type_info_decls->decls_scope = decls_scope;17237 lazy_type_info_decls->decls_scope = decls_scope;
1717917238
17180 return ErrorNone;17239 return ErrorNone;
...@@ -17202,7 +17261,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa...@@ -17202,7 +17261,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
17202 }17261 }
1720317262
17204 if (curr_entry->value->resolution == TldResolutionResolving) {17263 if (curr_entry->value->resolution == TldResolutionResolving) {
17205 ir_error_dependency_loop(ira, source_instr);17264 ir_error_dependency_loop(ira, source_node);
17206 return ErrorSemanticAnalyzeFail;17265 return ErrorSemanticAnalyzeFail;
17207 }17266 }
1720817267
...@@ -17435,7 +17494,7 @@ static PtrLen size_enum_index_to_ptr_len(BuiltinPtrSize size_enum_index) {...@@ -17435,7 +17494,7 @@ static PtrLen size_enum_index_to_ptr_len(BuiltinPtrSize size_enum_index) {
17435 zig_unreachable();17494 zig_unreachable();
17436}17495}
1743717496
17438static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, IrInst *source_instr, ZigType *ptr_type_entry) {17497static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ptr_type_entry) {
17439 ZigType *attrs_type;17498 ZigType *attrs_type;
17440 BuiltinPtrSize size_enum_index;17499 BuiltinPtrSize size_enum_index;
17441 if (is_slice(ptr_type_entry)) {17500 if (is_slice(ptr_type_entry)) {
...@@ -17489,7 +17548,7 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, IrInst *source_instr,...@@ -17489,7 +17548,7 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, IrInst *source_instr,
17489 fields[3]->special = ConstValSpecialLazy;17548 fields[3]->special = ConstValSpecialLazy;
17490 fields[3]->data.x_lazy = &lazy_align_of->base;17549 fields[3]->data.x_lazy = &lazy_align_of->base;
17491 lazy_align_of->base.id = LazyValueIdAlignOf;17550 lazy_align_of->base.id = LazyValueIdAlignOf;
17492 lazy_align_of->target_type = ir_const_type(ira, source_instr, attrs_type->data.pointer.child_type);17551 lazy_align_of->target_type = ir_const_type(ira, scope, source_node, attrs_type->data.pointer.child_type);
17493 }17552 }
17494 // child: type17553 // child: type
17495 ensure_field_index(result->type, "child", 4);17554 ensure_field_index(result->type, "child", 4);
...@@ -17532,7 +17591,7 @@ static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEn...@@ -17532,7 +17591,7 @@ static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEn
17532 enum_field_val->data.x_struct.fields = inner_fields;17591 enum_field_val->data.x_struct.fields = inner_fields;
17533}17592}
1753417593
17535static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigType *type_entry,17594static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *type_entry,
17536 ZigValue **out)17595 ZigValue **out)
17537{17596{
17538 Error err;17597 Error err;
...@@ -17601,7 +17660,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -17601,7 +17660,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
17601 }17660 }
17602 case ZigTypeIdPointer:17661 case ZigTypeIdPointer:
17603 {17662 {
17604 result = create_ptr_like_type_info(ira, source_instr, type_entry);17663 result = create_ptr_like_type_info(ira, scope, source_node, type_entry);
17605 if (result == nullptr)17664 if (result == nullptr)
17606 return ErrorSemanticAnalyzeFail;17665 return ErrorSemanticAnalyzeFail;
17607 break;17666 break;
...@@ -17739,7 +17798,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -17739,7 +17798,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
17739 }17798 }
17740 // decls: []TypeInfo.Declaration17799 // decls: []TypeInfo.Declaration
17741 ensure_field_index(result->type, "decls", 3);17800 ensure_field_index(result->type, "decls", 3);
17742 if ((err = ir_make_type_info_decls(ira, source_instr, fields[3],17801 if ((err = ir_make_type_info_decls(ira, source_node, fields[3],
17743 type_entry->data.enumeration.decls_scope, false)))17802 type_entry->data.enumeration.decls_scope, false)))
17744 {17803 {
17745 return err;17804 return err;
...@@ -17759,7 +17818,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -17759,7 +17818,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
17759 result->type = ir_type_info_get_type(ira, "ErrorSet", nullptr);17818 result->type = ir_type_info_get_type(ira, "ErrorSet", nullptr);
1776017819
17761 ZigType *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr);17820 ZigType *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr);
17762 if (!resolve_inferred_error_set(ira->codegen, type_entry, source_instr->source_node)) {17821 if (!resolve_inferred_error_set(ira->codegen, type_entry, source_node)) {
17763 return ErrorSemanticAnalyzeFail;17822 return ErrorSemanticAnalyzeFail;
17764 }17823 }
17765 if (type_is_global_error_set(type_entry)) {17824 if (type_is_global_error_set(type_entry)) {
...@@ -17905,7 +17964,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -17905,7 +17964,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
17905 }17964 }
17906 // decls: []TypeInfo.Declaration17965 // decls: []TypeInfo.Declaration
17907 ensure_field_index(result->type, "decls", 3);17966 ensure_field_index(result->type, "decls", 3);
17908 if ((err = ir_make_type_info_decls(ira, source_instr, fields[3],17967 if ((err = ir_make_type_info_decls(ira, source_node, fields[3],
17909 type_entry->data.unionation.decls_scope, false)))17968 type_entry->data.unionation.decls_scope, false)))
17910 {17969 {
17911 return err;17970 return err;
...@@ -17916,7 +17975,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -17916,7 +17975,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
17916 case ZigTypeIdStruct:17975 case ZigTypeIdStruct:
17917 {17976 {
17918 if (type_entry->data.structure.special == StructSpecialSlice) {17977 if (type_entry->data.structure.special == StructSpecialSlice) {
17919 result = create_ptr_like_type_info(ira, source_instr, type_entry);17978 result = create_ptr_like_type_info(ira, scope, source_node, type_entry);
17920 if (result == nullptr)17979 if (result == nullptr)
17921 return ErrorSemanticAnalyzeFail;17980 return ErrorSemanticAnalyzeFail;
17922 break;17981 break;
...@@ -17997,7 +18056,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -17997,7 +18056,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
17997 }18056 }
17998 // decls: []TypeInfo.Declaration18057 // decls: []TypeInfo.Declaration
17999 ensure_field_index(result->type, "decls", 2);18058 ensure_field_index(result->type, "decls", 2);
18000 if ((err = ir_make_type_info_decls(ira, source_instr, fields[2],18059 if ((err = ir_make_type_info_decls(ira, source_node, fields[2],
18001 type_entry->data.structure.decls_scope, false)))18060 type_entry->data.structure.decls_scope, false)))
18002 {18061 {
18003 return err;18062 return err;
...@@ -18112,7 +18171,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -18112,7 +18171,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
18112 {18171 {
18113 ZigType *fn_type = type_entry->data.bound_fn.fn_type;18172 ZigType *fn_type = type_entry->data.bound_fn.fn_type;
18114 assert(fn_type->id == ZigTypeIdFn);18173 assert(fn_type->id == ZigTypeIdFn);
18115 if ((err = ir_make_type_info_value(ira, source_instr, fn_type, &result)))18174 if ((err = ir_make_type_info_value(ira, scope, source_node, fn_type, &result)))
18116 return err;18175 return err;
1811718176
18118 break;18177 break;
...@@ -18128,7 +18187,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -18128,7 +18187,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
1812818187
18129 // decls: []TypeInfo.Declaration18188 // decls: []TypeInfo.Declaration
18130 ensure_field_index(result->type, "decls", 0);18189 ensure_field_index(result->type, "decls", 0);
18131 if ((err = ir_make_type_info_decls(ira, source_instr, fields[0],18190 if ((err = ir_make_type_info_decls(ira, source_node, fields[0],
18132 type_entry->data.opaque.decls_scope, false)))18191 type_entry->data.opaque.decls_scope, false)))
18133 {18192 {
18134 return err;18193 return err;
...@@ -18167,10 +18226,10 @@ static IrInstGen *ir_analyze_instruction_type_info(IrAnalyze *ira, IrInstSrcType...@@ -18167,10 +18226,10 @@ static IrInstGen *ir_analyze_instruction_type_info(IrAnalyze *ira, IrInstSrcType
18167 ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);18226 ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);
1816818227
18169 ZigValue *payload;18228 ZigValue *payload;
18170 if ((err = ir_make_type_info_value(ira, &instruction->base.base, type_entry, &payload)))18229 if ((err = ir_make_type_info_value(ira, instruction->base.scope, instruction->base.source_node, type_entry, &payload)))
18171 return ira->codegen->invalid_inst_gen;18230 return ira->codegen->invalid_inst_gen;
1817218231
18173 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);18232 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, result_type);
18174 ZigValue *out_val = result->value;18233 ZigValue *out_val = result->value;
18175 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry));18234 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry));
18176 out_val->data.x_union.payload = payload;18235 out_val->data.x_union.payload = payload;
...@@ -18194,14 +18253,14 @@ static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue...@@ -18194,14 +18253,14 @@ static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue
18194 return val;18253 return val;
18195}18254}
1819618255
18197static Error get_const_field_sentinel(IrAnalyze *ira, IrInst* source_instr, ZigValue *struct_value,18256static Error get_const_field_sentinel(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigValue *struct_value,
18198 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)18257 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)
18199{18258{
18200 ZigValue *field_val = get_const_field(ira, source_instr->source_node, struct_value, name, field_index);18259 ZigValue *field_val = get_const_field(ira, source_node, struct_value, name, field_index);
18201 if (field_val == nullptr)18260 if (field_val == nullptr)
18202 return ErrorSemanticAnalyzeFail;18261 return ErrorSemanticAnalyzeFail;
1820318262
18204 IrInstGen *field_inst = ir_const_move(ira, source_instr, field_val);18263 IrInstGen *field_inst = ir_const_move(ira, scope, source_node, field_val);
18205 IrInstGen *casted_field_inst = ir_implicit_cast(ira, field_inst,18264 IrInstGen *casted_field_inst = ir_implicit_cast(ira, field_inst,
18206 get_optional_type(ira->codegen, elem_type));18265 get_optional_type(ira->codegen, elem_type));
18207 if (type_is_invalid(casted_field_inst->value->type))18266 if (type_is_invalid(casted_field_inst->value->type))
...@@ -18295,7 +18354,7 @@ static Error get_const_field_buf(IrAnalyze *ira, AstNode *source_node, ZigValue...@@ -18295,7 +18354,7 @@ static Error get_const_field_buf(IrAnalyze *ira, AstNode *source_node, ZigValue
18295 return ErrorNone;18354 return ErrorNone;
18296}18355}
1829718356
18298static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeId tagTypeId, ZigValue *payload) {18357static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigTypeId tagTypeId, ZigValue *payload) {
18299 Error err;18358 Error err;
18300 switch (tagTypeId) {18359 switch (tagTypeId) {
18301 case ZigTypeIdInvalid:18360 case ZigTypeIdInvalid:
...@@ -18319,7 +18378,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18319,7 +18378,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18319 case ZigTypeIdEnumLiteral:18378 case ZigTypeIdEnumLiteral:
18320 return ira->codegen->builtin_types.entry_enum_literal;18379 return ira->codegen->builtin_types.entry_enum_literal;
18321 default:18380 default:
18322 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_instr->source_node, payload, UndefBad)))18381 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_node, payload, UndefBad)))
18323 return ira->codegen->invalid_inst_gen->value->type;18382 return ira->codegen->invalid_inst_gen->value->type;
18324 }18383 }
18325 switch (tagTypeId) {18384 switch (tagTypeId) {
...@@ -18337,10 +18396,10 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18337,10 +18396,10 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18337 case ZigTypeIdInt: {18396 case ZigTypeIdInt: {
18338 assert(payload->special == ConstValSpecialStatic);18397 assert(payload->special == ConstValSpecialStatic);
18339 assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr));18398 assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr));
18340 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "bits", 1);18399 BigInt *bi = get_const_field_lit_int(ira, source_node, payload, "bits", 1);
18341 if (bi == nullptr)18400 if (bi == nullptr)
18342 return ira->codegen->invalid_inst_gen->value->type;18401 return ira->codegen->invalid_inst_gen->value->type;
18343 ZigValue *value = get_const_field(ira, source_instr->source_node, payload, "signedness", 0);18402 ZigValue *value = get_const_field(ira, source_node, payload, "signedness", 0);
18344 if (value == nullptr)18403 if (value == nullptr)
18345 return ira->codegen->invalid_inst_gen->value->type;18404 return ira->codegen->invalid_inst_gen->value->type;
18346 assert(value->type == get_builtin_type(ira->codegen, "Signedness"));18405 assert(value->type == get_builtin_type(ira->codegen, "Signedness"));
...@@ -18351,7 +18410,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18351,7 +18410,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18351 {18410 {
18352 assert(payload->special == ConstValSpecialStatic);18411 assert(payload->special == ConstValSpecialStatic);
18353 assert(payload->type == ir_type_info_get_type(ira, "Float", nullptr));18412 assert(payload->type == ir_type_info_get_type(ira, "Float", nullptr));
18354 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "bits", 0);18413 BigInt *bi = get_const_field_lit_int(ira, source_node, payload, "bits", 0);
18355 if (bi == nullptr)18414 if (bi == nullptr)
18356 return ira->codegen->invalid_inst_gen->value->type;18415 return ira->codegen->invalid_inst_gen->value->type;
18357 uint32_t bits = bigint_as_u32(bi);18416 uint32_t bits = bigint_as_u32(bi);
...@@ -18361,7 +18420,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18361,7 +18420,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18361 case 64: return ira->codegen->builtin_types.entry_f64;18420 case 64: return ira->codegen->builtin_types.entry_f64;
18362 case 128: return ira->codegen->builtin_types.entry_f128;18421 case 128: return ira->codegen->builtin_types.entry_f128;
18363 }18422 }
18364 ir_add_error(ira, source_instr, buf_sprintf("%d-bit float unsupported", bits));18423 ir_add_error_node(ira, source_node, buf_sprintf("%d-bit float unsupported", bits));
18365 return ira->codegen->invalid_inst_gen->value->type;18424 return ira->codegen->invalid_inst_gen->value->type;
18366 }18425 }
18367 case ZigTypeIdPointer:18426 case ZigTypeIdPointer:
...@@ -18369,45 +18428,45 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18369,45 +18428,45 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18369 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);18428 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
18370 assert(payload->special == ConstValSpecialStatic);18429 assert(payload->special == ConstValSpecialStatic);
18371 assert(payload->type == type_info_pointer_type);18430 assert(payload->type == type_info_pointer_type);
18372 ZigValue *size_value = get_const_field(ira, source_instr->source_node, payload, "size", 0);18431 ZigValue *size_value = get_const_field(ira, source_node, payload, "size", 0);
18373 if (size_value == nullptr)18432 if (size_value == nullptr)
18374 return ira->codegen->invalid_inst_gen->value->type;18433 return ira->codegen->invalid_inst_gen->value->type;
1837518434
18376 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));18435 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));
18377 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);18436 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);
18378 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);18437 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);
18379 ZigType *elem_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 4);18438 ZigType *elem_type = get_const_field_meta_type(ira, source_node, payload, "child", 4);
18380 if (type_is_invalid(elem_type))18439 if (type_is_invalid(elem_type))
18381 return ira->codegen->invalid_inst_gen->value->type;18440 return ira->codegen->invalid_inst_gen->value->type;
18382 ZigValue *sentinel;18441 ZigValue *sentinel;
18383 if ((err = get_const_field_sentinel(ira, source_instr, payload, "sentinel", 6,18442 if ((err = get_const_field_sentinel(ira, scope, source_node, payload, "sentinel", 6,
18384 elem_type, &sentinel)))18443 elem_type, &sentinel)))
18385 {18444 {
18386 return ira->codegen->invalid_inst_gen->value->type;18445 return ira->codegen->invalid_inst_gen->value->type;
18387 }18446 }
18388 if (sentinel != nullptr && (size_enum_index == BuiltinPtrSizeOne || size_enum_index == BuiltinPtrSizeC)) {18447 if (sentinel != nullptr && (size_enum_index == BuiltinPtrSizeOne || size_enum_index == BuiltinPtrSizeC)) {
18389 ir_add_error(ira, source_instr,18448 ir_add_error_node(ira, source_node,
18390 buf_sprintf("sentinels are only allowed on slices and unknown-length pointers"));18449 buf_sprintf("sentinels are only allowed on slices and unknown-length pointers"));
18391 return ira->codegen->invalid_inst_gen->value->type;18450 return ira->codegen->invalid_inst_gen->value->type;
18392 }18451 }
1839318452
18394 BigInt *alignment = get_const_field_lit_int(ira, source_instr->source_node, payload, "alignment", 3);18453 BigInt *alignment = get_const_field_lit_int(ira, source_node, payload, "alignment", 3);
18395 if (alignment == nullptr)18454 if (alignment == nullptr)
18396 return ira->codegen->invalid_inst_gen->value->type;18455 return ira->codegen->invalid_inst_gen->value->type;
1839718456
18398 bool is_const;18457 bool is_const;
18399 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_const", 1, &is_const)))18458 if ((err = get_const_field_bool(ira, source_node, payload, "is_const", 1, &is_const)))
18400 return ira->codegen->invalid_inst_gen->value->type;18459 return ira->codegen->invalid_inst_gen->value->type;
1840118460
18402 bool is_volatile;18461 bool is_volatile;
18403 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_volatile", 2,18462 if ((err = get_const_field_bool(ira, source_node, payload, "is_volatile", 2,
18404 &is_volatile)))18463 &is_volatile)))
18405 {18464 {
18406 return ira->codegen->invalid_inst_gen->value->type;18465 return ira->codegen->invalid_inst_gen->value->type;
18407 }18466 }
1840818467
18409 bool is_allowzero;18468 bool is_allowzero;
18410 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_allowzero", 5,18469 if ((err = get_const_field_bool(ira, source_node, payload, "is_allowzero", 5,
18411 &is_allowzero)))18470 &is_allowzero)))
18412 {18471 {
18413 return ira->codegen->invalid_inst_gen->value->type;18472 return ira->codegen->invalid_inst_gen->value->type;
...@@ -18431,16 +18490,16 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18431,16 +18490,16 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18431 case ZigTypeIdArray: {18490 case ZigTypeIdArray: {
18432 assert(payload->special == ConstValSpecialStatic);18491 assert(payload->special == ConstValSpecialStatic);
18433 assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));18492 assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));
18434 ZigType *elem_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 1);18493 ZigType *elem_type = get_const_field_meta_type(ira, source_node, payload, "child", 1);
18435 if (type_is_invalid(elem_type))18494 if (type_is_invalid(elem_type))
18436 return ira->codegen->invalid_inst_gen->value->type;18495 return ira->codegen->invalid_inst_gen->value->type;
18437 ZigValue *sentinel;18496 ZigValue *sentinel;
18438 if ((err = get_const_field_sentinel(ira, source_instr, payload, "sentinel", 2,18497 if ((err = get_const_field_sentinel(ira, scope, source_node, payload, "sentinel", 2,
18439 elem_type, &sentinel)))18498 elem_type, &sentinel)))
18440 {18499 {
18441 return ira->codegen->invalid_inst_gen->value->type;18500 return ira->codegen->invalid_inst_gen->value->type;
18442 }18501 }
18443 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "len", 0);18502 BigInt *bi = get_const_field_lit_int(ira, source_node, payload, "len", 0);
18444 if (bi == nullptr)18503 if (bi == nullptr)
18445 return ira->codegen->invalid_inst_gen->value->type;18504 return ira->codegen->invalid_inst_gen->value->type;
18446 return get_array_type(ira->codegen, elem_type, bigint_as_u64(bi), sentinel);18505 return get_array_type(ira->codegen, elem_type, bigint_as_u64(bi), sentinel);
...@@ -18448,7 +18507,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18448,7 +18507,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18448 case ZigTypeIdOptional: {18507 case ZigTypeIdOptional: {
18449 assert(payload->special == ConstValSpecialStatic);18508 assert(payload->special == ConstValSpecialStatic);
18450 assert(payload->type == ir_type_info_get_type(ira, "Optional", nullptr));18509 assert(payload->type == ir_type_info_get_type(ira, "Optional", nullptr));
18451 ZigType *child_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 0);18510 ZigType *child_type = get_const_field_meta_type(ira, source_node, payload, "child", 0);
18452 if (type_is_invalid(child_type))18511 if (type_is_invalid(child_type))
18453 return ira->codegen->invalid_inst_gen->value->type;18512 return ira->codegen->invalid_inst_gen->value->type;
18454 return get_optional_type(ira->codegen, child_type);18513 return get_optional_type(ira->codegen, child_type);
...@@ -18456,11 +18515,11 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18456,11 +18515,11 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18456 case ZigTypeIdErrorUnion: {18515 case ZigTypeIdErrorUnion: {
18457 assert(payload->special == ConstValSpecialStatic);18516 assert(payload->special == ConstValSpecialStatic);
18458 assert(payload->type == ir_type_info_get_type(ira, "ErrorUnion", nullptr));18517 assert(payload->type == ir_type_info_get_type(ira, "ErrorUnion", nullptr));
18459 ZigType *err_set_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "error_set", 0);18518 ZigType *err_set_type = get_const_field_meta_type(ira, source_node, payload, "error_set", 0);
18460 if (type_is_invalid(err_set_type))18519 if (type_is_invalid(err_set_type))
18461 return ira->codegen->invalid_inst_gen->value->type;18520 return ira->codegen->invalid_inst_gen->value->type;
1846218521
18463 ZigType *payload_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "payload", 1);18522 ZigType *payload_type = get_const_field_meta_type(ira, source_node, payload, "payload", 1);
18464 if (type_is_invalid(payload_type))18523 if (type_is_invalid(payload_type))
18465 return ira->codegen->invalid_inst_gen->value->type;18524 return ira->codegen->invalid_inst_gen->value->type;
1846618525
...@@ -18470,7 +18529,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18470,7 +18529,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18470 assert(payload->special == ConstValSpecialStatic);18529 assert(payload->special == ConstValSpecialStatic);
18471 assert(payload->type == ir_type_info_get_type(ira, "Opaque", nullptr));18530 assert(payload->type == ir_type_info_get_type(ira, "Opaque", nullptr));
1847218531
18473 ZigValue *decls_value = get_const_field(ira, source_instr->source_node, payload, "decls", 0);18532 ZigValue *decls_value = get_const_field(ira, source_node, payload, "decls", 0);
18474 if (decls_value == nullptr)18533 if (decls_value == nullptr)
18475 return ira->codegen->invalid_inst_gen->value->type;18534 return ira->codegen->invalid_inst_gen->value->type;
18476 assert(decls_value->special == ConstValSpecialStatic);18535 assert(decls_value->special == ConstValSpecialStatic);
...@@ -18478,25 +18537,25 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18478,25 +18537,25 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18478 ZigValue *decls_len_value = decls_value->data.x_struct.fields[slice_len_index];18537 ZigValue *decls_len_value = decls_value->data.x_struct.fields[slice_len_index];
18479 size_t decls_len = bigint_as_usize(&decls_len_value->data.x_bigint);18538 size_t decls_len = bigint_as_usize(&decls_len_value->data.x_bigint);
18480 if (decls_len != 0) {18539 if (decls_len != 0) {
18481 ir_add_error(ira, source_instr, buf_create_from_str("TypeInfo.Struct.decls must be empty for @Type"));18540 ir_add_error_node(ira, source_node, buf_create_from_str("TypeInfo.Struct.decls must be empty for @Type"));
18482 return ira->codegen->invalid_inst_gen->value->type;18541 return ira->codegen->invalid_inst_gen->value->type;
18483 }18542 }
1848418543
18485 Buf *bare_name = buf_alloc();18544 Buf *bare_name = buf_alloc();
18486 Buf *full_name = get_anon_type_name(ira->codegen,18545 Buf *full_name = get_anon_type_name(ira->codegen,
18487 ira->zir, "opaque", source_instr->scope, source_instr->source_node, bare_name);18546 ira->zir, "opaque", scope, source_node, bare_name);
18488 return get_opaque_type(ira->codegen,18547 return get_opaque_type(ira->codegen,
18489 source_instr->scope, source_instr->source_node, buf_ptr(full_name), bare_name);18548 scope, source_node, buf_ptr(full_name), bare_name);
18490 }18549 }
18491 case ZigTypeIdVector: {18550 case ZigTypeIdVector: {
18492 assert(payload->special == ConstValSpecialStatic);18551 assert(payload->special == ConstValSpecialStatic);
18493 assert(payload->type == ir_type_info_get_type(ira, "Vector", nullptr));18552 assert(payload->type == ir_type_info_get_type(ira, "Vector", nullptr));
18494 BigInt *len = get_const_field_lit_int(ira, source_instr->source_node, payload, "len", 0);18553 BigInt *len = get_const_field_lit_int(ira, source_node, payload, "len", 0);
18495 if (len == nullptr)18554 if (len == nullptr)
18496 return ira->codegen->invalid_inst_gen->value->type;18555 return ira->codegen->invalid_inst_gen->value->type;
1849718556
18498 ZigType *child_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 1);18557 ZigType *child_type = get_const_field_meta_type(ira, source_node, payload, "child", 1);
18499 if ((err = ir_validate_vector_elem_type(ira, source_instr->source_node, child_type))) {18558 if ((err = ir_validate_vector_elem_type(ira, source_node, child_type))) {
18500 return ira->codegen->invalid_inst_gen->value->type;18559 return ira->codegen->invalid_inst_gen->value->type;
18501 }18560 }
18502 return get_vector_type(ira->codegen, bigint_as_u32(len), child_type);18561 return get_vector_type(ira->codegen, bigint_as_u32(len), child_type);
...@@ -18504,7 +18563,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18504,7 +18563,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18504 case ZigTypeIdAnyFrame: {18563 case ZigTypeIdAnyFrame: {
18505 assert(payload->special == ConstValSpecialStatic);18564 assert(payload->special == ConstValSpecialStatic);
18506 assert(payload->type == ir_type_info_get_type(ira, "AnyFrame", nullptr));18565 assert(payload->type == ir_type_info_get_type(ira, "AnyFrame", nullptr));
18507 ZigType *child_type = get_const_field_meta_type_optional(ira, source_instr->source_node, payload, "child", 0);18566 ZigType *child_type = get_const_field_meta_type_optional(ira, source_node, payload, "child", 0);
18508 if (child_type != nullptr && type_is_invalid(child_type))18567 if (child_type != nullptr && type_is_invalid(child_type))
18509 return ira->codegen->invalid_inst_gen->value->type;18568 return ira->codegen->invalid_inst_gen->value->type;
1851018569
...@@ -18513,7 +18572,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18513,7 +18572,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18513 case ZigTypeIdFnFrame: {18572 case ZigTypeIdFnFrame: {
18514 assert(payload->special == ConstValSpecialStatic);18573 assert(payload->special == ConstValSpecialStatic);
18515 assert(payload->type == ir_type_info_get_type(ira, "Frame", nullptr));18574 assert(payload->type == ir_type_info_get_type(ira, "Frame", nullptr));
18516 ZigValue *function = get_const_field(ira, source_instr->source_node, payload, "function", 0);18575 ZigValue *function = get_const_field(ira, source_node, payload, "function", 0);
18517 if (function == nullptr)18576 if (function == nullptr)
18518 return ira->codegen->invalid_inst_gen->value->type;18577 return ira->codegen->invalid_inst_gen->value->type;
1851918578
...@@ -18531,7 +18590,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18531,7 +18590,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18531 assert(is_slice(slice->type));18590 assert(is_slice(slice->type));
18532 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);18591 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
18533 Buf bare_name = BUF_INIT;18592 Buf bare_name = BUF_INIT;
18534 buf_init_from_buf(&err_set_type->name, get_anon_type_name(ira->codegen, ira->zir, "error", source_instr->scope, source_instr->source_node, &bare_name));18593 buf_init_from_buf(&err_set_type->name, get_anon_type_name(ira->codegen, ira->zir, "error", scope, source_node, &bare_name));
18535 err_set_type->size_in_bits = ira->codegen->builtin_types.entry_global_error_set->size_in_bits;18594 err_set_type->size_in_bits = ira->codegen->builtin_types.entry_global_error_set->size_in_bits;
18536 err_set_type->abi_align = ira->codegen->builtin_types.entry_global_error_set->abi_align;18595 err_set_type->abi_align = ira->codegen->builtin_types.entry_global_error_set->abi_align;
18537 err_set_type->abi_size = ira->codegen->builtin_types.entry_global_error_set->abi_size;18596 err_set_type->abi_size = ira->codegen->builtin_types.entry_global_error_set->abi_size;
...@@ -18550,8 +18609,8 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18550,8 +18609,8 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18550 ZigValue *error = &arr->data.x_array.data.s_none.elements[i];18609 ZigValue *error = &arr->data.x_array.data.s_none.elements[i];
18551 assert(error->type == ir_type_info_get_type(ira, "Error", nullptr));18610 assert(error->type == ir_type_info_get_type(ira, "Error", nullptr));
18552 ErrorTableEntry *err_entry = heap::c_allocator.create<ErrorTableEntry>();18611 ErrorTableEntry *err_entry = heap::c_allocator.create<ErrorTableEntry>();
18553 err_entry->decl_node = source_instr->source_node;18612 err_entry->decl_node = source_node;
18554 if ((err = get_const_field_buf(ira, source_instr->source_node, error, "name", 0, &err_entry->name)))18613 if ((err = get_const_field_buf(ira, source_node, error, "name", 0, &err_entry->name)))
18555 return ira->codegen->invalid_inst_gen->value->type;18614 return ira->codegen->invalid_inst_gen->value->type;
18556 auto existing_entry = ira->codegen->error_table.put_unique(&err_entry->name, err_entry);18615 auto existing_entry = ira->codegen->error_table.put_unique(&err_entry->name, err_entry);
18557 if (existing_entry) {18616 if (existing_entry) {
...@@ -18563,7 +18622,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18563,7 +18622,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18563 ira->codegen->errors_by_index.append(err_entry);18622 ira->codegen->errors_by_index.append(err_entry);
18564 }18623 }
18565 if (already_set[err_entry->value]) {18624 if (already_set[err_entry->value]) {
18566 ir_add_error(ira, source_instr, buf_sprintf("duplicate error: %s", buf_ptr(&err_entry->name)));18625 ir_add_error_node(ira, source_node, buf_sprintf("duplicate error: %s", buf_ptr(&err_entry->name)));
18567 return ira->codegen->invalid_inst_gen->value->type;18626 return ira->codegen->invalid_inst_gen->value->type;
18568 } else {18627 } else {
18569 already_set[err_entry->value] = true;18628 already_set[err_entry->value] = true;
...@@ -18576,14 +18635,14 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18576,14 +18635,14 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18576 assert(payload->special == ConstValSpecialStatic);18635 assert(payload->special == ConstValSpecialStatic);
18577 assert(payload->type == ir_type_info_get_type(ira, "Struct", nullptr));18636 assert(payload->type == ir_type_info_get_type(ira, "Struct", nullptr));
1857818637
18579 ZigValue *layout_value = get_const_field(ira, source_instr->source_node, payload, "layout", 0);18638 ZigValue *layout_value = get_const_field(ira, source_node, payload, "layout", 0);
18580 if (layout_value == nullptr)18639 if (layout_value == nullptr)
18581 return ira->codegen->invalid_inst_gen->value->type;18640 return ira->codegen->invalid_inst_gen->value->type;
18582 assert(layout_value->special == ConstValSpecialStatic);18641 assert(layout_value->special == ConstValSpecialStatic);
18583 assert(layout_value->type == ir_type_info_get_type(ira, "ContainerLayout", nullptr));18642 assert(layout_value->type == ir_type_info_get_type(ira, "ContainerLayout", nullptr));
18584 ContainerLayout layout = (ContainerLayout)bigint_as_u32(&layout_value->data.x_enum_tag);18643 ContainerLayout layout = (ContainerLayout)bigint_as_u32(&layout_value->data.x_enum_tag);
1858518644
18586 ZigValue *fields_value = get_const_field(ira, source_instr->source_node, payload, "fields", 1);18645 ZigValue *fields_value = get_const_field(ira, source_node, payload, "fields", 1);
18587 if (fields_value == nullptr)18646 if (fields_value == nullptr)
18588 return ira->codegen->invalid_inst_gen->value->type;18647 return ira->codegen->invalid_inst_gen->value->type;
18589 assert(fields_value->special == ConstValSpecialStatic);18648 assert(fields_value->special == ConstValSpecialStatic);
...@@ -18592,7 +18651,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18592,7 +18651,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18592 ZigValue *fields_len_value = fields_value->data.x_struct.fields[slice_len_index];18651 ZigValue *fields_len_value = fields_value->data.x_struct.fields[slice_len_index];
18593 size_t fields_len = bigint_as_usize(&fields_len_value->data.x_bigint);18652 size_t fields_len = bigint_as_usize(&fields_len_value->data.x_bigint);
1859418653
18595 ZigValue *decls_value = get_const_field(ira, source_instr->source_node, payload, "decls", 2);18654 ZigValue *decls_value = get_const_field(ira, source_node, payload, "decls", 2);
18596 if (decls_value == nullptr)18655 if (decls_value == nullptr)
18597 return ira->codegen->invalid_inst_gen->value->type;18656 return ira->codegen->invalid_inst_gen->value->type;
18598 assert(decls_value->special == ConstValSpecialStatic);18657 assert(decls_value->special == ConstValSpecialStatic);
...@@ -18600,18 +18659,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18600,18 +18659,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18600 ZigValue *decls_len_value = decls_value->data.x_struct.fields[slice_len_index];18659 ZigValue *decls_len_value = decls_value->data.x_struct.fields[slice_len_index];
18601 size_t decls_len = bigint_as_usize(&decls_len_value->data.x_bigint);18660 size_t decls_len = bigint_as_usize(&decls_len_value->data.x_bigint);
18602 if (decls_len != 0) {18661 if (decls_len != 0) {
18603 ir_add_error(ira, source_instr, buf_create_from_str("TypeInfo.Struct.decls must be empty for @Type"));18662 ir_add_error_node(ira, source_node, buf_create_from_str("TypeInfo.Struct.decls must be empty for @Type"));
18604 return ira->codegen->invalid_inst_gen->value->type;18663 return ira->codegen->invalid_inst_gen->value->type;
18605 }18664 }
1860618665
18607 bool is_tuple;18666 bool is_tuple;
18608 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_tuple", 3, &is_tuple)))18667 if ((err = get_const_field_bool(ira, source_node, payload, "is_tuple", 3, &is_tuple)))
18609 return ira->codegen->invalid_inst_gen->value->type;18668 return ira->codegen->invalid_inst_gen->value->type;
1861018669
18611 ZigType *entry = new_type_table_entry(ZigTypeIdStruct);18670 ZigType *entry = new_type_table_entry(ZigTypeIdStruct);
18612 buf_init_from_buf(&entry->name,18671 buf_init_from_buf(&entry->name,
18613 get_anon_type_name(ira->codegen, ira->zir, "struct", source_instr->scope, source_instr->source_node, &entry->name));18672 get_anon_type_name(ira->codegen, ira->zir, "struct", scope, source_node, &entry->name));
18614 entry->data.structure.decl_node = source_instr->source_node;18673 entry->data.structure.decl_node = source_node;
18615 entry->data.structure.fields = alloc_type_struct_fields(fields_len);18674 entry->data.structure.fields = alloc_type_struct_fields(fields_len);
18616 entry->data.structure.fields_by_name.init(fields_len);18675 entry->data.structure.fields_by_name.init(fields_len);
18617 entry->data.structure.src_field_count = fields_len;18676 entry->data.structure.src_field_count = fields_len;
...@@ -18619,7 +18678,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18619,7 +18678,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18619 entry->data.structure.special = is_tuple ? StructSpecialInferredTuple : StructSpecialNone;18678 entry->data.structure.special = is_tuple ? StructSpecialInferredTuple : StructSpecialNone;
18620 entry->data.structure.created_by_at_type = true;18679 entry->data.structure.created_by_at_type = true;
18621 entry->data.structure.decls_scope = create_decls_scope(18680 entry->data.structure.decls_scope = create_decls_scope(
18622 ira->codegen, source_instr->source_node, source_instr->scope, entry, get_scope_import(source_instr->scope), &entry->name);18681 ira->codegen, source_node, scope, entry, get_scope_import(scope), &entry->name);
1862318682
18624 assert(fields_ptr->data.x_ptr.special == ConstPtrSpecialBaseArray);18683 assert(fields_ptr->data.x_ptr.special == ConstPtrSpecialBaseArray);
18625 assert(fields_ptr->data.x_ptr.data.base_array.elem_index == 0);18684 assert(fields_ptr->data.x_ptr.data.base_array.elem_index == 0);
...@@ -18631,19 +18690,19 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18631,19 +18690,19 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18631 assert(field_value->type == ir_type_info_get_type(ira, "StructField", nullptr));18690 assert(field_value->type == ir_type_info_get_type(ira, "StructField", nullptr));
18632 TypeStructField *field = entry->data.structure.fields[i];18691 TypeStructField *field = entry->data.structure.fields[i];
18633 field->name = buf_alloc();18692 field->name = buf_alloc();
18634 if ((err = get_const_field_buf(ira, source_instr->source_node, field_value, "name", 0, field->name)))18693 if ((err = get_const_field_buf(ira, source_node, field_value, "name", 0, field->name)))
18635 return ira->codegen->invalid_inst_gen->value->type;18694 return ira->codegen->invalid_inst_gen->value->type;
18636 field->decl_node = source_instr->source_node;18695 field->decl_node = source_node;
18637 ZigValue *type_value = get_const_field(ira, source_instr->source_node, field_value, "field_type", 1);18696 ZigValue *type_value = get_const_field(ira, source_node, field_value, "field_type", 1);
18638 if (type_value == nullptr)18697 if (type_value == nullptr)
18639 return ira->codegen->invalid_inst_gen->value->type;18698 return ira->codegen->invalid_inst_gen->value->type;
18640 field->type_val = type_value;18699 field->type_val = type_value;
18641 field->type_entry = type_value->data.x_type;18700 field->type_entry = type_value->data.x_type;
18642 if (entry->data.structure.fields_by_name.put_unique(field->name, field) != nullptr) {18701 if (entry->data.structure.fields_by_name.put_unique(field->name, field) != nullptr) {
18643 ir_add_error(ira, source_instr, buf_sprintf("duplicate struct field '%s'", buf_ptr(field->name)));18702 ir_add_error_node(ira, source_node, buf_sprintf("duplicate struct field '%s'", buf_ptr(field->name)));
18644 return ira->codegen->invalid_inst_gen->value->type;18703 return ira->codegen->invalid_inst_gen->value->type;
18645 }18704 }
18646 ZigValue *default_value = get_const_field(ira, source_instr->source_node, field_value, "default_value", 2);18705 ZigValue *default_value = get_const_field(ira, source_node, field_value, "default_value", 2);
18647 if (default_value == nullptr)18706 if (default_value == nullptr)
18648 return ira->codegen->invalid_inst_gen->value->type;18707 return ira->codegen->invalid_inst_gen->value->type;
18649 if (default_value->type->id == ZigTypeIdNull) {18708 if (default_value->type->id == ZigTypeIdNull) {
...@@ -18653,15 +18712,15 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18653,15 +18712,15 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18653 } else if (default_value->type == field->type_entry) {18712 } else if (default_value->type == field->type_entry) {
18654 field->init_val = default_value;18713 field->init_val = default_value;
18655 } else {18714 } else {
18656 ir_add_error(ira, source_instr,18715 ir_add_error_node(ira, source_node,
18657 buf_sprintf("default_value of field '%s' is of type '%s', expected '%s' or '?%s'",18716 buf_sprintf("default_value of field '%s' is of type '%s', expected '%s' or '?%s'",
18658 buf_ptr(field->name), buf_ptr(&default_value->type->name),18717 buf_ptr(field->name), buf_ptr(&default_value->type->name),
18659 buf_ptr(&field->type_entry->name), buf_ptr(&field->type_entry->name)));18718 buf_ptr(&field->type_entry->name), buf_ptr(&field->type_entry->name)));
18660 return ira->codegen->invalid_inst_gen->value->type;18719 return ira->codegen->invalid_inst_gen->value->type;
18661 }18720 }
18662 if ((err = get_const_field_bool(ira, source_instr->source_node, field_value, "is_comptime", 3, &field->is_comptime)))18721 if ((err = get_const_field_bool(ira, source_node, field_value, "is_comptime", 3, &field->is_comptime)))
18663 return ira->codegen->invalid_inst_gen->value->type;18722 return ira->codegen->invalid_inst_gen->value->type;
18664 BigInt *alignment = get_const_field_lit_int(ira, source_instr->source_node, field_value, "alignment", 4);18723 BigInt *alignment = get_const_field_lit_int(ira, source_node, field_value, "alignment", 4);
18665 if (alignment == nullptr)18724 if (alignment == nullptr)
18666 return ira->codegen->invalid_inst_gen->value->type;18725 return ira->codegen->invalid_inst_gen->value->type;
18667 field->align = bigint_as_u32(alignment);18726 field->align = bigint_as_u32(alignment);
...@@ -18673,7 +18732,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18673,7 +18732,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18673 assert(payload->special == ConstValSpecialStatic);18732 assert(payload->special == ConstValSpecialStatic);
18674 assert(payload->type == ir_type_info_get_type(ira, "Enum", nullptr));18733 assert(payload->type == ir_type_info_get_type(ira, "Enum", nullptr));
1867518734
18676 ZigValue *layout_value = get_const_field(ira, source_instr->source_node, payload, "layout", 0);18735 ZigValue *layout_value = get_const_field(ira, source_node, payload, "layout", 0);
18677 if (layout_value == nullptr)18736 if (layout_value == nullptr)
18678 return ira->codegen->invalid_inst_gen->value->type;18737 return ira->codegen->invalid_inst_gen->value->type;
1867918738
...@@ -18681,16 +18740,16 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18681,16 +18740,16 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18681 assert(layout_value->type == ir_type_info_get_type(ira, "ContainerLayout", nullptr));18740 assert(layout_value->type == ir_type_info_get_type(ira, "ContainerLayout", nullptr));
18682 ContainerLayout layout = (ContainerLayout)bigint_as_u32(&layout_value->data.x_enum_tag);18741 ContainerLayout layout = (ContainerLayout)bigint_as_u32(&layout_value->data.x_enum_tag);
1868318742
18684 ZigType *tag_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "tag_type", 1);18743 ZigType *tag_type = get_const_field_meta_type(ira, source_node, payload, "tag_type", 1);
18685 if (type_is_invalid(tag_type))18744 if (type_is_invalid(tag_type))
18686 return ira->codegen->invalid_inst_gen->value->type;18745 return ira->codegen->invalid_inst_gen->value->type;
18687 if (tag_type->id != ZigTypeIdInt) {18746 if (tag_type->id != ZigTypeIdInt) {
18688 ir_add_error(ira, source_instr, buf_sprintf(18747 ir_add_error_node(ira, source_node, buf_sprintf(
18689 "TypeInfo.Enum.tag_type must be an integer type, not '%s'", buf_ptr(&tag_type->name)));18748 "TypeInfo.Enum.tag_type must be an integer type, not '%s'", buf_ptr(&tag_type->name)));
18690 return ira->codegen->invalid_inst_gen->value->type;18749 return ira->codegen->invalid_inst_gen->value->type;
18691 }18750 }
1869218751
18693 ZigValue *fields_value = get_const_field(ira, source_instr->source_node, payload, "fields", 2);18752 ZigValue *fields_value = get_const_field(ira, source_node, payload, "fields", 2);
18694 if (fields_value == nullptr)18753 if (fields_value == nullptr)
18695 return ira->codegen->invalid_inst_gen->value->type;18754 return ira->codegen->invalid_inst_gen->value->type;
1869618755
...@@ -18700,7 +18759,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18700,7 +18759,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18700 ZigValue *fields_len_value = fields_value->data.x_struct.fields[slice_len_index];18759 ZigValue *fields_len_value = fields_value->data.x_struct.fields[slice_len_index];
18701 size_t fields_len = bigint_as_usize(&fields_len_value->data.x_bigint);18760 size_t fields_len = bigint_as_usize(&fields_len_value->data.x_bigint);
1870218761
18703 ZigValue *decls_value = get_const_field(ira, source_instr->source_node, payload, "decls", 3);18762 ZigValue *decls_value = get_const_field(ira, source_node, payload, "decls", 3);
18704 if (decls_value == nullptr)18763 if (decls_value == nullptr)
18705 return ira->codegen->invalid_inst_gen->value->type;18764 return ira->codegen->invalid_inst_gen->value->type;
1870618765
...@@ -18709,22 +18768,22 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18709,22 +18768,22 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18709 ZigValue *decls_len_value = decls_value->data.x_struct.fields[slice_len_index];18768 ZigValue *decls_len_value = decls_value->data.x_struct.fields[slice_len_index];
18710 size_t decls_len = bigint_as_usize(&decls_len_value->data.x_bigint);18769 size_t decls_len = bigint_as_usize(&decls_len_value->data.x_bigint);
18711 if (decls_len != 0) {18770 if (decls_len != 0) {
18712 ir_add_error(ira, source_instr, buf_create_from_str("TypeInfo.Enum.decls must be empty for @Type"));18771 ir_add_error_node(ira, source_node, buf_create_from_str("TypeInfo.Enum.decls must be empty for @Type"));
18713 return ira->codegen->invalid_inst_gen->value->type;18772 return ira->codegen->invalid_inst_gen->value->type;
18714 }18773 }
1871518774
18716 Error err;18775 Error err;
18717 bool is_exhaustive;18776 bool is_exhaustive;
18718 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_exhaustive", 4, &is_exhaustive)))18777 if ((err = get_const_field_bool(ira, source_node, payload, "is_exhaustive", 4, &is_exhaustive)))
18719 return ira->codegen->invalid_inst_gen->value->type;18778 return ira->codegen->invalid_inst_gen->value->type;
1872018779
18721 ZigType *entry = new_type_table_entry(ZigTypeIdEnum);18780 ZigType *entry = new_type_table_entry(ZigTypeIdEnum);
18722 buf_init_from_buf(&entry->name,18781 buf_init_from_buf(&entry->name,
18723 get_anon_type_name(ira->codegen, ira->zir, "enum", source_instr->scope, source_instr->source_node, &entry->name));18782 get_anon_type_name(ira->codegen, ira->zir, "enum", scope, source_node, &entry->name));
18724 entry->data.enumeration.decl_node = source_instr->source_node;18783 entry->data.enumeration.decl_node = source_node;
18725 entry->data.enumeration.tag_int_type = tag_type;18784 entry->data.enumeration.tag_int_type = tag_type;
18726 entry->data.enumeration.decls_scope = create_decls_scope(18785 entry->data.enumeration.decls_scope = create_decls_scope(
18727 ira->codegen, source_instr->source_node, source_instr->scope, entry, get_scope_import(source_instr->scope), &entry->name);18786 ira->codegen, source_node, scope, entry, get_scope_import(scope), &entry->name);
18728 entry->data.enumeration.fields = heap::c_allocator.allocate<TypeEnumField>(fields_len);18787 entry->data.enumeration.fields = heap::c_allocator.allocate<TypeEnumField>(fields_len);
18729 entry->data.enumeration.fields_by_name.init(fields_len);18788 entry->data.enumeration.fields_by_name.init(fields_len);
18730 entry->data.enumeration.src_field_count = fields_len;18789 entry->data.enumeration.src_field_count = fields_len;
...@@ -18741,15 +18800,15 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18741,15 +18800,15 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18741 assert(field_value->type == ir_type_info_get_type(ira, "EnumField", nullptr));18800 assert(field_value->type == ir_type_info_get_type(ira, "EnumField", nullptr));
18742 TypeEnumField *field = &entry->data.enumeration.fields[i];18801 TypeEnumField *field = &entry->data.enumeration.fields[i];
18743 field->name = buf_alloc();18802 field->name = buf_alloc();
18744 if ((err = get_const_field_buf(ira, source_instr->source_node, field_value, "name", 0, field->name)))18803 if ((err = get_const_field_buf(ira, source_node, field_value, "name", 0, field->name)))
18745 return ira->codegen->invalid_inst_gen->value->type;18804 return ira->codegen->invalid_inst_gen->value->type;
18746 field->decl_index = i;18805 field->decl_index = i;
18747 field->decl_node = source_instr->source_node;18806 field->decl_node = source_node;
18748 if (entry->data.enumeration.fields_by_name.put_unique(field->name, field) != nullptr) {18807 if (entry->data.enumeration.fields_by_name.put_unique(field->name, field) != nullptr) {
18749 ir_add_error(ira, source_instr, buf_sprintf("duplicate enum field '%s'", buf_ptr(field->name)));18808 ir_add_error_node(ira, source_node, buf_sprintf("duplicate enum field '%s'", buf_ptr(field->name)));
18750 return ira->codegen->invalid_inst_gen->value->type;18809 return ira->codegen->invalid_inst_gen->value->type;
18751 }18810 }
18752 BigInt *field_int_value = get_const_field_lit_int(ira, source_instr->source_node, field_value, "value", 1);18811 BigInt *field_int_value = get_const_field_lit_int(ira, source_node, field_value, "value", 1);
18753 if (field_int_value == nullptr)18812 if (field_int_value == nullptr)
18754 return ira->codegen->invalid_inst_gen->value->type;18813 return ira->codegen->invalid_inst_gen->value->type;
18755 field->value = *field_int_value;18814 field->value = *field_int_value;
...@@ -18760,24 +18819,24 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18760,24 +18819,24 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18760 assert(payload->special == ConstValSpecialStatic);18819 assert(payload->special == ConstValSpecialStatic);
18761 assert(payload->type == ir_type_info_get_type(ira, "Union", nullptr));18820 assert(payload->type == ir_type_info_get_type(ira, "Union", nullptr));
1876218821
18763 ZigValue *layout_value = get_const_field(ira, source_instr->source_node, payload, "layout", 0);18822 ZigValue *layout_value = get_const_field(ira, source_node, payload, "layout", 0);
18764 if (layout_value == nullptr)18823 if (layout_value == nullptr)
18765 return ira->codegen->invalid_inst_gen->value->type;18824 return ira->codegen->invalid_inst_gen->value->type;
18766 assert(layout_value->special == ConstValSpecialStatic);18825 assert(layout_value->special == ConstValSpecialStatic);
18767 assert(layout_value->type == ir_type_info_get_type(ira, "ContainerLayout", nullptr));18826 assert(layout_value->type == ir_type_info_get_type(ira, "ContainerLayout", nullptr));
18768 ContainerLayout layout = (ContainerLayout)bigint_as_u32(&layout_value->data.x_enum_tag);18827 ContainerLayout layout = (ContainerLayout)bigint_as_u32(&layout_value->data.x_enum_tag);
1876918828
18770 ZigType *tag_type = get_const_field_meta_type_optional(ira, source_instr->source_node, payload, "tag_type", 1);18829 ZigType *tag_type = get_const_field_meta_type_optional(ira, source_node, payload, "tag_type", 1);
18771 if (tag_type != nullptr && type_is_invalid(tag_type)) {18830 if (tag_type != nullptr && type_is_invalid(tag_type)) {
18772 return ira->codegen->invalid_inst_gen->value->type;18831 return ira->codegen->invalid_inst_gen->value->type;
18773 }18832 }
18774 if (tag_type != nullptr && tag_type->id != ZigTypeIdEnum) {18833 if (tag_type != nullptr && tag_type->id != ZigTypeIdEnum) {
18775 ir_add_error(ira, source_instr, buf_sprintf(18834 ir_add_error_node(ira, source_node, buf_sprintf(
18776 "expected enum type, found '%s'", type_id_name(tag_type->id)));18835 "expected enum type, found '%s'", type_id_name(tag_type->id)));
18777 return ira->codegen->invalid_inst_gen->value->type;18836 return ira->codegen->invalid_inst_gen->value->type;
18778 }18837 }
1877918838
18780 ZigValue *fields_value = get_const_field(ira, source_instr->source_node, payload, "fields", 2);18839 ZigValue *fields_value = get_const_field(ira, source_node, payload, "fields", 2);
18781 if (fields_value == nullptr)18840 if (fields_value == nullptr)
18782 return ira->codegen->invalid_inst_gen->value->type;18841 return ira->codegen->invalid_inst_gen->value->type;
1878318842
...@@ -18787,7 +18846,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18787,7 +18846,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18787 ZigValue *fields_len_value = fields_value->data.x_struct.fields[slice_len_index];18846 ZigValue *fields_len_value = fields_value->data.x_struct.fields[slice_len_index];
18788 size_t fields_len = bigint_as_usize(&fields_len_value->data.x_bigint);18847 size_t fields_len = bigint_as_usize(&fields_len_value->data.x_bigint);
1878918848
18790 ZigValue *decls_value = get_const_field(ira, source_instr->source_node, payload, "decls", 3);18849 ZigValue *decls_value = get_const_field(ira, source_node, payload, "decls", 3);
18791 if (decls_value == nullptr)18850 if (decls_value == nullptr)
18792 return ira->codegen->invalid_inst_gen->value->type;18851 return ira->codegen->invalid_inst_gen->value->type;
1879318852
...@@ -18796,18 +18855,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18796,18 +18855,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18796 ZigValue *decls_len_value = decls_value->data.x_struct.fields[slice_len_index];18855 ZigValue *decls_len_value = decls_value->data.x_struct.fields[slice_len_index];
18797 size_t decls_len = bigint_as_usize(&decls_len_value->data.x_bigint);18856 size_t decls_len = bigint_as_usize(&decls_len_value->data.x_bigint);
18798 if (decls_len != 0) {18857 if (decls_len != 0) {
18799 ir_add_error(ira, source_instr, buf_create_from_str("TypeInfo.Union.decls must be empty for @Type"));18858 ir_add_error_node(ira, source_node, buf_create_from_str("TypeInfo.Union.decls must be empty for @Type"));
18800 return ira->codegen->invalid_inst_gen->value->type;18859 return ira->codegen->invalid_inst_gen->value->type;
18801 }18860 }
1880218861
18803 ZigType *entry = new_type_table_entry(ZigTypeIdUnion);18862 ZigType *entry = new_type_table_entry(ZigTypeIdUnion);
18804 buf_init_from_buf(&entry->name,18863 buf_init_from_buf(&entry->name,
18805 get_anon_type_name(ira->codegen, ira->zir, "union", source_instr->scope, source_instr->source_node, &entry->name));18864 get_anon_type_name(ira->codegen, ira->zir, "union", scope, source_node, &entry->name));
18806 entry->data.unionation.decl_node = source_instr->source_node;18865 entry->data.unionation.decl_node = source_node;
18807 entry->data.unionation.fields = heap::c_allocator.allocate<TypeUnionField>(fields_len);18866 entry->data.unionation.fields = heap::c_allocator.allocate<TypeUnionField>(fields_len);
18808 entry->data.unionation.fields_by_name.init(fields_len);18867 entry->data.unionation.fields_by_name.init(fields_len);
18809 entry->data.unionation.decls_scope = create_decls_scope(18868 entry->data.unionation.decls_scope = create_decls_scope(
18810 ira->codegen, source_instr->source_node, source_instr->scope, entry, get_scope_import(source_instr->scope), &entry->name);18869 ira->codegen, source_node, scope, entry, get_scope_import(scope), &entry->name);
18811 entry->data.unionation.tag_type = tag_type;18870 entry->data.unionation.tag_type = tag_type;
18812 entry->data.unionation.src_field_count = fields_len;18871 entry->data.unionation.src_field_count = fields_len;
18813 entry->data.unionation.layout = layout;18872 entry->data.unionation.layout = layout;
...@@ -18822,19 +18881,19 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18822,19 +18881,19 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18822 assert(field_value->type == ir_type_info_get_type(ira, "UnionField", nullptr));18881 assert(field_value->type == ir_type_info_get_type(ira, "UnionField", nullptr));
18823 TypeUnionField *field = &entry->data.unionation.fields[i];18882 TypeUnionField *field = &entry->data.unionation.fields[i];
18824 field->name = buf_alloc();18883 field->name = buf_alloc();
18825 if ((err = get_const_field_buf(ira, source_instr->source_node, field_value, "name", 0, field->name)))18884 if ((err = get_const_field_buf(ira, source_node, field_value, "name", 0, field->name)))
18826 return ira->codegen->invalid_inst_gen->value->type;18885 return ira->codegen->invalid_inst_gen->value->type;
18827 if (entry->data.unionation.fields_by_name.put_unique(field->name, field) != nullptr) {18886 if (entry->data.unionation.fields_by_name.put_unique(field->name, field) != nullptr) {
18828 ir_add_error(ira, source_instr, buf_sprintf("duplicate union field '%s'", buf_ptr(field->name)));18887 ir_add_error_node(ira, source_node, buf_sprintf("duplicate union field '%s'", buf_ptr(field->name)));
18829 return ira->codegen->invalid_inst_gen->value->type;18888 return ira->codegen->invalid_inst_gen->value->type;
18830 }18889 }
18831 field->decl_node = source_instr->source_node;18890 field->decl_node = source_node;
18832 ZigValue *type_value = get_const_field(ira, source_instr->source_node, field_value, "field_type", 1);18891 ZigValue *type_value = get_const_field(ira, source_node, field_value, "field_type", 1);
18833 if (type_value == nullptr)18892 if (type_value == nullptr)
18834 return ira->codegen->invalid_inst_gen->value->type;18893 return ira->codegen->invalid_inst_gen->value->type;
18835 field->type_val = type_value;18894 field->type_val = type_value;
18836 field->type_entry = type_value->data.x_type;18895 field->type_entry = type_value->data.x_type;
18837 BigInt *alignment = get_const_field_lit_int(ira, source_instr->source_node, field_value, "alignment", 2);18896 BigInt *alignment = get_const_field_lit_int(ira, source_node, field_value, "alignment", 2);
18838 if (alignment == nullptr)18897 if (alignment == nullptr)
18839 return ira->codegen->invalid_inst_gen->value->type;18898 return ira->codegen->invalid_inst_gen->value->type;
18840 field->align = bigint_as_u32(alignment);18899 field->align = bigint_as_u32(alignment);
...@@ -18846,41 +18905,41 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18846,41 +18905,41 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18846 assert(payload->special == ConstValSpecialStatic);18905 assert(payload->special == ConstValSpecialStatic);
18847 assert(payload->type == ir_type_info_get_type(ira, "Fn", nullptr));18906 assert(payload->type == ir_type_info_get_type(ira, "Fn", nullptr));
1884818907
18849 ZigValue *cc_value = get_const_field(ira, source_instr->source_node, payload, "calling_convention", 0);18908 ZigValue *cc_value = get_const_field(ira, source_node, payload, "calling_convention", 0);
18850 if (cc_value == nullptr)18909 if (cc_value == nullptr)
18851 return ira->codegen->invalid_inst_gen->value->type;18910 return ira->codegen->invalid_inst_gen->value->type;
18852 assert(cc_value->special == ConstValSpecialStatic);18911 assert(cc_value->special == ConstValSpecialStatic);
18853 assert(cc_value->type == get_builtin_type(ira->codegen, "CallingConvention"));18912 assert(cc_value->type == get_builtin_type(ira->codegen, "CallingConvention"));
18854 CallingConvention cc = (CallingConvention)bigint_as_u32(&cc_value->data.x_enum_tag);18913 CallingConvention cc = (CallingConvention)bigint_as_u32(&cc_value->data.x_enum_tag);
1885518914
18856 BigInt *alignment = get_const_field_lit_int(ira, source_instr->source_node, payload, "alignment", 1);18915 BigInt *alignment = get_const_field_lit_int(ira, source_node, payload, "alignment", 1);
18857 if (alignment == nullptr)18916 if (alignment == nullptr)
18858 return ira->codegen->invalid_inst_gen->value->type;18917 return ira->codegen->invalid_inst_gen->value->type;
1885918918
18860 Error err;18919 Error err;
18861 bool is_generic;18920 bool is_generic;
18862 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_generic", 2, &is_generic)))18921 if ((err = get_const_field_bool(ira, source_node, payload, "is_generic", 2, &is_generic)))
18863 return ira->codegen->invalid_inst_gen->value->type;18922 return ira->codegen->invalid_inst_gen->value->type;
18864 if (is_generic) {18923 if (is_generic) {
18865 ir_add_error(ira, source_instr, buf_sprintf("TypeInfo.Fn.is_generic must be false for @Type"));18924 ir_add_error_node(ira, source_node, buf_sprintf("TypeInfo.Fn.is_generic must be false for @Type"));
18866 return ira->codegen->invalid_inst_gen->value->type;18925 return ira->codegen->invalid_inst_gen->value->type;
18867 }18926 }
1886818927
18869 bool is_var_args;18928 bool is_var_args;
18870 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_var_args", 3, &is_var_args)))18929 if ((err = get_const_field_bool(ira, source_node, payload, "is_var_args", 3, &is_var_args)))
18871 return ira->codegen->invalid_inst_gen->value->type;18930 return ira->codegen->invalid_inst_gen->value->type;
18872 if (is_var_args && cc != CallingConventionC) {18931 if (is_var_args && cc != CallingConventionC) {
18873 ir_add_error(ira, source_instr, buf_sprintf("varargs functions must have C calling convention"));18932 ir_add_error_node(ira, source_node, buf_sprintf("varargs functions must have C calling convention"));
18874 return ira->codegen->invalid_inst_gen->value->type;18933 return ira->codegen->invalid_inst_gen->value->type;
18875 }18934 }
1887618935
18877 ZigType *return_type = get_const_field_meta_type_optional(ira, source_instr->source_node, payload, "return_type", 4);18936 ZigType *return_type = get_const_field_meta_type_optional(ira, source_node, payload, "return_type", 4);
18878 if (return_type == nullptr) {18937 if (return_type == nullptr) {
18879 ir_add_error(ira, source_instr, buf_sprintf("TypeInfo.Fn.return_type must be non-null for @Type"));18938 ir_add_error_node(ira, source_node, buf_sprintf("TypeInfo.Fn.return_type must be non-null for @Type"));
18880 return ira->codegen->invalid_inst_gen->value->type;18939 return ira->codegen->invalid_inst_gen->value->type;
18881 }18940 }
1888218941
18883 ZigValue *args_value = get_const_field(ira, source_instr->source_node, payload, "args", 5);18942 ZigValue *args_value = get_const_field(ira, source_node, payload, "args", 5);
18884 if (args_value == nullptr)18943 if (args_value == nullptr)
18885 return ira->codegen->invalid_inst_gen->value->type;18944 return ira->codegen->invalid_inst_gen->value->type;
18886 assert(args_value->special == ConstValSpecialStatic);18945 assert(args_value->special == ConstValSpecialStatic);
...@@ -18909,18 +18968,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -18909,18 +18968,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
18909 FnTypeParamInfo *info = &fn_type_id.param_info[i];18968 FnTypeParamInfo *info = &fn_type_id.param_info[i];
18910 Error err;18969 Error err;
18911 bool is_generic;18970 bool is_generic;
18912 if ((err = get_const_field_bool(ira, source_instr->source_node, arg_value, "is_generic", 0, &is_generic)))18971 if ((err = get_const_field_bool(ira, source_node, arg_value, "is_generic", 0, &is_generic)))
18913 return ira->codegen->invalid_inst_gen->value->type;18972 return ira->codegen->invalid_inst_gen->value->type;
18914 if (is_generic) {18973 if (is_generic) {
18915 ir_add_error(ira, source_instr, buf_sprintf("TypeInfo.FnArg.is_generic must be false for @Type"));18974 ir_add_error_node(ira, source_node, buf_sprintf("TypeInfo.FnArg.is_generic must be false for @Type"));
18916 return ira->codegen->invalid_inst_gen->value->type;18975 return ira->codegen->invalid_inst_gen->value->type;
18917 }18976 }
18918 if ((err = get_const_field_bool(ira, source_instr->source_node, arg_value, "is_noalias", 1, &info->is_noalias)))18977 if ((err = get_const_field_bool(ira, source_node, arg_value, "is_noalias", 1, &info->is_noalias)))
18919 return ira->codegen->invalid_inst_gen->value->type;18978 return ira->codegen->invalid_inst_gen->value->type;
18920 ZigType *type = get_const_field_meta_type_optional(18979 ZigType *type = get_const_field_meta_type_optional(
18921 ira, source_instr->source_node, arg_value, "arg_type", 2);18980 ira, source_node, arg_value, "arg_type", 2);
18922 if (type == nullptr) {18981 if (type == nullptr) {
18923 ir_add_error(ira, source_instr, buf_sprintf("TypeInfo.FnArg.arg_type must be non-null for @Type"));18982 ir_add_error_node(ira, source_node, buf_sprintf("TypeInfo.FnArg.arg_type must be non-null for @Type"));
18924 return ira->codegen->invalid_inst_gen->value->type;18983 return ira->codegen->invalid_inst_gen->value->type;
18925 }18984 }
18926 info->type = type;18985 info->type = type;
...@@ -18958,11 +19017,11 @@ static IrInstGen *ir_analyze_instruction_type(IrAnalyze *ira, IrInstSrcType *ins...@@ -18958,11 +19017,11 @@ static IrInstGen *ir_analyze_instruction_type(IrAnalyze *ira, IrInstSrcType *ins
18958 if (type_info_val == nullptr)19017 if (type_info_val == nullptr)
18959 return ira->codegen->invalid_inst_gen;19018 return ira->codegen->invalid_inst_gen;
18960 ZigTypeId type_id_tag = type_id_at_index(bigint_as_usize(&type_info_val->data.x_union.tag));19019 ZigTypeId type_id_tag = type_id_at_index(bigint_as_usize(&type_info_val->data.x_union.tag));
18961 ZigType *type = type_info_to_type(ira, &uncasted_type_info->base, type_id_tag,19020 ZigType *type = type_info_to_type(ira, uncasted_type_info->scope,
18962 type_info_val->data.x_union.payload);19021 uncasted_type_info->source_node, type_id_tag, type_info_val->data.x_union.payload);
18963 if (type_is_invalid(type))19022 if (type_is_invalid(type))
18964 return ira->codegen->invalid_inst_gen;19023 return ira->codegen->invalid_inst_gen;
18965 return ir_const_type(ira, &instruction->base.base, type);19024 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, type);
18966}19025}
1896719026
18968static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,19027static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
...@@ -18976,7 +19035,7 @@ static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,...@@ -18976,7 +19035,7 @@ static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
18976 *ira->backward_branch_quota = new_quota;19035 *ira->backward_branch_quota = new_quota;
18977 }19036 }
1897819037
18979 return ir_const_void(ira, &instruction->base.base);19038 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
18980}19039}
1898119040
18982static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcTypeName *instruction) {19041static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcTypeName *instruction) {
...@@ -18988,18 +19047,18 @@ static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcType...@@ -18988,18 +19047,18 @@ static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcType
18988 if (!type_entry->cached_const_name_val) {19047 if (!type_entry->cached_const_name_val) {
18989 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));19048 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));
18990 }19049 }
18991 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);19050 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr);
18992 copy_const_val(ira->codegen, result->value, type_entry->cached_const_name_val);19051 copy_const_val(ira->codegen, result->value, type_entry->cached_const_name_val);
18993 return result;19052 return result;
18994}19053}
1899519054
18996static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImport *instruction) {19055static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImport *instruction) {
18997 Error err;19056 Error err;
18998 AstNode *node = instruction->base.base.source_node;19057 AstNode *node = instruction->base.source_node;
18999 assert(node->type == NodeTypeFnCallExpr);19058 assert(node->type == NodeTypeFnCallExpr);
19000 AstNode *block_node = node->data.fn_call_expr.params.at(0);19059 AstNode *block_node = node->data.fn_call_expr.params.at(0);
1900119060
19002 ScopeCImport *cimport_scope = create_cimport_scope(ira->codegen, node, instruction->base.base.scope);19061 ScopeCImport *cimport_scope = create_cimport_scope(ira->codegen, node, instruction->base.scope);
1900319062
19004 // Execute the C import block like an inline function19063 // Execute the C import block like an inline function
19005 ZigType *void_type = ira->codegen->builtin_types.entry_void;19064 ZigType *void_type = ira->codegen->builtin_types.entry_void;
...@@ -19015,7 +19074,7 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo...@@ -19015,7 +19074,7 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo
19015 if (type_is_invalid(cimport_result->type))19074 if (type_is_invalid(cimport_result->type))
19016 return ira->codegen->invalid_inst_gen;19075 return ira->codegen->invalid_inst_gen;
1901719076
19018 ZigPackage *cur_scope_pkg = scope_package(instruction->base.base.scope);19077 ZigPackage *cur_scope_pkg = scope_package(instruction->base.scope);
19019 RootStruct *root_struct = node->owner->data.structure.root_struct;19078 RootStruct *root_struct = node->owner->data.structure.root_struct;
19020 TokenLoc tok_loc = root_struct->token_locs[node->main_token];19079 TokenLoc tok_loc = root_struct->token_locs[node->main_token];
19021 Buf *namespace_name = buf_sprintf("%s.cimport:%" PRIu32 ":%" PRIu32,19080 Buf *namespace_name = buf_sprintf("%s.cimport:%" PRIu32 ":%" PRIu32,
...@@ -19072,7 +19131,7 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo...@@ -19072,7 +19131,7 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo
19072 }19131 }
19073 ZigType *child_import = add_source_file(ira->codegen, cimport_pkg, out_zig_path,19132 ZigType *child_import = add_source_file(ira->codegen, cimport_pkg, out_zig_path,
19074 import_code, SourceKindCImport);19133 import_code, SourceKindCImport);
19075 return ir_const_type(ira, &instruction->base.base, child_import);19134 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, child_import);
19076}19135}
1907719136
19078static IrInstGen *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstSrcCInclude *instruction) {19137static IrInstGen *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstSrcCInclude *instruction) {
...@@ -19090,7 +19149,7 @@ static IrInstGen *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstSrcCInc...@@ -19090,7 +19149,7 @@ static IrInstGen *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstSrcCInc
1909019149
19091 buf_appendf(c_import_buf, "#include <%s>\n", buf_ptr(include_name));19150 buf_appendf(c_import_buf, "#include <%s>\n", buf_ptr(include_name));
1909219151
19093 return ir_const_void(ira, &instruction->base.base);19152 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
19094}19153}
1909519154
19096static IrInstGen *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstSrcCDefine *instruction) {19155static IrInstGen *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstSrcCDefine *instruction) {
...@@ -19121,7 +19180,7 @@ static IrInstGen *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstSrcCDefi...@@ -19121,7 +19180,7 @@ static IrInstGen *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstSrcCDefi
19121 buf_appendf(c_import_buf, "#define %s %s\n", buf_ptr(define_name),19180 buf_appendf(c_import_buf, "#define %s %s\n", buf_ptr(define_name),
19122 define_value ? buf_ptr(define_value) : "");19181 define_value ? buf_ptr(define_value) : "");
1912319182
19124 return ir_const_void(ira, &instruction->base.base);19183 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
19125}19184}
1912619185
19127static IrInstGen *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstSrcCUndef *instruction) {19186static IrInstGen *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstSrcCUndef *instruction) {
...@@ -19139,7 +19198,7 @@ static IrInstGen *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstSrcCUndef...@@ -19139,7 +19198,7 @@ static IrInstGen *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstSrcCUndef
1913919198
19140 buf_appendf(c_import_buf, "#undef %s\n", buf_ptr(undef_name));19199 buf_appendf(c_import_buf, "#undef %s\n", buf_ptr(undef_name));
1914119200
19142 return ir_const_void(ira, &instruction->base.base);19201 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
19143}19202}
1914419203
19145static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmbedFile *instruction) {19204static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmbedFile *instruction) {
...@@ -19151,7 +19210,7 @@ static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmb...@@ -19151,7 +19210,7 @@ static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmb
19151 if (!rel_file_path)19210 if (!rel_file_path)
19152 return ira->codegen->invalid_inst_gen;19211 return ira->codegen->invalid_inst_gen;
1915319212
19154 ZigType *import = get_scope_import(instruction->base.base.scope);19213 ZigType *import = get_scope_import(instruction->base.scope);
19155 // figure out absolute path to resource19214 // figure out absolute path to resource
19156 Buf source_dir_path = BUF_INIT;19215 Buf source_dir_path = BUF_INIT;
19157 os_path_dirname(import->data.structure.root_struct->path, &source_dir_path);19216 os_path_dirname(import->data.structure.root_struct->path, &source_dir_path);
...@@ -19168,17 +19227,17 @@ static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmb...@@ -19168,17 +19227,17 @@ static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmb
19168 Error err;19227 Error err;
19169 if ((err = file_fetch(ira->codegen, file_path, file_contents))) {19228 if ((err = file_fetch(ira->codegen, file_path, file_contents))) {
19170 if (err == ErrorFileNotFound) {19229 if (err == ErrorFileNotFound) {
19171 ir_add_error(ira, &instruction->name->base,19230 ir_add_error_node(ira, instruction->name->source_node,
19172 buf_sprintf("unable to find '%s'", buf_ptr(file_path)));19231 buf_sprintf("unable to find '%s'", buf_ptr(file_path)));
19173 return ira->codegen->invalid_inst_gen;19232 return ira->codegen->invalid_inst_gen;
19174 } else {19233 } else {
19175 ir_add_error(ira, &instruction->name->base,19234 ir_add_error_node(ira, instruction->name->source_node,
19176 buf_sprintf("unable to open '%s': %s", buf_ptr(file_path), err_str(err)));19235 buf_sprintf("unable to open '%s': %s", buf_ptr(file_path), err_str(err)));
19177 return ira->codegen->invalid_inst_gen;19236 return ira->codegen->invalid_inst_gen;
19178 }19237 }
19179 }19238 }
1918019239
19181 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);19240 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr);
19182 init_const_str_lit(ira->codegen, result->value, file_contents, true);19241 init_const_str_lit(ira->codegen, result->value, file_contents, true);
19183 return result;19242 return result;
19184}19243}
...@@ -19189,7 +19248,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch...@@ -19189,7 +19248,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
19189 return ira->codegen->invalid_inst_gen;19248 return ira->codegen->invalid_inst_gen;
1919019249
19191 if (operand_type->id == ZigTypeIdFloat) {19250 if (operand_type->id == ZigTypeIdFloat) {
19192 ir_add_error(ira, &instruction->type_value->child->base,19251 ir_add_error(ira, instruction->type_value->child,
19193 buf_sprintf("expected bool, integer, enum or pointer type, found '%s'", buf_ptr(&operand_type->name)));19252 buf_sprintf("expected bool, integer, enum or pointer type, found '%s'", buf_ptr(&operand_type->name)));
19194 return ira->codegen->invalid_inst_gen;19253 return ira->codegen->invalid_inst_gen;
19195 }19254 }
...@@ -19200,7 +19259,8 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch...@@ -19200,7 +19259,8 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
1920019259
19201 // TODO let this be volatile19260 // TODO let this be volatile
19202 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);19261 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
19203 IrInstGen *casted_ptr = ir_implicit_cast2(ira, &instruction->ptr->base, ptr, ptr_type);19262 IrInstGen *casted_ptr = ir_implicit_cast2(ira, instruction->ptr->scope,
19263 instruction->ptr->source_node, ptr, ptr_type);
19204 if (type_is_invalid(casted_ptr->value->type))19264 if (type_is_invalid(casted_ptr->value->type))
19205 return ira->codegen->invalid_inst_gen;19265 return ira->codegen->invalid_inst_gen;
1920619266
...@@ -19228,31 +19288,33 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch...@@ -19228,31 +19288,33 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
19228 if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order))19288 if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order))
19229 return ira->codegen->invalid_inst_gen;19289 return ira->codegen->invalid_inst_gen;
1923019290
19231 IrInstGen *casted_cmp_value = ir_implicit_cast2(ira, &instruction->cmp_value->base, cmp_value, operand_type);19291 IrInstGen *casted_cmp_value = ir_implicit_cast2(ira, instruction->cmp_value->scope,
19292 instruction->cmp_value->source_node, cmp_value, operand_type);
19232 if (type_is_invalid(casted_cmp_value->value->type))19293 if (type_is_invalid(casted_cmp_value->value->type))
19233 return ira->codegen->invalid_inst_gen;19294 return ira->codegen->invalid_inst_gen;
1923419295
19235 IrInstGen *casted_new_value = ir_implicit_cast2(ira, &instruction->new_value->base, new_value, operand_type);19296 IrInstGen *casted_new_value = ir_implicit_cast2(ira, instruction->new_value->scope,
19297 instruction->new_value->source_node, new_value, operand_type);
19236 if (type_is_invalid(casted_new_value->value->type))19298 if (type_is_invalid(casted_new_value->value->type))
19237 return ira->codegen->invalid_inst_gen;19299 return ira->codegen->invalid_inst_gen;
1923819300
19239 if (success_order < AtomicOrderMonotonic) {19301 if (success_order < AtomicOrderMonotonic) {
19240 ir_add_error(ira, &success_order_value->base,19302 ir_add_error(ira, success_order_value,
19241 buf_sprintf("success atomic ordering must be Monotonic or stricter"));19303 buf_sprintf("success atomic ordering must be Monotonic or stricter"));
19242 return ira->codegen->invalid_inst_gen;19304 return ira->codegen->invalid_inst_gen;
19243 }19305 }
19244 if (failure_order < AtomicOrderMonotonic) {19306 if (failure_order < AtomicOrderMonotonic) {
19245 ir_add_error(ira, &failure_order_value->base,19307 ir_add_error(ira, failure_order_value,
19246 buf_sprintf("failure atomic ordering must be Monotonic or stricter"));19308 buf_sprintf("failure atomic ordering must be Monotonic or stricter"));
19247 return ira->codegen->invalid_inst_gen;19309 return ira->codegen->invalid_inst_gen;
19248 }19310 }
19249 if (failure_order > success_order) {19311 if (failure_order > success_order) {
19250 ir_add_error(ira, &failure_order_value->base,19312 ir_add_error(ira, failure_order_value,
19251 buf_sprintf("failure atomic ordering must be no stricter than success"));19313 buf_sprintf("failure atomic ordering must be no stricter than success"));
19252 return ira->codegen->invalid_inst_gen;19314 return ira->codegen->invalid_inst_gen;
19253 }19315 }
19254 if (failure_order == AtomicOrderRelease || failure_order == AtomicOrderAcqRel) {19316 if (failure_order == AtomicOrderRelease || failure_order == AtomicOrderAcqRel) {
19255 ir_add_error(ira, &failure_order_value->base,19317 ir_add_error(ira, failure_order_value,
19256 buf_sprintf("failure atomic ordering must not be Release or AcqRel"));19318 buf_sprintf("failure atomic ordering must not be Release or AcqRel"));
19257 return ira->codegen->invalid_inst_gen;19319 return ira->codegen->invalid_inst_gen;
19258 }19320 }
...@@ -19264,7 +19326,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch...@@ -19264,7 +19326,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
19264 case OnePossibleValueInvalid:19326 case OnePossibleValueInvalid:
19265 return ira->codegen->invalid_inst_gen;19327 return ira->codegen->invalid_inst_gen;
19266 case OnePossibleValueYes: {19328 case OnePossibleValueYes: {
19267 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);19329 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, result_type);
19268 set_optional_value_to_null(result->value);19330 set_optional_value_to_null(result->value);
19269 return result;19331 return result;
19270 }19332 }
...@@ -19278,7 +19340,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch...@@ -19278,7 +19340,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
19278 if (ptr_val == nullptr)19340 if (ptr_val == nullptr)
19279 return ira->codegen->invalid_inst_gen;19341 return ira->codegen->invalid_inst_gen;
1928019342
19281 ZigValue *stored_val = const_ptr_pointee(ira, ira->codegen, ptr_val, instruction->base.base.source_node);19343 ZigValue *stored_val = const_ptr_pointee(ira, ira->codegen, ptr_val, instruction->base.source_node);
19282 if (stored_val == nullptr)19344 if (stored_val == nullptr)
19283 return ira->codegen->invalid_inst_gen;19345 return ira->codegen->invalid_inst_gen;
1928419346
...@@ -19291,7 +19353,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch...@@ -19291,7 +19353,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
19291 return ira->codegen->invalid_inst_gen;19353 return ira->codegen->invalid_inst_gen;
1929219354
19293 bool eql = const_values_equal(ira->codegen, stored_val, expected_val);19355 bool eql = const_values_equal(ira->codegen, stored_val, expected_val);
19294 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);19356 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, result_type);
19295 if (eql) {19357 if (eql) {
19296 copy_const_val(ira->codegen, stored_val, new_val);19358 copy_const_val(ira->codegen, stored_val, new_val);
19297 set_optional_value_to_null(result->value);19359 set_optional_value_to_null(result->value);
...@@ -19303,7 +19365,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch...@@ -19303,7 +19365,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
1930319365
19304 IrInstGen *result_loc;19366 IrInstGen *result_loc;
19305 if (handle_is_ptr(ira->codegen, result_type)) {19367 if (handle_is_ptr(ira->codegen, result_type)) {
19306 result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,19368 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
19307 result_type, nullptr, true, true);19369 result_type, nullptr, true, true);
19308 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {19370 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
19309 return result_loc;19371 return result_loc;
...@@ -19312,12 +19374,12 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch...@@ -19312,12 +19374,12 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
19312 result_loc = nullptr;19374 result_loc = nullptr;
19313 }19375 }
1931419376
19315 return ir_build_cmpxchg_gen(ira, &instruction->base.base, result_type,19377 return ir_build_cmpxchg_gen(ira, instruction->base.scope, instruction->base.source_node, result_type,
19316 casted_ptr, casted_cmp_value, casted_new_value,19378 casted_ptr, casted_cmp_value, casted_new_value,
19317 success_order, failure_order, instruction->is_weak, result_loc);19379 success_order, failure_order, instruction->is_weak, result_loc);
19318}19380}
1931919381
19320static ErrorMsg *ir_eval_reduce(IrAnalyze *ira, IrInst *source_instr, ReduceOp op, ZigValue *value, ZigValue *out_value) {19382static ErrorMsg *ir_eval_reduce(IrAnalyze *ira, Scope *scope, AstNode *source_node, ReduceOp op, ZigValue *value, ZigValue *out_value) {
19321 assert(value->type->id == ZigTypeIdVector);19383 assert(value->type->id == ZigTypeIdVector);
19322 ZigType *scalar_type = value->type->data.vector.elem_type;19384 ZigType *scalar_type = value->type->data.vector.elem_type;
19323 const size_t len = value->type->data.vector.len;19385 const size_t len = value->type->data.vector.len;
...@@ -19371,7 +19433,7 @@ static ErrorMsg *ir_eval_reduce(IrAnalyze *ira, IrInst *source_instr, ReduceOp o...@@ -19371,7 +19433,7 @@ static ErrorMsg *ir_eval_reduce(IrAnalyze *ira, IrInst *source_instr, ReduceOp o
19371 default: zig_unreachable();19433 default: zig_unreachable();
19372 }19434 }
1937319435
19374 ErrorMsg *msg = ir_eval_math_op_scalar(ira, source_instr, scalar_type,19436 ErrorMsg *msg = ir_eval_math_op_scalar(ira, scope, source_node, scalar_type,
19375 out_value, bin_op, elem_val, out_value);19437 out_value, bin_op, elem_val, out_value);
19376 if (msg != nullptr)19438 if (msg != nullptr)
19377 return msg;19439 return msg;
...@@ -19407,7 +19469,7 @@ static ErrorMsg *ir_eval_reduce(IrAnalyze *ira, IrInst *source_instr, ReduceOp o...@@ -19407,7 +19469,7 @@ static ErrorMsg *ir_eval_reduce(IrAnalyze *ira, IrInst *source_instr, ReduceOp o
19407 default: zig_unreachable();19469 default: zig_unreachable();
19408 }19470 }
1940919471
19410 ErrorMsg *msg = ir_eval_math_op_scalar(ira, source_instr, scalar_type,19472 ErrorMsg *msg = ir_eval_math_op_scalar(ira, scope, source_node, scalar_type,
19411 out_value, bin_op, elem_val, out_value);19473 out_value, bin_op, elem_val, out_value);
19412 if (msg != nullptr)19474 if (msg != nullptr)
19413 return msg;19475 return msg;
...@@ -19430,7 +19492,7 @@ static ErrorMsg *ir_eval_reduce(IrAnalyze *ira, IrInst *source_instr, ReduceOp o...@@ -19430,7 +19492,7 @@ static ErrorMsg *ir_eval_reduce(IrAnalyze *ira, IrInst *source_instr, ReduceOp o
19430 default: zig_unreachable();19492 default: zig_unreachable();
19431 }19493 }
1943219494
19433 ErrorMsg *msg = ir_eval_bin_op_cmp_scalar(ira, source_instr,19495 ErrorMsg *msg = ir_eval_bin_op_cmp_scalar(ira, scope, source_node,
19434 elem_val, bin_op, candidate_elem_val, dummy_cmp_value);19496 elem_val, bin_op, candidate_elem_val, dummy_cmp_value);
19435 if (msg != nullptr)19497 if (msg != nullptr)
19436 return msg;19498 return msg;
...@@ -19456,7 +19518,7 @@ static IrInstGen *ir_analyze_instruction_reduce(IrAnalyze *ira, IrInstSrcReduce...@@ -19456,7 +19518,7 @@ static IrInstGen *ir_analyze_instruction_reduce(IrAnalyze *ira, IrInstSrcReduce
1945619518
19457 ZigType *value_type = value_inst->value->type;19519 ZigType *value_type = value_inst->value->type;
19458 if (value_type->id != ZigTypeIdVector) {19520 if (value_type->id != ZigTypeIdVector) {
19459 ir_add_error(ira, &value_inst->base,19521 ir_add_error(ira, value_inst,
19460 buf_sprintf("expected vector type, found '%s'",19522 buf_sprintf("expected vector type, found '%s'",
19461 buf_ptr(&value_type->name)));19523 buf_ptr(&value_type->name)));
19462 return ira->codegen->invalid_inst_gen;19524 return ira->codegen->invalid_inst_gen;
...@@ -19472,14 +19534,14 @@ static IrInstGen *ir_analyze_instruction_reduce(IrAnalyze *ira, IrInstSrcReduce...@@ -19472,14 +19534,14 @@ static IrInstGen *ir_analyze_instruction_reduce(IrAnalyze *ira, IrInstSrcReduce
19472 break;19534 break;
19473 case ZigTypeIdBool:19535 case ZigTypeIdBool:
19474 if (op > ReduceOp_xor) {19536 if (op > ReduceOp_xor) {
19475 ir_add_error(ira, &op_inst->base,19537 ir_add_error(ira, op_inst,
19476 buf_sprintf("invalid operation for '%s' type",19538 buf_sprintf("invalid operation for '%s' type",
19477 buf_ptr(&elem_type->name)));19539 buf_ptr(&elem_type->name)));
19478 return ira->codegen->invalid_inst_gen;19540 return ira->codegen->invalid_inst_gen;
19479 } break;19541 } break;
19480 case ZigTypeIdFloat:19542 case ZigTypeIdFloat:
19481 if (op < ReduceOp_min) {19543 if (op < ReduceOp_min) {
19482 ir_add_error(ira, &op_inst->base,19544 ir_add_error(ira, op_inst,
19483 buf_sprintf("invalid operation for '%s' type",19545 buf_sprintf("invalid operation for '%s' type",
19484 buf_ptr(&elem_type->name)));19546 buf_ptr(&elem_type->name)));
19485 return ira->codegen->invalid_inst_gen;19547 return ira->codegen->invalid_inst_gen;
...@@ -19494,20 +19556,20 @@ static IrInstGen *ir_analyze_instruction_reduce(IrAnalyze *ira, IrInstSrcReduce...@@ -19494,20 +19556,20 @@ static IrInstGen *ir_analyze_instruction_reduce(IrAnalyze *ira, IrInstSrcReduce
19494 case OnePossibleValueInvalid:19556 case OnePossibleValueInvalid:
19495 return ira->codegen->invalid_inst_gen;19557 return ira->codegen->invalid_inst_gen;
19496 case OnePossibleValueYes:19558 case OnePossibleValueYes:
19497 return ir_const_move(ira, &instruction->base.base,19559 return ir_const_move(ira, instruction->base.scope, instruction->base.source_node,
19498 get_the_one_possible_value(ira->codegen, elem_type));19560 get_the_one_possible_value(ira->codegen, elem_type));
19499 case OnePossibleValueNo:19561 case OnePossibleValueNo:
19500 break;19562 break;
19501 }19563 }
1950219564
19503 if (instr_is_comptime(value_inst)) {19565 if (instr_is_comptime(value_inst)) {
19504 IrInstGen *result = ir_const(ira, &instruction->base.base, elem_type);19566 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, elem_type);
19505 if (ir_eval_reduce(ira, &instruction->base.base, op, value_inst->value, result->value))19567 if (ir_eval_reduce(ira, instruction->base.scope, instruction->base.source_node, op, value_inst->value, result->value))
19506 return ira->codegen->invalid_inst_gen;19568 return ira->codegen->invalid_inst_gen;
19507 return result;19569 return result;
19508 }19570 }
1950919571
19510 return ir_build_reduce_gen(ira, &instruction->base.base, op, value_inst, elem_type);19572 return ir_build_reduce_gen(ira, instruction->base.scope, instruction->base.source_node, op, value_inst, elem_type);
19511}19573}
1951219574
19513static IrInstGen *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstSrcFence *instruction) {19575static IrInstGen *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstSrcFence *instruction) {
...@@ -19520,12 +19582,12 @@ static IrInstGen *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstSrcFence *i...@@ -19520,12 +19582,12 @@ static IrInstGen *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstSrcFence *i
19520 return ira->codegen->invalid_inst_gen;19582 return ira->codegen->invalid_inst_gen;
1952119583
19522 if (order < AtomicOrderAcquire) {19584 if (order < AtomicOrderAcquire) {
19523 ir_add_error(ira, &order_inst->base,19585 ir_add_error(ira, order_inst,
19524 buf_sprintf("atomic ordering must be Acquire or stricter"));19586 buf_sprintf("atomic ordering must be Acquire or stricter"));
19525 return ira->codegen->invalid_inst_gen;19587 return ira->codegen->invalid_inst_gen;
19526 }19588 }
1952719589
19528 return ir_build_fence_gen(ira, &instruction->base.base, order);19590 return ir_build_fence_gen(ira, instruction->base.scope, instruction->base.source_node, order);
19529}19591}
1953019592
19531static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTruncate *instruction) {19593static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTruncate *instruction) {
...@@ -19537,7 +19599,7 @@ static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTrunc...@@ -19537,7 +19599,7 @@ static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTrunc
19537 if (dest_type->id != ZigTypeIdInt &&19599 if (dest_type->id != ZigTypeIdInt &&
19538 dest_type->id != ZigTypeIdComptimeInt)19600 dest_type->id != ZigTypeIdComptimeInt)
19539 {19601 {
19540 ir_add_error(ira, &dest_type_value->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));19602 ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
19541 return ira->codegen->invalid_inst_gen;19603 return ira->codegen->invalid_inst_gen;
19542 }19604 }
1954319605
...@@ -19549,21 +19611,21 @@ static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTrunc...@@ -19549,21 +19611,21 @@ static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTrunc
19549 if (src_type->id != ZigTypeIdInt &&19611 if (src_type->id != ZigTypeIdInt &&
19550 src_type->id != ZigTypeIdComptimeInt)19612 src_type->id != ZigTypeIdComptimeInt)
19551 {19613 {
19552 ir_add_error(ira, &target->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));19614 ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));
19553 return ira->codegen->invalid_inst_gen;19615 return ira->codegen->invalid_inst_gen;
19554 }19616 }
1955519617
19556 if (dest_type->id == ZigTypeIdComptimeInt) {19618 if (dest_type->id == ZigTypeIdComptimeInt) {
19557 return ir_implicit_cast2(ira, &instruction->target->base, target, dest_type);19619 return ir_implicit_cast2(ira, instruction->target->scope, instruction->target->source_node, target, dest_type);
19558 }19620 }
1955919621
19560 if (src_type->id != ZigTypeIdComptimeInt) {19622 if (src_type->id != ZigTypeIdComptimeInt) {
19561 if (src_type->data.integral.is_signed != dest_type->data.integral.is_signed) {19623 if (src_type->data.integral.is_signed != dest_type->data.integral.is_signed) {
19562 const char *sign_str = dest_type->data.integral.is_signed ? "signed" : "unsigned";19624 const char *sign_str = dest_type->data.integral.is_signed ? "signed" : "unsigned";
19563 ir_add_error(ira, &target->base, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name)));19625 ir_add_error(ira, target, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name)));
19564 return ira->codegen->invalid_inst_gen;19626 return ira->codegen->invalid_inst_gen;
19565 } else if (src_type->data.integral.bit_count > 0 && src_type->data.integral.bit_count < dest_type->data.integral.bit_count) {19627 } else if (src_type->data.integral.bit_count > 0 && src_type->data.integral.bit_count < dest_type->data.integral.bit_count) {
19566 ir_add_error(ira, &target->base, buf_sprintf("type '%s' has fewer bits than destination type '%s'",19628 ir_add_error(ira, target, buf_sprintf("type '%s' has fewer bits than destination type '%s'",
19567 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));19629 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));
19568 return ira->codegen->invalid_inst_gen;19630 return ira->codegen->invalid_inst_gen;
19569 }19631 }
...@@ -19574,19 +19636,19 @@ static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTrunc...@@ -19574,19 +19636,19 @@ static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTrunc
19574 if (val == nullptr)19636 if (val == nullptr)
19575 return ira->codegen->invalid_inst_gen;19637 return ira->codegen->invalid_inst_gen;
1957619638
19577 IrInstGen *result = ir_const(ira, &instruction->base.base, dest_type);19639 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, dest_type);
19578 bigint_truncate(&result->value->data.x_bigint, &val->data.x_bigint,19640 bigint_truncate(&result->value->data.x_bigint, &val->data.x_bigint,
19579 dest_type->data.integral.bit_count, dest_type->data.integral.is_signed);19641 dest_type->data.integral.bit_count, dest_type->data.integral.is_signed);
19580 return result;19642 return result;
19581 }19643 }
1958219644
19583 if (src_type->data.integral.bit_count == 0 || dest_type->data.integral.bit_count == 0) {19645 if (src_type->data.integral.bit_count == 0 || dest_type->data.integral.bit_count == 0) {
19584 IrInstGen *result = ir_const(ira, &instruction->base.base, dest_type);19646 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, dest_type);
19585 bigint_init_unsigned(&result->value->data.x_bigint, 0);19647 bigint_init_unsigned(&result->value->data.x_bigint, 0);
19586 return result;19648 return result;
19587 }19649 }
1958819650
19589 return ir_build_truncate_gen(ira, &instruction->base.base, dest_type, target);19651 return ir_build_truncate_gen(ira, instruction->base.scope, instruction->base.source_node, dest_type, target);
19590}19652}
1959119653
19592static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCast *instruction) {19654static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCast *instruction) {
...@@ -19598,7 +19660,7 @@ static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCa...@@ -19598,7 +19660,7 @@ static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCa
19598 dest_type->data.vector.elem_type : dest_type;19660 dest_type->data.vector.elem_type : dest_type;
1959919661
19600 if (scalar_dest_type->id != ZigTypeIdInt && scalar_dest_type->id != ZigTypeIdComptimeInt) {19662 if (scalar_dest_type->id != ZigTypeIdInt && scalar_dest_type->id != ZigTypeIdComptimeInt) {
19601 ir_add_error(ira, &instruction->dest_type->base,19663 ir_add_error_node(ira, instruction->dest_type->source_node,
19602 buf_sprintf("expected integer type, found '%s'", buf_ptr(&scalar_dest_type->name)));19664 buf_sprintf("expected integer type, found '%s'", buf_ptr(&scalar_dest_type->name)));
19603 return ira->codegen->invalid_inst_gen;19665 return ira->codegen->invalid_inst_gen;
19604 }19666 }
...@@ -19611,7 +19673,7 @@ static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCa...@@ -19611,7 +19673,7 @@ static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCa
19611 target->value->type->data.vector.elem_type : target->value->type;19673 target->value->type->data.vector.elem_type : target->value->type;
1961219674
19613 if (scalar_target_type->id != ZigTypeIdInt && scalar_target_type->id != ZigTypeIdComptimeInt) {19675 if (scalar_target_type->id != ZigTypeIdInt && scalar_target_type->id != ZigTypeIdComptimeInt) {
19614 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected integer type, found '%s'",19676 ir_add_error_node(ira, instruction->target->source_node, buf_sprintf("expected integer type, found '%s'",
19615 buf_ptr(&scalar_target_type->name)));19677 buf_ptr(&scalar_target_type->name)));
19616 return ira->codegen->invalid_inst_gen;19678 return ira->codegen->invalid_inst_gen;
19617 }19679 }
...@@ -19621,10 +19683,10 @@ static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCa...@@ -19621,10 +19683,10 @@ static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCa
19621 if (val == nullptr)19683 if (val == nullptr)
19622 return ira->codegen->invalid_inst_gen;19684 return ira->codegen->invalid_inst_gen;
1962319685
19624 return ir_implicit_cast2(ira, &instruction->target->base, target, dest_type);19686 return ir_implicit_cast2(ira, instruction->target->scope, instruction->target->source_node, target, dest_type);
19625 }19687 }
1962619688
19627 return ir_analyze_widen_or_shorten(ira, &instruction->base.base, target, dest_type);19689 return ir_analyze_widen_or_shorten(ira, instruction->base.scope, instruction->base.source_node, target, dest_type);
19628}19690}
1962919691
19630static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFloatCast *instruction) {19692static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFloatCast *instruction) {
...@@ -19633,7 +19695,7 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo...@@ -19633,7 +19695,7 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo
19633 return ira->codegen->invalid_inst_gen;19695 return ira->codegen->invalid_inst_gen;
1963419696
19635 if (dest_type->id != ZigTypeIdFloat && dest_type->id != ZigTypeIdComptimeFloat) {19697 if (dest_type->id != ZigTypeIdFloat && dest_type->id != ZigTypeIdComptimeFloat) {
19636 ir_add_error(ira, &instruction->dest_type->base,19698 ir_add_error_node(ira, instruction->dest_type->source_node,
19637 buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name)));19699 buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name)));
19638 return ira->codegen->invalid_inst_gen;19700 return ira->codegen->invalid_inst_gen;
19639 }19701 }
...@@ -19652,14 +19714,14 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo...@@ -19652,14 +19714,14 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo
19652 } else {19714 } else {
19653 op = CastOpNumLitToConcrete;19715 op = CastOpNumLitToConcrete;
19654 }19716 }
19655 return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, op);19717 return ir_resolve_cast(ira, instruction->base.scope, instruction->base.source_node, target, dest_type, op);
19656 } else {19718 } else {
19657 return ira->codegen->invalid_inst_gen;19719 return ira->codegen->invalid_inst_gen;
19658 }19720 }
19659 }19721 }
1966019722
19661 if (target->value->type->id != ZigTypeIdFloat) {19723 if (target->value->type->id != ZigTypeIdFloat) {
19662 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected float type, found '%s'",19724 ir_add_error_node(ira, instruction->target->source_node, buf_sprintf("expected float type, found '%s'",
19663 buf_ptr(&target->value->type->name)));19725 buf_ptr(&target->value->type->name)));
19664 return ira->codegen->invalid_inst_gen;19726 return ira->codegen->invalid_inst_gen;
19665 }19727 }
...@@ -19670,10 +19732,11 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo...@@ -19670,10 +19732,11 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo
19670 return ira->codegen->invalid_inst_gen;19732 return ira->codegen->invalid_inst_gen;
1967119733
19672 // XXX: This will trigger an assertion failure if dest_type is comptime_float19734 // XXX: This will trigger an assertion failure if dest_type is comptime_float
19673 return ir_analyze_widen_or_shorten(ira, &instruction->target->base, target, dest_type);19735 return ir_analyze_widen_or_shorten(ira, instruction->target->scope,
19736 instruction->target->source_node, target, dest_type);
19674 }19737 }
1967519738
19676 return ir_analyze_widen_or_shorten(ira, &instruction->base.base, target, dest_type);19739 return ir_analyze_widen_or_shorten(ira, instruction->base.scope, instruction->base.source_node, target, dest_type);
19677}19740}
1967819741
19679static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcErrSetCast *instruction) {19742static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcErrSetCast *instruction) {
...@@ -19682,7 +19745,7 @@ static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcE...@@ -19682,7 +19745,7 @@ static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcE
19682 return ira->codegen->invalid_inst_gen;19745 return ira->codegen->invalid_inst_gen;
1968319746
19684 if (dest_type->id != ZigTypeIdErrorSet) {19747 if (dest_type->id != ZigTypeIdErrorSet) {
19685 ir_add_error(ira, &instruction->dest_type->base,19748 ir_add_error_node(ira, instruction->dest_type->source_node,
19686 buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name)));19749 buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name)));
19687 return ira->codegen->invalid_inst_gen;19750 return ira->codegen->invalid_inst_gen;
19688 }19751 }
...@@ -19692,12 +19755,12 @@ static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcE...@@ -19692,12 +19755,12 @@ static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcE
19692 return ira->codegen->invalid_inst_gen;19755 return ira->codegen->invalid_inst_gen;
1969319756
19694 if (target->value->type->id != ZigTypeIdErrorSet) {19757 if (target->value->type->id != ZigTypeIdErrorSet) {
19695 ir_add_error(ira, &instruction->target->base,19758 ir_add_error_node(ira, instruction->target->source_node,
19696 buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value->type->name)));19759 buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value->type->name)));
19697 return ira->codegen->invalid_inst_gen;19760 return ira->codegen->invalid_inst_gen;
19698 }19761 }
1969919762
19700 return ir_analyze_err_set_cast(ira, &instruction->base.base, target, dest_type);19763 return ir_analyze_err_set_cast(ira, instruction->base.scope, instruction->base.source_node, target, dest_type);
19701}19764}
1970219765
19703static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align) {19766static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align) {
...@@ -19731,7 +19794,7 @@ static IrInstGen *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstSrcI...@@ -19731,7 +19794,7 @@ static IrInstGen *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstSrcI
19731 return ira->codegen->invalid_inst_gen;19794 return ira->codegen->invalid_inst_gen;
1973219795
19733 if (dest_type->id != ZigTypeIdFloat && dest_type->id != ZigTypeIdComptimeFloat) {19796 if (dest_type->id != ZigTypeIdFloat && dest_type->id != ZigTypeIdComptimeFloat) {
19734 ir_add_error(ira, &instruction->dest_type->base,19797 ir_add_error_node(ira, instruction->dest_type->source_node,
19735 buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name)));19798 buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name)));
19736 return ira->codegen->invalid_inst_gen;19799 return ira->codegen->invalid_inst_gen;
19737 }19800 }
...@@ -19741,12 +19804,12 @@ static IrInstGen *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstSrcI...@@ -19741,12 +19804,12 @@ static IrInstGen *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstSrcI
19741 return ira->codegen->invalid_inst_gen;19804 return ira->codegen->invalid_inst_gen;
1974219805
19743 if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) {19806 if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) {
19744 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected int type, found '%s'",19807 ir_add_error_node(ira, instruction->target->source_node,
19745 buf_ptr(&target->value->type->name)));19808 buf_sprintf("expected int type, found '%s'", buf_ptr(&target->value->type->name)));
19746 return ira->codegen->invalid_inst_gen;19809 return ira->codegen->invalid_inst_gen;
19747 }19810 }
1974819811
19749 return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, CastOpIntToFloat);19812 return ir_resolve_cast(ira, instruction->base.scope, instruction->base.source_node, target, dest_type, CastOpIntToFloat);
19750}19813}
1975119814
19752static IrInstGen *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstSrcFloatToInt *instruction) {19815static IrInstGen *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstSrcFloatToInt *instruction) {
...@@ -19755,7 +19818,8 @@ static IrInstGen *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstSrcF...@@ -19755,7 +19818,8 @@ static IrInstGen *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstSrcF
19755 return ira->codegen->invalid_inst_gen;19818 return ira->codegen->invalid_inst_gen;
1975619819
19757 if (dest_type->id != ZigTypeIdInt && dest_type->id != ZigTypeIdComptimeInt) {19820 if (dest_type->id != ZigTypeIdInt && dest_type->id != ZigTypeIdComptimeInt) {
19758 ir_add_error(ira, &instruction->dest_type->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));19821 ir_add_error_node(ira, instruction->dest_type->source_node,
19822 buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
19759 return ira->codegen->invalid_inst_gen;19823 return ira->codegen->invalid_inst_gen;
19760 }19824 }
1976119825
...@@ -19768,12 +19832,12 @@ static IrInstGen *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstSrcF...@@ -19768,12 +19832,12 @@ static IrInstGen *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstSrcF
19768 }19832 }
1976919833
19770 if (target->value->type->id != ZigTypeIdFloat && target->value->type->id != ZigTypeIdComptimeFloat) {19834 if (target->value->type->id != ZigTypeIdFloat && target->value->type->id != ZigTypeIdComptimeFloat) {
19771 ir_add_error_node(ira, target->base.source_node, buf_sprintf("expected float type, found '%s'",19835 ir_add_error_node(ira, target->source_node, buf_sprintf("expected float type, found '%s'",
19772 buf_ptr(&target->value->type->name)));19836 buf_ptr(&target->value->type->name)));
19773 return ira->codegen->invalid_inst_gen;19837 return ira->codegen->invalid_inst_gen;
19774 }19838 }
1977519839
19776 return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, CastOpFloatToInt);19840 return ir_resolve_cast(ira, instruction->base.scope, instruction->base.source_node, target, dest_type, CastOpFloatToInt);
19777}19841}
1977819842
19779static IrInstGen *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstSrcErrToInt *instruction) {19843static IrInstGen *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstSrcErrToInt *instruction) {
...@@ -19790,7 +19854,7 @@ static IrInstGen *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstSrcErr...@@ -19790,7 +19854,7 @@ static IrInstGen *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstSrcErr
19790 return ira->codegen->invalid_inst_gen;19854 return ira->codegen->invalid_inst_gen;
19791 }19855 }
1979219856
19793 return ir_analyze_err_to_int(ira, &instruction->base.base, casted_target, ira->codegen->err_tag_type);19857 return ir_analyze_err_to_int(ira, instruction->base.scope, instruction->base.source_node, casted_target, ira->codegen->err_tag_type);
19794}19858}
1979519859
19796static IrInstGen *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstSrcIntToErr *instruction) {19860static IrInstGen *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstSrcIntToErr *instruction) {
...@@ -19802,7 +19866,7 @@ static IrInstGen *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstSrcInt...@@ -19802,7 +19866,7 @@ static IrInstGen *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstSrcInt
19802 if (type_is_invalid(casted_target->value->type))19866 if (type_is_invalid(casted_target->value->type))
19803 return ira->codegen->invalid_inst_gen;19867 return ira->codegen->invalid_inst_gen;
1980419868
19805 return ir_analyze_int_to_err(ira, &instruction->base.base, casted_target, ira->codegen->builtin_types.entry_global_error_set);19869 return ir_analyze_int_to_err(ira, instruction->base.scope, instruction->base.source_node, casted_target, ira->codegen->builtin_types.entry_global_error_set);
19806}19870}
1980719871
19808static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBoolToInt *instruction) {19872static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBoolToInt *instruction) {
...@@ -19811,8 +19875,8 @@ static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBo...@@ -19811,8 +19875,8 @@ static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBo
19811 return ira->codegen->invalid_inst_gen;19875 return ira->codegen->invalid_inst_gen;
1981219876
19813 if (target->value->type->id != ZigTypeIdBool) {19877 if (target->value->type->id != ZigTypeIdBool) {
19814 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected bool, found '%s'",19878 ir_add_error_node(ira, instruction->target->source_node,
19815 buf_ptr(&target->value->type->name)));19879 buf_sprintf("expected bool, found '%s'", buf_ptr(&target->value->type->name)));
19816 return ira->codegen->invalid_inst_gen;19880 return ira->codegen->invalid_inst_gen;
19817 }19881 }
1981819882
...@@ -19821,11 +19885,11 @@ static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBo...@@ -19821,11 +19885,11 @@ static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBo
19821 if (!ir_resolve_bool(ira, target, &is_true))19885 if (!ir_resolve_bool(ira, target, &is_true))
19822 return ira->codegen->invalid_inst_gen;19886 return ira->codegen->invalid_inst_gen;
1982319887
19824 return ir_const_unsigned(ira, &instruction->base.base, is_true ? 1 : 0);19888 return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, is_true ? 1 : 0);
19825 }19889 }
1982619890
19827 ZigType *u1_type = get_int_type(ira->codegen, false, 1);19891 ZigType *u1_type = get_int_type(ira->codegen, false, 1);
19828 return ir_resolve_cast(ira, &instruction->base.base, target, u1_type, CastOpBoolToInt);19892 return ir_resolve_cast(ira, instruction->base.scope, instruction->base.source_node, target, u1_type, CastOpBoolToInt);
19829}19893}
1983019894
19831static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVectorType *instruction) {19895static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVectorType *instruction) {
...@@ -19839,16 +19903,16 @@ static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVe...@@ -19839,16 +19903,16 @@ static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVe
1983919903
19840 ZigType *vector_type = get_vector_type(ira->codegen, len, elem_type);19904 ZigType *vector_type = get_vector_type(ira->codegen, len, elem_type);
1984119905
19842 return ir_const_type(ira, &instruction->base.base, vector_type);19906 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, vector_type);
19843}19907}
1984419908
19845static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr,19909static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, Scope *scope, AstNode *source_node,
19846 ZigType *scalar_type, IrInstGen *a, IrInstGen *b, IrInstGen *mask)19910 ZigType *scalar_type, IrInstGen *a, IrInstGen *b, IrInstGen *mask)
19847{19911{
19848 Error err;19912 Error err;
19849 ir_assert(source_instr && scalar_type && a && b && mask, source_instr);19913 src_assert(source_node && scalar_type && a && b && mask, source_node);
1985019914
19851 if ((err = ir_validate_vector_elem_type(ira, source_instr->source_node, scalar_type)))19915 if ((err = ir_validate_vector_elem_type(ira, source_node, scalar_type)))
19852 return ira->codegen->invalid_inst_gen;19916 return ira->codegen->invalid_inst_gen;
1985319917
19854 uint32_t len_mask;19918 uint32_t len_mask;
...@@ -19857,7 +19921,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr...@@ -19857,7 +19921,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
19857 } else if (mask->value->type->id == ZigTypeIdArray) {19921 } else if (mask->value->type->id == ZigTypeIdArray) {
19858 len_mask = mask->value->type->data.array.len;19922 len_mask = mask->value->type->data.array.len;
19859 } else {19923 } else {
19860 ir_add_error(ira, &mask->base,19924 ir_add_error(ira, mask,
19861 buf_sprintf("expected vector or array, found '%s'",19925 buf_sprintf("expected vector or array, found '%s'",
19862 buf_ptr(&mask->value->type->name)));19926 buf_ptr(&mask->value->type->name)));
19863 return ira->codegen->invalid_inst_gen;19927 return ira->codegen->invalid_inst_gen;
...@@ -19875,7 +19939,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr...@@ -19875,7 +19939,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
19875 } else if (a->value->type->id == ZigTypeIdUndefined) {19939 } else if (a->value->type->id == ZigTypeIdUndefined) {
19876 len_a = UINT32_MAX;19940 len_a = UINT32_MAX;
19877 } else {19941 } else {
19878 ir_add_error(ira, &a->base,19942 ir_add_error(ira, a,
19879 buf_sprintf("expected vector or array with element type '%s', found '%s'",19943 buf_sprintf("expected vector or array with element type '%s', found '%s'",
19880 buf_ptr(&scalar_type->name),19944 buf_ptr(&scalar_type->name),
19881 buf_ptr(&a->value->type->name)));19945 buf_ptr(&a->value->type->name)));
...@@ -19890,7 +19954,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr...@@ -19890,7 +19954,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
19890 } else if (b->value->type->id == ZigTypeIdUndefined) {19954 } else if (b->value->type->id == ZigTypeIdUndefined) {
19891 len_b = UINT32_MAX;19955 len_b = UINT32_MAX;
19892 } else {19956 } else {
19893 ir_add_error(ira, &b->base,19957 ir_add_error(ira, b,
19894 buf_sprintf("expected vector or array with element type '%s', found '%s'",19958 buf_sprintf("expected vector or array with element type '%s', found '%s'",
19895 buf_ptr(&scalar_type->name),19959 buf_ptr(&scalar_type->name),
19896 buf_ptr(&b->value->type->name)));19960 buf_ptr(&b->value->type->name)));
...@@ -19898,12 +19962,12 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr...@@ -19898,12 +19962,12 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
19898 }19962 }
1989919963
19900 if (len_a == UINT32_MAX && len_b == UINT32_MAX) {19964 if (len_a == UINT32_MAX && len_b == UINT32_MAX) {
19901 return ir_const_undef(ira, &a->base, get_vector_type(ira->codegen, len_mask, scalar_type));19965 return ir_const_undef(ira, a->scope, a->source_node, get_vector_type(ira->codegen, len_mask, scalar_type));
19902 }19966 }
1990319967
19904 if (len_a == UINT32_MAX) {19968 if (len_a == UINT32_MAX) {
19905 len_a = len_b;19969 len_a = len_b;
19906 a = ir_const_undef(ira, &a->base, get_vector_type(ira->codegen, len_a, scalar_type));19970 a = ir_const_undef(ira, a->scope, a->source_node, get_vector_type(ira->codegen, len_a, scalar_type));
19907 } else {19971 } else {
19908 a = ir_implicit_cast(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));19972 a = ir_implicit_cast(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));
19909 if (type_is_invalid(a->value->type))19973 if (type_is_invalid(a->value->type))
...@@ -19912,7 +19976,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr...@@ -19912,7 +19976,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
1991219976
19913 if (len_b == UINT32_MAX) {19977 if (len_b == UINT32_MAX) {
19914 len_b = len_a;19978 len_b = len_a;
19915 b = ir_const_undef(ira, &b->base, get_vector_type(ira->codegen, len_b, scalar_type));19979 b = ir_const_undef(ira, b->scope, b->source_node, get_vector_type(ira->codegen, len_b, scalar_type));
19916 } else {19980 } else {
19917 b = ir_implicit_cast(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));19981 b = ir_implicit_cast(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));
19918 if (type_is_invalid(b->value->type))19982 if (type_is_invalid(b->value->type))
...@@ -19940,13 +20004,13 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr...@@ -19940,13 +20004,13 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
19940 chosen_operand = b;20004 chosen_operand = b;
19941 }20005 }
19942 if (v >= chosen_operand->value->type->data.vector.len) {20006 if (v >= chosen_operand->value->type->data.vector.len) {
19943 ErrorMsg *msg = ir_add_error(ira, &mask->base,20007 ErrorMsg *msg = ir_add_error(ira, mask,
19944 buf_sprintf("mask index '%u' has out-of-bounds selection", i));20008 buf_sprintf("mask index '%u' has out-of-bounds selection", i));
19945 add_error_note(ira->codegen, msg, chosen_operand->base.source_node,20009 add_error_note(ira->codegen, msg, chosen_operand->source_node,
19946 buf_sprintf("selected index '%u' out of bounds of %s", v,20010 buf_sprintf("selected index '%u' out of bounds of %s", v,
19947 buf_ptr(&chosen_operand->value->type->name)));20011 buf_ptr(&chosen_operand->value->type->name)));
19948 if (chosen_operand == a && v < len_a + len_b) {20012 if (chosen_operand == a && v < len_a + len_b) {
19949 add_error_note(ira->codegen, msg, b->base.source_node,20013 add_error_note(ira->codegen, msg, b->source_node,
19950 buf_create_from_str("selections from the second vector are specified with negative numbers"));20014 buf_create_from_str("selections from the second vector are specified with negative numbers"));
19951 }20015 }
19952 return ira->codegen->invalid_inst_gen;20016 return ira->codegen->invalid_inst_gen;
...@@ -19966,7 +20030,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr...@@ -19966,7 +20030,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
19966 expand_undef_array(ira->codegen, a_val);20030 expand_undef_array(ira->codegen, a_val);
19967 expand_undef_array(ira->codegen, b_val);20031 expand_undef_array(ira->codegen, b_val);
1996820032
19969 IrInstGen *result = ir_const(ira, source_instr, result_type);20033 IrInstGen *result = ir_const(ira, scope, source_node, result_type);
19970 result->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(len_mask);20034 result->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(len_mask);
19971 for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) {20035 for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) {
19972 ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i];20036 ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i];
...@@ -19982,7 +20046,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr...@@ -19982,7 +20046,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
19982 &b->value->data.x_array.data.s_none.elements[~v];20046 &b->value->data.x_array.data.s_none.elements[~v];
19983 copy_const_val(ira->codegen, result_elem_val, src_elem_val);20047 copy_const_val(ira->codegen, result_elem_val, src_elem_val);
1998420048
19985 ir_assert(result_elem_val->special == ConstValSpecialStatic, source_instr);20049 src_assert(result_elem_val->special == ConstValSpecialStatic, source_node);
19986 }20050 }
19987 result->value->special = ConstValSpecialStatic;20051 result->value->special = ConstValSpecialStatic;
19988 return result;20052 return result;
...@@ -19998,7 +20062,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr...@@ -19998,7 +20062,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
19998 uint32_t len_min = min(len_a, len_b);20062 uint32_t len_min = min(len_a, len_b);
19999 uint32_t len_max = max(len_a, len_b);20063 uint32_t len_max = max(len_a, len_b);
2000020064
20001 IrInstGen *expand_mask = ir_const(ira, &mask->base,20065 IrInstGen *expand_mask = ir_const(ira, mask->scope, mask->source_node,
20002 get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32));20066 get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32));
20003 expand_mask->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(len_max);20067 expand_mask->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(len_max);
20004 uint32_t i = 0;20068 uint32_t i = 0;
...@@ -20007,17 +20071,17 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr...@@ -20007,17 +20071,17 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
20007 for (; i < len_max; i += 1)20071 for (; i < len_max; i += 1)
20008 bigint_init_signed(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, -1);20072 bigint_init_signed(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, -1);
2000920073
20010 IrInstGen *undef = ir_const_undef(ira, source_instr,20074 IrInstGen *undef = ir_const_undef(ira, scope, source_node,
20011 get_vector_type(ira->codegen, len_min, scalar_type));20075 get_vector_type(ira->codegen, len_min, scalar_type));
2001220076
20013 if (len_b < len_a) {20077 if (len_b < len_a) {
20014 b = ir_analyze_shuffle_vector(ira, source_instr, scalar_type, b, undef, expand_mask);20078 b = ir_analyze_shuffle_vector(ira, scope, source_node, scalar_type, b, undef, expand_mask);
20015 } else {20079 } else {
20016 a = ir_analyze_shuffle_vector(ira, source_instr, scalar_type, a, undef, expand_mask);20080 a = ir_analyze_shuffle_vector(ira, scope, source_node, scalar_type, a, undef, expand_mask);
20017 }20081 }
20018 }20082 }
2001920083
20020 return ir_build_shuffle_vector_gen(ira, source_instr->scope, source_instr->source_node,20084 return ir_build_shuffle_vector_gen(ira, scope, source_node,
20021 result_type, a, b, mask);20085 result_type, a, b, mask);
20022}20086}
2002320087
...@@ -20038,7 +20102,7 @@ static IrInstGen *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrInstSr...@@ -20038,7 +20102,7 @@ static IrInstGen *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrInstSr
20038 if (type_is_invalid(mask->value->type))20102 if (type_is_invalid(mask->value->type))
20039 return ira->codegen->invalid_inst_gen;20103 return ira->codegen->invalid_inst_gen;
2004020104
20041 return ir_analyze_shuffle_vector(ira, &instruction->base.base, scalar_type, a, b, mask);20105 return ir_analyze_shuffle_vector(ira, instruction->base.scope, instruction->base.source_node, scalar_type, a, b, mask);
20042}20106}
2004320107
20044static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *instruction) {20108static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *instruction) {
...@@ -20057,7 +20121,7 @@ static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *i...@@ -20057,7 +20121,7 @@ static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *i
20057 return ira->codegen->invalid_inst_gen;20121 return ira->codegen->invalid_inst_gen;
20058 uint32_t len_int = len_u64;20122 uint32_t len_int = len_u64;
2005920123
20060 if ((err = ir_validate_vector_elem_type(ira, scalar->base.source_node, scalar->value->type)))20124 if ((err = ir_validate_vector_elem_type(ira, scalar->source_node, scalar->value->type)))
20061 return ira->codegen->invalid_inst_gen;20125 return ira->codegen->invalid_inst_gen;
2006220126
20063 ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value->type);20127 ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value->type);
...@@ -20067,9 +20131,9 @@ static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *i...@@ -20067,9 +20131,9 @@ static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *i
20067 if (scalar_val == nullptr)20131 if (scalar_val == nullptr)
20068 return ira->codegen->invalid_inst_gen;20132 return ira->codegen->invalid_inst_gen;
20069 if (scalar_val->special == ConstValSpecialUndef)20133 if (scalar_val->special == ConstValSpecialUndef)
20070 return ir_const_undef(ira, &instruction->base.base, return_type);20134 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, return_type);
2007120135
20072 IrInstGen *result = ir_const(ira, &instruction->base.base, return_type);20136 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, return_type);
20073 result->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(len_int);20137 result->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(len_int);
20074 for (uint32_t i = 0; i < len_int; i += 1) {20138 for (uint32_t i = 0; i < len_int; i += 1) {
20075 copy_const_val(ira->codegen, &result->value->data.x_array.data.s_none.elements[i], scalar_val);20139 copy_const_val(ira->codegen, &result->value->data.x_array.data.s_none.elements[i], scalar_val);
...@@ -20077,7 +20141,7 @@ static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *i...@@ -20077,7 +20141,7 @@ static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *i
20077 return result;20141 return result;
20078 }20142 }
2007920143
20080 return ir_build_splat_gen(ira, &instruction->base.base, return_type, scalar);20144 return ir_build_splat_gen(ira, instruction->base.scope, instruction->base.source_node, return_type, scalar);
20081}20145}
2008220146
20083static IrInstGen *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstSrcBoolNot *instruction) {20147static IrInstGen *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstSrcBoolNot *instruction) {
...@@ -20096,10 +20160,10 @@ static IrInstGen *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstSrcBoolN...@@ -20096,10 +20160,10 @@ static IrInstGen *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstSrcBoolN
20096 if (value == nullptr)20160 if (value == nullptr)
20097 return ira->codegen->invalid_inst_gen;20161 return ira->codegen->invalid_inst_gen;
2009820162
20099 return ir_const_bool(ira, &instruction->base.base, !value->data.x_bool);20163 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, !value->data.x_bool);
20100 }20164 }
2010120165
20102 return ir_build_bool_not_gen(ira, &instruction->base.base, casted_value);20166 return ir_build_bool_not_gen(ira, instruction->base.scope, instruction->base.source_node, casted_value);
20103}20167}
2010420168
20105static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset *instruction) {20169static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset *instruction) {
...@@ -20206,7 +20270,7 @@ static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset...@@ -20206,7 +20270,7 @@ static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset
20206 size_t count = bigint_as_usize(&count_val->data.x_bigint);20270 size_t count = bigint_as_usize(&count_val->data.x_bigint);
20207 size_t end = start + count;20271 size_t end = start + count;
20208 if (end > bound_end) {20272 if (end > bound_end) {
20209 ir_add_error(ira, &count_value->base, buf_sprintf("out of bounds pointer access"));20273 ir_add_error(ira, count_value, buf_sprintf("out of bounds pointer access"));
20210 return ira->codegen->invalid_inst_gen;20274 return ira->codegen->invalid_inst_gen;
20211 }20275 }
2021220276
...@@ -20214,11 +20278,11 @@ static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset...@@ -20214,11 +20278,11 @@ static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset
20214 copy_const_val(ira->codegen, &dest_elements[i], byte_val);20278 copy_const_val(ira->codegen, &dest_elements[i], byte_val);
20215 }20279 }
2021620280
20217 return ir_const_void(ira, &instruction->base.base);20281 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
20218 }20282 }
20219 }20283 }
2022020284
20221 return ir_build_memset_gen(ira, &instruction->base.base, casted_dest_ptr, casted_byte, casted_count);20285 return ir_build_memset_gen(ira, instruction->base.scope, instruction->base.source_node, casted_dest_ptr, casted_byte, casted_count);
20222}20286}
2022320287
20224static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy *instruction) {20288static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy *instruction) {
...@@ -20338,7 +20402,7 @@ static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy...@@ -20338,7 +20402,7 @@ static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy
20338 }20402 }
2033920403
20340 if (dest_start + count > dest_end) {20404 if (dest_start + count > dest_end) {
20341 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds pointer access"));20405 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("out of bounds pointer access"));
20342 return ira->codegen->invalid_inst_gen;20406 return ira->codegen->invalid_inst_gen;
20343 }20407 }
2034420408
...@@ -20382,7 +20446,7 @@ static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy...@@ -20382,7 +20446,7 @@ static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy
20382 }20446 }
2038320447
20384 if (src_start + count > src_end) {20448 if (src_start + count > src_end) {
20385 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds pointer access"));20449 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("out of bounds pointer access"));
20386 return ira->codegen->invalid_inst_gen;20450 return ira->codegen->invalid_inst_gen;
20387 }20451 }
2038820452
...@@ -20392,11 +20456,11 @@ static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy...@@ -20392,11 +20456,11 @@ static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy
20392 copy_const_val(ira->codegen, &dest_elements[dest_start + i], &src_elements[src_start + i]);20456 copy_const_val(ira->codegen, &dest_elements[dest_start + i], &src_elements[src_start + i]);
20393 }20457 }
2039420458
20395 return ir_const_void(ira, &instruction->base.base);20459 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
20396 }20460 }
20397 }20461 }
2039820462
20399 return ir_build_memcpy_gen(ira, &instruction->base.base, casted_dest_ptr, casted_src_ptr, casted_count);20463 return ir_build_memcpy_gen(ira, instruction->base.scope, instruction->base.source_node, casted_dest_ptr, casted_src_ptr, casted_count);
20400}20464}
2040120465
20402static ZigType *get_result_loc_type(IrAnalyze *ira, ResultLoc *result_loc) {20466static ZigType *get_result_loc_type(IrAnalyze *ira, ResultLoc *result_loc) {
...@@ -20465,7 +20529,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i...@@ -20465,7 +20529,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i
20465 PtrLenUnknown,20529 PtrLenUnknown,
20466 array_type->data.pointer.explicit_alignment, 0, 0, false);20530 array_type->data.pointer.explicit_alignment, 0, 0, false);
20467 } else {20531 } else {
20468 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of single-item pointer"));20532 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice of single-item pointer"));
20469 return ira->codegen->invalid_inst_gen;20533 return ira->codegen->invalid_inst_gen;
20470 }20534 }
20471 } else {20535 } else {
...@@ -20484,7 +20548,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i...@@ -20484,7 +20548,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i
20484 ZigType *maybe_sentineled_slice_ptr_type = array_type;20548 ZigType *maybe_sentineled_slice_ptr_type = array_type;
20485 non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr);20549 non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr);
20486 if (!end) {20550 if (!end) {
20487 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of pointer must include end value"));20551 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice of pointer must include end value"));
20488 return ira->codegen->invalid_inst_gen;20552 return ira->codegen->invalid_inst_gen;
20489 }20553 }
20490 }20554 }
...@@ -20494,7 +20558,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i...@@ -20494,7 +20558,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i
20494 non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr);20558 non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr);
20495 elem_type = non_sentinel_slice_ptr_type->data.pointer.child_type;20559 elem_type = non_sentinel_slice_ptr_type->data.pointer.child_type;
20496 } else {20560 } else {
20497 ir_add_error(ira, &instruction->base.base,20561 ir_add_error_node(ira, instruction->base.source_node,
20498 buf_sprintf("slice of non-array type '%s'", buf_ptr(&array_type->name)));20562 buf_sprintf("slice of non-array type '%s'", buf_ptr(&array_type->name)));
20499 return ira->codegen->invalid_inst_gen;20563 return ira->codegen->invalid_inst_gen;
20500 }20564 }
...@@ -20549,7 +20613,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i...@@ -20549,7 +20613,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i
20549 uint64_t start_scalar = bigint_as_u64(&start_val->data.x_bigint);20613 uint64_t start_scalar = bigint_as_u64(&start_val->data.x_bigint);
2055020614
20551 if (start_scalar > end_scalar) {20615 if (start_scalar > end_scalar) {
20552 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice"));20616 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("out of bounds slice"));
20553 return ira->codegen->invalid_inst_gen;20617 return ira->codegen->invalid_inst_gen;
20554 }20618 }
2055520619
...@@ -20592,7 +20656,7 @@ done_with_return_type:...@@ -20592,7 +20656,7 @@ done_with_return_type:
20592 bool ptr_is_undef = false;20656 bool ptr_is_undef = false;
20593 if (child_array_type->id == ZigTypeIdArray) {20657 if (child_array_type->id == ZigTypeIdArray) {
20594 if (array_type->id == ZigTypeIdPointer) {20658 if (array_type->id == ZigTypeIdPointer) {
20595 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);20659 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
20596 if (parent_ptr == nullptr)20660 if (parent_ptr == nullptr)
20597 return ira->codegen->invalid_inst_gen;20661 return ira->codegen->invalid_inst_gen;
2059820662
...@@ -20606,7 +20670,7 @@ done_with_return_type:...@@ -20606,7 +20670,7 @@ done_with_return_type:
20606 abs_offset = 0;20670 abs_offset = 0;
20607 rel_end = SIZE_MAX;20671 rel_end = SIZE_MAX;
20608 } else {20672 } else {
20609 array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.base.source_node);20673 array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.source_node);
20610 if (array_val == nullptr)20674 if (array_val == nullptr)
20611 return ira->codegen->invalid_inst_gen;20675 return ira->codegen->invalid_inst_gen;
2061220676
...@@ -20614,7 +20678,7 @@ done_with_return_type:...@@ -20614,7 +20678,7 @@ done_with_return_type:
20614 abs_offset = 0;20678 abs_offset = 0;
20615 }20679 }
20616 } else {20680 } else {
20617 array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);20681 array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
20618 if (array_val == nullptr)20682 if (array_val == nullptr)
20619 return ira->codegen->invalid_inst_gen;20683 return ira->codegen->invalid_inst_gen;
20620 rel_end = array_type->data.array.len;20684 rel_end = array_type->data.array.len;
...@@ -20623,7 +20687,7 @@ done_with_return_type:...@@ -20623,7 +20687,7 @@ done_with_return_type:
20623 }20687 }
20624 } else if (array_type->id == ZigTypeIdPointer) {20688 } else if (array_type->id == ZigTypeIdPointer) {
20625 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);20689 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);
20626 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);20690 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
20627 if (parent_ptr == nullptr)20691 if (parent_ptr == nullptr)
20628 return ira->codegen->invalid_inst_gen;20692 return ira->codegen->invalid_inst_gen;
2062920693
...@@ -20672,18 +20736,18 @@ done_with_return_type:...@@ -20672,18 +20736,18 @@ done_with_return_type:
20672 zig_panic("TODO slice of null ptr");20736 zig_panic("TODO slice of null ptr");
20673 }20737 }
20674 } else if (is_slice(array_type)) {20738 } else if (is_slice(array_type)) {
20675 ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);20739 ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
20676 if (slice_ptr == nullptr)20740 if (slice_ptr == nullptr)
20677 return ira->codegen->invalid_inst_gen;20741 return ira->codegen->invalid_inst_gen;
2067820742
20679 if (slice_ptr->special == ConstValSpecialUndef) {20743 if (slice_ptr->special == ConstValSpecialUndef) {
20680 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of undefined"));20744 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice of undefined"));
20681 return ira->codegen->invalid_inst_gen;20745 return ira->codegen->invalid_inst_gen;
20682 }20746 }
2068320747
20684 parent_ptr = slice_ptr->data.x_struct.fields[slice_ptr_index];20748 parent_ptr = slice_ptr->data.x_struct.fields[slice_ptr_index];
20685 if (parent_ptr->special == ConstValSpecialUndef) {20749 if (parent_ptr->special == ConstValSpecialUndef) {
20686 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of undefined"));20750 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice of undefined"));
20687 return ira->codegen->invalid_inst_gen;20751 return ira->codegen->invalid_inst_gen;
20688 }20752 }
2068920753
...@@ -20732,7 +20796,7 @@ done_with_return_type:...@@ -20732,7 +20796,7 @@ done_with_return_type:
2073220796
20733 uint64_t start_scalar = bigint_as_u64(&start_val->data.x_bigint);20797 uint64_t start_scalar = bigint_as_u64(&start_val->data.x_bigint);
20734 if (!ptr_is_undef && start_scalar > rel_end) {20798 if (!ptr_is_undef && start_scalar > rel_end) {
20735 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice"));20799 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("out of bounds slice"));
20736 return ira->codegen->invalid_inst_gen;20800 return ira->codegen->invalid_inst_gen;
20737 }20801 }
2073820802
...@@ -20745,16 +20809,16 @@ done_with_return_type:...@@ -20745,16 +20809,16 @@ done_with_return_type:
20745 }20809 }
20746 if (!ptr_is_undef) {20810 if (!ptr_is_undef) {
20747 if (end_scalar > rel_end) {20811 if (end_scalar > rel_end) {
20748 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice"));20812 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("out of bounds slice"));
20749 return ira->codegen->invalid_inst_gen;20813 return ira->codegen->invalid_inst_gen;
20750 }20814 }
20751 if (start_scalar > end_scalar) {20815 if (start_scalar > end_scalar) {
20752 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice start is greater than end"));20816 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice start is greater than end"));
20753 return ira->codegen->invalid_inst_gen;20817 return ira->codegen->invalid_inst_gen;
20754 }20818 }
20755 }20819 }
20756 if (ptr_is_undef && start_scalar != end_scalar) {20820 if (ptr_is_undef && start_scalar != end_scalar) {
20757 ir_add_error(ira, &instruction->base.base, buf_sprintf("non-zero length slice of undefined pointer"));20821 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("non-zero length slice of undefined pointer"));
20758 return ira->codegen->invalid_inst_gen;20822 return ira->codegen->invalid_inst_gen;
20759 }20823 }
2076020824
...@@ -20773,7 +20837,7 @@ done_with_return_type:...@@ -20773,7 +20837,7 @@ done_with_return_type:
20773 }20837 }
2077420838
20775 // prepare check parameters20839 // prepare check parameters
20776 ZigValue *target = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);20840 ZigValue *target = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);
20777 if (target == nullptr)20841 if (target == nullptr)
20778 return ira->codegen->invalid_inst_gen;20842 return ira->codegen->invalid_inst_gen;
2077920843
...@@ -20790,7 +20854,7 @@ done_with_return_type:...@@ -20790,7 +20854,7 @@ done_with_return_type:
20790 break;20854 break;
20791 } else if (target->type->id == ZigTypeIdPointer && target->type->data.pointer.child_type->id == ZigTypeIdArray) {20855 } else if (target->type->id == ZigTypeIdPointer && target->type->data.pointer.child_type->id == ZigTypeIdArray) {
20792 // handle `*[N]T`20856 // handle `*[N]T`
20793 target = const_ptr_pointee(ira, ira->codegen, target, instruction->base.base.source_node);20857 target = const_ptr_pointee(ira, ira->codegen, target, instruction->base.source_node);
20794 if (target == nullptr)20858 if (target == nullptr)
20795 return ira->codegen->invalid_inst_gen;20859 return ira->codegen->invalid_inst_gen;
20796 assert(target->type->id == ZigTypeIdArray);20860 assert(target->type->id == ZigTypeIdArray);
...@@ -20841,23 +20905,23 @@ done_with_return_type:...@@ -20841,23 +20905,23 @@ done_with_return_type:
20841 // perform check20905 // perform check
20842 if (target_sentinel == nullptr) {20906 if (target_sentinel == nullptr) {
20843 if (end_scalar >= target_len) {20907 if (end_scalar >= target_len) {
20844 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice-sentinel is out of bounds"));20908 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice-sentinel is out of bounds"));
20845 return ira->codegen->invalid_inst_gen;20909 return ira->codegen->invalid_inst_gen;
20846 }20910 }
20847 if (!const_values_equal(ira->codegen, sentinel_val, &target_elements[end_scalar])) {20911 if (!const_values_equal(ira->codegen, sentinel_val, &target_elements[end_scalar])) {
20848 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice-sentinel does not match memory at target index"));20912 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice-sentinel does not match memory at target index"));
20849 return ira->codegen->invalid_inst_gen;20913 return ira->codegen->invalid_inst_gen;
20850 }20914 }
20851 } else {20915 } else {
20852 assert(end_scalar <= target_len);20916 assert(end_scalar <= target_len);
20853 if (end_scalar == target_len) {20917 if (end_scalar == target_len) {
20854 if (!const_values_equal(ira->codegen, sentinel_val, target_sentinel)) {20918 if (!const_values_equal(ira->codegen, sentinel_val, target_sentinel)) {
20855 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice-sentinel does not match target-sentinel"));20919 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice-sentinel does not match target-sentinel"));
20856 return ira->codegen->invalid_inst_gen;20920 return ira->codegen->invalid_inst_gen;
20857 }20921 }
20858 } else {20922 } else {
20859 if (!const_values_equal(ira->codegen, sentinel_val, &target_elements[end_scalar])) {20923 if (!const_values_equal(ira->codegen, sentinel_val, &target_elements[end_scalar])) {
20860 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice-sentinel does not match memory at target index"));20924 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice-sentinel does not match memory at target index"));
20861 return ira->codegen->invalid_inst_gen;20925 return ira->codegen->invalid_inst_gen;
20862 }20926 }
20863 }20927 }
...@@ -20865,7 +20929,7 @@ done_with_return_type:...@@ -20865,7 +20929,7 @@ done_with_return_type:
20865 }20929 }
20866 exit_check_sentinel:20930 exit_check_sentinel:
2086720931
20868 IrInstGen *result = ir_const(ira, &instruction->base.base, return_type);20932 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, return_type);
2086920933
20870 ZigValue *ptr_val;20934 ZigValue *ptr_val;
20871 if (return_type->id == ZigTypeIdPointer) {20935 if (return_type->id == ZigTypeIdPointer) {
...@@ -20936,40 +21000,42 @@ done_with_return_type:...@@ -20936,40 +21000,42 @@ done_with_return_type:
20936 }21000 }
2093721001
20938 if (generate_non_null_assert) {21002 if (generate_non_null_assert) {
20939 IrInstGen *ptr_val = ir_get_deref(ira, &instruction->base.base, ptr_ptr, nullptr);21003 IrInstGen *ptr_val = ir_get_deref(ira, instruction->base.scope,
21004 instruction->base.source_node, ptr_ptr, nullptr);
2094021005
20941 if (type_is_invalid(ptr_val->value->type))21006 if (type_is_invalid(ptr_val->value->type))
20942 return ira->codegen->invalid_inst_gen;21007 return ira->codegen->invalid_inst_gen;
2094321008
20944 ir_build_assert_non_null(ira, &instruction->base.base, ptr_val);21009 ir_build_assert_non_null(ira, instruction->base.scope, instruction->base.source_node, ptr_val);
20945 }21010 }
2094621011
20947 IrInstGen *result_loc = nullptr;21012 IrInstGen *result_loc = nullptr;
2094821013
20949 if (return_type->id != ZigTypeIdPointer) {21014 if (return_type->id != ZigTypeIdPointer) {
20950 result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,21015 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
20951 return_type, nullptr, true, true);21016 return_type, nullptr, true, true);
20952 if (result_loc != nullptr) {21017 if (result_loc != nullptr) {
20953 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {21018 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
20954 return result_loc;21019 return result_loc;
20955 }21020 }
2095621021
20957 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base);21022 src_assert(result_loc->value->type->id == ZigTypeIdPointer, instruction->base.source_node);
20958 if (result_loc->value->type->data.pointer.is_const) {21023 if (result_loc->value->type->data.pointer.is_const) {
20959 ir_add_error(ira, &instruction->base.base, buf_sprintf("cannot assign to constant"));21024 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("cannot assign to constant"));
20960 return ira->codegen->invalid_inst_gen;21025 return ira->codegen->invalid_inst_gen;
20961 }21026 }
2096221027
20963 IrInstGen *dummy_value = ir_const(ira, &instruction->base.base, return_type);21028 IrInstGen *dummy_value = ir_const(ira, instruction->base.scope, instruction->base.source_node, return_type);
20964 dummy_value->value->special = ConstValSpecialRuntime;21029 dummy_value->value->special = ConstValSpecialRuntime;
20965 IrInstGen *dummy_result = ir_implicit_cast2(ira, &instruction->base.base,21030 IrInstGen *dummy_result = ir_implicit_cast2(ira,
21031 instruction->base.scope, instruction->base.source_node,
20966 dummy_value, result_loc->value->type->data.pointer.child_type);21032 dummy_value, result_loc->value->type->data.pointer.child_type);
20967 if (type_is_invalid(dummy_result->value->type))21033 if (type_is_invalid(dummy_result->value->type))
20968 return ira->codegen->invalid_inst_gen;21034 return ira->codegen->invalid_inst_gen;
20969 }21035 }
20970 }21036 }
2097121037
20972 return ir_build_slice_gen(ira, &instruction->base.base, return_type, ptr_ptr,21038 return ir_build_slice_gen(ira, instruction->base.scope, instruction->base.source_node, return_type, ptr_ptr,
20973 casted_start, end, instruction->safety_check_on, result_loc, sentinel_val);21039 casted_start, end, instruction->safety_check_on, result_loc, sentinel_val);
20974}21040}
2097521041
...@@ -20994,17 +21060,17 @@ static IrInstGen *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstSrcHasF...@@ -20994,17 +21060,17 @@ static IrInstGen *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstSrcHasF
20994 } else if (container_type->id == ZigTypeIdUnion) {21060 } else if (container_type->id == ZigTypeIdUnion) {
20995 result = find_union_type_field(container_type, field_name) != nullptr;21061 result = find_union_type_field(container_type, field_name) != nullptr;
20996 } else {21062 } else {
20997 ir_add_error(ira, &instruction->container_type->base,21063 ir_add_error_node(ira, instruction->container_type->source_node,
20998 buf_sprintf("type '%s' does not support @hasField", buf_ptr(&container_type->name)));21064 buf_sprintf("type '%s' does not support @hasField", buf_ptr(&container_type->name)));
20999 return ira->codegen->invalid_inst_gen;21065 return ira->codegen->invalid_inst_gen;
21000 }21066 }
21001 return ir_const_bool(ira, &instruction->base.base, result);21067 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, result);
21002}21068}
2100321069
21004static IrInstGen *ir_analyze_instruction_wasm_memory_size(IrAnalyze *ira, IrInstSrcWasmMemorySize *instruction) {21070static IrInstGen *ir_analyze_instruction_wasm_memory_size(IrAnalyze *ira, IrInstSrcWasmMemorySize *instruction) {
21005 // TODO generate compile error for target_arch different than 32bit21071 // TODO generate compile error for target_arch different than 32bit
21006 if (!target_is_wasm(ira->codegen->zig_target)) {21072 if (!target_is_wasm(ira->codegen->zig_target)) {
21007 ir_add_error_node(ira, instruction->base.base.source_node,21073 ir_add_error_node(ira, instruction->base.source_node,
21008 buf_sprintf("@wasmMemorySize is a wasm32 feature only"));21074 buf_sprintf("@wasmMemorySize is a wasm32 feature only"));
21009 return ira->codegen->invalid_inst_gen;21075 return ira->codegen->invalid_inst_gen;
21010 }21076 }
...@@ -21019,13 +21085,13 @@ static IrInstGen *ir_analyze_instruction_wasm_memory_size(IrAnalyze *ira, IrInst...@@ -21019,13 +21085,13 @@ static IrInstGen *ir_analyze_instruction_wasm_memory_size(IrAnalyze *ira, IrInst
21019 if (type_is_invalid(casted_index->value->type))21085 if (type_is_invalid(casted_index->value->type))
21020 return ira->codegen->invalid_inst_gen;21086 return ira->codegen->invalid_inst_gen;
2102121087
21022 return ir_build_wasm_memory_size_gen(ira, &instruction->base.base, casted_index);21088 return ir_build_wasm_memory_size_gen(ira, instruction->base.scope, instruction->base.source_node, casted_index);
21023}21089}
2102421090
21025static IrInstGen *ir_analyze_instruction_wasm_memory_grow(IrAnalyze *ira, IrInstSrcWasmMemoryGrow *instruction) {21091static IrInstGen *ir_analyze_instruction_wasm_memory_grow(IrAnalyze *ira, IrInstSrcWasmMemoryGrow *instruction) {
21026 // TODO generate compile error for target_arch different than 32bit21092 // TODO generate compile error for target_arch different than 32bit
21027 if (!target_is_wasm(ira->codegen->zig_target)) {21093 if (!target_is_wasm(ira->codegen->zig_target)) {
21028 ir_add_error_node(ira, instruction->base.base.source_node,21094 ir_add_error_node(ira, instruction->base.source_node,
21029 buf_sprintf("@wasmMemoryGrow is a wasm32 feature only"));21095 buf_sprintf("@wasmMemoryGrow is a wasm32 feature only"));
21030 return ira->codegen->invalid_inst_gen;21096 return ira->codegen->invalid_inst_gen;
21031 }21097 }
...@@ -21048,33 +21114,33 @@ static IrInstGen *ir_analyze_instruction_wasm_memory_grow(IrAnalyze *ira, IrInst...@@ -21048,33 +21114,33 @@ static IrInstGen *ir_analyze_instruction_wasm_memory_grow(IrAnalyze *ira, IrInst
21048 if (type_is_invalid(casted_delta->value->type))21114 if (type_is_invalid(casted_delta->value->type))
21049 return ira->codegen->invalid_inst_gen;21115 return ira->codegen->invalid_inst_gen;
2105021116
21051 return ir_build_wasm_memory_grow_gen(ira, &instruction->base.base, casted_index, casted_delta);21117 return ir_build_wasm_memory_grow_gen(ira, instruction->base.scope, instruction->base.source_node, casted_index, casted_delta);
21052}21118}
2105321119
21054static IrInstGen *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstSrcBreakpoint *instruction) {21120static IrInstGen *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstSrcBreakpoint *instruction) {
21055 return ir_build_breakpoint_gen(ira, &instruction->base.base);21121 return ir_build_breakpoint_gen(ira, instruction->base.scope, instruction->base.source_node);
21056}21122}
2105721123
21058static IrInstGen *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstSrcReturnAddress *instruction) {21124static IrInstGen *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstSrcReturnAddress *instruction) {
21059 return ir_build_return_address_gen(ira, &instruction->base.base);21125 return ir_build_return_address_gen(ira, instruction->base.scope, instruction->base.source_node);
21060}21126}
2106121127
21062static IrInstGen *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstSrcFrameAddress *instruction) {21128static IrInstGen *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstSrcFrameAddress *instruction) {
21063 return ir_build_frame_address_gen(ira, &instruction->base.base);21129 return ir_build_frame_address_gen(ira, instruction->base.scope, instruction->base.source_node);
21064}21130}
2106521131
21066static IrInstGen *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInstSrcFrameHandle *instruction) {21132static IrInstGen *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInstSrcFrameHandle *instruction) {
21067 ZigFn *fn = ira->fn;21133 ZigFn *fn = ira->fn;
21068 ir_assert(fn != nullptr, &instruction->base.base);21134 src_assert(fn != nullptr, instruction->base.source_node);
2106921135
21070 if (fn->inferred_async_node == nullptr) {21136 if (fn->inferred_async_node == nullptr) {
21071 fn->inferred_async_node = instruction->base.base.source_node;21137 fn->inferred_async_node = instruction->base.source_node;
21072 }21138 }
2107321139
21074 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn);21140 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn);
21075 ZigType *ptr_frame_type = get_pointer_to_type(ira->codegen, frame_type, false);21141 ZigType *ptr_frame_type = get_pointer_to_type(ira->codegen, frame_type, false);
2107621142
21077 return ir_build_handle_gen(ira, &instruction->base.base, ptr_frame_type);21143 return ir_build_handle_gen(ira, instruction->base.scope, instruction->base.source_node, ptr_frame_type);
21078}21144}
2107921145
21080static IrInstGen *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstSrcFrameType *instruction) {21146static IrInstGen *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstSrcFrameType *instruction) {
...@@ -21083,13 +21149,13 @@ static IrInstGen *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstSrcFra...@@ -21083,13 +21149,13 @@ static IrInstGen *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstSrcFra
21083 return ira->codegen->invalid_inst_gen;21149 return ira->codegen->invalid_inst_gen;
2108421150
21085 if (fn->type_entry->data.fn.is_generic) {21151 if (fn->type_entry->data.fn.is_generic) {
21086 ir_add_error(ira, &instruction->base.base,21152 ir_add_error_node(ira, instruction->base.source_node,
21087 buf_sprintf("@Frame() of generic function"));21153 buf_sprintf("@Frame() of generic function"));
21088 return ira->codegen->invalid_inst_gen;21154 return ira->codegen->invalid_inst_gen;
21089 }21155 }
2109021156
21091 ZigType *ty = get_fn_frame_type(ira->codegen, fn);21157 ZigType *ty = get_fn_frame_type(ira->codegen, fn);
21092 return ir_const_type(ira, &instruction->base.base, ty);21158 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, ty);
21093}21159}
2109421160
21095static IrInstGen *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstSrcFrameSize *instruction) {21161static IrInstGen *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstSrcFrameSize *instruction) {
...@@ -21098,14 +21164,14 @@ static IrInstGen *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstSrcFra...@@ -21098,14 +21164,14 @@ static IrInstGen *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstSrcFra
21098 return ira->codegen->invalid_inst_gen;21164 return ira->codegen->invalid_inst_gen;
2109921165
21100 if (fn->value->type->id != ZigTypeIdFn) {21166 if (fn->value->type->id != ZigTypeIdFn) {
21101 ir_add_error(ira, &fn->base,21167 ir_add_error(ira, fn,
21102 buf_sprintf("expected function, found '%s'", buf_ptr(&fn->value->type->name)));21168 buf_sprintf("expected function, found '%s'", buf_ptr(&fn->value->type->name)));
21103 return ira->codegen->invalid_inst_gen;21169 return ira->codegen->invalid_inst_gen;
21104 }21170 }
2110521171
21106 ira->codegen->need_frame_size_prefix_data = true;21172 ira->codegen->need_frame_size_prefix_data = true;
2110721173
21108 return ir_build_frame_size_gen(ira, &instruction->base.base, fn);21174 return ir_build_frame_size_gen(ira, instruction->base.scope, instruction->base.source_node, fn);
21109}21175}
2111021176
21111static IrInstGen *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstSrcAlignOf *instruction) {21177static IrInstGen *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstSrcAlignOf *instruction) {
...@@ -21114,7 +21180,7 @@ static IrInstGen *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstSrcAlign...@@ -21114,7 +21180,7 @@ static IrInstGen *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstSrcAlign
21114 // const Node = struct {21180 // const Node = struct {
21115 // field: []align(@alignOf(Node)) Node,21181 // field: []align(@alignOf(Node)) Node,
21116 // };21182 // };
21117 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);21183 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int);
21118 result->value->special = ConstValSpecialLazy;21184 result->value->special = ConstValSpecialLazy;
2111921185
21120 LazyValueAlignOf *lazy_align_of = heap::c_allocator.create<LazyValueAlignOf>();21186 LazyValueAlignOf *lazy_align_of = heap::c_allocator.create<LazyValueAlignOf>();
...@@ -21141,7 +21207,7 @@ static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOv...@@ -21141,7 +21207,7 @@ static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOv
21141 return ira->codegen->invalid_inst_gen;21207 return ira->codegen->invalid_inst_gen;
2114221208
21143 if (dest_type->id != ZigTypeIdInt) {21209 if (dest_type->id != ZigTypeIdInt) {
21144 ir_add_error(ira, &type_value->base,21210 ir_add_error(ira, type_value,
21145 buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));21211 buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
21146 return ira->codegen->invalid_inst_gen;21212 return ira->codegen->invalid_inst_gen;
21147 }21213 }
...@@ -21192,7 +21258,7 @@ static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOv...@@ -21192,7 +21258,7 @@ static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOv
2119221258
21193 // Don't write anything to the result pointer.21259 // Don't write anything to the result pointer.
21194 if (dest_type->data.integral.bit_count == 0)21260 if (dest_type->data.integral.bit_count == 0)
21195 return ir_const_bool(ira, &instruction->base.base, false);21261 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, false);
2119621262
21197 if (instr_is_comptime(casted_op1) &&21263 if (instr_is_comptime(casted_op1) &&
21198 instr_is_comptime(casted_op2) &&21264 instr_is_comptime(casted_op2) &&
...@@ -21213,7 +21279,7 @@ static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOv...@@ -21213,7 +21279,7 @@ static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOv
21213 BigInt *op1_bigint = &op1_val->data.x_bigint;21279 BigInt *op1_bigint = &op1_val->data.x_bigint;
21214 BigInt *op2_bigint = &op2_val->data.x_bigint;21280 BigInt *op2_bigint = &op2_val->data.x_bigint;
21215 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val,21281 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val,
21216 casted_result_ptr->base.source_node);21282 casted_result_ptr->source_node);
21217 if (pointee_val == nullptr)21283 if (pointee_val == nullptr)
21218 return ira->codegen->invalid_inst_gen;21284 return ira->codegen->invalid_inst_gen;
21219 BigInt *dest_bigint = &pointee_val->data.x_bigint;21285 BigInt *dest_bigint = &pointee_val->data.x_bigint;
...@@ -21242,14 +21308,14 @@ static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOv...@@ -21242,14 +21308,14 @@ static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOv
21242 dest_type->data.integral.is_signed);21308 dest_type->data.integral.is_signed);
21243 }21309 }
21244 pointee_val->special = ConstValSpecialStatic;21310 pointee_val->special = ConstValSpecialStatic;
21245 return ir_const_bool(ira, &instruction->base.base, result_bool);21311 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, result_bool);
21246 }21312 }
2124721313
21248 return ir_build_overflow_op_gen(ira, &instruction->base.base, instruction->op,21314 return ir_build_overflow_op_gen(ira, instruction->base.scope, instruction->base.source_node, instruction->op,
21249 casted_op1, casted_op2, casted_result_ptr, dest_type);21315 casted_op1, casted_op2, casted_result_ptr, dest_type);
21250}21316}
2125121317
21252static void ir_eval_mul_add(IrAnalyze *ira, IrInstSrcMulAdd *source_instr, ZigType *float_type,21318static void ir_eval_mul_add(IrAnalyze *ira, ZigType *float_type,
21253 ZigValue *op1, ZigValue *op2, ZigValue *op3, ZigValue *out_val) {21319 ZigValue *op1, ZigValue *op2, ZigValue *op3, ZigValue *out_val) {
21254 if (float_type->id == ZigTypeIdComptimeFloat) {21320 if (float_type->id == ZigTypeIdComptimeFloat) {
21255 f128M_mulAdd(&out_val->data.x_bigfloat.value, &op1->data.x_bigfloat.value, &op2->data.x_bigfloat.value,21321 f128M_mulAdd(&out_val->data.x_bigfloat.value, &op1->data.x_bigfloat.value, &op2->data.x_bigfloat.value,
...@@ -21288,7 +21354,7 @@ static IrInstGen *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstSrcMulAdd...@@ -21288,7 +21354,7 @@ static IrInstGen *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstSrcMulAdd
21288 // Only allow float types, and vectors of floats.21354 // Only allow float types, and vectors of floats.
21289 ZigType *float_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type;21355 ZigType *float_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type;
21290 if (float_type->id != ZigTypeIdFloat) {21356 if (float_type->id != ZigTypeIdFloat) {
21291 ir_add_error(ira, &type_value->base,21357 ir_add_error(ira, type_value,
21292 buf_sprintf("expected float or vector of float type, found '%s'", buf_ptr(&float_type->name)));21358 buf_sprintf("expected float or vector of float type, found '%s'", buf_ptr(&float_type->name)));
21293 return ira->codegen->invalid_inst_gen;21359 return ira->codegen->invalid_inst_gen;
21294 }21360 }
...@@ -21330,7 +21396,7 @@ static IrInstGen *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstSrcMulAdd...@@ -21330,7 +21396,7 @@ static IrInstGen *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstSrcMulAdd
21330 if (!op3_const)21396 if (!op3_const)
21331 return ira->codegen->invalid_inst_gen;21397 return ira->codegen->invalid_inst_gen;
2133221398
21333 IrInstGen *result = ir_const(ira, &instruction->base.base, expr_type);21399 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, expr_type);
21334 ZigValue *out_val = result->value;21400 ZigValue *out_val = result->value;
2133521401
21336 if (expr_type->id == ZigTypeIdVector) {21402 if (expr_type->id == ZigTypeIdVector) {
...@@ -21349,19 +21415,19 @@ static IrInstGen *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstSrcMulAdd...@@ -21349,19 +21415,19 @@ static IrInstGen *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstSrcMulAdd
21349 assert(float_operand_op2->type == float_type);21415 assert(float_operand_op2->type == float_type);
21350 assert(float_operand_op3->type == float_type);21416 assert(float_operand_op3->type == float_type);
21351 assert(float_out_val->type == float_type);21417 assert(float_out_val->type == float_type);
21352 ir_eval_mul_add(ira, instruction, float_type,21418 ir_eval_mul_add(ira, float_type,
21353 op1_const, op2_const, op3_const, float_out_val);21419 op1_const, op2_const, op3_const, float_out_val);
21354 float_out_val->type = float_type;21420 float_out_val->type = float_type;
21355 }21421 }
21356 out_val->type = expr_type;21422 out_val->type = expr_type;
21357 out_val->special = ConstValSpecialStatic;21423 out_val->special = ConstValSpecialStatic;
21358 } else {21424 } else {
21359 ir_eval_mul_add(ira, instruction, float_type, op1_const, op2_const, op3_const, out_val);21425 ir_eval_mul_add(ira, float_type, op1_const, op2_const, op3_const, out_val);
21360 }21426 }
21361 return result;21427 return result;
21362 }21428 }
2136321429
21364 return ir_build_mul_add_gen(ira, &instruction->base.base, casted_op1, casted_op2, casted_op3, expr_type);21430 return ir_build_mul_add_gen(ira, instruction->base.scope, instruction->base.source_node, casted_op1, casted_op2, casted_op3, expr_type);
21365}21431}
2136621432
21367static IrInstGen *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstSrcTestErr *instruction) {21433static IrInstGen *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstSrcTestErr *instruction) {
...@@ -21373,7 +21439,8 @@ static IrInstGen *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstSrcTestE...@@ -21373,7 +21439,8 @@ static IrInstGen *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstSrcTestE
21373 if (instruction->base_ptr_is_payload) {21439 if (instruction->base_ptr_is_payload) {
21374 value = base_ptr;21440 value = base_ptr;
21375 } else {21441 } else {
21376 value = ir_get_deref(ira, &instruction->base.base, base_ptr, nullptr);21442 value = ir_get_deref(ira, instruction->base.scope, instruction->base.source_node,
21443 base_ptr, nullptr);
21377 }21444 }
2137821445
21379 ZigType *type_entry = value->value->type;21446 ZigType *type_entry = value->value->type;
...@@ -21387,32 +21454,32 @@ static IrInstGen *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstSrcTestE...@@ -21387,32 +21454,32 @@ static IrInstGen *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstSrcTestE
2138721454
21388 if (err_union_val->special != ConstValSpecialRuntime) {21455 if (err_union_val->special != ConstValSpecialRuntime) {
21389 ErrorTableEntry *err = err_union_val->data.x_err_union.error_set->data.x_err_set;21456 ErrorTableEntry *err = err_union_val->data.x_err_union.error_set->data.x_err_set;
21390 return ir_const_bool(ira, &instruction->base.base, (err != nullptr));21457 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, (err != nullptr));
21391 }21458 }
21392 }21459 }
2139321460
21394 if (instruction->resolve_err_set) {21461 if (instruction->resolve_err_set) {
21395 ZigType *err_set_type = type_entry->data.error_union.err_set_type;21462 ZigType *err_set_type = type_entry->data.error_union.err_set_type;
21396 if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.base.source_node)) {21463 if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) {
21397 return ira->codegen->invalid_inst_gen;21464 return ira->codegen->invalid_inst_gen;
21398 }21465 }
21399 if (!type_is_global_error_set(err_set_type) &&21466 if (!type_is_global_error_set(err_set_type) &&
21400 err_set_type->data.error_set.err_count == 0)21467 err_set_type->data.error_set.err_count == 0)
21401 {21468 {
21402 assert(!err_set_type->data.error_set.incomplete);21469 assert(!err_set_type->data.error_set.incomplete);
21403 return ir_const_bool(ira, &instruction->base.base, false);21470 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, false);
21404 }21471 }
21405 }21472 }
2140621473
21407 return ir_build_test_err_gen(ira, &instruction->base.base, value);21474 return ir_build_test_err_gen(ira, instruction->base.scope, instruction->base.source_node, value);
21408 } else if (type_entry->id == ZigTypeIdErrorSet) {21475 } else if (type_entry->id == ZigTypeIdErrorSet) {
21409 return ir_const_bool(ira, &instruction->base.base, true);21476 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, true);
21410 } else {21477 } else {
21411 return ir_const_bool(ira, &instruction->base.base, false);21478 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, false);
21412 }21479 }
21413}21480}
2141421481
21415static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_instr,21482static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, Scope *scope, AstNode *source_node,
21416 IrInstGen *base_ptr, bool initializing)21483 IrInstGen *base_ptr, bool initializing)
21417{21484{
21418 ZigType *ptr_type = base_ptr->value->type;21485 ZigType *ptr_type = base_ptr->value->type;
...@@ -21425,7 +21492,7 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst...@@ -21425,7 +21492,7 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst
21425 return ira->codegen->invalid_inst_gen;21492 return ira->codegen->invalid_inst_gen;
2142621493
21427 if (type_entry->id != ZigTypeIdErrorUnion) {21494 if (type_entry->id != ZigTypeIdErrorUnion) {
21428 ir_add_error(ira, &base_ptr->base,21495 ir_add_error(ira, base_ptr,
21429 buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name)));21496 buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name)));
21430 return ira->codegen->invalid_inst_gen;21497 return ira->codegen->invalid_inst_gen;
21431 }21498 }
...@@ -21442,7 +21509,7 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst...@@ -21442,7 +21509,7 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst
21442 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&21509 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
21443 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)21510 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)
21444 {21511 {
21445 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);21512 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_node);
21446 if (err_union_val == nullptr)21513 if (err_union_val == nullptr)
21447 return ira->codegen->invalid_inst_gen;21514 return ira->codegen->invalid_inst_gen;
2144821515
...@@ -21465,15 +21532,15 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst...@@ -21465,15 +21532,15 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst
21465 err_union_val->data.x_err_union.error_set = err_set_val;21532 err_union_val->data.x_err_union.error_set = err_set_val;
21466 err_union_val->data.x_err_union.payload = payload_val;21533 err_union_val->data.x_err_union.payload = payload_val;
21467 }21534 }
21468 ir_assert(err_union_val->special != ConstValSpecialRuntime, source_instr);21535 src_assert(err_union_val->special != ConstValSpecialRuntime, source_node);
2146921536
21470 IrInstGen *result;21537 IrInstGen *result;
21471 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {21538 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
21472 result = ir_build_unwrap_err_code_gen(ira, source_instr->scope,21539 result = ir_build_unwrap_err_code_gen(ira, scope,
21473 source_instr->source_node, base_ptr, result_type);21540 source_node, base_ptr, result_type);
21474 result->value->special = ConstValSpecialStatic;21541 result->value->special = ConstValSpecialStatic;
21475 } else {21542 } else {
21476 result = ir_const(ira, source_instr, result_type);21543 result = ir_const(ira, scope, source_node, result_type);
21477 }21544 }
21478 ZigValue *const_val = result->value;21545 ZigValue *const_val = result->value;
21479 const_val->data.x_ptr.special = ConstPtrSpecialBaseErrorUnionCode;21546 const_val->data.x_ptr.special = ConstPtrSpecialBaseErrorUnionCode;
...@@ -21483,17 +21550,17 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst...@@ -21483,17 +21550,17 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst
21483 }21550 }
21484 }21551 }
2148521552
21486 return ir_build_unwrap_err_code_gen(ira, source_instr->scope, source_instr->source_node, base_ptr, result_type);21553 return ir_build_unwrap_err_code_gen(ira, scope, source_node, base_ptr, result_type);
21487}21554}
2148821555
21489static IrInstGen *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, IrInstSrcUnwrapErrCode *instruction) {21556static IrInstGen *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, IrInstSrcUnwrapErrCode *instruction) {
21490 IrInstGen *base_ptr = instruction->err_union_ptr->child;21557 IrInstGen *base_ptr = instruction->err_union_ptr->child;
21491 if (type_is_invalid(base_ptr->value->type))21558 if (type_is_invalid(base_ptr->value->type))
21492 return ira->codegen->invalid_inst_gen;21559 return ira->codegen->invalid_inst_gen;
21493 return ir_analyze_unwrap_err_code(ira, &instruction->base.base, base_ptr, false);21560 return ir_analyze_unwrap_err_code(ira, instruction->base.scope, instruction->base.source_node, base_ptr, false);
21494}21561}
2149521562
21496static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr,21563static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, Scope *scope, AstNode *source_node,
21497 IrInstGen *base_ptr, bool safety_check_on, bool initializing)21564 IrInstGen *base_ptr, bool safety_check_on, bool initializing)
21498{21565{
21499 ZigType *ptr_type = base_ptr->value->type;21566 ZigType *ptr_type = base_ptr->value->type;
...@@ -21506,7 +21573,7 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source...@@ -21506,7 +21573,7 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source
21506 return ira->codegen->invalid_inst_gen;21573 return ira->codegen->invalid_inst_gen;
2150721574
21508 if (type_entry->id != ZigTypeIdErrorUnion) {21575 if (type_entry->id != ZigTypeIdErrorUnion) {
21509 ir_add_error(ira, &base_ptr->base,21576 ir_add_error(ira, base_ptr,
21510 buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name)));21577 buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name)));
21511 return ira->codegen->invalid_inst_gen;21578 return ira->codegen->invalid_inst_gen;
21512 }21579 }
...@@ -21524,7 +21591,7 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source...@@ -21524,7 +21591,7 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source
21524 if (!ptr_val)21591 if (!ptr_val)
21525 return ira->codegen->invalid_inst_gen;21592 return ira->codegen->invalid_inst_gen;
21526 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {21593 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
21527 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);21594 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_node);
21528 if (err_union_val == nullptr)21595 if (err_union_val == nullptr)
21529 return ira->codegen->invalid_inst_gen;21596 return ira->codegen->invalid_inst_gen;
21530 if (initializing && err_union_val->special == ConstValSpecialUndef) {21597 if (initializing && err_union_val->special == ConstValSpecialUndef) {
...@@ -21547,18 +21614,18 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source...@@ -21547,18 +21614,18 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source
21547 if (err_union_val->special != ConstValSpecialRuntime) {21614 if (err_union_val->special != ConstValSpecialRuntime) {
21548 ErrorTableEntry *err = err_union_val->data.x_err_union.error_set->data.x_err_set;21615 ErrorTableEntry *err = err_union_val->data.x_err_union.error_set->data.x_err_set;
21549 if (err != nullptr) {21616 if (err != nullptr) {
21550 ir_add_error(ira, source_instr,21617 ir_add_error_node(ira, source_node,
21551 buf_sprintf("caught unexpected error '%s'", buf_ptr(&err->name)));21618 buf_sprintf("caught unexpected error '%s'", buf_ptr(&err->name)));
21552 return ira->codegen->invalid_inst_gen;21619 return ira->codegen->invalid_inst_gen;
21553 }21620 }
2155421621
21555 IrInstGen *result;21622 IrInstGen *result;
21556 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {21623 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
21557 result = ir_build_unwrap_err_payload_gen(ira, source_instr->scope,21624 result = ir_build_unwrap_err_payload_gen(ira, scope,
21558 source_instr->source_node, base_ptr, safety_check_on, initializing, result_type);21625 source_node, base_ptr, safety_check_on, initializing, result_type);
21559 result->value->special = ConstValSpecialStatic;21626 result->value->special = ConstValSpecialStatic;
21560 } else {21627 } else {
21561 result = ir_const(ira, source_instr, result_type);21628 result = ir_const(ira, scope, source_node, result_type);
21562 }21629 }
21563 result->value->data.x_ptr.special = ConstPtrSpecialRef;21630 result->value->data.x_ptr.special = ConstPtrSpecialRef;
21564 result->value->data.x_ptr.data.ref.pointee = err_union_val->data.x_err_union.payload;21631 result->value->data.x_ptr.data.ref.pointee = err_union_val->data.x_err_union.payload;
...@@ -21568,7 +21635,7 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source...@@ -21568,7 +21635,7 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source
21568 }21635 }
21569 }21636 }
2157021637
21571 return ir_build_unwrap_err_payload_gen(ira, source_instr->scope, source_instr->source_node,21638 return ir_build_unwrap_err_payload_gen(ira, scope, source_node,
21572 base_ptr, safety_check_on, initializing, result_type);21639 base_ptr, safety_check_on, initializing, result_type);
21573}21640}
2157421641
...@@ -21580,14 +21647,14 @@ static IrInstGen *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,...@@ -21580,14 +21647,14 @@ static IrInstGen *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
21580 if (type_is_invalid(value->value->type))21647 if (type_is_invalid(value->value->type))
21581 return ira->codegen->invalid_inst_gen;21648 return ira->codegen->invalid_inst_gen;
2158221649
21583 return ir_analyze_unwrap_error_payload(ira, &instruction->base.base, value, instruction->safety_check_on, false);21650 return ir_analyze_unwrap_error_payload(ira, instruction->base.scope, instruction->base.source_node, value, instruction->safety_check_on, false);
21584}21651}
2158521652
21586static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnProto *instruction) {21653static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnProto *instruction) {
21587 AstNode *proto_node = instruction->base.base.source_node;21654 AstNode *proto_node = instruction->base.source_node;
21588 assert(proto_node->type == NodeTypeFnProto);21655 assert(proto_node->type == NodeTypeFnProto);
2158921656
21590 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);21657 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_type);
21591 result->value->special = ConstValSpecialLazy;21658 result->value->special = ConstValSpecialLazy;
2159221659
21593 LazyValueFnType *lazy_fn_type = heap::c_allocator.create<LazyValueFnType>();21660 LazyValueFnType *lazy_fn_type = heap::c_allocator.create<LazyValueFnType>();
...@@ -21596,7 +21663,7 @@ static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnPro...@@ -21596,7 +21663,7 @@ static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnPro
21596 lazy_fn_type->base.id = LazyValueIdFnType;21663 lazy_fn_type->base.id = LazyValueIdFnType;
2159721664
21598 if (proto_node->data.fn_proto.auto_err_set) {21665 if (proto_node->data.fn_proto.auto_err_set) {
21599 ir_add_error(ira, &instruction->base.base,21666 ir_add_error_node(ira, instruction->base.source_node,
21600 buf_sprintf("inferring error set of return type valid only for function definitions"));21667 buf_sprintf("inferring error set of return type valid only for function definitions"));
21601 return ira->codegen->invalid_inst_gen;21668 return ira->codegen->invalid_inst_gen;
21602 }21669 }
...@@ -21631,7 +21698,7 @@ static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnPro...@@ -21631,7 +21698,7 @@ static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnPro
21631 if (cc == CallingConventionC) {21698 if (cc == CallingConventionC) {
21632 break;21699 break;
21633 } else {21700 } else {
21634 ir_add_error(ira, &instruction->base.base,21701 ir_add_error_node(ira, instruction->base.source_node,
21635 buf_sprintf("var args only allowed in functions with C calling convention"));21702 buf_sprintf("var args only allowed in functions with C calling convention"));
21636 return ira->codegen->invalid_inst_gen;21703 return ira->codegen->invalid_inst_gen;
21637 }21704 }
...@@ -21668,7 +21735,7 @@ static IrInstGen *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstSrc...@@ -21668,7 +21735,7 @@ static IrInstGen *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstSrc
21668 if (type_is_invalid(value->value->type))21735 if (type_is_invalid(value->value->type))
21669 return ira->codegen->invalid_inst_gen;21736 return ira->codegen->invalid_inst_gen;
2167021737
21671 return ir_const_bool(ira, &instruction->base.base, instr_is_comptime(value));21738 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, instr_is_comptime(value));
21672}21739}
2167321740
21674static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,21741static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
...@@ -21713,7 +21780,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -21713,7 +21780,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
21713 bigint_init_bigint(&end_index, &end_value->value->data.x_enum_tag);21780 bigint_init_bigint(&end_index, &end_value->value->data.x_enum_tag);
2171421781
21715 if (bigint_cmp(&start_index, &end_index) == CmpGT) {21782 if (bigint_cmp(&start_index, &end_index) == CmpGT) {
21716 ir_add_error(ira, &start_value->base,21783 ir_add_error(ira, start_value,
21717 buf_sprintf("range start value is greater than the end value"));21784 buf_sprintf("range start value is greater than the end value"));
21718 }21785 }
2171921786
...@@ -21724,12 +21791,12 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -21724,12 +21791,12 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
21724 if (cmp == CmpGT) {21791 if (cmp == CmpGT) {
21725 break;21792 break;
21726 }21793 }
21727 auto entry = field_prev_uses.put_unique(field_index, start_value->base.source_node);21794 auto entry = field_prev_uses.put_unique(field_index, start_value->source_node);
21728 if (entry) {21795 if (entry) {
21729 AstNode *prev_node = entry->value;21796 AstNode *prev_node = entry->value;
21730 TypeEnumField *enum_field = find_enum_field_by_tag(switch_type, &field_index);21797 TypeEnumField *enum_field = find_enum_field_by_tag(switch_type, &field_index);
21731 assert(enum_field != nullptr);21798 assert(enum_field != nullptr);
21732 ErrorMsg *msg = ir_add_error(ira, &start_value->base,21799 ErrorMsg *msg = ir_add_error(ira, start_value,
21733 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name),21800 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name),
21734 buf_ptr(enum_field->name)));21801 buf_ptr(enum_field->name)));
21735 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value here"));21802 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value here"));
...@@ -21739,10 +21806,10 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -21739,10 +21806,10 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
21739 }21806 }
21740 if (have_underscore_prong) {21807 if (have_underscore_prong) {
21741 if (!switch_type->data.enumeration.non_exhaustive) {21808 if (!switch_type->data.enumeration.non_exhaustive) {
21742 ir_add_error(ira, &instruction->base.base,21809 ir_add_error_node(ira, instruction->base.source_node,
21743 buf_sprintf("switch on exhaustive enum has `_` prong"));21810 buf_sprintf("switch on exhaustive enum has `_` prong"));
21744 } else if (target_is_originally_union) {21811 } else if (target_is_originally_union) {
21745 ir_add_error(ira, &instruction->base.base,21812 ir_add_error_node(ira, instruction->base.source_node,
21746 buf_sprintf("`_` prong not allowed when switching on tagged union"));21813 buf_sprintf("`_` prong not allowed when switching on tagged union"));
21747 }21814 }
21748 for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) {21815 for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) {
...@@ -21752,14 +21819,14 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -21752,14 +21819,14 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2175221819
21753 auto entry = field_prev_uses.maybe_get(enum_field->value);21820 auto entry = field_prev_uses.maybe_get(enum_field->value);
21754 if (!entry) {21821 if (!entry) {
21755 ir_add_error(ira, &instruction->base.base,21822 ir_add_error_node(ira, instruction->base.source_node,
21756 buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name),21823 buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name),
21757 buf_ptr(enum_field->name)));21824 buf_ptr(enum_field->name)));
21758 }21825 }
21759 }21826 }
21760 } else if (instruction->else_prong == nullptr) {21827 } else if (instruction->else_prong == nullptr) {
21761 if (switch_type->data.enumeration.non_exhaustive && !target_is_originally_union) {21828 if (switch_type->data.enumeration.non_exhaustive && !target_is_originally_union) {
21762 ir_add_error(ira, &instruction->base.base,21829 ir_add_error_node(ira, instruction->base.source_node,
21763 buf_sprintf("switch on non-exhaustive enum must include `else` or `_` prong"));21830 buf_sprintf("switch on non-exhaustive enum must include `else` or `_` prong"));
21764 }21831 }
21765 for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) {21832 for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) {
...@@ -21767,7 +21834,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -21767,7 +21834,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2176721834
21768 auto entry = field_prev_uses.maybe_get(enum_field->value);21835 auto entry = field_prev_uses.maybe_get(enum_field->value);
21769 if (!entry) {21836 if (!entry) {
21770 ir_add_error(ira, &instruction->base.base,21837 ir_add_error_node(ira, instruction->base.source_node,
21771 buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name),21838 buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name),
21772 buf_ptr(enum_field->name)));21839 buf_ptr(enum_field->name)));
21773 }21840 }
...@@ -21778,7 +21845,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -21778,7 +21845,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
21778 return ira->codegen->invalid_inst_gen;21845 return ira->codegen->invalid_inst_gen;
21779 }21846 }
21780 } else if (switch_type->id == ZigTypeIdErrorSet) {21847 } else if (switch_type->id == ZigTypeIdErrorSet) {
21781 if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->base.source_node)) {21848 if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) {
21782 return ira->codegen->invalid_inst_gen;21849 return ira->codegen->invalid_inst_gen;
21783 }21850 }
2178421851
...@@ -21802,29 +21869,29 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -21802,29 +21869,29 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
21802 if (type_is_invalid(end_value->value->type))21869 if (type_is_invalid(end_value->value->type))
21803 return ira->codegen->invalid_inst_gen;21870 return ira->codegen->invalid_inst_gen;
2180421871
21805 ir_assert(start_value->value->type->id == ZigTypeIdErrorSet, &instruction->base.base);21872 src_assert(start_value->value->type->id == ZigTypeIdErrorSet, instruction->base.source_node);
21806 uint32_t start_index = start_value->value->data.x_err_set->value;21873 uint32_t start_index = start_value->value->data.x_err_set->value;
2180721874
21808 ir_assert(end_value->value->type->id == ZigTypeIdErrorSet, &instruction->base.base);21875 src_assert(end_value->value->type->id == ZigTypeIdErrorSet, instruction->base.source_node);
21809 uint32_t end_index = end_value->value->data.x_err_set->value;21876 uint32_t end_index = end_value->value->data.x_err_set->value;
2181021877
21811 if (start_index != end_index) {21878 if (start_index != end_index) {
21812 ir_add_error(ira, &end_value->base, buf_sprintf("ranges not allowed when switching on errors"));21879 ir_add_error(ira, end_value, buf_sprintf("ranges not allowed when switching on errors"));
21813 return ira->codegen->invalid_inst_gen;21880 return ira->codegen->invalid_inst_gen;
21814 }21881 }
2181521882
21816 AstNode *prev_node = field_prev_uses[start_index];21883 AstNode *prev_node = field_prev_uses[start_index];
21817 if (prev_node != nullptr) {21884 if (prev_node != nullptr) {
21818 Buf *err_name = &ira->codegen->errors_by_index.at(start_index)->name;21885 Buf *err_name = &ira->codegen->errors_by_index.at(start_index)->name;
21819 ErrorMsg *msg = ir_add_error(ira, &start_value->base,21886 ErrorMsg *msg = ir_add_error(ira, start_value,
21820 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name), buf_ptr(err_name)));21887 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name), buf_ptr(err_name)));
21821 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value here"));21888 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value here"));
21822 }21889 }
21823 field_prev_uses[start_index] = start_value->base.source_node;21890 field_prev_uses[start_index] = start_value->source_node;
21824 }21891 }
21825 if (instruction->else_prong == nullptr) {21892 if (instruction->else_prong == nullptr) {
21826 if (type_is_global_error_set(switch_type)) {21893 if (type_is_global_error_set(switch_type)) {
21827 ir_add_error(ira, &instruction->base.base,21894 ir_add_error_node(ira, instruction->base.source_node,
21828 buf_sprintf("else prong required when switching on type 'anyerror'"));21895 buf_sprintf("else prong required when switching on type 'anyerror'"));
21829 return ira->codegen->invalid_inst_gen;21896 return ira->codegen->invalid_inst_gen;
21830 } else {21897 } else {
...@@ -21833,7 +21900,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -21833,7 +21900,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2183321900
21834 AstNode *prev_node = field_prev_uses[err_entry->value];21901 AstNode *prev_node = field_prev_uses[err_entry->value];
21835 if (prev_node == nullptr) {21902 if (prev_node == nullptr) {
21836 ir_add_error(ira, &instruction->base.base,21903 ir_add_error_node(ira, instruction->base.source_node,
21837 buf_sprintf("error.%s not handled in switch", buf_ptr(&err_entry->name)));21904 buf_sprintf("error.%s not handled in switch", buf_ptr(&err_entry->name)));
21838 }21905 }
21839 }21906 }
...@@ -21872,14 +21939,14 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -21872,14 +21939,14 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
21872 assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt);21939 assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt);
2187321940
21874 if (bigint_cmp(&start_val->data.x_bigint, &end_val->data.x_bigint) == CmpGT) {21941 if (bigint_cmp(&start_val->data.x_bigint, &end_val->data.x_bigint) == CmpGT) {
21875 ir_add_error(ira, &start_value->base,21942 ir_add_error(ira, start_value,
21876 buf_sprintf("range start value is greater than the end value"));21943 buf_sprintf("range start value is greater than the end value"));
21877 }21944 }
2187821945
21879 AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint,21946 AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint,
21880 start_value->base.source_node);21947 start_value->source_node);
21881 if (prev_node != nullptr) {21948 if (prev_node != nullptr) {
21882 ErrorMsg *msg = ir_add_error(ira, &start_value->base, buf_sprintf("duplicate switch value"));21949 ErrorMsg *msg = ir_add_error(ira, start_value, buf_sprintf("duplicate switch value"));
21883 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("previous value here"));21950 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("previous value here"));
21884 return ira->codegen->invalid_inst_gen;21951 return ira->codegen->invalid_inst_gen;
21885 }21952 }
...@@ -21891,7 +21958,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -21891,7 +21958,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
21891 eval_min_max_value_int(ira->codegen, switch_type, &max_val, true);21958 eval_min_max_value_int(ira->codegen, switch_type, &max_val, true);
21892 bool handles_all_cases = rangeset_spans(&rs, &min_val, &max_val);21959 bool handles_all_cases = rangeset_spans(&rs, &min_val, &max_val);
21893 if (!handles_all_cases && instruction->else_prong == nullptr) {21960 if (!handles_all_cases && instruction->else_prong == nullptr) {
21894 ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities"));21961 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("switch must handle all possibilities"));
21895 return ira->codegen->invalid_inst_gen;21962 return ira->codegen->invalid_inst_gen;
21896 } else if(handles_all_cases && instruction->else_prong != nullptr) {21963 } else if(handles_all_cases && instruction->else_prong != nullptr) {
21897 ir_add_error_node(ira, instruction->else_prong,21964 ir_add_error_node(ira, instruction->else_prong,
...@@ -21923,12 +21990,12 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -21923,12 +21990,12 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
21923 }21990 }
2192421991
21925 if ((seenTrue > 1) || (seenFalse > 1)) {21992 if ((seenTrue > 1) || (seenFalse > 1)) {
21926 ir_add_error(ira, &value->base, buf_sprintf("duplicate switch value"));21993 ir_add_error(ira, value, buf_sprintf("duplicate switch value"));
21927 return ira->codegen->invalid_inst_gen;21994 return ira->codegen->invalid_inst_gen;
21928 }21995 }
21929 }21996 }
21930 if (((seenTrue < 1) || (seenFalse < 1)) && instruction->else_prong == nullptr) {21997 if (((seenTrue < 1) || (seenFalse < 1)) && instruction->else_prong == nullptr) {
21931 ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities"));21998 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("switch must handle all possibilities"));
21932 return ira->codegen->invalid_inst_gen;21999 return ira->codegen->invalid_inst_gen;
21933 }22000 }
2193422001
...@@ -21938,7 +22005,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -21938,7 +22005,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
21938 return ira->codegen->invalid_inst_gen;22005 return ira->codegen->invalid_inst_gen;
21939 }22006 }
21940 } else if (instruction->else_prong == nullptr) {22007 } else if (instruction->else_prong == nullptr) {
21941 ir_add_error(ira, &instruction->base.base,22008 ir_add_error_node(ira, instruction->base.source_node,
21942 buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name)));22009 buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name)));
21943 return ira->codegen->invalid_inst_gen;22010 return ira->codegen->invalid_inst_gen;
21944 } else if(switch_type->id == ZigTypeIdMetaType) {22011 } else if(switch_type->id == ZigTypeIdMetaType) {
...@@ -21964,15 +22031,15 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -21964,15 +22031,15 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2196422031
21965 auto entry = prevs.put_unique(const_expr_val->data.x_type, value);22032 auto entry = prevs.put_unique(const_expr_val->data.x_type, value);
21966 if(entry != nullptr) {22033 if(entry != nullptr) {
21967 ErrorMsg *msg = ir_add_error(ira, &value->base, buf_sprintf("duplicate switch value"));22034 ErrorMsg *msg = ir_add_error(ira, value, buf_sprintf("duplicate switch value"));
21968 add_error_note(ira->codegen, msg, entry->value->base.source_node, buf_sprintf("previous value here"));22035 add_error_note(ira->codegen, msg, entry->value->source_node, buf_sprintf("previous value here"));
21969 prevs.deinit();22036 prevs.deinit();
21970 return ira->codegen->invalid_inst_gen;22037 return ira->codegen->invalid_inst_gen;
21971 }22038 }
21972 }22039 }
21973 prevs.deinit();22040 prevs.deinit();
21974 }22041 }
21975 return ir_const_void(ira, &instruction->base.base);22042 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
21976}22043}
2197722044
21978static IrInstGen *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,22045static IrInstGen *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,
...@@ -21985,13 +22052,13 @@ static IrInstGen *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,...@@ -21985,13 +22052,13 @@ static IrInstGen *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,
2198522052
21986 if (statement_type->id != ZigTypeIdVoid && statement_type->id != ZigTypeIdUnreachable) {22053 if (statement_type->id != ZigTypeIdVoid && statement_type->id != ZigTypeIdUnreachable) {
21987 if(statement_type->id == ZigTypeIdErrorUnion || statement_type->id == ZigTypeIdErrorSet) {22054 if(statement_type->id == ZigTypeIdErrorUnion || statement_type->id == ZigTypeIdErrorSet) {
21988 ir_add_error(ira, &instruction->base.base, buf_sprintf("error is ignored. consider using `try`, `catch`, or `if`"));22055 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("error is ignored. consider using `try`, `catch`, or `if`"));
21989 }else{22056 }else{
21990 ir_add_error(ira, &instruction->base.base, buf_sprintf("expression value is ignored"));22057 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("expression value is ignored"));
21991 }22058 }
21992 }22059 }
2199322060
21994 return ir_const_void(ira, &instruction->base.base);22061 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
21995}22062}
2199622063
21997static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *instruction) {22064static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *instruction) {
...@@ -21999,8 +22066,8 @@ static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *i...@@ -21999,8 +22066,8 @@ static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *i
21999 if (type_is_invalid(msg->value->type))22066 if (type_is_invalid(msg->value->type))
22000 return ir_unreach_error(ira);22067 return ir_unreach_error(ira);
2200122068
22002 if (ir_should_inline(ira->zir, instruction->base.base.scope)) {22069 if (ir_should_inline(ira->zir, instruction->base.scope)) {
22003 ir_add_error(ira, &instruction->base.base, buf_sprintf("encountered @panic at compile-time"));22070 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("encountered @panic at compile-time"));
22004 return ir_unreach_error(ira);22071 return ir_unreach_error(ira);
22005 }22072 }
2200622073
...@@ -22011,7 +22078,7 @@ static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *i...@@ -22011,7 +22078,7 @@ static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *i
22011 if (type_is_invalid(casted_msg->value->type))22078 if (type_is_invalid(casted_msg->value->type))
22012 return ir_unreach_error(ira);22079 return ir_unreach_error(ira);
2201322080
22014 IrInstGen *new_instruction = ir_build_panic_gen(ira, &instruction->base.base, casted_msg);22081 IrInstGen *new_instruction = ir_build_panic_gen(ira, instruction->base.scope, instruction->base.source_node, casted_msg);
22015 return ir_finish_anal(ira, new_instruction);22082 return ir_finish_anal(ira, new_instruction);
22016}22083}
2201722084
...@@ -22032,7 +22099,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig...@@ -22032,7 +22099,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig
22032 }22099 }
2203322100
22034 if (safety_check_on && !type_has_bits(ira->codegen, actual_ptr)) {22101 if (safety_check_on && !type_has_bits(ira->codegen, actual_ptr)) {
22035 ir_add_error(ira, &target->base,22102 ir_add_error(ira, target,
22036 buf_sprintf("cannot adjust alignment of zero sized type '%s'", buf_ptr(&target_type->name)));22103 buf_sprintf("cannot adjust alignment of zero sized type '%s'", buf_ptr(&target_type->name)));
22037 return ira->codegen->invalid_inst_gen;22104 return ira->codegen->invalid_inst_gen;
22038 }22105 }
...@@ -22050,7 +22117,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig...@@ -22050,7 +22117,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig
22050 if (align_bytes >= get_async_frame_align_bytes(ira->codegen)) {22117 if (align_bytes >= get_async_frame_align_bytes(ira->codegen)) {
22051 result_type = target_type;22118 result_type = target_type;
22052 } else {22119 } else {
22053 ir_add_error(ira, &target->base, buf_sprintf("sub-aligned anyframe not allowed"));22120 ir_add_error(ira, target, buf_sprintf("sub-aligned anyframe not allowed"));
22054 return ira->codegen->invalid_inst_gen;22121 return ira->codegen->invalid_inst_gen;
22055 }22122 }
22056 } else if (target_type->id == ZigTypeIdOptional &&22123 } else if (target_type->id == ZigTypeIdOptional &&
...@@ -22077,7 +22144,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig...@@ -22077,7 +22144,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig
22077 ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes);22144 ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes);
22078 result_type = get_slice_type(ira->codegen, result_ptr_type);22145 result_type = get_slice_type(ira->codegen, result_ptr_type);
22079 } else {22146 } else {
22080 ir_add_error(ira, &target->base,22147 ir_add_error(ira, target,
22081 buf_sprintf("expected pointer or slice, found '%s'", buf_ptr(&target_type->name)));22148 buf_sprintf("expected pointer or slice, found '%s'", buf_ptr(&target_type->name)));
22082 return ira->codegen->invalid_inst_gen;22149 return ira->codegen->invalid_inst_gen;
22083 }22150 }
...@@ -22090,28 +22157,28 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig...@@ -22090,28 +22157,28 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig
22090 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&22157 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
22091 val->data.x_ptr.data.hard_coded_addr.addr % align_bytes != 0)22158 val->data.x_ptr.data.hard_coded_addr.addr % align_bytes != 0)
22092 {22159 {
22093 ir_add_error(ira, &target->base,22160 ir_add_error(ira, target,
22094 buf_sprintf("pointer address 0x%" ZIG_PRI_x64 " is not aligned to %" PRIu32 " bytes",22161 buf_sprintf("pointer address 0x%" ZIG_PRI_x64 " is not aligned to %" PRIu32 " bytes",
22095 val->data.x_ptr.data.hard_coded_addr.addr, align_bytes));22162 val->data.x_ptr.data.hard_coded_addr.addr, align_bytes));
22096 return ira->codegen->invalid_inst_gen;22163 return ira->codegen->invalid_inst_gen;
22097 }22164 }
2209822165
22099 IrInstGen *result = ir_const(ira, &target->base, result_type);22166 IrInstGen *result = ir_const(ira, target->scope, target->source_node, result_type);
22100 copy_const_val(ira->codegen, result->value, val);22167 copy_const_val(ira->codegen, result->value, val);
22101 result->value->type = result_type;22168 result->value->type = result_type;
22102 return result;22169 return result;
22103 }22170 }
2210422171
22105 if (safety_check_on && align_bytes > old_align_bytes && align_bytes != 1) {22172 if (safety_check_on && align_bytes > old_align_bytes && align_bytes != 1) {
22106 return ir_build_align_cast_gen(ira, target->base.scope, target->base.source_node, target, result_type);22173 return ir_build_align_cast_gen(ira, target->scope, target->source_node, target, result_type);
22107 } else {22174 } else {
22108 return ir_build_cast(ira, &target->base, result_type, target, CastOpNoop);22175 return ir_build_cast(ira, target->scope, target->source_node, result_type, target, CastOpNoop);
22109 }22176 }
22110}22177}
2211122178
22112static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr,22179static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node,
22113 IrInst *ptr_src, ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on,22180 IrInstGen *ptr, AstNode *ptr_src, ZigType *dest_type, AstNode *dest_type_src,
22114 bool keep_bigger_alignment)22181 bool safety_check_on, bool keep_bigger_alignment)
22115{22182{
22116 Error err;22183 Error err;
2211722184
...@@ -22134,20 +22201,21 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn...@@ -22134,20 +22201,21 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2213422201
22135 ZigType *src_ptr_type = get_src_ptr_type(src_type);22202 ZigType *src_ptr_type = get_src_ptr_type(src_type);
22136 if (src_ptr_type == nullptr) {22203 if (src_ptr_type == nullptr) {
22137 ir_add_error(ira, ptr_src, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));22204 ir_add_error_node(ira, ptr_src,
22205 buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));
22138 return ira->codegen->invalid_inst_gen;22206 return ira->codegen->invalid_inst_gen;
22139 }22207 }
22140 }22208 }
2214122209
22142 ZigType *dest_ptr_type = get_src_ptr_type(dest_type);22210 ZigType *dest_ptr_type = get_src_ptr_type(dest_type);
22143 if (dest_ptr_type == nullptr) {22211 if (dest_ptr_type == nullptr) {
22144 ir_add_error(ira, dest_type_src,22212 ir_add_error_node(ira, dest_type_src,
22145 buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));22213 buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
22146 return ira->codegen->invalid_inst_gen;22214 return ira->codegen->invalid_inst_gen;
22147 }22215 }
2214822216
22149 if (get_ptr_const(ira->codegen, src_type) && !get_ptr_const(ira->codegen, dest_type)) {22217 if (get_ptr_const(ira->codegen, src_type) && !get_ptr_const(ira->codegen, dest_type)) {
22150 ir_add_error(ira, source_instr, buf_sprintf("cast discards const qualifier"));22218 ir_add_error_node(ira, source_node, buf_sprintf("cast discards const qualifier"));
22151 return ira->codegen->invalid_inst_gen;22219 return ira->codegen->invalid_inst_gen;
22152 }22220 }
22153 uint32_t dest_align_bytes;22221 uint32_t dest_align_bytes;
...@@ -22170,12 +22238,12 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn...@@ -22170,12 +22238,12 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
22170 type_has_bits(ira->codegen, dest_type) &&22238 type_has_bits(ira->codegen, dest_type) &&
22171 !type_has_bits(ira->codegen, if_slice_ptr_type))22239 !type_has_bits(ira->codegen, if_slice_ptr_type))
22172 {22240 {
22173 ErrorMsg *msg = ir_add_error(ira, source_instr,22241 ErrorMsg *msg = ir_add_error_node(ira, source_node,
22174 buf_sprintf("'%s' and '%s' do not have the same in-memory representation",22242 buf_sprintf("'%s' and '%s' do not have the same in-memory representation",
22175 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));22243 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));
22176 add_error_note(ira->codegen, msg, ptr_src->source_node,22244 add_error_note(ira->codegen, msg, ptr_src,
22177 buf_sprintf("'%s' has no in-memory bits", buf_ptr(&src_type->name)));22245 buf_sprintf("'%s' has no in-memory bits", buf_ptr(&src_type->name)));
22178 add_error_note(ira->codegen, msg, dest_type_src->source_node,22246 add_error_note(ira->codegen, msg, dest_type_src,
22179 buf_sprintf("'%s' has in-memory bits", buf_ptr(&dest_type->name)));22247 buf_sprintf("'%s' has in-memory bits", buf_ptr(&dest_type->name)));
22180 return ira->codegen->invalid_inst_gen;22248 return ira->codegen->invalid_inst_gen;
22181 }22249 }
...@@ -22183,9 +22251,9 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn...@@ -22183,9 +22251,9 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
22183 // For slices, follow the `ptr` field.22251 // For slices, follow the `ptr` field.
22184 if (is_slice(src_type)) {22252 if (is_slice(src_type)) {
22185 TypeStructField *ptr_field = src_type->data.structure.fields[slice_ptr_index];22253 TypeStructField *ptr_field = src_type->data.structure.fields[slice_ptr_index];
22186 IrInstGen *ptr_ref = ir_get_ref(ira, source_instr, ptr, true, false);22254 IrInstGen *ptr_ref = ir_get_ref(ira, scope, source_node, ptr, true, false);
22187 IrInstGen *ptr_ptr = ir_analyze_struct_field_ptr(ira, source_instr, ptr_field, ptr_ref, src_type, false);22255 IrInstGen *ptr_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, ptr_field, ptr_ref, src_type, false);
22188 ptr = ir_get_deref(ira, source_instr, ptr_ptr, nullptr);22256 ptr = ir_get_deref(ira, scope, source_node, ptr_ptr, nullptr);
22189 }22257 }
2219022258
22191 if (instr_is_comptime(ptr)) {22259 if (instr_is_comptime(ptr)) {
...@@ -22200,7 +22268,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn...@@ -22200,7 +22268,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
22200 (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&22268 (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
22201 val->data.x_ptr.data.hard_coded_addr.addr == 0);22269 val->data.x_ptr.data.hard_coded_addr.addr == 0);
22202 if (is_addr_zero && !dest_allows_addr_zero) {22270 if (is_addr_zero && !dest_allows_addr_zero) {
22203 ir_add_error(ira, source_instr,22271 ir_add_error_node(ira, source_node,
22204 buf_sprintf("null pointer casted to type '%s'", buf_ptr(&dest_type->name)));22272 buf_sprintf("null pointer casted to type '%s'", buf_ptr(&dest_type->name)));
22205 return ira->codegen->invalid_inst_gen;22273 return ira->codegen->invalid_inst_gen;
22206 }22274 }
...@@ -22208,9 +22276,9 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn...@@ -22208,9 +22276,9 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2220822276
22209 IrInstGen *result;22277 IrInstGen *result;
22210 if (val->data.x_ptr.mut == ConstPtrMutInfer) {22278 if (val->data.x_ptr.mut == ConstPtrMutInfer) {
22211 result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);22279 result = ir_build_ptr_cast_gen(ira, scope, source_node, dest_type, ptr, safety_check_on);
22212 } else {22280 } else {
22213 result = ir_const(ira, source_instr, dest_type);22281 result = ir_const(ira, scope, source_node, dest_type);
22214 }22282 }
22215 InferredStructField *isf = (val->type->id == ZigTypeIdPointer) ?22283 InferredStructField *isf = (val->type->id == ZigTypeIdPointer) ?
22216 val->type->data.pointer.inferred_struct_field : nullptr;22284 val->type->data.pointer.inferred_struct_field : nullptr;
...@@ -22243,15 +22311,15 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn...@@ -22243,15 +22311,15 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
22243 }22311 }
2224422312
22245 if (src_align_bytes != 0 && dest_align_bytes > src_align_bytes) {22313 if (src_align_bytes != 0 && dest_align_bytes > src_align_bytes) {
22246 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment"));22314 ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("cast increases pointer alignment"));
22247 add_error_note(ira->codegen, msg, ptr_src->source_node,22315 add_error_note(ira->codegen, msg, ptr_src,
22248 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_type->name), src_align_bytes));22316 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_type->name), src_align_bytes));
22249 add_error_note(ira->codegen, msg, dest_type_src->source_node,22317 add_error_note(ira->codegen, msg, dest_type_src,
22250 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_type->name), dest_align_bytes));22318 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_type->name), dest_align_bytes));
22251 return ira->codegen->invalid_inst_gen;22319 return ira->codegen->invalid_inst_gen;
22252 }22320 }
2225322321
22254 IrInstGen *casted_ptr = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);22322 IrInstGen *casted_ptr = ir_build_ptr_cast_gen(ira, scope, source_node, dest_type, ptr, safety_check_on);
2225522323
22256 // Keep the bigger alignment, it can only help- unless the target is zero bits.22324 // Keep the bigger alignment, it can only help- unless the target is zero bits.
22257 IrInstGen *result;22325 IrInstGen *result;
...@@ -22277,8 +22345,9 @@ static IrInstGen *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstSrcPtrCa...@@ -22277,8 +22345,9 @@ static IrInstGen *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstSrcPtrCa
22277 return ira->codegen->invalid_inst_gen;22345 return ira->codegen->invalid_inst_gen;
2227822346
22279 bool keep_bigger_alignment = true;22347 bool keep_bigger_alignment = true;
22280 return ir_analyze_ptr_cast(ira, &instruction->base.base, ptr, &instruction->ptr->base,22348 return ir_analyze_ptr_cast(ira, instruction->base.scope, instruction->base.source_node, ptr,
22281 dest_type, &dest_type_value->base, instruction->safety_check_on, keep_bigger_alignment);22349 instruction->ptr->source_node, dest_type, dest_type_value->source_node,
22350 instruction->safety_check_on, keep_bigger_alignment);
22282}22351}
2228322352
22284static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ZigValue *val, size_t len) {22353static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ZigValue *val, size_t len) {
...@@ -22622,19 +22691,19 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou...@@ -22622,19 +22691,19 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
22622 zig_unreachable();22691 zig_unreachable();
22623}22692}
2262422693
22625static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,22694static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value,
22626 ZigType *dest_type)22695 ZigType *dest_type)
22627{22696{
22628 Error err;22697 Error err;
2262922698
22630 ZigType *src_type = value->value->type;22699 ZigType *src_type = value->value->type;
22631 ir_assert(type_can_bit_cast(src_type), source_instr);22700 src_assert(type_can_bit_cast(src_type), source_node);
22632 ir_assert(type_can_bit_cast(dest_type), source_instr);22701 src_assert(type_can_bit_cast(dest_type), source_node);
2263322702
22634 if (dest_type->id == ZigTypeIdEnum) {22703 if (dest_type->id == ZigTypeIdEnum) {
22635 ErrorMsg *msg = ir_add_error_node(ira, source_instr->source_node,22704 ErrorMsg *msg = ir_add_error_node(ira, source_node,
22636 buf_sprintf("cannot cast a value of type '%s'", buf_ptr(&dest_type->name)));22705 buf_sprintf("cannot cast a value of type '%s'", buf_ptr(&dest_type->name)));
22637 add_error_note(ira->codegen, msg, source_instr->source_node,22706 add_error_note(ira->codegen, msg, source_node,
22638 buf_sprintf("use @intToEnum for type coercion"));22707 buf_sprintf("use @intToEnum for type coercion"));
22639 return ira->codegen->invalid_inst_gen;22708 return ira->codegen->invalid_inst_gen;
22640 }22709 }
...@@ -22651,7 +22720,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn...@@ -22651,7 +22720,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
22651 const uint64_t dest_size_bytes = type_size(ira->codegen, dest_type);22720 const uint64_t dest_size_bytes = type_size(ira->codegen, dest_type);
22652 const uint64_t src_size_bytes = type_size(ira->codegen, src_type);22721 const uint64_t src_size_bytes = type_size(ira->codegen, src_type);
22653 if (dest_size_bytes != src_size_bytes) {22722 if (dest_size_bytes != src_size_bytes) {
22654 ir_add_error(ira, source_instr,22723 ir_add_error_node(ira, source_node,
22655 buf_sprintf("destination type '%s' has size %" ZIG_PRI_u64 " but source type '%s' has size %" ZIG_PRI_u64,22724 buf_sprintf("destination type '%s' has size %" ZIG_PRI_u64 " but source type '%s' has size %" ZIG_PRI_u64,
22656 buf_ptr(&dest_type->name), dest_size_bytes,22725 buf_ptr(&dest_type->name), dest_size_bytes,
22657 buf_ptr(&src_type->name), src_size_bytes));22726 buf_ptr(&src_type->name), src_size_bytes));
...@@ -22661,7 +22730,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn...@@ -22661,7 +22730,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
22661 const uint64_t dest_size_bits = type_size_bits(ira->codegen, dest_type);22730 const uint64_t dest_size_bits = type_size_bits(ira->codegen, dest_type);
22662 const uint64_t src_size_bits = type_size_bits(ira->codegen, src_type);22731 const uint64_t src_size_bits = type_size_bits(ira->codegen, src_type);
22663 if (dest_size_bits != src_size_bits) {22732 if (dest_size_bits != src_size_bits) {
22664 ir_add_error(ira, source_instr,22733 ir_add_error_node(ira, source_node,
22665 buf_sprintf("destination type '%s' has %" ZIG_PRI_u64 " bits but source type '%s' has %" ZIG_PRI_u64 " bits",22734 buf_sprintf("destination type '%s' has %" ZIG_PRI_u64 " bits but source type '%s' has %" ZIG_PRI_u64 " bits",
22666 buf_ptr(&dest_type->name), dest_size_bits,22735 buf_ptr(&dest_type->name), dest_size_bits,
22667 buf_ptr(&src_type->name), src_size_bits));22736 buf_ptr(&src_type->name), src_size_bits));
...@@ -22673,10 +22742,10 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn...@@ -22673,10 +22742,10 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
22673 if (!val)22742 if (!val)
22674 return ira->codegen->invalid_inst_gen;22743 return ira->codegen->invalid_inst_gen;
2267522744
22676 IrInstGen *result = ir_const(ira, source_instr, dest_type);22745 IrInstGen *result = ir_const(ira, scope, source_node, dest_type);
22677 uint8_t *buf = heap::c_allocator.allocate_nonzero<uint8_t>(src_size_bytes);22746 uint8_t *buf = heap::c_allocator.allocate_nonzero<uint8_t>(src_size_bytes);
22678 buf_write_value_bytes(ira->codegen, buf, val);22747 buf_write_value_bytes(ira->codegen, buf, val);
22679 if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value)))22748 if ((err = buf_read_value_bytes(ira, ira->codegen, source_node, buf, result->value)))
22680 return ira->codegen->invalid_inst_gen;22749 return ira->codegen->invalid_inst_gen;
22681 heap::c_allocator.deallocate(buf, src_size_bytes);22750 heap::c_allocator.deallocate(buf, src_size_bytes);
22682 return result;22751 return result;
...@@ -22684,19 +22753,19 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn...@@ -22684,19 +22753,19 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2268422753
22685 if (dest_is_ptr && !src_is_ptr) {22754 if (dest_is_ptr && !src_is_ptr) {
22686 // Spill the scalar into a local memory location and take its address22755 // Spill the scalar into a local memory location and take its address
22687 value = ir_get_ref(ira, source_instr, value, false, false);22756 value = ir_get_ref(ira, scope, source_node, value, false, false);
22688 }22757 }
2268922758
22690 return ir_build_bit_cast_gen(ira, source_instr, value, dest_type);22759 return ir_build_bit_cast_gen(ira, scope, source_node, value, dest_type);
22691}22760}
2269222761
22693static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,22762static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
22694 ZigType *ptr_type)22763 ZigType *ptr_type)
22695{22764{
22696 Error err;22765 Error err;
2269722766
22698 ir_assert(get_src_ptr_type(ptr_type) != nullptr, source_instr);22767 src_assert(get_src_ptr_type(ptr_type) != nullptr, source_node);
22699 ir_assert(type_has_bits(ira->codegen, ptr_type), source_instr);22768 src_assert(type_has_bits(ira->codegen, ptr_type), source_node);
2270022769
22701 IrInstGen *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize);22770 IrInstGen *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize);
22702 if (type_is_invalid(casted_int->value->type))22771 if (type_is_invalid(casted_int->value->type))
...@@ -22709,7 +22778,7 @@ static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, Ir...@@ -22709,7 +22778,7 @@ static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, Ir
2270922778
22710 uint64_t addr = bigint_as_u64(&val->data.x_bigint);22779 uint64_t addr = bigint_as_u64(&val->data.x_bigint);
22711 if (!ptr_allows_addr_zero(ptr_type) && addr == 0) {22780 if (!ptr_allows_addr_zero(ptr_type) && addr == 0) {
22712 ir_add_error(ira, source_instr,22781 ir_add_error_node(ira, source_node,
22713 buf_sprintf("pointer type '%s' does not allow address zero", buf_ptr(&ptr_type->name)));22782 buf_sprintf("pointer type '%s' does not allow address zero", buf_ptr(&ptr_type->name)));
22714 return ira->codegen->invalid_inst_gen;22783 return ira->codegen->invalid_inst_gen;
22715 }22784 }
...@@ -22719,13 +22788,13 @@ static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, Ir...@@ -22719,13 +22788,13 @@ static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, Ir
22719 return ira->codegen->invalid_inst_gen;22788 return ira->codegen->invalid_inst_gen;
2272022789
22721 if (addr != 0 && addr % align_bytes != 0) {22790 if (addr != 0 && addr % align_bytes != 0) {
22722 ir_add_error(ira, source_instr,22791 ir_add_error_node(ira, source_node,
22723 buf_sprintf("pointer type '%s' requires aligned address",22792 buf_sprintf("pointer type '%s' requires aligned address",
22724 buf_ptr(&ptr_type->name)));22793 buf_ptr(&ptr_type->name)));
22725 return ira->codegen->invalid_inst_gen;22794 return ira->codegen->invalid_inst_gen;
22726 }22795 }
2272722796
22728 IrInstGen *result = ir_const(ira, source_instr, ptr_type);22797 IrInstGen *result = ir_const(ira, scope, source_node, ptr_type);
22729 if (ptr_type->id == ZigTypeIdOptional && addr == 0) {22798 if (ptr_type->id == ZigTypeIdOptional && addr == 0) {
22730 result->value->data.x_ptr.special = ConstPtrSpecialNull;22799 result->value->data.x_ptr.special = ConstPtrSpecialNull;
22731 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;22800 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;
...@@ -22738,7 +22807,7 @@ static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, Ir...@@ -22738,7 +22807,7 @@ static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, Ir
22738 return result;22807 return result;
22739 }22808 }
2274022809
22741 return ir_build_int_to_ptr_gen(ira, source_instr->scope, source_instr->source_node, casted_int, ptr_type);22810 return ir_build_int_to_ptr_gen(ira, scope, source_node, casted_int, ptr_type);
22742}22811}
2274322812
22744static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcIntToPtr *instruction) {22813static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcIntToPtr *instruction) {
...@@ -22750,7 +22819,7 @@ static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcInt...@@ -22750,7 +22819,7 @@ static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcInt
2275022819
22751 // We explicitly check for the size, so we can use get_src_ptr_type22820 // We explicitly check for the size, so we can use get_src_ptr_type
22752 if (get_src_ptr_type(dest_type) == nullptr) {22821 if (get_src_ptr_type(dest_type) == nullptr) {
22753 ir_add_error(ira, &dest_type_value->base, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));22822 ir_add_error(ira, dest_type_value, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
22754 return ira->codegen->invalid_inst_gen;22823 return ira->codegen->invalid_inst_gen;
22755 }22824 }
2275622825
...@@ -22759,7 +22828,7 @@ static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcInt...@@ -22759,7 +22828,7 @@ static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcInt
22759 return ira->codegen->invalid_inst_gen;22828 return ira->codegen->invalid_inst_gen;
2276022829
22761 if (!has_bits) {22830 if (!has_bits) {
22762 ir_add_error(ira, &dest_type_value->base,22831 ir_add_error(ira, dest_type_value,
22763 buf_sprintf("type '%s' has 0 bits and cannot store information", buf_ptr(&dest_type->name)));22832 buf_sprintf("type '%s' has 0 bits and cannot store information", buf_ptr(&dest_type->name)));
22764 return ira->codegen->invalid_inst_gen;22833 return ira->codegen->invalid_inst_gen;
22765 }22834 }
...@@ -22768,11 +22837,11 @@ static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcInt...@@ -22768,11 +22837,11 @@ static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcInt
22768 if (type_is_invalid(target->value->type))22837 if (type_is_invalid(target->value->type))
22769 return ira->codegen->invalid_inst_gen;22838 return ira->codegen->invalid_inst_gen;
2277022839
22771 return ir_analyze_int_to_ptr(ira, &instruction->base.base, target, dest_type);22840 return ir_analyze_int_to_ptr(ira, instruction->base.scope, instruction->base.source_node, target, dest_type);
22772}22841}
2277322842
22774static IrInstGen *ir_analyze_instruction_decl_ref(IrAnalyze *ira, IrInstSrcDeclRef *instruction) {22843static IrInstGen *ir_analyze_instruction_decl_ref(IrAnalyze *ira, IrInstSrcDeclRef *instruction) {
22775 IrInstGen *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base.base, instruction->tld);22844 IrInstGen *ref_instruction = ir_analyze_decl_ref(ira, instruction->base.scope, instruction->base.source_node, instruction->tld);
22776 if (type_is_invalid(ref_instruction->value->type)) {22845 if (type_is_invalid(ref_instruction->value->type)) {
22777 return ira->codegen->invalid_inst_gen;22846 return ira->codegen->invalid_inst_gen;
22778 }22847 }
...@@ -22780,7 +22849,7 @@ static IrInstGen *ir_analyze_instruction_decl_ref(IrAnalyze *ira, IrInstSrcDeclR...@@ -22780,7 +22849,7 @@ static IrInstGen *ir_analyze_instruction_decl_ref(IrAnalyze *ira, IrInstSrcDeclR
22780 if (instruction->lval == LValPtr || instruction->lval == LValAssign) {22849 if (instruction->lval == LValPtr || instruction->lval == LValAssign) {
22781 return ref_instruction;22850 return ref_instruction;
22782 } else {22851 } else {
22783 return ir_get_deref(ira, &instruction->base.base, ref_instruction, nullptr);22852 return ir_get_deref(ira, instruction->base.scope, instruction->base.source_node, ref_instruction, nullptr);
22784 }22853 }
22785}22854}
2278622855
...@@ -22794,7 +22863,7 @@ static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtr...@@ -22794,7 +22863,7 @@ static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtr
2279422863
22795 ZigType *src_ptr_type = get_src_ptr_type(target->value->type);22864 ZigType *src_ptr_type = get_src_ptr_type(target->value->type);
22796 if (src_ptr_type == nullptr) {22865 if (src_ptr_type == nullptr) {
22797 ir_add_error(ira, &target->base,22866 ir_add_error(ira, target,
22798 buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value->type->name)));22867 buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value->type->name)));
22799 return ira->codegen->invalid_inst_gen;22868 return ira->codegen->invalid_inst_gen;
22800 }22869 }
...@@ -22804,7 +22873,7 @@ static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtr...@@ -22804,7 +22873,7 @@ static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtr
22804 return ira->codegen->invalid_inst_gen;22873 return ira->codegen->invalid_inst_gen;
2280522874
22806 if (!has_bits) {22875 if (!has_bits) {
22807 ir_add_error(ira, &target->base,22876 ir_add_error(ira, target,
22808 buf_sprintf("pointer to size 0 type has no address"));22877 buf_sprintf("pointer to size 0 type has no address"));
22809 return ira->codegen->invalid_inst_gen;22878 return ira->codegen->invalid_inst_gen;
22810 }22879 }
...@@ -22817,25 +22886,25 @@ static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtr...@@ -22817,25 +22886,25 @@ static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtr
22817 // Since we've already run this type trough get_src_ptr_type it is22886 // Since we've already run this type trough get_src_ptr_type it is
22818 // safe to access the x_ptr fields22887 // safe to access the x_ptr fields
22819 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {22888 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
22820 IrInstGen *result = ir_const(ira, &instruction->base.base, usize);22889 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, usize);
22821 bigint_init_unsigned(&result->value->data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr);22890 bigint_init_unsigned(&result->value->data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr);
22822 result->value->type = usize;22891 result->value->type = usize;
22823 return result;22892 return result;
22824 } else if (val->data.x_ptr.special == ConstPtrSpecialNull) {22893 } else if (val->data.x_ptr.special == ConstPtrSpecialNull) {
22825 IrInstGen *result = ir_const(ira, &instruction->base.base, usize);22894 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, usize);
22826 bigint_init_unsigned(&result->value->data.x_bigint, 0);22895 bigint_init_unsigned(&result->value->data.x_bigint, 0);
22827 result->value->type = usize;22896 result->value->type = usize;
22828 return result;22897 return result;
22829 }22898 }
22830 }22899 }
2283122900
22832 return ir_build_ptr_to_int_gen(ira, &instruction->base.base, target);22901 return ir_build_ptr_to_int_gen(ira, instruction->base.scope, instruction->base.source_node, target);
22833}22902}
2283422903
22835static IrInstGen *ir_analyze_instruction_ptr_type_simple(IrAnalyze *ira,22904static IrInstGen *ir_analyze_instruction_ptr_type_simple(IrAnalyze *ira,
22836 IrInstSrcPtrTypeSimple *instruction, bool is_const)22905 IrInstSrcPtrTypeSimple *instruction, bool is_const)
22837{22906{
22838 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);22907 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_type);
22839 result->value->special = ConstValSpecialLazy;22908 result->value->special = ConstValSpecialLazy;
2284022909
22841 LazyValuePtrTypeSimple *lazy_ptr_type = heap::c_allocator.create<LazyValuePtrTypeSimple>();22910 LazyValuePtrTypeSimple *lazy_ptr_type = heap::c_allocator.create<LazyValuePtrTypeSimple>();
...@@ -22851,7 +22920,7 @@ static IrInstGen *ir_analyze_instruction_ptr_type_simple(IrAnalyze *ira,...@@ -22851,7 +22920,7 @@ static IrInstGen *ir_analyze_instruction_ptr_type_simple(IrAnalyze *ira,
22851}22920}
2285222921
22853static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrType *instruction) {22922static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrType *instruction) {
22854 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);22923 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_type);
22855 result->value->special = ConstValSpecialLazy;22924 result->value->special = ConstValSpecialLazy;
2285622925
22857 LazyValuePtrType *lazy_ptr_type = heap::c_allocator.create<LazyValuePtrType>();22926 LazyValuePtrType *lazy_ptr_type = heap::c_allocator.create<LazyValuePtrType>();
...@@ -22861,7 +22930,7 @@ static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrTy...@@ -22861,7 +22930,7 @@ static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrTy
2286122930
22862 if (instruction->sentinel != nullptr) {22931 if (instruction->sentinel != nullptr) {
22863 if (instruction->ptr_len != PtrLenUnknown) {22932 if (instruction->ptr_len != PtrLenUnknown) {
22864 ir_add_error(ira, &instruction->base.base,22933 ir_add_error_node(ira, instruction->base.source_node,
22865 buf_sprintf("sentinels are only allowed on unknown-length pointers"));22934 buf_sprintf("sentinels are only allowed on unknown-length pointers"));
22866 return ira->codegen->invalid_inst_gen;22935 return ira->codegen->invalid_inst_gen;
22867 }22936 }
...@@ -22923,36 +22992,36 @@ static IrInstGen *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstS...@@ -22923,36 +22992,36 @@ static IrInstGen *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstS
22923 return ira->codegen->invalid_inst_gen;22992 return ira->codegen->invalid_inst_gen;
2292422993
22925 if (align_bytes > 256) {22994 if (align_bytes > 256) {
22926 ir_add_error(ira, &instruction->base.base, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes));22995 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes));
22927 return ira->codegen->invalid_inst_gen;22996 return ira->codegen->invalid_inst_gen;
22928 }22997 }
2292922998
22930 ZigFn *fn_entry = ira->fn;22999 ZigFn *fn_entry = ira->fn;
22931 if (fn_entry == nullptr) {23000 if (fn_entry == nullptr) {
22932 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack outside function"));23001 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("@setAlignStack outside function"));
22933 return ira->codegen->invalid_inst_gen;23002 return ira->codegen->invalid_inst_gen;
22934 }23003 }
22935 if (fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionNaked) {23004 if (fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionNaked) {
22936 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack in naked function"));23005 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("@setAlignStack in naked function"));
22937 return ira->codegen->invalid_inst_gen;23006 return ira->codegen->invalid_inst_gen;
22938 }23007 }
2293923008
22940 if (fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionInline) {23009 if (fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionInline) {
22941 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack in inline function"));23010 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("@setAlignStack in inline function"));
22942 return ira->codegen->invalid_inst_gen;23011 return ira->codegen->invalid_inst_gen;
22943 }23012 }
2294423013
22945 if (fn_entry->set_alignstack_node != nullptr) {23014 if (fn_entry->set_alignstack_node != nullptr) {
22946 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,23015 ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node,
22947 buf_sprintf("alignstack set twice"));23016 buf_sprintf("alignstack set twice"));
22948 add_error_note(ira->codegen, msg, fn_entry->set_alignstack_node, buf_sprintf("first set here"));23017 add_error_note(ira->codegen, msg, fn_entry->set_alignstack_node, buf_sprintf("first set here"));
22949 return ira->codegen->invalid_inst_gen;23018 return ira->codegen->invalid_inst_gen;
22950 }23019 }
2295123020
22952 fn_entry->set_alignstack_node = instruction->base.base.source_node;23021 fn_entry->set_alignstack_node = instruction->base.source_node;
22953 fn_entry->alignstack_value = align_bytes;23022 fn_entry->alignstack_value = align_bytes;
2295423023
22955 return ir_const_void(ira, &instruction->base.base);23024 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
22956}23025}
2295723026
22958static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgType *instruction,23027static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgType *instruction,
...@@ -22973,7 +23042,7 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy...@@ -22973,7 +23042,7 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy
22973 arg_index += 1;23042 arg_index += 1;
22974 }23043 }
22975 if (fn_type->id != ZigTypeIdFn) {23044 if (fn_type->id != ZigTypeIdFn) {
22976 ir_add_error(ira, &fn_type_inst->base, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));23045 ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));
22977 return ira->codegen->invalid_inst_gen;23046 return ira->codegen->invalid_inst_gen;
22978 }23047 }
2297923048
...@@ -22981,9 +23050,9 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy...@@ -22981,9 +23050,9 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy
22981 if (arg_index >= fn_type_id->param_count) {23050 if (arg_index >= fn_type_id->param_count) {
22982 if (allow_var) {23051 if (allow_var) {
22983 // TODO remove this with var args23052 // TODO remove this with var args
22984 return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_anytype);23053 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_anytype);
22985 }23054 }
22986 ir_add_error(ira, &arg_index_inst->base,23055 ir_add_error(ira, arg_index_inst,
22987 buf_sprintf("arg index %" ZIG_PRI_u64 " out of bounds; '%s' has %" ZIG_PRI_usize " argument(s)",23056 buf_sprintf("arg index %" ZIG_PRI_u64 " out of bounds; '%s' has %" ZIG_PRI_usize " argument(s)",
22988 arg_index, buf_ptr(&fn_type->name), fn_type_id->param_count));23057 arg_index, buf_ptr(&fn_type->name), fn_type_id->param_count));
22989 return ira->codegen->invalid_inst_gen;23058 return ira->codegen->invalid_inst_gen;
...@@ -22992,18 +23061,18 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy...@@ -22992,18 +23061,18 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy
22992 ZigType *result_type = fn_type_id->param_info[arg_index].type;23061 ZigType *result_type = fn_type_id->param_info[arg_index].type;
22993 if (result_type == nullptr) {23062 if (result_type == nullptr) {
22994 // Args are only unresolved if our function is generic.23063 // Args are only unresolved if our function is generic.
22995 ir_assert(fn_type->data.fn.is_generic, &instruction->base.base);23064 src_assert(fn_type->data.fn.is_generic, instruction->base.source_node);
2299623065
22997 if (allow_var) {23066 if (allow_var) {
22998 return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_anytype);23067 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_anytype);
22999 } else {23068 } else {
23000 ir_add_error(ira, &arg_index_inst->base,23069 ir_add_error(ira, arg_index_inst,
23001 buf_sprintf("@ArgType could not resolve the type of arg %" ZIG_PRI_u64 " because '%s' is generic",23070 buf_sprintf("@ArgType could not resolve the type of arg %" ZIG_PRI_u64 " because '%s' is generic",
23002 arg_index, buf_ptr(&fn_type->name)));23071 arg_index, buf_ptr(&fn_type->name)));
23003 return ira->codegen->invalid_inst_gen;23072 return ira->codegen->invalid_inst_gen;
23004 }23073 }
23005 }23074 }
23006 return ir_const_type(ira, &instruction->base.base, result_type);23075 return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, result_type);
23007}23076}
2300823077
23009static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {23078static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {
...@@ -23022,7 +23091,7 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {...@@ -23022,7 +23091,7 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {
23022 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);23091 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);
2302323092
23024 if (bit_count > max_atomic_bits) {23093 if (bit_count > max_atomic_bits) {
23025 ir_add_error(ira, &op->base,23094 ir_add_error(ira, op,
23026 buf_sprintf("expected %" PRIu32 "-bit integer type or smaller, found %" PRIu32 "-bit integer type",23095 buf_sprintf("expected %" PRIu32 "-bit integer type or smaller, found %" PRIu32 "-bit integer type",
23027 max_atomic_bits, bit_count));23096 max_atomic_bits, bit_count));
23028 return ira->codegen->builtin_types.entry_invalid;23097 return ira->codegen->builtin_types.entry_invalid;
...@@ -23030,7 +23099,7 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {...@@ -23030,7 +23099,7 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {
23030 } else if (operand_type->id == ZigTypeIdFloat) {23099 } else if (operand_type->id == ZigTypeIdFloat) {
23031 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);23100 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);
23032 if (operand_type->data.floating.bit_count > max_atomic_bits) {23101 if (operand_type->data.floating.bit_count > max_atomic_bits) {
23033 ir_add_error(ira, &op->base,23102 ir_add_error(ira, op,
23034 buf_sprintf("expected %" PRIu32 "-bit float or smaller, found %" PRIu32 "-bit float",23103 buf_sprintf("expected %" PRIu32 "-bit float or smaller, found %" PRIu32 "-bit float",
23035 max_atomic_bits, (uint32_t) operand_type->data.floating.bit_count));23104 max_atomic_bits, (uint32_t) operand_type->data.floating.bit_count));
23036 return ira->codegen->builtin_types.entry_invalid;23105 return ira->codegen->builtin_types.entry_invalid;
...@@ -23043,7 +23112,7 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {...@@ -23043,7 +23112,7 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {
23043 if ((err = get_codegen_ptr_type(ira->codegen, operand_type, &operand_ptr_type)))23112 if ((err = get_codegen_ptr_type(ira->codegen, operand_type, &operand_ptr_type)))
23044 return ira->codegen->builtin_types.entry_invalid;23113 return ira->codegen->builtin_types.entry_invalid;
23045 if (operand_ptr_type == nullptr) {23114 if (operand_ptr_type == nullptr) {
23046 ir_add_error(ira, &op->base,23115 ir_add_error(ira, op,
23047 buf_sprintf("expected bool, integer, float, enum or pointer type, found '%s'",23116 buf_sprintf("expected bool, integer, float, enum or pointer type, found '%s'",
23048 buf_ptr(&operand_type->name)));23117 buf_ptr(&operand_type->name)));
23049 return ira->codegen->builtin_types.entry_invalid;23118 return ira->codegen->builtin_types.entry_invalid;
...@@ -23074,15 +23143,15 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto...@@ -23074,15 +23143,15 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto
23074 }23143 }
2307523144
23076 if (operand_type->id == ZigTypeIdEnum && op != AtomicRmwOp_xchg) {23145 if (operand_type->id == ZigTypeIdEnum && op != AtomicRmwOp_xchg) {
23077 ir_add_error(ira, &instruction->op->base,23146 ir_add_error_node(ira, instruction->op->source_node,
23078 buf_sprintf("@atomicRmw with enum only allowed with .Xchg"));23147 buf_sprintf("@atomicRmw with enum only allowed with .Xchg"));
23079 return ira->codegen->invalid_inst_gen;23148 return ira->codegen->invalid_inst_gen;
23080 } else if (operand_type->id == ZigTypeIdBool && op != AtomicRmwOp_xchg) {23149 } else if (operand_type->id == ZigTypeIdBool && op != AtomicRmwOp_xchg) {
23081 ir_add_error(ira, &instruction->op->base,23150 ir_add_error_node(ira, instruction->op->source_node,
23082 buf_sprintf("@atomicRmw with bool only allowed with .Xchg"));23151 buf_sprintf("@atomicRmw with bool only allowed with .Xchg"));
23083 return ira->codegen->invalid_inst_gen;23152 return ira->codegen->invalid_inst_gen;
23084 } else if (operand_type->id == ZigTypeIdFloat && op > AtomicRmwOp_sub) {23153 } else if (operand_type->id == ZigTypeIdFloat && op > AtomicRmwOp_sub) {
23085 ir_add_error(ira, &instruction->op->base,23154 ir_add_error_node(ira, instruction->op->source_node,
23086 buf_sprintf("@atomicRmw with float only allowed with .Xchg, .Add and .Sub"));23155 buf_sprintf("@atomicRmw with float only allowed with .Xchg, .Add and .Sub"));
23087 return ira->codegen->invalid_inst_gen;23156 return ira->codegen->invalid_inst_gen;
23088 }23157 }
...@@ -23099,7 +23168,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto...@@ -23099,7 +23168,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto
23099 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))23168 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
23100 return ira->codegen->invalid_inst_gen;23169 return ira->codegen->invalid_inst_gen;
23101 if (ordering == AtomicOrderUnordered) {23170 if (ordering == AtomicOrderUnordered) {
23102 ir_add_error(ira, &instruction->ordering->base,23171 ir_add_error_node(ira, instruction->ordering->source_node,
23103 buf_sprintf("@atomicRmw atomic ordering must not be Unordered"));23172 buf_sprintf("@atomicRmw atomic ordering must not be Unordered"));
23104 return ira->codegen->invalid_inst_gen;23173 return ira->codegen->invalid_inst_gen;
23105 }23174 }
...@@ -23109,18 +23178,19 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto...@@ -23109,18 +23178,19 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto
23109 case OnePossibleValueInvalid:23178 case OnePossibleValueInvalid:
23110 return ira->codegen->invalid_inst_gen;23179 return ira->codegen->invalid_inst_gen;
23111 case OnePossibleValueYes:23180 case OnePossibleValueYes:
23112 return ir_const_move(ira, &instruction->base.base, get_the_one_possible_value(ira->codegen, operand_type));23181 return ir_const_move(ira, instruction->base.scope, instruction->base.source_node, get_the_one_possible_value(ira->codegen, operand_type));
23113 case OnePossibleValueNo:23182 case OnePossibleValueNo:
23114 break;23183 break;
23115 }23184 }
2311623185
23117 IrInst *source_inst = &instruction->base.base;23186 Scope *scope = instruction->base.scope;
23187 AstNode *source_node = instruction->base.source_node;
23118 if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar) {23188 if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar) {
23119 ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad);23189 ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad);
23120 if (ptr_val == nullptr)23190 if (ptr_val == nullptr)
23121 return ira->codegen->invalid_inst_gen;23191 return ira->codegen->invalid_inst_gen;
2312223192
23123 ZigValue *op1_val = const_ptr_pointee(ira, ira->codegen, ptr_val, instruction->base.base.source_node);23193 ZigValue *op1_val = const_ptr_pointee(ira, ira->codegen, ptr_val, instruction->base.source_node);
23124 if (op1_val == nullptr)23194 if (op1_val == nullptr)
23125 return ira->codegen->invalid_inst_gen;23195 return ira->codegen->invalid_inst_gen;
2312623196
...@@ -23128,7 +23198,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto...@@ -23128,7 +23198,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto
23128 if (op2_val == nullptr)23198 if (op2_val == nullptr)
23129 return ira->codegen->invalid_inst_gen;23199 return ira->codegen->invalid_inst_gen;
2313023200
23131 IrInstGen *result = ir_const(ira, source_inst, operand_type);23201 IrInstGen *result = ir_const(ira, scope, source_node, operand_type);
23132 copy_const_val(ira->codegen, result->value, op1_val);23202 copy_const_val(ira->codegen, result->value, op1_val);
23133 if (op == AtomicRmwOp_xchg) {23203 if (op == AtomicRmwOp_xchg) {
23134 copy_const_val(ira->codegen, op1_val, op2_val);23204 copy_const_val(ira->codegen, op1_val, op2_val);
...@@ -23136,7 +23206,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto...@@ -23136,7 +23206,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto
23136 }23206 }
2313723207
23138 if (operand_type->id == ZigTypeIdPointer || operand_type->id == ZigTypeIdOptional) {23208 if (operand_type->id == ZigTypeIdPointer || operand_type->id == ZigTypeIdOptional) {
23139 ir_add_error(ira, &instruction->ordering->base,23209 ir_add_error_node(ira, instruction->ordering->source_node,
23140 buf_sprintf("TODO comptime @atomicRmw with pointers other than .Xchg"));23210 buf_sprintf("TODO comptime @atomicRmw with pointers other than .Xchg"));
23141 return ira->codegen->invalid_inst_gen;23211 return ira->codegen->invalid_inst_gen;
23142 }23212 }
...@@ -23151,8 +23221,8 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto...@@ -23151,8 +23221,8 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto
23151 // store op2 if op2 > op123221 // store op2 if op2 > op1
23152 bin_op = IrBinOpCmpLessThan;23222 bin_op = IrBinOpCmpLessThan;
2315323223
23154 IrInstGen *dummy_value = ir_const(ira, source_inst, operand_type);23224 IrInstGen *dummy_value = ir_const(ira, scope, source_node, operand_type);
23155 msg = ir_eval_bin_op_cmp_scalar(ira, source_inst, op1_val, bin_op, op2_val, dummy_value->value);23225 msg = ir_eval_bin_op_cmp_scalar(ira, scope, source_node, op1_val, bin_op, op2_val, dummy_value->value);
23156 if (msg != nullptr) {23226 if (msg != nullptr) {
23157 return ira->codegen->invalid_inst_gen;23227 return ira->codegen->invalid_inst_gen;
23158 }23228 }
...@@ -23188,7 +23258,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto...@@ -23188,7 +23258,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto
23188 bin_op = IrBinOpBinXor;23258 bin_op = IrBinOpBinXor;
23189 break;23259 break;
23190 }23260 }
23191 msg = ir_eval_math_op_scalar(ira, source_inst, operand_type, op1_val, bin_op, op2_val, op1_val);23261 msg = ir_eval_math_op_scalar(ira, scope, source_node, operand_type, op1_val, bin_op, op2_val, op1_val);
23192 if (msg != nullptr) {23262 if (msg != nullptr) {
23193 return ira->codegen->invalid_inst_gen;23263 return ira->codegen->invalid_inst_gen;
23194 }23264 }
...@@ -23200,7 +23270,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto...@@ -23200,7 +23270,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto
23200 return result;23270 return result;
23201 }23271 }
2320223272
23203 return ir_build_atomic_rmw_gen(ira, source_inst, casted_ptr, casted_operand, op,23273 return ir_build_atomic_rmw_gen(ira, scope, source_node, casted_ptr, casted_operand, op,
23204 ordering, operand_type);23274 ordering, operand_type);
23205}23275}
2320623276
...@@ -23223,19 +23293,20 @@ static IrInstGen *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstSrcAt...@@ -23223,19 +23293,20 @@ static IrInstGen *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstSrcAt
23223 return ira->codegen->invalid_inst_gen;23293 return ira->codegen->invalid_inst_gen;
2322423294
23225 if (ordering == AtomicOrderRelease || ordering == AtomicOrderAcqRel) {23295 if (ordering == AtomicOrderRelease || ordering == AtomicOrderAcqRel) {
23226 ir_assert(instruction->ordering != nullptr, &instruction->base.base);23296 src_assert(instruction->ordering != nullptr, instruction->base.source_node);
23227 ir_add_error(ira, &instruction->ordering->base,23297 ir_add_error_node(ira, instruction->ordering->source_node,
23228 buf_sprintf("@atomicLoad atomic ordering must not be Release or AcqRel"));23298 buf_sprintf("@atomicLoad atomic ordering must not be Release or AcqRel"));
23229 return ira->codegen->invalid_inst_gen;23299 return ira->codegen->invalid_inst_gen;
23230 }23300 }
2323123301
23232 if (instr_is_comptime(casted_ptr)) {23302 if (instr_is_comptime(casted_ptr)) {
23233 IrInstGen *result = ir_get_deref(ira, &instruction->base.base, casted_ptr, nullptr);23303 IrInstGen *result = ir_get_deref(ira, instruction->base.scope,
23234 ir_assert(result->value->type != nullptr, &instruction->base.base);23304 instruction->base.source_node, casted_ptr, nullptr);
23305 src_assert(result->value->type != nullptr, instruction->base.source_node);
23235 return result;23306 return result;
23236 }23307 }
2323723308
23238 return ir_build_atomic_load_gen(ira, &instruction->base.base, casted_ptr, ordering, operand_type);23309 return ir_build_atomic_load_gen(ira, instruction->base.scope, instruction->base.source_node, casted_ptr, ordering, operand_type);
23239}23310}
2324023311
23241static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcAtomicStore *instruction) {23312static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcAtomicStore *instruction) {
...@@ -23266,8 +23337,8 @@ static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcA...@@ -23266,8 +23337,8 @@ static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcA
23266 return ira->codegen->invalid_inst_gen;23337 return ira->codegen->invalid_inst_gen;
2326723338
23268 if (ordering == AtomicOrderAcquire || ordering == AtomicOrderAcqRel) {23339 if (ordering == AtomicOrderAcquire || ordering == AtomicOrderAcqRel) {
23269 ir_assert(instruction->ordering != nullptr, &instruction->base.base);23340 src_assert(instruction->ordering != nullptr, instruction->base.source_node);
23270 ir_add_error(ira, &instruction->ordering->base,23341 ir_add_error_node(ira, instruction->ordering->source_node,
23271 buf_sprintf("@atomicStore atomic ordering must not be Acquire or AcqRel"));23342 buf_sprintf("@atomicStore atomic ordering must not be Acquire or AcqRel"));
23272 return ira->codegen->invalid_inst_gen;23343 return ira->codegen->invalid_inst_gen;
23273 }23344 }
...@@ -23277,28 +23348,28 @@ static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcA...@@ -23277,28 +23348,28 @@ static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcA
23277 case OnePossibleValueInvalid:23348 case OnePossibleValueInvalid:
23278 return ira->codegen->invalid_inst_gen;23349 return ira->codegen->invalid_inst_gen;
23279 case OnePossibleValueYes:23350 case OnePossibleValueYes:
23280 return ir_const_void(ira, &instruction->base.base);23351 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
23281 case OnePossibleValueNo:23352 case OnePossibleValueNo:
23282 break;23353 break;
23283 }23354 }
2328423355
23285 if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) {23356 if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) {
23286 IrInstGen *result = ir_analyze_store_ptr(ira, &instruction->base.base, casted_ptr, value, false);23357 IrInstGen *result = ir_analyze_store_ptr(ira, instruction->base.scope, instruction->base.source_node, casted_ptr, value, false);
23287 result->value->type = ira->codegen->builtin_types.entry_void;23358 result->value->type = ira->codegen->builtin_types.entry_void;
23288 return result;23359 return result;
23289 }23360 }
2329023361
23291 return ir_build_atomic_store_gen(ira, &instruction->base.base, casted_ptr, casted_value, ordering);23362 return ir_build_atomic_store_gen(ira, instruction->base.scope, instruction->base.source_node, casted_ptr, casted_value, ordering);
23292}23363}
2329323364
23294static IrInstGen *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstSrcSaveErrRetAddr *instruction) {23365static IrInstGen *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstSrcSaveErrRetAddr *instruction) {
23295 return ir_build_save_err_ret_addr_gen(ira, &instruction->base.base);23366 return ir_build_save_err_ret_addr_gen(ira, instruction->base.scope, instruction->base.source_node);
23296}23367}
2329723368
23298static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInst* source_instr, BuiltinFnId fop, ZigType *float_type,23369static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, Scope *scope, AstNode *source_node, BuiltinFnId fop, ZigType *float_type,
23299 ZigValue *op, ZigValue *out_val)23370 ZigValue *op, ZigValue *out_val)
23300{23371{
23301 assert(ira && source_instr && float_type && out_val && op);23372 assert(ira && source_node && float_type && out_val && op);
23302 assert(float_type->id == ZigTypeIdFloat ||23373 assert(float_type->id == ZigTypeIdFloat ||
23303 float_type->id == ZigTypeIdComptimeFloat);23374 float_type->id == ZigTypeIdComptimeFloat);
2330423375
...@@ -23464,7 +23535,7 @@ static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInst* source_instr, BuiltinF...@@ -23464,7 +23535,7 @@ static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInst* source_instr, BuiltinF
23464 break;23535 break;
23465 }23536 }
23466 case 80:23537 case 80:
23467 return ir_add_error(ira, source_instr,23538 return ir_add_error_node(ira, source_node,
23468 buf_sprintf("compiler bug: TODO: implement '%s' for type '%s'. See https://github.com/ziglang/zig/issues/4026",23539 buf_sprintf("compiler bug: TODO: implement '%s' for type '%s'. See https://github.com/ziglang/zig/issues/4026",
23469 float_op_to_name(fop), buf_ptr(&float_type->name)));23540 float_op_to_name(fop), buf_ptr(&float_type->name)));
23470 case 128: {23541 case 128: {
...@@ -23503,7 +23574,7 @@ static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInst* source_instr, BuiltinF...@@ -23503,7 +23574,7 @@ static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInst* source_instr, BuiltinF
23503 case BuiltinFnIdLog:23574 case BuiltinFnIdLog:
23504 case BuiltinFnIdLog10:23575 case BuiltinFnIdLog10:
23505 case BuiltinFnIdLog2:23576 case BuiltinFnIdLog2:
23506 return ir_add_error(ira, source_instr,23577 return ir_add_error_node(ira, source_node,
23507 buf_sprintf("compiler bug: TODO: implement '%s' for type '%s'. See https://github.com/ziglang/zig/issues/4026",23578 buf_sprintf("compiler bug: TODO: implement '%s' for type '%s'. See https://github.com/ziglang/zig/issues/4026",
23508 float_op_to_name(fop), buf_ptr(&float_type->name)));23579 float_op_to_name(fop), buf_ptr(&float_type->name)));
23509 default:23580 default:
...@@ -23529,7 +23600,7 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat...@@ -23529,7 +23600,7 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat
23529 operand_type->data.vector.elem_type : operand_type;23600 operand_type->data.vector.elem_type : operand_type;
2353023601
23531 if (scalar_type->id != ZigTypeIdFloat && scalar_type->id != ZigTypeIdComptimeFloat) {23602 if (scalar_type->id != ZigTypeIdFloat && scalar_type->id != ZigTypeIdComptimeFloat) {
23532 ir_add_error(ira, &operand->base,23603 ir_add_error(ira, operand,
23533 buf_sprintf("expected float type, found '%s'", buf_ptr(&scalar_type->name)));23604 buf_sprintf("expected float type, found '%s'", buf_ptr(&scalar_type->name)));
23534 return ira->codegen->invalid_inst_gen;23605 return ira->codegen->invalid_inst_gen;
23535 }23606 }
...@@ -23539,9 +23610,9 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat...@@ -23539,9 +23610,9 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat
23539 if (operand_val == nullptr)23610 if (operand_val == nullptr)
23540 return ira->codegen->invalid_inst_gen;23611 return ira->codegen->invalid_inst_gen;
23541 if (operand_val->special == ConstValSpecialUndef)23612 if (operand_val->special == ConstValSpecialUndef)
23542 return ir_const_undef(ira, &instruction->base.base, operand_type);23613 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, operand_type);
2354323614
23544 IrInstGen *result = ir_const(ira, &instruction->base.base, operand_type);23615 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, operand_type);
23545 ZigValue *out_val = result->value;23616 ZigValue *out_val = result->value;
2354623617
23547 if (operand_type->id == ZigTypeIdVector) {23618 if (operand_type->id == ZigTypeIdVector) {
...@@ -23552,12 +23623,12 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat...@@ -23552,12 +23623,12 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat
23552 for (size_t i = 0; i < len; i += 1) {23623 for (size_t i = 0; i < len; i += 1) {
23553 ZigValue *elem_operand = &operand_val->data.x_array.data.s_none.elements[i];23624 ZigValue *elem_operand = &operand_val->data.x_array.data.s_none.elements[i];
23554 ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i];23625 ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i];
23555 ir_assert(elem_operand->type == scalar_type, &instruction->base.base);23626 src_assert(elem_operand->type == scalar_type, instruction->base.source_node);
23556 ir_assert(float_out_val->type == scalar_type, &instruction->base.base);23627 src_assert(float_out_val->type == scalar_type, instruction->base.source_node);
23557 ErrorMsg *msg = ir_eval_float_op(ira, &instruction->base.base, instruction->fn_id, scalar_type,23628 ErrorMsg *msg = ir_eval_float_op(ira, instruction->base.scope, instruction->base.source_node, instruction->fn_id, scalar_type,
23558 elem_operand, float_out_val);23629 elem_operand, float_out_val);
23559 if (msg != nullptr) {23630 if (msg != nullptr) {
23560 add_error_note(ira->codegen, msg, instruction->base.base.source_node,23631 add_error_note(ira->codegen, msg, instruction->base.source_node,
23561 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));23632 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
23562 return ira->codegen->invalid_inst_gen;23633 return ira->codegen->invalid_inst_gen;
23563 }23634 }
...@@ -23566,7 +23637,7 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat...@@ -23566,7 +23637,7 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat
23566 out_val->type = operand_type;23637 out_val->type = operand_type;
23567 out_val->special = ConstValSpecialStatic;23638 out_val->special = ConstValSpecialStatic;
23568 } else {23639 } else {
23569 if (ir_eval_float_op(ira, &instruction->base.base, instruction->fn_id, scalar_type,23640 if (ir_eval_float_op(ira, instruction->base.scope, instruction->base.source_node, instruction->fn_id, scalar_type,
23570 operand_val, out_val) != nullptr)23641 operand_val, out_val) != nullptr)
23571 {23642 {
23572 return ira->codegen->invalid_inst_gen;23643 return ira->codegen->invalid_inst_gen;
...@@ -23575,9 +23646,9 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat...@@ -23575,9 +23646,9 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat
23575 return result;23646 return result;
23576 }23647 }
2357723648
23578 ir_assert(scalar_type->id == ZigTypeIdFloat, &instruction->base.base);23649 src_assert(scalar_type->id == ZigTypeIdFloat, instruction->base.source_node);
2357923650
23580 return ir_build_float_op_gen(ira, &instruction->base.base, operand, instruction->fn_id, operand_type);23651 return ir_build_float_op_gen(ira, instruction->base.scope, instruction->base.source_node, operand, instruction->fn_id, operand_type);
23581}23652}
2358223653
23583static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *instruction) {23654static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *instruction) {
...@@ -23617,7 +23688,7 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i...@@ -23617,7 +23688,7 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i
23617 return op;23688 return op;
2361823689
23619 if (int_type->data.integral.bit_count % 8 != 0) {23690 if (int_type->data.integral.bit_count % 8 != 0) {
23620 ir_add_error(ira, &instruction->op->base,23691 ir_add_error_node(ira, instruction->op->source_node,
23621 buf_sprintf("@byteSwap integer type '%s' has %" PRIu32 " bits which is not evenly divisible by 8",23692 buf_sprintf("@byteSwap integer type '%s' has %" PRIu32 " bits which is not evenly divisible by 8",
23622 buf_ptr(&int_type->name), int_type->data.integral.bit_count));23693 buf_ptr(&int_type->name), int_type->data.integral.bit_count));
23623 return ira->codegen->invalid_inst_gen;23694 return ira->codegen->invalid_inst_gen;
...@@ -23628,9 +23699,9 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i...@@ -23628,9 +23699,9 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i
23628 if (val == nullptr)23699 if (val == nullptr)
23629 return ira->codegen->invalid_inst_gen;23700 return ira->codegen->invalid_inst_gen;
23630 if (val->special == ConstValSpecialUndef)23701 if (val->special == ConstValSpecialUndef)
23631 return ir_const_undef(ira, &instruction->base.base, op_type);23702 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, op_type);
2363223703
23633 IrInstGen *result = ir_const(ira, &instruction->base.base, op_type);23704 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, op_type);
23634 const size_t buf_size = int_type->data.integral.bit_count / 8;23705 const size_t buf_size = int_type->data.integral.bit_count / 8;
23635 uint8_t *buf = heap::c_allocator.allocate_nonzero<uint8_t>(buf_size);23706 uint8_t *buf = heap::c_allocator.allocate_nonzero<uint8_t>(buf_size);
23636 if (is_vector) {23707 if (is_vector) {
...@@ -23638,7 +23709,7 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i...@@ -23638,7 +23709,7 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i
23638 result->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(op_type->data.vector.len);23709 result->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(op_type->data.vector.len);
23639 for (unsigned i = 0; i < op_type->data.vector.len; i += 1) {23710 for (unsigned i = 0; i < op_type->data.vector.len; i += 1) {
23640 ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i];23711 ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i];
23641 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.base.source_node,23712 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.source_node,
23642 op_elem_val, UndefOk)))23713 op_elem_val, UndefOk)))
23643 {23714 {
23644 return ira->codegen->invalid_inst_gen;23715 return ira->codegen->invalid_inst_gen;
...@@ -23663,7 +23734,7 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i...@@ -23663,7 +23734,7 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i
23663 return result;23734 return result;
23664 }23735 }
2366523736
23666 return ir_build_bswap_gen(ira, &instruction->base.base, op_type, op);23737 return ir_build_bswap_gen(ira, instruction->base.scope, instruction->base.source_node, op_type, op);
23667}23738}
2366823739
23669static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBitReverse *instruction) {23740static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBitReverse *instruction) {
...@@ -23676,7 +23747,7 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi...@@ -23676,7 +23747,7 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi
23676 return ira->codegen->invalid_inst_gen;23747 return ira->codegen->invalid_inst_gen;
2367723748
23678 if (int_type->data.integral.bit_count == 0) {23749 if (int_type->data.integral.bit_count == 0) {
23679 IrInstGen *result = ir_const(ira, &instruction->base.base, int_type);23750 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, int_type);
23680 bigint_init_unsigned(&result->value->data.x_bigint, 0);23751 bigint_init_unsigned(&result->value->data.x_bigint, 0);
23681 return result;23752 return result;
23682 }23753 }
...@@ -23686,9 +23757,9 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi...@@ -23686,9 +23757,9 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi
23686 if (val == nullptr)23757 if (val == nullptr)
23687 return ira->codegen->invalid_inst_gen;23758 return ira->codegen->invalid_inst_gen;
23688 if (val->special == ConstValSpecialUndef)23759 if (val->special == ConstValSpecialUndef)
23689 return ir_const_undef(ira, &instruction->base.base, int_type);23760 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, int_type);
2369023761
23691 IrInstGen *result = ir_const(ira, &instruction->base.base, int_type);23762 IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, int_type);
23692 size_t num_bits = int_type->data.integral.bit_count;23763 size_t num_bits = int_type->data.integral.bit_count;
23693 size_t buf_size = (num_bits + 7) / 8;23764 size_t buf_size = (num_bits + 7) / 8;
23694 uint8_t *comptime_buf = heap::c_allocator.allocate_nonzero<uint8_t>(buf_size);23765 uint8_t *comptime_buf = heap::c_allocator.allocate_nonzero<uint8_t>(buf_size);
...@@ -23717,7 +23788,7 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi...@@ -23717,7 +23788,7 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi
23717 return result;23788 return result;
23718 }23789 }
2371923790
23720 return ir_build_bit_reverse_gen(ira, &instruction->base.base, int_type, op);23791 return ir_build_bit_reverse_gen(ira, instruction->base.scope, instruction->base.source_node, int_type, op);
23721}23792}
2372223793
2372323794
...@@ -23726,7 +23797,7 @@ static IrInstGen *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstSrcEn...@@ -23726,7 +23797,7 @@ static IrInstGen *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstSrcEn
23726 if (type_is_invalid(target->value->type))23797 if (type_is_invalid(target->value->type))
23727 return ira->codegen->invalid_inst_gen;23798 return ira->codegen->invalid_inst_gen;
2372823799
23729 return ir_analyze_enum_to_int(ira, &instruction->base.base, target);23800 return ir_analyze_enum_to_int(ira, instruction->base.scope, instruction->base.source_node, target);
23730}23801}
2373123802
23732static IrInstGen *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstSrcIntToEnum *instruction) {23803static IrInstGen *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstSrcIntToEnum *instruction) {
...@@ -23737,7 +23808,7 @@ static IrInstGen *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstSrcIn...@@ -23737,7 +23808,7 @@ static IrInstGen *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstSrcIn
23737 return ira->codegen->invalid_inst_gen;23808 return ira->codegen->invalid_inst_gen;
2373823809
23739 if (dest_type->id != ZigTypeIdEnum) {23810 if (dest_type->id != ZigTypeIdEnum) {
23740 ir_add_error(ira, &instruction->dest_type->base,23811 ir_add_error_node(ira, instruction->dest_type->source_node,
23741 buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name)));23812 buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name)));
23742 return ira->codegen->invalid_inst_gen;23813 return ira->codegen->invalid_inst_gen;
23743 }23814 }
...@@ -23755,7 +23826,7 @@ static IrInstGen *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstSrcIn...@@ -23755,7 +23826,7 @@ static IrInstGen *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstSrcIn
23755 if (type_is_invalid(casted_target->value->type))23826 if (type_is_invalid(casted_target->value->type))
23756 return ira->codegen->invalid_inst_gen;23827 return ira->codegen->invalid_inst_gen;
2375723828
23758 return ir_analyze_int_to_enum(ira, &instruction->base.base, casted_target, dest_type);23829 return ir_analyze_int_to_enum(ira, instruction->base.scope, instruction->base.source_node, casted_target, dest_type);
23759}23830}
2376023831
23761static IrInstGen *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstSrcCheckRuntimeScope *instruction) {23832static IrInstGen *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstSrcCheckRuntimeScope *instruction) {
...@@ -23770,14 +23841,14 @@ static IrInstGen *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrI...@@ -23770,14 +23841,14 @@ static IrInstGen *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrI
23770 return ira->codegen->invalid_inst_gen;23841 return ira->codegen->invalid_inst_gen;
2377123842
23772 if (!scope_is_comptime && is_comptime) {23843 if (!scope_is_comptime && is_comptime) {
23773 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,23844 ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node,
23774 buf_sprintf("comptime control flow inside runtime block"));23845 buf_sprintf("comptime control flow inside runtime block"));
23775 add_error_note(ira->codegen, msg, block_comptime_inst->base.source_node,23846 add_error_note(ira->codegen, msg, block_comptime_inst->source_node,
23776 buf_sprintf("runtime block created here"));23847 buf_sprintf("runtime block created here"));
23777 return ira->codegen->invalid_inst_gen;23848 return ira->codegen->invalid_inst_gen;
23778 }23849 }
2377923850
23780 return ir_const_void(ira, &instruction->base.base);23851 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
23781}23852}
2378223853
23783static IrInstGen *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstSrcHasDecl *instruction) {23854static IrInstGen *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstSrcHasDecl *instruction) {
...@@ -23790,7 +23861,7 @@ static IrInstGen *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstSrcHasDe...@@ -23790,7 +23861,7 @@ static IrInstGen *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstSrcHasDe
23790 return ira->codegen->invalid_inst_gen;23861 return ira->codegen->invalid_inst_gen;
2379123862
23792 if (!is_container(container_type)) {23863 if (!is_container(container_type)) {
23793 ir_add_error(ira, &instruction->container->base,23864 ir_add_error_node(ira, instruction->container->source_node,
23794 buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&container_type->name)));23865 buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&container_type->name)));
23795 return ira->codegen->invalid_inst_gen;23866 return ira->codegen->invalid_inst_gen;
23796 }23867 }
...@@ -23798,13 +23869,13 @@ static IrInstGen *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstSrcHasDe...@@ -23798,13 +23869,13 @@ static IrInstGen *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstSrcHasDe
23798 ScopeDecls *container_scope = get_container_scope(container_type);23869 ScopeDecls *container_scope = get_container_scope(container_type);
23799 Tld *tld = find_container_decl(ira->codegen, container_scope, name);23870 Tld *tld = find_container_decl(ira->codegen, container_scope, name);
23800 if (tld == nullptr)23871 if (tld == nullptr)
23801 return ir_const_bool(ira, &instruction->base.base, false);23872 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, false);
2380223873
23803 if (tld->visib_mod == VisibModPrivate && tld->import != get_scope_import(instruction->base.base.scope)) {23874 if (tld->visib_mod == VisibModPrivate && tld->import != get_scope_import(instruction->base.scope)) {
23804 return ir_const_bool(ira, &instruction->base.base, false);23875 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, false);
23805 }23876 }
2380623877
23807 return ir_const_bool(ira, &instruction->base.base, true);23878 return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, true);
23808}23879}
2380923880
23810static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode *node, Buf *var_name) {23881static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode *node, Buf *var_name) {
...@@ -23826,9 +23897,9 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode...@@ -23826,9 +23897,9 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode
23826static IrInstGen *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, IrInstSrcUndeclaredIdent *instruction) {23897static IrInstGen *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, IrInstSrcUndeclaredIdent *instruction) {
23827 // put a variable of same name with invalid type in global scope23898 // put a variable of same name with invalid type in global scope
23828 // so that future references to this same name will find a variable with an invalid type23899 // so that future references to this same name will find a variable with an invalid type
23829 populate_invalid_variable_in_scope(ira->codegen, instruction->base.base.scope,23900 populate_invalid_variable_in_scope(ira->codegen, instruction->base.scope,
23830 instruction->base.base.source_node, instruction->name);23901 instruction->base.source_node, instruction->name);
23831 ir_add_error(ira, &instruction->base.base,23902 ir_add_error_node(ira, instruction->base.source_node,
23832 buf_sprintf("use of undeclared identifier '%s'", buf_ptr(instruction->name)));23903 buf_sprintf("use of undeclared identifier '%s'", buf_ptr(instruction->name)));
23833 return ira->codegen->invalid_inst_gen;23904 return ira->codegen->invalid_inst_gen;
23834}23905}
...@@ -23839,7 +23910,7 @@ static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndEx...@@ -23839,7 +23910,7 @@ static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndEx
23839 return ira->codegen->invalid_inst_gen;23910 return ira->codegen->invalid_inst_gen;
2384023911
23841 bool was_written = instruction->result_loc->written;23912 bool was_written = instruction->result_loc->written;
23842 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,23913 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
23843 value->value->type, value, false, true);23914 value->value->type, value, false, true);
23844 if (result_loc != nullptr) {23915 if (result_loc != nullptr) {
23845 if (type_is_invalid(result_loc->value->type))23916 if (type_is_invalid(result_loc->value->type))
...@@ -23848,7 +23919,7 @@ static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndEx...@@ -23848,7 +23919,7 @@ static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndEx
23848 return result_loc;23919 return result_loc;
2384923920
23850 if (!was_written || instruction->result_loc->id == ResultLocIdPeer) {23921 if (!was_written || instruction->result_loc->id == ResultLocIdPeer) {
23851 IrInstGen *store_ptr = ir_analyze_store_ptr(ira, &instruction->base.base, result_loc, value,23922 IrInstGen *store_ptr = ir_analyze_store_ptr(ira, instruction->base.scope, instruction->base.source_node, result_loc, value,
23852 instruction->result_loc->allow_write_through_const);23923 instruction->result_loc->allow_write_through_const);
23853 if (type_is_invalid(store_ptr->value->type)) {23924 if (type_is_invalid(store_ptr->value->type)) {
23854 if (instruction->result_loc->id == ResultLocIdReturn &&23925 if (instruction->result_loc->id == ResultLocIdReturn &&
...@@ -23873,7 +23944,7 @@ static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndEx...@@ -23873,7 +23944,7 @@ static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndEx
23873 }23944 }
23874 }23945 }
2387523946
23876 return ir_const_void(ira, &instruction->base.base);23947 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
23877}23948}
2387823949
23879static IrInstGen *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstSrcImplicitCast *instruction) {23950static IrInstGen *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstSrcImplicitCast *instruction) {
...@@ -23884,7 +23955,8 @@ static IrInstGen *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstSrc...@@ -23884,7 +23955,8 @@ static IrInstGen *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstSrc
23884 ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child);23955 ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child);
23885 if (type_is_invalid(dest_type))23956 if (type_is_invalid(dest_type))
23886 return ira->codegen->invalid_inst_gen;23957 return ira->codegen->invalid_inst_gen;
23887 return ir_implicit_cast2(ira, &instruction->base.base, operand, dest_type);23958 return ir_implicit_cast2(ira, instruction->base.scope, instruction->base.source_node,
23959 operand, dest_type);
23888}23960}
2388923961
23890static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcBitCast *instruction) {23962static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcBitCast *instruction) {
...@@ -23892,7 +23964,7 @@ static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcB...@@ -23892,7 +23964,7 @@ static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcB
23892 if (type_is_invalid(operand->value->type))23964 if (type_is_invalid(operand->value->type))
23893 return operand;23965 return operand;
2389423966
23895 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base,23967 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base,
23896 &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, true);23968 &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, true);
23897 if (result_loc != nullptr &&23969 if (result_loc != nullptr &&
23898 (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))23970 (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))
...@@ -23904,7 +23976,7 @@ static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcB...@@ -23904,7 +23976,7 @@ static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcB
23904 instruction->result_loc_bit_cast->base.source_instruction->child);23976 instruction->result_loc_bit_cast->base.source_instruction->child);
23905 if (type_is_invalid(dest_type))23977 if (type_is_invalid(dest_type))
23906 return ira->codegen->invalid_inst_gen;23978 return ira->codegen->invalid_inst_gen;
23907 return ir_analyze_bit_cast(ira, &instruction->base.base, operand, dest_type);23979 return ir_analyze_bit_cast(ira, instruction->base.scope, instruction->base.source_node, operand, dest_type);
23908}23980}
2390923981
23910static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira,23982static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira,
...@@ -23915,7 +23987,7 @@ static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira,...@@ -23915,7 +23987,7 @@ static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira,
23915 return ira->codegen->invalid_inst_gen;23987 return ira->codegen->invalid_inst_gen;
2391623988
23917 if (union_type->id != ZigTypeIdUnion) {23989 if (union_type->id != ZigTypeIdUnion) {
23918 ir_add_error(ira, &instruction->union_type->base,23990 ir_add_error_node(ira, instruction->union_type->source_node,
23919 buf_sprintf("non-union type '%s' passed to @unionInit", buf_ptr(&union_type->name)));23991 buf_sprintf("non-union type '%s' passed to @unionInit", buf_ptr(&union_type->name)));
23920 return ira->codegen->invalid_inst_gen;23992 return ira->codegen->invalid_inst_gen;
23921 }23993 }
...@@ -23932,32 +24004,32 @@ static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira,...@@ -23932,32 +24004,32 @@ static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira,
23932 if (type_is_invalid(result_loc->value->type))24004 if (type_is_invalid(result_loc->value->type))
23933 return ira->codegen->invalid_inst_gen;24005 return ira->codegen->invalid_inst_gen;
2393424006
23935 return ir_analyze_union_init(ira, &instruction->base.base, instruction->base.base.source_node,24007 return ir_analyze_union_init(ira, instruction->base.scope, instruction->base.source_node, instruction->base.source_node,
23936 union_type, field_name, field_result_loc, result_loc);24008 union_type, field_name, field_result_loc, result_loc);
23937}24009}
2393824010
23939static IrInstGen *ir_analyze_instruction_suspend_begin(IrAnalyze *ira, IrInstSrcSuspendBegin *instruction) {24011static IrInstGen *ir_analyze_instruction_suspend_begin(IrAnalyze *ira, IrInstSrcSuspendBegin *instruction) {
23940 return ir_build_suspend_begin_gen(ira, &instruction->base.base);24012 return ir_build_suspend_begin_gen(ira, instruction->base.scope, instruction->base.source_node);
23941}24013}
2394224014
23943static IrInstGen *ir_analyze_instruction_suspend_finish(IrAnalyze *ira, IrInstSrcSuspendFinish *instruction) {24015static IrInstGen *ir_analyze_instruction_suspend_finish(IrAnalyze *ira, IrInstSrcSuspendFinish *instruction) {
23944 IrInstGen *begin_base = instruction->begin->base.child;24016 IrInstGen *begin_base = instruction->begin->base.child;
23945 if (type_is_invalid(begin_base->value->type))24017 if (type_is_invalid(begin_base->value->type))
23946 return ira->codegen->invalid_inst_gen;24018 return ira->codegen->invalid_inst_gen;
23947 ir_assert(begin_base->id == IrInstGenIdSuspendBegin, &instruction->base.base);24019 src_assert(begin_base->id == IrInstGenIdSuspendBegin, instruction->base.source_node);
23948 IrInstGenSuspendBegin *begin = reinterpret_cast<IrInstGenSuspendBegin *>(begin_base);24020 IrInstGenSuspendBegin *begin = reinterpret_cast<IrInstGenSuspendBegin *>(begin_base);
2394924021
23950 ZigFn *fn_entry = ira->fn;24022 ZigFn *fn_entry = ira->fn;
23951 ir_assert(fn_entry != nullptr, &instruction->base.base);24023 src_assert(fn_entry != nullptr, instruction->base.source_node);
2395224024
23953 if (fn_entry->inferred_async_node == nullptr) {24025 if (fn_entry->inferred_async_node == nullptr) {
23954 fn_entry->inferred_async_node = instruction->base.base.source_node;24026 fn_entry->inferred_async_node = instruction->base.source_node;
23955 }24027 }
2395624028
23957 return ir_build_suspend_finish_gen(ira, &instruction->base.base, begin);24029 return ir_build_suspend_finish_gen(ira, instruction->base.scope, instruction->base.source_node, begin);
23958}24030}
2395924031
23960static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInst* source_instr,24032static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, Scope *scope, AstNode *source_node,
23961 IrInstGen *frame_ptr, ZigFn **target_fn)24033 IrInstGen *frame_ptr, ZigFn **target_fn)
23962{24034{
23963 if (type_is_invalid(frame_ptr->value->type))24035 if (type_is_invalid(frame_ptr->value->type))
...@@ -23976,7 +24048,7 @@ static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInst* source...@@ -23976,7 +24048,7 @@ static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInst* source
23976 *target_fn = func;24048 *target_fn = func;
23977 frame = frame_ptr;24049 frame = frame_ptr;
23978 } else {24050 } else {
23979 frame = ir_get_deref(ira, source_instr, frame_ptr, nullptr);24051 frame = ir_get_deref(ira, scope, source_node, frame_ptr, nullptr);
23980 if (frame->value->type->id == ZigTypeIdPointer &&24052 if (frame->value->type->id == ZigTypeIdPointer &&
23981 frame->value->type->data.pointer.ptr_len == PtrLenSingle &&24053 frame->value->type->data.pointer.ptr_len == PtrLenSingle &&
23982 frame->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)24054 frame->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)
...@@ -23987,7 +24059,7 @@ static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInst* source...@@ -23987,7 +24059,7 @@ static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInst* source
23987 } else if (frame->value->type->id != ZigTypeIdAnyFrame ||24059 } else if (frame->value->type->id != ZigTypeIdAnyFrame ||
23988 frame->value->type->data.any_frame.result_type == nullptr)24060 frame->value->type->data.any_frame.result_type == nullptr)
23989 {24061 {
23990 ir_add_error(ira, source_instr,24062 ir_add_error_node(ira, source_node,
23991 buf_sprintf("expected anyframe->T, found '%s'", buf_ptr(&frame->value->type->name)));24063 buf_sprintf("expected anyframe->T, found '%s'", buf_ptr(&frame->value->type->name)));
23992 return ira->codegen->invalid_inst_gen;24064 return ira->codegen->invalid_inst_gen;
23993 } else {24065 } else {
...@@ -24008,19 +24080,19 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i...@@ -24008,19 +24080,19 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i
24008 if (type_is_invalid(operand->value->type))24080 if (type_is_invalid(operand->value->type))
24009 return ira->codegen->invalid_inst_gen;24081 return ira->codegen->invalid_inst_gen;
24010 ZigFn *target_fn;24082 ZigFn *target_fn;
24011 IrInstGen *frame = analyze_frame_ptr_to_anyframe_T(ira, &instruction->base.base, operand, &target_fn);24083 IrInstGen *frame = analyze_frame_ptr_to_anyframe_T(ira, instruction->base.scope, instruction->base.source_node, operand, &target_fn);
24012 if (type_is_invalid(frame->value->type))24084 if (type_is_invalid(frame->value->type))
24013 return ira->codegen->invalid_inst_gen;24085 return ira->codegen->invalid_inst_gen;
2401424086
24015 ZigType *result_type = frame->value->type->data.any_frame.result_type;24087 ZigType *result_type = frame->value->type->data.any_frame.result_type;
2401624088
24017 ZigFn *fn_entry = ira->fn;24089 ZigFn *fn_entry = ira->fn;
24018 ir_assert(fn_entry != nullptr, &instruction->base.base);24090 src_assert(fn_entry != nullptr, instruction->base.source_node);
2401924091
24020 // If it's not @Frame(func) then it's definitely a suspend point24092 // If it's not @Frame(func) then it's definitely a suspend point
24021 if (target_fn == nullptr && !instruction->is_nosuspend) {24093 if (target_fn == nullptr && !instruction->is_nosuspend) {
24022 if (fn_entry->inferred_async_node == nullptr) {24094 if (fn_entry->inferred_async_node == nullptr) {
24023 fn_entry->inferred_async_node = instruction->base.base.source_node;24095 fn_entry->inferred_async_node = instruction->base.source_node;
24024 }24096 }
24025 }24097 }
2402624098
...@@ -24030,7 +24102,7 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i...@@ -24030,7 +24102,7 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i
2403024102
24031 IrInstGen *result_loc;24103 IrInstGen *result_loc;
24032 if (type_has_bits(ira->codegen, result_type)) {24104 if (type_has_bits(ira->codegen, result_type)) {
24033 result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,24105 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
24034 result_type, nullptr, true, true);24106 result_type, nullptr, true, true);
24035 if (result_loc != nullptr &&24107 if (result_loc != nullptr &&
24036 (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))24108 (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))
...@@ -24041,7 +24113,7 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i...@@ -24041,7 +24113,7 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i
24041 result_loc = nullptr;24113 result_loc = nullptr;
24042 }24114 }
2404324115
24044 IrInstGenAwait *result = ir_build_await_gen(ira, &instruction->base.base, frame, result_type, result_loc,24116 IrInstGenAwait *result = ir_build_await_gen(ira, instruction->base.scope, instruction->base.source_node, frame, result_type, result_loc,
24045 instruction->is_nosuspend);24117 instruction->is_nosuspend);
24046 result->target_fn = target_fn;24118 result->target_fn = target_fn;
24047 fn_entry->await_list.append(result);24119 fn_entry->await_list.append(result);
...@@ -24060,27 +24132,29 @@ static IrInstGen *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstSrcResume...@@ -24060,27 +24132,29 @@ static IrInstGen *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstSrcResume
24060 {24132 {
24061 frame = frame_ptr;24133 frame = frame_ptr;
24062 } else {24134 } else {
24063 frame = ir_get_deref(ira, &instruction->base.base, frame_ptr, nullptr);24135 frame = ir_get_deref(ira, instruction->base.scope, instruction->base.source_node,
24136 frame_ptr, nullptr);
24064 }24137 }
2406524138
24066 ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr);24139 ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr);
24067 IrInstGen *casted_frame = ir_implicit_cast2(ira, &instruction->frame->base, frame, any_frame_type);24140 IrInstGen *casted_frame = ir_implicit_cast2(ira, instruction->frame->scope,
24141 instruction->frame->source_node, frame, any_frame_type);
24068 if (type_is_invalid(casted_frame->value->type))24142 if (type_is_invalid(casted_frame->value->type))
24069 return ira->codegen->invalid_inst_gen;24143 return ira->codegen->invalid_inst_gen;
2407024144
24071 return ir_build_resume_gen(ira, &instruction->base.base, casted_frame);24145 return ir_build_resume_gen(ira, instruction->base.scope, instruction->base.source_node, casted_frame);
24072}24146}
2407324147
24074static IrInstGen *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstSrcSpillBegin *instruction) {24148static IrInstGen *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstSrcSpillBegin *instruction) {
24075 if (ir_should_inline(ira->zir, instruction->base.base.scope))24149 if (ir_should_inline(ira->zir, instruction->base.scope))
24076 return ir_const_void(ira, &instruction->base.base);24150 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
2407724151
24078 IrInstGen *operand = instruction->operand->child;24152 IrInstGen *operand = instruction->operand->child;
24079 if (type_is_invalid(operand->value->type))24153 if (type_is_invalid(operand->value->type))
24080 return ira->codegen->invalid_inst_gen;24154 return ira->codegen->invalid_inst_gen;
2408124155
24082 if (!type_has_bits(ira->codegen, operand->value->type))24156 if (!type_has_bits(ira->codegen, operand->value->type))
24083 return ir_const_void(ira, &instruction->base.base);24157 return ir_const_void(ira, instruction->base.scope, instruction->base.source_node);
2408424158
24085 switch (instruction->spill_id) {24159 switch (instruction->spill_id) {
24086 case SpillIdInvalid:24160 case SpillIdInvalid:
...@@ -24090,7 +24164,7 @@ static IrInstGen *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstSrcSp...@@ -24090,7 +24164,7 @@ static IrInstGen *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstSrcSp
24090 break;24164 break;
24091 }24165 }
2409224166
24093 return ir_build_spill_begin_gen(ira, &instruction->base.base, operand, instruction->spill_id);24167 return ir_build_spill_begin_gen(ira, instruction->base.scope, instruction->base.source_node, operand, instruction->spill_id);
24094}24168}
2409524169
24096static IrInstGen *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstSrcSpillEnd *instruction) {24170static IrInstGen *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstSrcSpillEnd *instruction) {
...@@ -24098,23 +24172,23 @@ static IrInstGen *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstSrcSpil...@@ -24098,23 +24172,23 @@ static IrInstGen *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstSrcSpil
24098 if (type_is_invalid(operand->value->type))24172 if (type_is_invalid(operand->value->type))
24099 return ira->codegen->invalid_inst_gen;24173 return ira->codegen->invalid_inst_gen;
2410024174
24101 if (ir_should_inline(ira->zir, instruction->base.base.scope) ||24175 if (ir_should_inline(ira->zir, instruction->base.scope) ||
24102 !type_has_bits(ira->codegen, operand->value->type) ||24176 !type_has_bits(ira->codegen, operand->value->type) ||
24103 instr_is_comptime(operand))24177 instr_is_comptime(operand))
24104 {24178 {
24105 return operand;24179 return operand;
24106 }24180 }
2410724181
24108 ir_assert(instruction->begin->base.child->id == IrInstGenIdSpillBegin, &instruction->base.base);24182 src_assert(instruction->begin->base.child->id == IrInstGenIdSpillBegin, instruction->base.source_node);
24109 IrInstGenSpillBegin *begin = reinterpret_cast<IrInstGenSpillBegin *>(instruction->begin->base.child);24183 IrInstGenSpillBegin *begin = reinterpret_cast<IrInstGenSpillBegin *>(instruction->begin->base.child);
2411024184
24111 return ir_build_spill_end_gen(ira, &instruction->base.base, begin, operand->value->type);24185 return ir_build_spill_end_gen(ira, instruction->base.scope, instruction->base.source_node, begin, operand->value->type);
24112}24186}
2411324187
24114static IrInstGen *ir_analyze_instruction_src(IrAnalyze *ira, IrInstSrcSrc *instruction) {24188static IrInstGen *ir_analyze_instruction_src(IrAnalyze *ira, IrInstSrcSrc *instruction) {
24115 ZigFn *fn_entry = scope_fn_entry(instruction->base.base.scope);24189 ZigFn *fn_entry = scope_fn_entry(instruction->base.scope);
24116 if (fn_entry == nullptr) {24190 if (fn_entry == nullptr) {
24117 ir_add_error(ira, &instruction->base.base, buf_sprintf("@src outside function"));24191 ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("@src outside function"));
24118 return ira->codegen->invalid_inst_gen;24192 return ira->codegen->invalid_inst_gen;
24119 }24193 }
2412024194
...@@ -24140,7 +24214,7 @@ static IrInstGen *ir_analyze_instruction_src(IrAnalyze *ira, IrInstSrcSrc *instr...@@ -24140,7 +24214,7 @@ static IrInstGen *ir_analyze_instruction_src(IrAnalyze *ira, IrInstSrcSrc *instr
24140 ensure_field_index(source_location_type, "file", 0);24214 ensure_field_index(source_location_type, "file", 0);
24141 fields[0]->special = ConstValSpecialStatic;24215 fields[0]->special = ConstValSpecialStatic;
2414224216
24143 ZigType *import = instruction->base.base.source_node->owner;24217 ZigType *import = instruction->base.source_node->owner;
24144 RootStruct *root_struct = import->data.structure.root_struct;24218 RootStruct *root_struct = import->data.structure.root_struct;
24145 Buf *path = root_struct->path;24219 Buf *path = root_struct->path;
24146 ZigValue *file_name = create_const_str_lit(ira->codegen, path)->data.x_ptr.data.ref.pointee;24220 ZigValue *file_name = create_const_str_lit(ira->codegen, path)->data.x_ptr.data.ref.pointee;
...@@ -24156,7 +24230,7 @@ static IrInstGen *ir_analyze_instruction_src(IrAnalyze *ira, IrInstSrcSrc *instr...@@ -24156,7 +24230,7 @@ static IrInstGen *ir_analyze_instruction_src(IrAnalyze *ira, IrInstSrcSrc *instr
24156 fields[1]->type = u8_slice;24230 fields[1]->type = u8_slice;
2415724231
2415824232
24159 TokenLoc tok_loc = root_struct->token_locs[instruction->base.base.source_node->main_token];24233 TokenLoc tok_loc = root_struct->token_locs[instruction->base.source_node->main_token];
2416024234
24161 // line: u3224235 // line: u32
24162 ensure_field_index(source_location_type, "line", 2);24236 ensure_field_index(source_location_type, "line", 2);
...@@ -24170,7 +24244,7 @@ static IrInstGen *ir_analyze_instruction_src(IrAnalyze *ira, IrInstSrcSrc *instr...@@ -24170,7 +24244,7 @@ static IrInstGen *ir_analyze_instruction_src(IrAnalyze *ira, IrInstSrcSrc *instr
24170 fields[3]->type = ira->codegen->builtin_types.entry_u32;24244 fields[3]->type = ira->codegen->builtin_types.entry_u32;
24171 bigint_init_unsigned(&fields[3]->data.x_bigint, tok_loc.column + 1);24245 bigint_init_unsigned(&fields[3]->data.x_bigint, tok_loc.column + 1);
2417224246
24173 return ir_const_move(ira, &instruction->base.base, result);24247 return ir_const_move(ira, instruction->base.scope, instruction->base.source_node, result);
24174}24248}
2417524249
24176static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruction) {24250static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruction) {
...@@ -24507,7 +24581,7 @@ ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *stage1_zir, Stage1Air *stage1_a...@@ -24507,7 +24581,7 @@ ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *stage1_zir, Stage1Air *stage1_a
24507 while (ira->old_bb_index < ira->zir->basic_block_list.length) {24581 while (ira->old_bb_index < ira->zir->basic_block_list.length) {
24508 IrInstSrc *old_instruction = ira->zir_current_basic_block->instruction_list.at(ira->instruction_index);24582 IrInstSrc *old_instruction = ira->zir_current_basic_block->instruction_list.at(ira->instruction_index);
2450924583
24510 if (old_instruction->base.ref_count == 0 && !ir_inst_src_has_side_effects(old_instruction)) {24584 if (old_instruction->ref_count == 0 && !ir_inst_src_has_side_effects(old_instruction)) {
24511 ira->instruction_index += 1;24585 ira->instruction_index += 1;
24512 continue;24586 continue;
24513 }24587 }
...@@ -24518,9 +24592,10 @@ ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *stage1_zir, Stage1Air *stage1_a...@@ -24518,9 +24592,10 @@ ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *stage1_zir, Stage1Air *stage1_a
24518 fprintf(stderr, "~ ");24592 fprintf(stderr, "~ ");
24519 ir_print_inst_src(codegen, stderr, old_instruction, 0);24593 ir_print_inst_src(codegen, stderr, old_instruction, 0);
24520 }24594 }
24595 ira->suspend_source_instr = old_instruction;
24521 IrInstGen *new_instruction = ir_analyze_instruction_base(ira, old_instruction);24596 IrInstGen *new_instruction = ir_analyze_instruction_base(ira, old_instruction);
24522 if (new_instruction != nullptr) {24597 if (new_instruction != nullptr) {
24523 ir_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, &old_instruction->base);24598 src_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, old_instruction->source_node);
24524 old_instruction->child = new_instruction;24599 old_instruction->child = new_instruction;
2452524600
24526 if (type_is_invalid(new_instruction->value->type)) {24601 if (type_is_invalid(new_instruction->value->type)) {
...@@ -24534,11 +24609,11 @@ ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *stage1_zir, Stage1Air *stage1_a...@@ -24534,11 +24609,11 @@ ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *stage1_zir, Stage1Air *stage1_a
24534 stage1_air->first_err_trace_msg = ira->codegen->trace_err;24609 stage1_air->first_err_trace_msg = ira->codegen->trace_err;
24535 }24610 }
24536 if (stage1_air->first_err_trace_msg != nullptr &&24611 if (stage1_air->first_err_trace_msg != nullptr &&
24537 !old_instruction->base.source_node->already_traced_this_node)24612 !old_instruction->source_node->already_traced_this_node)
24538 {24613 {
24539 old_instruction->base.source_node->already_traced_this_node = true;24614 old_instruction->source_node->already_traced_this_node = true;
24540 stage1_air->first_err_trace_msg = add_error_note(ira->codegen, stage1_air->first_err_trace_msg,24615 stage1_air->first_err_trace_msg = add_error_note(ira->codegen, stage1_air->first_err_trace_msg,
24541 old_instruction->base.source_node, buf_create_from_str("referenced here"));24616 old_instruction->source_node, buf_create_from_str("referenced here"));
24542 }24617 }
24543 return ira->codegen->builtin_types.entry_invalid;24618 return ira->codegen->builtin_types.entry_invalid;
24544 } else if (ira->codegen->verbose_ir) {24619 } else if (ira->codegen->verbose_ir) {
...@@ -24908,10 +24983,10 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La...@@ -24908,10 +24983,10 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
2490824983
24909 if(!is_valid_param_type(param_type)){24984 if(!is_valid_param_type(param_type)){
24910 if(param_type->id == ZigTypeIdOpaque){24985 if(param_type->id == ZigTypeIdOpaque){
24911 ir_add_error(ira, &param_type_inst->base,24986 ir_add_error(ira, param_type_inst,
24912 buf_sprintf("parameter of opaque type '%s' not allowed", buf_ptr(&param_type->name)));24987 buf_sprintf("parameter of opaque type '%s' not allowed", buf_ptr(&param_type->name)));
24913 } else {24988 } else {
24914 ir_add_error(ira, &param_type_inst->base,24989 ir_add_error(ira, param_type_inst,
24915 buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&param_type->name)));24990 buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&param_type->name)));
24916 }24991 }
2491724992
...@@ -24921,7 +24996,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La...@@ -24921,7 +24996,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
24921 switch (type_requires_comptime(ira->codegen, param_type)) {24996 switch (type_requires_comptime(ira->codegen, param_type)) {
24922 case ReqCompTimeYes:24997 case ReqCompTimeYes:
24923 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {24998 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
24924 ir_add_error(ira, &param_type_inst->base,24999 ir_add_error(ira, param_type_inst,
24925 buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'",25000 buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'",
24926 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));25001 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));
24927 return nullptr;25002 return nullptr;
...@@ -24939,7 +25014,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La...@@ -24939,7 +25014,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
24939 if ((err = type_has_bits2(ira->codegen, param_type, &has_bits)))25014 if ((err = type_has_bits2(ira->codegen, param_type, &has_bits)))
24940 return nullptr;25015 return nullptr;
24941 if (!has_bits) {25016 if (!has_bits) {
24942 ir_add_error(ira, &param_type_inst->base,25017 ir_add_error(ira, param_type_inst,
24943 buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'",25018 buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'",
24944 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));25019 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));
24945 return nullptr;25020 return nullptr;
...@@ -24958,7 +25033,8 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La...@@ -24958,7 +25033,8 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
24958 if (type_is_invalid(fn_type_id.return_type))25033 if (type_is_invalid(fn_type_id.return_type))
24959 return nullptr;25034 return nullptr;
24960 if (fn_type_id.return_type->id == ZigTypeIdOpaque) {25035 if (fn_type_id.return_type->id == ZigTypeIdOpaque) {
24961 ir_add_error(ira, &lazy_fn_type->return_type->base, buf_create_from_str("return type cannot be opaque"));25036 ir_add_error_node(ira, lazy_fn_type->return_type->source_node,
25037 buf_create_from_str("return type cannot be opaque"));
24962 return nullptr;25038 return nullptr;
24963 }25039 }
2496425040
...@@ -24976,7 +25052,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -24976,7 +25052,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
24976 LazyValueTypeInfoDecls *type_info_decls = reinterpret_cast<LazyValueTypeInfoDecls *>(val->data.x_lazy);25052 LazyValueTypeInfoDecls *type_info_decls = reinterpret_cast<LazyValueTypeInfoDecls *>(val->data.x_lazy);
24977 IrAnalyze *ira = type_info_decls->ira;25053 IrAnalyze *ira = type_info_decls->ira;
2497825054
24979 if ((err = ir_make_type_info_decls(ira, type_info_decls->source_instr, val, type_info_decls->decls_scope, true)))25055 if ((err = ir_make_type_info_decls(ira, type_info_decls->source_node, val, type_info_decls->decls_scope, true)))
24980 {25056 {
24981 return err;25057 return err;
24982 };25058 };
...@@ -25002,7 +25078,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -25002,7 +25078,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
25002 case ZigTypeIdBoundFn:25078 case ZigTypeIdBoundFn:
25003 case ZigTypeIdVoid:25079 case ZigTypeIdVoid:
25004 case ZigTypeIdOpaque:25080 case ZigTypeIdOpaque:
25005 ir_add_error(ira, &lazy_align_of->target_type->base,25081 ir_add_error_node(ira, lazy_align_of->target_type->source_node,
25006 buf_sprintf("no align available for type '%s'",25082 buf_sprintf("no align available for type '%s'",
25007 buf_ptr(&lazy_align_of->target_type->value->data.x_type->name)));25083 buf_ptr(&lazy_align_of->target_type->value->data.x_type->name)));
25008 return ErrorSemanticAnalyzeFail;25084 return ErrorSemanticAnalyzeFail;
...@@ -25052,7 +25128,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -25052,7 +25128,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
25052 case ZigTypeIdNull:25128 case ZigTypeIdNull:
25053 case ZigTypeIdBoundFn:25129 case ZigTypeIdBoundFn:
25054 case ZigTypeIdOpaque:25130 case ZigTypeIdOpaque:
25055 ir_add_error(ira, &lazy_size_of->target_type->base,25131 ir_add_error_node(ira, lazy_size_of->target_type->source_node,
25056 buf_sprintf("no size available for type '%s'",25132 buf_sprintf("no size available for type '%s'",
25057 buf_ptr(&lazy_size_of->target_type->value->data.x_type->name)));25133 buf_ptr(&lazy_size_of->target_type->value->data.x_type->name)));
25058 return ErrorSemanticAnalyzeFail;25134 return ErrorSemanticAnalyzeFail;
...@@ -25133,7 +25209,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -25133,7 +25209,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
25133 case ZigTypeIdUndefined:25209 case ZigTypeIdUndefined:
25134 case ZigTypeIdNull:25210 case ZigTypeIdNull:
25135 case ZigTypeIdOpaque:25211 case ZigTypeIdOpaque:
25136 ir_add_error(ira, &lazy_slice_type->elem_type->base,25212 ir_add_error_node(ira, lazy_slice_type->elem_type->source_node,
25137 buf_sprintf("slice of type '%s' not allowed", buf_ptr(&elem_type->name)));25213 buf_sprintf("slice of type '%s' not allowed", buf_ptr(&elem_type->name)));
25138 return ErrorSemanticAnalyzeFail;25214 return ErrorSemanticAnalyzeFail;
25139 case ZigTypeIdMetaType:25215 case ZigTypeIdMetaType:
...@@ -25206,11 +25282,11 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -25206,11 +25282,11 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
25206 }25282 }
2520725283
25208 if (elem_type->id == ZigTypeIdUnreachable) {25284 if (elem_type->id == ZigTypeIdUnreachable) {
25209 ir_add_error(ira, &lazy_ptr_type->elem_type->base,25285 ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node,
25210 buf_create_from_str("pointer to noreturn not allowed"));25286 buf_create_from_str("pointer to noreturn not allowed"));
25211 return ErrorSemanticAnalyzeFail;25287 return ErrorSemanticAnalyzeFail;
25212 } else if (elem_type->id == ZigTypeIdOpaque && lazy_ptr_type->ptr_len == PtrLenUnknown) {25288 } else if (elem_type->id == ZigTypeIdOpaque && lazy_ptr_type->ptr_len == PtrLenUnknown) {
25213 ir_add_error(ira, &lazy_ptr_type->elem_type->base,25289 ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node,
25214 buf_create_from_str("unknown-length pointer to opaque"));25290 buf_create_from_str("unknown-length pointer to opaque"));
25215 return ErrorSemanticAnalyzeFail;25291 return ErrorSemanticAnalyzeFail;
25216 } else if (lazy_ptr_type->ptr_len == PtrLenC) {25292 } else if (lazy_ptr_type->ptr_len == PtrLenC) {
...@@ -25218,16 +25294,16 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -25218,16 +25294,16 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
25218 if ((err = type_allowed_in_extern(ira->codegen, elem_type, ExternPositionOther, &ok_type)))25294 if ((err = type_allowed_in_extern(ira->codegen, elem_type, ExternPositionOther, &ok_type)))
25219 return err;25295 return err;
25220 if (!ok_type) {25296 if (!ok_type) {
25221 ir_add_error(ira, &lazy_ptr_type->elem_type->base,25297 ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node,
25222 buf_sprintf("C pointers cannot point to non-C-ABI-compatible type '%s'",25298 buf_sprintf("C pointers cannot point to non-C-ABI-compatible type '%s'",
25223 buf_ptr(&elem_type->name)));25299 buf_ptr(&elem_type->name)));
25224 return ErrorSemanticAnalyzeFail;25300 return ErrorSemanticAnalyzeFail;
25225 } else if (elem_type->id == ZigTypeIdOpaque) {25301 } else if (elem_type->id == ZigTypeIdOpaque) {
25226 ir_add_error(ira, &lazy_ptr_type->elem_type->base,25302 ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node,
25227 buf_sprintf("C pointers cannot point to opaque types"));25303 buf_sprintf("C pointers cannot point to opaque types"));
25228 return ErrorSemanticAnalyzeFail;25304 return ErrorSemanticAnalyzeFail;
25229 } else if (lazy_ptr_type->is_allowzero) {25305 } else if (lazy_ptr_type->is_allowzero) {
25230 ir_add_error(ira, &lazy_ptr_type->elem_type->base,25306 ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node,
25231 buf_sprintf("C pointers always allow address zero"));25307 buf_sprintf("C pointers always allow address zero"));
25232 return ErrorSemanticAnalyzeFail;25308 return ErrorSemanticAnalyzeFail;
25233 }25309 }
...@@ -25259,7 +25335,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -25259,7 +25335,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
25259 return ErrorSemanticAnalyzeFail;25335 return ErrorSemanticAnalyzeFail;
2526025336
25261 if (elem_type->id == ZigTypeIdUnreachable) {25337 if (elem_type->id == ZigTypeIdUnreachable) {
25262 ir_add_error(ira, &lazy_ptr_type->elem_type->base,25338 ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node,
25263 buf_create_from_str("pointer to noreturn not allowed"));25339 buf_create_from_str("pointer to noreturn not allowed"));
25264 return ErrorSemanticAnalyzeFail;25340 return ErrorSemanticAnalyzeFail;
25265 }25341 }
...@@ -25283,7 +25359,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -25283,7 +25359,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
25283 return ErrorSemanticAnalyzeFail;25359 return ErrorSemanticAnalyzeFail;
2528425360
25285 if (elem_type->id == ZigTypeIdUnreachable) {25361 if (elem_type->id == ZigTypeIdUnreachable) {
25286 ir_add_error(ira, &lazy_ptr_type->elem_type->base,25362 ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node,
25287 buf_create_from_str("pointer to noreturn not allowed"));25363 buf_create_from_str("pointer to noreturn not allowed"));
25288 return ErrorSemanticAnalyzeFail;25364 return ErrorSemanticAnalyzeFail;
25289 }25365 }
...@@ -25313,7 +25389,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -25313,7 +25389,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
25313 case ZigTypeIdUndefined:25389 case ZigTypeIdUndefined:
25314 case ZigTypeIdNull:25390 case ZigTypeIdNull:
25315 case ZigTypeIdOpaque:25391 case ZigTypeIdOpaque:
25316 ir_add_error(ira, &lazy_array_type->elem_type->base,25392 ir_add_error_node(ira, lazy_array_type->elem_type->source_node,
25317 buf_sprintf("array of type '%s' not allowed",25393 buf_sprintf("array of type '%s' not allowed",
25318 buf_ptr(&elem_type->name)));25394 buf_ptr(&elem_type->name)));
25319 return ErrorSemanticAnalyzeFail;25395 return ErrorSemanticAnalyzeFail;
...@@ -25377,7 +25453,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -25377,7 +25453,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
25377 return ErrorSemanticAnalyzeFail;25453 return ErrorSemanticAnalyzeFail;
2537825454
25379 if (payload_type->id == ZigTypeIdOpaque || payload_type->id == ZigTypeIdUnreachable) {25455 if (payload_type->id == ZigTypeIdOpaque || payload_type->id == ZigTypeIdUnreachable) {
25380 ir_add_error(ira, &lazy_opt_type->payload_type->base,25456 ir_add_error_node(ira, lazy_opt_type->payload_type->source_node,
25381 buf_sprintf("type '%s' cannot be optional", buf_ptr(&payload_type->name)));25457 buf_sprintf("type '%s' cannot be optional", buf_ptr(&payload_type->name)));
25382 return ErrorSemanticAnalyzeFail;25458 return ErrorSemanticAnalyzeFail;
25383 }25459 }
...@@ -25419,7 +25495,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -25419,7 +25495,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
25419 return ErrorSemanticAnalyzeFail;25495 return ErrorSemanticAnalyzeFail;
2542025496
25421 if (err_set_type->id != ZigTypeIdErrorSet) {25497 if (err_set_type->id != ZigTypeIdErrorSet) {
25422 ir_add_error(ira, &lazy_err_union_type->err_set_type->base,25498 ir_add_error_node(ira, lazy_err_union_type->err_set_type->source_node,
25423 buf_sprintf("expected error set type, found type '%s'",25499 buf_sprintf("expected error set type, found type '%s'",
25424 buf_ptr(&err_set_type->name)));25500 buf_ptr(&err_set_type->name)));
25425 return ErrorSemanticAnalyzeFail;25501 return ErrorSemanticAnalyzeFail;
...@@ -25455,8 +25531,8 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) {...@@ -25455,8 +25531,8 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) {
25455 return ErrorNone;25531 return ErrorNone;
25456}25532}
2545725533
25458void IrInst::src() {25534void IrInstGen::src() {
25459 IrInst *inst = this;25535 IrInstGen *inst = this;
25460 if (inst->source_node != nullptr) {25536 if (inst->source_node != nullptr) {
25461 inst->source_node->src();25537 inst->source_node->src();
25462 } else {25538 } else {
...@@ -25464,37 +25540,13 @@ void IrInst::src() {...@@ -25464,37 +25540,13 @@ void IrInst::src() {
25464 }25540 }
25465}25541}
2546625542
25467void IrInst::dump() {
25468 this->src();
25469 fprintf(stderr, "IrInst(#%" PRIu32 ")\n", this->debug_id);
25470}
25471
25472void IrInstSrc::src() {
25473 this->base.src();
25474}
25475
25476void IrInstGen::src() {
25477 this->base.src();
25478}
25479
25480void IrInstSrc::dump() {
25481 IrInstSrc *inst = this;
25482 inst->src();
25483 if (inst->base.scope == nullptr) {
25484 fprintf(stderr, "(null scope)\n");
25485 } else {
25486 ir_print_inst_src(inst->base.scope->codegen, stderr, inst, 0);
25487 fprintf(stderr, "-> ");
25488 ir_print_inst_gen(inst->base.scope->codegen, stderr, inst->child, 0);
25489 }
25490}
25491void IrInstGen::dump() {25543void IrInstGen::dump() {
25492 IrInstGen *inst = this;25544 IrInstGen *inst = this;
25493 inst->src();25545 inst->src();
25494 if (inst->base.scope == nullptr) {25546 if (inst->scope == nullptr) {
25495 fprintf(stderr, "(null scope)\n");25547 fprintf(stderr, "(null scope)\n");
25496 } else {25548 } else {
25497 ir_print_inst_gen(inst->base.scope->codegen, stderr, inst, 0);25549 ir_print_inst_gen(inst->scope->codegen, stderr, inst, 0);
25498 }25550 }
25499}25551}
2550025552
src/stage1/ir_print.cpp+24-12
...@@ -581,8 +581,8 @@ static void ir_print_prefix_src(IrPrintSrc *irp, IrInstSrc *instruction, bool tr...@@ -581,8 +581,8 @@ static void ir_print_prefix_src(IrPrintSrc *irp, IrInstSrc *instruction, bool tr
581 type_name = "(unknown)";581 type_name = "(unknown)";
582 }582 }
583 const char *ref_count = ir_inst_src_has_side_effects(instruction) ?583 const char *ref_count = ir_inst_src_has_side_effects(instruction) ?
584 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->base.ref_count));584 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->ref_count));
585 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->base.debug_id,585 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->debug_id,
586 ir_inst_src_type_str(instruction->id), type_name, ref_count);586 ir_inst_src_type_str(instruction->id), type_name, ref_count);
587}587}
588588
...@@ -591,17 +591,17 @@ static void ir_print_prefix_gen(IrPrintGen *irp, IrInstGen *instruction, bool tr...@@ -591,17 +591,17 @@ static void ir_print_prefix_gen(IrPrintGen *irp, IrInstGen *instruction, bool tr
591 const char mark = trailing ? ':' : '#';591 const char mark = trailing ? ':' : '#';
592 const char *type_name = instruction->value->type ? buf_ptr(&instruction->value->type->name) : "(unknown)";592 const char *type_name = instruction->value->type ? buf_ptr(&instruction->value->type->name) : "(unknown)";
593 const char *ref_count = ir_inst_gen_has_side_effects(instruction) ?593 const char *ref_count = ir_inst_gen_has_side_effects(instruction) ?
594 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->base.ref_count));594 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->ref_count));
595 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->base.debug_id,595 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->debug_id,
596 ir_inst_gen_type_str(instruction->id), type_name, ref_count);596 ir_inst_gen_type_str(instruction->id), type_name, ref_count);
597}597}
598598
599static void ir_print_var_src(IrPrintSrc *irp, IrInstSrc *inst) {599static void ir_print_var_src(IrPrintSrc *irp, IrInstSrc *inst) {
600 fprintf(irp->f, "#%" PRIu32 "", inst->base.debug_id);600 fprintf(irp->f, "#%" PRIu32 "", inst->debug_id);
601}601}
602602
603static void ir_print_var_gen(IrPrintGen *irp, IrInstGen *inst) {603static void ir_print_var_gen(IrPrintGen *irp, IrInstGen *inst) {
604 fprintf(irp->f, "#%" PRIu32 "", inst->base.debug_id);604 fprintf(irp->f, "#%" PRIu32 "", inst->debug_id);
605 if (irp->printed.maybe_get(inst) == nullptr) {605 if (irp->printed.maybe_get(inst) == nullptr) {
606 irp->printed.put(inst, 0);606 irp->printed.put(inst, 0);
607 irp->pending.append(inst);607 irp->pending.append(inst);
...@@ -1231,8 +1231,8 @@ static void ir_print_any_frame_type(IrPrintSrc *irp, IrInstSrcAnyFrameType *inst...@@ -1231,8 +1231,8 @@ static void ir_print_any_frame_type(IrPrintSrc *irp, IrInstSrcAnyFrameType *inst
1231}1231}
12321232
1233static void ir_print_asm_src(IrPrintSrc *irp, IrInstSrcAsm *instruction) {1233static void ir_print_asm_src(IrPrintSrc *irp, IrInstSrcAsm *instruction) {
1234 assert(instruction->base.base.source_node->type == NodeTypeAsmExpr);1234 assert(instruction->base.source_node->type == NodeTypeAsmExpr);
1235 AstNodeAsmExpr *asm_expr = &instruction->base.base.source_node->data.asm_expr;1235 AstNodeAsmExpr *asm_expr = &instruction->base.source_node->data.asm_expr;
1236 const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";1236 const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";
1237 fprintf(irp->f, "asm%s (", volatile_kw);1237 fprintf(irp->f, "asm%s (", volatile_kw);
1238 ir_print_other_inst_src(irp, instruction->asm_template);1238 ir_print_other_inst_src(irp, instruction->asm_template);
...@@ -1274,8 +1274,8 @@ static void ir_print_asm_src(IrPrintSrc *irp, IrInstSrcAsm *instruction) {...@@ -1274,8 +1274,8 @@ static void ir_print_asm_src(IrPrintSrc *irp, IrInstSrcAsm *instruction) {
1274}1274}
12751275
1276static void ir_print_asm_gen(IrPrintGen *irp, IrInstGenAsm *instruction) {1276static void ir_print_asm_gen(IrPrintGen *irp, IrInstGenAsm *instruction) {
1277 assert(instruction->base.base.source_node->type == NodeTypeAsmExpr);1277 assert(instruction->base.source_node->type == NodeTypeAsmExpr);
1278 AstNodeAsmExpr *asm_expr = &instruction->base.base.source_node->data.asm_expr;1278 AstNodeAsmExpr *asm_expr = &instruction->base.source_node->data.asm_expr;
1279 const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";1279 const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";
1280 fprintf(irp->f, "asm%s (\"%s\") : ", volatile_kw, buf_ptr(instruction->asm_template));1280 fprintf(irp->f, "asm%s (\"%s\") : ", volatile_kw, buf_ptr(instruction->asm_template));
12811281
...@@ -2003,10 +2003,10 @@ static void ir_print_err_wrap_payload(IrPrintGen *irp, IrInstGenErrWrapPayload *...@@ -2003,10 +2003,10 @@ static void ir_print_err_wrap_payload(IrPrintGen *irp, IrInstGenErrWrapPayload *
20032003
2004static void ir_print_fn_proto(IrPrintSrc *irp, IrInstSrcFnProto *instruction) {2004static void ir_print_fn_proto(IrPrintSrc *irp, IrInstSrcFnProto *instruction) {
2005 fprintf(irp->f, "fn(");2005 fprintf(irp->f, "fn(");
2006 for (size_t i = 0; i < instruction->base.base.source_node->data.fn_proto.params.length; i += 1) {2006 for (size_t i = 0; i < instruction->base.source_node->data.fn_proto.params.length; i += 1) {
2007 if (i != 0)2007 if (i != 0)
2008 fprintf(irp->f, ",");2008 fprintf(irp->f, ",");
2009 if (instruction->is_var_args && i == instruction->base.base.source_node->data.fn_proto.params.length - 1) {2009 if (instruction->is_var_args && i == instruction->base.source_node->data.fn_proto.params.length - 1) {
2010 fprintf(irp->f, "...");2010 fprintf(irp->f, "...");
2011 } else {2011 } else {
2012 ir_print_other_inst_src(irp, instruction->param_types[i]);2012 ir_print_other_inst_src(irp, instruction->param_types[i]);
...@@ -3450,3 +3450,15 @@ void ir_print_inst_gen(CodeGen *codegen, FILE *f, IrInstGen *instruction, int in...@@ -3450,3 +3450,15 @@ void ir_print_inst_gen(CodeGen *codegen, FILE *f, IrInstGen *instruction, int in
34503450
3451 ir_print_inst_gen(irp, instruction, false);3451 ir_print_inst_gen(irp, instruction, false);
3452}3452}
3453
3454void IrInstSrc::dump() {
3455 IrInstSrc *inst = this;
3456 inst->src();
3457 if (inst->scope == nullptr) {
3458 fprintf(stderr, "(null scope)\n");
3459 } else {
3460 ir_print_inst_src(inst->scope->codegen, stderr, inst, 0);
3461 fprintf(stderr, "-> ");
3462 ir_print_inst_gen(inst->scope->codegen, stderr, inst->child, 0);
3463 }
3464}