authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-19 19:54:51-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-19 19:54:51-05:00
log3ea4f264ffa4a189bc489113fe4ae24741e78466
tree5d0a1232fe984e456306664c270f42d29835466b
parent2419f0c91436106f85ea8b6ec183cdaea438a1d0

IR: update all error messages to be useful if generic instantiation


1 files changed, 73 insertions(+), 71 deletions(-)

src/ir.cpp+73-71
......@@ -4286,17 +4286,19 @@ static void add_call_stack_errors(CodeGen *codegen, IrExecutable *exec, ErrorMsg
42864286 add_call_stack_errors(codegen, exec->parent_exec, err_msg, limit - 1);
42874287}
42884288
4289// TODO migrate the rest of the add_node_error errors to use this so that we get better
4290// messages for generic instantiations
4291static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, Buf *msg) {
4289static ErrorMsg *ir_add_error_node(IrAnalyze *ira, AstNode *source_node, Buf *msg) {
42924290 ira->new_irb.exec->invalid = true;
4293 ErrorMsg *err_msg = add_node_error(ira->codegen, source_instruction->source_node, msg);
4291 ErrorMsg *err_msg = add_node_error(ira->codegen, source_node, msg);
42944292 if (ira->new_irb.exec->parent_exec) {
42954293 add_call_stack_errors(ira->codegen, ira->new_irb.exec, err_msg, 10);
42964294 }
42974295 return err_msg;
42984296}
42994297
4298static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, Buf *msg) {
4299 return ir_add_error_node(ira, source_instruction->source_node, msg);
4300}
4301
43004302static IrInstruction *ir_exec_const_result(IrExecutable *exec) {
43014303 if (exec->basic_block_list.length != 1)
43024304 return nullptr;
......@@ -4546,7 +4548,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
45464548 return ira->codegen->builtin_types.entry_invalid;
45474549 }
45484550 } else {
4549 ErrorMsg *msg = add_node_error(ira->codegen, source_node,
4551 ErrorMsg *msg = ir_add_error_node(ira, source_node,
45504552 buf_sprintf("incompatible types: '%s' and '%s'",
45514553 buf_ptr(&prev_type->name), buf_ptr(&cur_type->name)));
45524554 add_error_note(ira->codegen, msg, prev_inst->source_node,
......@@ -4561,11 +4563,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
45614563 if (prev_inst->type_entry->id == TypeTableEntryIdNumLitInt ||
45624564 prev_inst->type_entry->id == TypeTableEntryIdNumLitFloat)
45634565 {
4564 add_node_error(ira->codegen, source_node,
4566 ir_add_error_node(ira, source_node,
45654567 buf_sprintf("unable to make error union out of number literal"));
45664568 return ira->codegen->builtin_types.entry_invalid;
45674569 } else if (prev_inst->type_entry->id == TypeTableEntryIdNullLit) {
4568 add_node_error(ira->codegen, source_node,
4570 ir_add_error_node(ira, source_node,
45694571 buf_sprintf("unable to make error union out of null literal"));
45704572 return ira->codegen->builtin_types.entry_invalid;
45714573 } else {
......@@ -4575,7 +4577,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
45754577 if (prev_inst->type_entry->id == TypeTableEntryIdNumLitInt ||
45764578 prev_inst->type_entry->id == TypeTableEntryIdNumLitFloat)
45774579 {
4578 add_node_error(ira->codegen, source_node,
4580 ir_add_error_node(ira, source_node,
45794581 buf_sprintf("unable to make maybe out of number literal"));
45804582 return ira->codegen->builtin_types.entry_invalid;
45814583 } else {
......@@ -4878,7 +4880,7 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
48784880 return nullptr;
48794881
48804882 if (fn_value->type_entry->id != TypeTableEntryIdFn) {
4881 add_node_error(ira->codegen, fn_value->source_node,
4883 ir_add_error_node(ira, fn_value->source_node,
48824884 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->type_entry->name)));
48834885 return nullptr;
48844886 }
......@@ -5114,7 +5116,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
51145116 if (actual_type->data.array.len % child_type_size == 0) {
51155117 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpBytesToSlice, true);
51165118 } else {
5117 add_node_error(ira->codegen, source_instr->source_node,
5119 ir_add_error_node(ira, source_instr->source_node,
51185120 buf_sprintf("unable to convert %s to %s: size mismatch",
51195121 buf_ptr(&actual_type->name), buf_ptr(&wanted_type->name)));
51205122 return ira->codegen->invalid_instruction;
......@@ -5222,7 +5224,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
52225224 {
52235225 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpErrToInt, false);
52245226 } else {
5225 add_node_error(ira->codegen, source_instr->source_node,
5227 ir_add_error_node(ira, source_instr->source_node,
52265228 buf_sprintf("too many error values to fit in '%s'", buf_ptr(&wanted_type->name)));
52275229 return ira->codegen->invalid_instruction;
52285230 }
......@@ -5257,7 +5259,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
52575259 }
52585260 }
52595261
5260 add_node_error(ira->codegen, source_instr->source_node,
5262 ir_add_error_node(ira, source_instr->source_node,
52615263 buf_sprintf("invalid cast from type '%s' to '%s'",
52625264 buf_ptr(&actual_type->name),
52635265 buf_ptr(&wanted_type->name)));
......@@ -5329,7 +5331,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
53295331 return ira->codegen->invalid_instruction;
53305332 }
53315333 } else {
5332 add_node_error(ira->codegen, source_instruction->source_node,
5334 ir_add_error_node(ira, source_instruction->source_node,
53335335 buf_sprintf("attempt to dereference non pointer type '%s'",
53345336 buf_ptr(&type_entry->name)));
53355337 return ira->codegen->invalid_instruction;
......@@ -5534,7 +5536,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
55345536 case TypeTableEntryIdBlock:
55355537 case TypeTableEntryIdBoundFn:
55365538 if (!is_equality_cmp) {
5537 add_node_error(ira->codegen, source_node,
5539 ir_add_error_node(ira, source_node,
55385540 buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));
55395541 return ira->codegen->builtin_types.entry_invalid;
55405542 }
......@@ -5542,7 +5544,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
55425544
55435545 case TypeTableEntryIdEnum:
55445546 if (!is_equality_cmp || resolved_type->data.enumeration.gen_field_count != 0) {
5545 add_node_error(ira->codegen, source_node,
5547 ir_add_error_node(ira, source_node,
55465548 buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));
55475549 return ira->codegen->builtin_types.entry_invalid;
55485550 }
......@@ -5556,7 +5558,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
55565558 case TypeTableEntryIdMaybe:
55575559 case TypeTableEntryIdErrorUnion:
55585560 case TypeTableEntryIdUnion:
5559 add_node_error(ira->codegen, source_node,
5561 ir_add_error_node(ira, source_node,
55605562 buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));
55615563 return ira->codegen->builtin_types.entry_invalid;
55625564
......@@ -5741,7 +5743,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
57415743 // float
57425744 } else {
57435745 AstNode *source_node = bin_op_instruction->base.source_node;
5744 add_node_error(ira->codegen, source_node,
5746 ir_add_error_node(ira, source_node,
57455747 buf_sprintf("invalid operands to binary expression: '%s' and '%s'",
57465748 buf_ptr(&op1->type_entry->name),
57475749 buf_ptr(&op2->type_entry->name)));
......@@ -5767,11 +5769,11 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
57675769 int err;
57685770 if ((err = ir_eval_math_op(op1_val, resolved_type, op_id, op2_val, resolved_type, out_val))) {
57695771 if (err == ErrorDivByZero) {
5770 add_node_error(ira->codegen, bin_op_instruction->base.source_node,
5772 ir_add_error_node(ira, bin_op_instruction->base.source_node,
57715773 buf_sprintf("division by zero is undefined"));
57725774 return ira->codegen->builtin_types.entry_invalid;
57735775 } else if (err == ErrorOverflow) {
5774 add_node_error(ira->codegen, bin_op_instruction->base.source_node,
5776 ir_add_error_node(ira, bin_op_instruction->base.source_node,
57755777 buf_sprintf("value cannot be represented in any integer type"));
57765778 return ira->codegen->builtin_types.entry_invalid;
57775779 }
......@@ -6037,7 +6039,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
60376039 case TypeTableEntryIdNumLitFloat:
60386040 case TypeTableEntryIdNumLitInt:
60396041 if (is_export || is_extern || casted_init_value->static_value.special == ConstValSpecialRuntime) {
6040 add_node_error(ira->codegen, source_node, buf_sprintf("unable to infer variable type"));
6042 ir_add_error_node(ira, source_node, buf_sprintf("unable to infer variable type"));
60416043 result_type = ira->codegen->builtin_types.entry_invalid;
60426044 }
60436045 break;
......@@ -6045,14 +6047,14 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
60456047 case TypeTableEntryIdVar:
60466048 case TypeTableEntryIdBlock:
60476049 case TypeTableEntryIdNullLit:
6048 add_node_error(ira->codegen, source_node,
6050 ir_add_error_node(ira, source_node,
60496051 buf_sprintf("variable of type '%s' not allowed", buf_ptr(&result_type->name)));
60506052 result_type = ira->codegen->builtin_types.entry_invalid;
60516053 break;
60526054 case TypeTableEntryIdMetaType:
60536055 case TypeTableEntryIdNamespace:
60546056 if (casted_init_value->static_value.special == ConstValSpecialRuntime) {
6055 add_node_error(ira->codegen, source_node,
6057 ir_add_error_node(ira, source_node,
60566058 buf_sprintf("variable of type '%s' must be constant", buf_ptr(&result_type->name)));
60576059 result_type = ira->codegen->builtin_types.entry_invalid;
60586060 }
......@@ -6212,7 +6214,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
62126214
62136215 if (fn_type_id->is_var_args) {
62146216 if (call_param_count < src_param_count) {
6215 ErrorMsg *msg = add_node_error(ira->codegen, source_node,
6217 ErrorMsg *msg = ir_add_error_node(ira, source_node,
62166218 buf_sprintf("expected at least %zu arguments, found %zu", src_param_count, call_param_count));
62176219 if (fn_proto_node) {
62186220 add_error_note(ira->codegen, msg, fn_proto_node,
......@@ -6221,7 +6223,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
62216223 return ira->codegen->builtin_types.entry_invalid;
62226224 }
62236225 } else if (src_param_count != call_param_count) {
6224 ErrorMsg *msg = add_node_error(ira->codegen, source_node,
6226 ErrorMsg *msg = ir_add_error_node(ira, source_node,
62256227 buf_sprintf("expected %zu arguments, found %zu", src_param_count, call_param_count));
62266228 if (fn_proto_node) {
62276229 add_error_note(ira->codegen, msg, fn_proto_node,
......@@ -6446,7 +6448,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
64466448 size_t actual_param_count = call_instruction->arg_count;
64476449
64486450 if (actual_param_count != 1) {
6449 add_node_error(ira->codegen, call_instruction->base.source_node,
6451 ir_add_error_node(ira, call_instruction->base.source_node,
64506452 buf_sprintf("cast expression expects exactly one parameter"));
64516453 return ira->codegen->builtin_types.entry_invalid;
64526454 }
......@@ -6470,7 +6472,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
64706472 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
64716473 nullptr, first_arg_ptr, is_inline);
64726474 } else {
6473 add_node_error(ira->codegen, fn_ref->source_node,
6475 ir_add_error_node(ira, fn_ref->source_node,
64746476 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->type_entry->name)));
64756477 return ira->codegen->builtin_types.entry_invalid;
64766478 }
......@@ -6480,7 +6482,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
64806482 return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->type_entry,
64816483 fn_ref, nullptr, false);
64826484 } else {
6483 add_node_error(ira->codegen, fn_ref->source_node,
6485 ir_add_error_node(ira, fn_ref->source_node,
64846486 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->type_entry->name)));
64856487 return ira->codegen->builtin_types.entry_invalid;
64866488 }
......@@ -6531,7 +6533,7 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct
65316533 case TypeTableEntryIdBlock:
65326534 case TypeTableEntryIdUnreachable:
65336535 case TypeTableEntryIdVar:
6534 add_node_error(ira->codegen, un_op_instruction->base.source_node,
6536 ir_add_error_node(ira, un_op_instruction->base.source_node,
65356537 buf_sprintf("unable to wrap type '%s' in error type", buf_ptr(&meta_type->name)));
65366538 // TODO if meta_type is type decl, add note pointing to type decl declaration
65376539 return ira->codegen->builtin_types.entry_invalid;
......@@ -6550,7 +6552,7 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp
65506552 } else if (ptr_type->id == TypeTableEntryIdPointer) {
65516553 child_type = ptr_type->data.pointer.child_type;
65526554 } else {
6553 add_node_error(ira->codegen, un_op_instruction->base.source_node,
6555 ir_add_error_node(ira, un_op_instruction->base.source_node,
65546556 buf_sprintf("attempt to dereference non-pointer type '%s'",
65556557 buf_ptr(&ptr_type->name)));
65566558 return ira->codegen->builtin_types.entry_invalid;
......@@ -6608,7 +6610,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
66086610 return ira->codegen->builtin_types.entry_type;
66096611 }
66106612 case TypeTableEntryIdUnreachable:
6611 add_node_error(ira->codegen, un_op_instruction->base.source_node,
6613 ir_add_error_node(ira, un_op_instruction->base.source_node,
66126614 buf_sprintf("type '%s' not nullable", buf_ptr(&type_entry->name)));
66136615 // TODO if it's a type decl, put an error note here pointing to the decl
66146616 return ira->codegen->builtin_types.entry_invalid;
......@@ -6813,7 +6815,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
68136815 if (resolved_type->id == TypeTableEntryIdNumLitFloat ||
68146816 resolved_type->id == TypeTableEntryIdNumLitInt)
68156817 {
6816 add_node_error(ira->codegen, phi_instruction->base.source_node,
6818 ir_add_error_node(ira, phi_instruction->base.source_node,
68176819 buf_sprintf("unable to infer expression type"));
68186820 return ira->codegen->builtin_types.entry_invalid;
68196821 }
......@@ -6891,7 +6893,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
68916893 return array_type;
68926894 } else if (array_type->id == TypeTableEntryIdArray) {
68936895 if (array_type->data.array.len == 0) {
6894 add_node_error(ira->codegen, elem_ptr_instruction->base.source_node,
6896 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
68956897 buf_sprintf("index 0 outside array of size 0"));
68966898 }
68976899 TypeTableEntry *child_type = array_type->data.array.child_type;
......@@ -6901,7 +6903,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
69016903 } else if (is_slice(array_type)) {
69026904 return_type = array_type->data.structure.fields[0].type_entry;
69036905 } else {
6904 add_node_error(ira->codegen, elem_ptr_instruction->base.source_node,
6906 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
69056907 buf_sprintf("array access of non-array type '%s'", buf_ptr(&array_type->name)));
69066908 return ira->codegen->builtin_types.entry_invalid;
69076909 }
......@@ -6917,7 +6919,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
69176919 if (array_type->id == TypeTableEntryIdArray) {
69186920 uint64_t array_len = array_type->data.array.len;
69196921 if (index >= array_len) {
6920 add_node_error(ira->codegen, elem_ptr_instruction->base.source_node,
6922 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
69216923 buf_sprintf("index %" PRIu64 " outside array of size %" PRIu64,
69226924 index, array_len));
69236925 return ira->codegen->builtin_types.entry_invalid;
......@@ -6948,7 +6950,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
69486950 old_size = mem_size - offset;
69496951 }
69506952 if (new_index >= mem_size) {
6951 add_node_error(ira->codegen, elem_ptr_instruction->base.source_node,
6953 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
69526954 buf_sprintf("index %" PRIu64 " outside pointer of size %" PRIu64, index, old_size));
69536955 return ira->codegen->builtin_types.entry_invalid;
69546956 }
......@@ -6959,7 +6961,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
69596961 ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index];
69606962 uint64_t slice_len = len_field->data.x_bignum.data.x_uint;
69616963 if (index >= slice_len) {
6962 add_node_error(ira->codegen, elem_ptr_instruction->base.source_node,
6964 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
69636965 buf_sprintf("index %" PRIu64 " outside slice of size %" PRIu64,
69646966 index, slice_len));
69656967 return ira->codegen->builtin_types.entry_invalid;
......@@ -7009,7 +7011,7 @@ static TypeTableEntry *ir_analyze_container_member_access_inner(IrAnalyze *ira,
70097011 return ir_analyze_ref(ira, &field_ptr_instruction->base, bound_fn_value);
70107012 }
70117013 }
7012 add_node_error(ira->codegen, field_ptr_instruction->base.source_node,
7014 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
70137015 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name), buf_ptr(&bare_struct_type->name)));
70147016 return ira->codegen->builtin_types.entry_invalid;
70157017}
......@@ -7138,7 +7140,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
71387140 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val,
71397141 usize, false, ConstPtrSpecialNone, ptr_is_const);
71407142 } else {
7141 add_node_error(ira->codegen, source_node,
7143 ir_add_error_node(ira, source_node,
71427144 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name),
71437145 buf_ptr(&container_type->name)));
71447146 return ira->codegen->builtin_types.entry_invalid;
......@@ -7253,7 +7255,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
72537255 if (tld->visib_mod == VisibModPrivate &&
72547256 tld->import != source_node->owner)
72557257 {
7256 ErrorMsg *msg = add_node_error(ira->codegen, source_node,
7258 ErrorMsg *msg = ir_add_error_node(ira, source_node,
72577259 buf_sprintf("'%s' is private", buf_ptr(field_name)));
72587260 add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));
72597261 return ira->codegen->builtin_types.entry_invalid;
......@@ -7261,12 +7263,12 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
72617263 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld, depends_on_compile_var);
72627264 } else {
72637265 const char *import_name = namespace_import->path ? buf_ptr(namespace_import->path) : "(C import)";
7264 add_node_error(ira->codegen, source_node,
7266 ir_add_error_node(ira, source_node,
72657267 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name), import_name));
72667268 return ira->codegen->builtin_types.entry_invalid;
72677269 }
72687270 } else {
7269 add_node_error(ira->codegen, field_ptr_instruction->base.source_node,
7271 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
72707272 buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));
72717273 return ira->codegen->builtin_types.entry_invalid;
72727274 }
......@@ -7348,7 +7350,7 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi
73487350 case TypeTableEntryIdInvalid:
73497351 return type_entry;
73507352 case TypeTableEntryIdVar:
7351 add_node_error(ira->codegen, expr_value->source_node,
7353 ir_add_error_node(ira, expr_value->source_node,
73527354 buf_sprintf("type '%s' not eligible for @typeOf", buf_ptr(&type_entry->name)));
73537355 return ira->codegen->builtin_types.entry_invalid;
73547356 case TypeTableEntryIdNumLitFloat:
......@@ -7402,7 +7404,7 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,
74027404 } else if (is_slice(type_entry)) {
74037405 ptr_type = type_entry->data.structure.fields[0].type_entry;
74047406 } else {
7405 add_node_error(ira->codegen, to_ptr_type_instruction->base.source_node,
7407 ir_add_error_node(ira, to_ptr_type_instruction->base.source_node,
74067408 buf_sprintf("expected array type, found '%s'", buf_ptr(&type_entry->name)));
74077409 return ira->codegen->builtin_types.entry_invalid;
74087410 }
......@@ -7423,7 +7425,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,
74237425
74247426 // TODO handle typedefs
74257427 if (type_entry->id != TypeTableEntryIdPointer) {
7426 add_node_error(ira->codegen, ptr_type_child_instruction->base.source_node,
7428 ir_add_error_node(ira, ptr_type_child_instruction->base.source_node,
74277429 buf_sprintf("expected pointer type, found '%s'", buf_ptr(&type_entry->name)));
74287430 return ira->codegen->builtin_types.entry_invalid;
74297431 }
......@@ -7468,7 +7470,7 @@ static TypeTableEntry *ir_analyze_instruction_set_fn_visible(IrAnalyze *ira,
74687470
74697471 AstNode *source_node = set_fn_visible_instruction->base.source_node;
74707472 if (fn_entry->fn_export_set_node) {
7471 ErrorMsg *msg = add_node_error(ira->codegen, source_node,
7473 ErrorMsg *msg = ir_add_error_node(ira, source_node,
74727474 buf_sprintf("function visibility set twice"));
74737475 add_error_note(ira->codegen, msg, fn_entry->fn_export_set_node, buf_sprintf("first set here"));
74747476 return ira->codegen->builtin_types.entry_invalid;
......@@ -7477,7 +7479,7 @@ static TypeTableEntry *ir_analyze_instruction_set_fn_visible(IrAnalyze *ira,
74777479
74787480 AstNodeFnProto *fn_proto = &fn_entry->proto_node->data.fn_proto;
74797481 if (fn_proto->visib_mod != VisibModExport) {
7480 ErrorMsg *msg = add_node_error(ira->codegen, source_node,
7482 ErrorMsg *msg = ir_add_error_node(ira, source_node,
74817483 buf_sprintf("function must be marked export to set function visibility"));
74827484 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("function declared here"));
74837485 return ira->codegen->builtin_types.entry_invalid;
......@@ -7520,14 +7522,14 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,
75207522 } else if (type_arg->id == TypeTableEntryIdUnion) {
75217523 decls_scope = type_arg->data.unionation.decls_scope;
75227524 } else {
7523 add_node_error(ira->codegen, target_instruction->source_node,
7525 ir_add_error_node(ira, target_instruction->source_node,
75247526 buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&type_arg->name)));
75257527 return ira->codegen->builtin_types.entry_invalid;
75267528 }
75277529 safety_off_ptr = &decls_scope->safety_off;
75287530 safety_set_node_ptr = &decls_scope->safety_set_node;
75297531 } else {
7530 add_node_error(ira->codegen, target_instruction->source_node,
7532 ir_add_error_node(ira, target_instruction->source_node,
75317533 buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&target_type->name)));
75327534 return ira->codegen->builtin_types.entry_invalid;
75337535 }
......@@ -7539,7 +7541,7 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,
75397541
75407542 AstNode *source_node = set_debug_safety_instruction->base.source_node;
75417543 if (*safety_set_node_ptr) {
7542 ErrorMsg *msg = add_node_error(ira->codegen, source_node,
7544 ErrorMsg *msg = ir_add_error_node(ira, source_node,
75437545 buf_sprintf("function test attribute set twice"));
75447546 add_error_note(ira->codegen, msg, *safety_set_node_ptr, buf_sprintf("first set here"));
75457547 return ira->codegen->builtin_types.entry_invalid;
......@@ -7571,7 +7573,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
75717573 case TypeTableEntryIdUndefLit:
75727574 case TypeTableEntryIdNullLit:
75737575 case TypeTableEntryIdBlock:
7574 add_node_error(ira->codegen, slice_type_instruction->base.source_node,
7576 ir_add_error_node(ira, slice_type_instruction->base.source_node,
75757577 buf_sprintf("slice of type '%s' not allowed", buf_ptr(&resolved_child_type->name)));
75767578 // TODO if this is a typedecl, add error note showing the declaration of the type decl
75777579 return ira->codegen->builtin_types.entry_invalid;
......@@ -7660,7 +7662,7 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
76607662 case TypeTableEntryIdUndefLit:
76617663 case TypeTableEntryIdNullLit:
76627664 case TypeTableEntryIdBlock:
7663 add_node_error(ira->codegen, array_type_instruction->base.source_node,
7665 ir_add_error_node(ira, array_type_instruction->base.source_node,
76647666 buf_sprintf("array of type '%s' not allowed", buf_ptr(&child_type->name)));
76657667 // TODO if this is a typedecl, add error note showing the declaration of the type decl
76667668 return ira->codegen->builtin_types.entry_invalid;
......@@ -7726,7 +7728,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_var(IrAnalyze *ira,
77267728 out_val->data.x_enum.tag = ira->codegen->target_oformat_index;
77277729 return ira->codegen->builtin_types.entry_oformat_enum;
77287730 } else {
7729 add_node_error(ira->codegen, name_value->source_node,
7731 ir_add_error_node(ira, name_value->source_node,
77307732 buf_sprintf("unrecognized compile variable: '%s'", buf_ptr(var_name)));
77317733 return ira->codegen->builtin_types.entry_invalid;
77327734 }
......@@ -7755,7 +7757,7 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,
77557757 case TypeTableEntryIdMetaType:
77567758 case TypeTableEntryIdFn:
77577759 case TypeTableEntryIdNamespace:
7758 add_node_error(ira->codegen, size_of_instruction->base.source_node,
7760 ir_add_error_node(ira, size_of_instruction->base.source_node,
77597761 buf_sprintf("no size available for type '%s'", buf_ptr(&type_entry->name)));
77607762 // TODO if this is a typedecl, add error note showing the declaration of the type decl
77617763 return ira->codegen->builtin_types.entry_invalid;
......@@ -7831,7 +7833,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
78317833 if (type_entry->id == TypeTableEntryIdInvalid) {
78327834 return ira->codegen->builtin_types.entry_invalid;
78337835 } else if (type_entry->id != TypeTableEntryIdMaybe) {
7834 add_node_error(ira->codegen, unwrap_maybe_instruction->base.source_node,
7836 ir_add_error_node(ira, unwrap_maybe_instruction->base.source_node,
78357837 buf_sprintf("expected nullable type, found '%s'", buf_ptr(&type_entry->name)));
78367838 return ira->codegen->builtin_types.entry_invalid;
78377839 }
......@@ -7882,7 +7884,7 @@ static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionC
78827884 ir_build_ctz_from(&ira->new_irb, &ctz_instruction->base, value);
78837885 return value->type_entry;
78847886 } else {
7885 add_node_error(ira->codegen, ctz_instruction->base.source_node,
7887 ir_add_error_node(ira, ctz_instruction->base.source_node,
78867888 buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->type_entry->name)));
78877889 return ira->codegen->builtin_types.entry_invalid;
78887890 }
......@@ -7906,7 +7908,7 @@ static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionC
79067908 ir_build_clz_from(&ira->new_irb, &clz_instruction->base, value);
79077909 return value->type_entry;
79087910 } else {
7909 add_node_error(ira->codegen, clz_instruction->base.source_node,
7911 ir_add_error_node(ira, clz_instruction->base.source_node,
79107912 buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->type_entry->name)));
79117913 return ira->codegen->builtin_types.entry_invalid;
79127914 }
......@@ -8095,7 +8097,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
80958097 case TypeTableEntryIdUnion:
80968098 case TypeTableEntryIdBlock:
80978099 case TypeTableEntryIdBoundFn:
8098 add_node_error(ira->codegen, switch_target_instruction->base.source_node,
8100 ir_add_error_node(ira, switch_target_instruction->base.source_node,
80998101 buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name)));
81008102 // TODO if this is a typedecl, add error note showing the declaration of the type decl
81018103 return ira->codegen->builtin_types.entry_invalid;
......@@ -8166,12 +8168,12 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi
81668168 int err;
81678169 if ((err = os_path_real(&full_path, abs_full_path))) {
81688170 if (err == ErrorFileNotFound) {
8169 add_node_error(ira->codegen, source_node,
8171 ir_add_error_node(ira, source_node,
81708172 buf_sprintf("unable to find '%s'", buf_ptr(import_target_path)));
81718173 return ira->codegen->builtin_types.entry_invalid;
81728174 } else {
81738175 ira->codegen->error_during_imports = true;
8174 add_node_error(ira->codegen, source_node,
8176 ir_add_error_node(ira, source_node,
81758177 buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err)));
81768178 return ira->codegen->builtin_types.entry_invalid;
81778179 }
......@@ -8186,11 +8188,11 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi
81868188
81878189 if ((err = os_fetch_file_path(abs_full_path, import_code))) {
81888190 if (err == ErrorFileNotFound) {
8189 add_node_error(ira->codegen, source_node,
8191 ir_add_error_node(ira, source_node,
81908192 buf_sprintf("unable to find '%s'", buf_ptr(import_target_path)));
81918193 return ira->codegen->builtin_types.entry_invalid;
81928194 } else {
8193 add_node_error(ira->codegen, source_node,
8195 ir_add_error_node(ira, source_node,
81948196 buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err)));
81958197 return ira->codegen->builtin_types.entry_invalid;
81968198 }
......@@ -8233,7 +8235,7 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,
82338235 ir_build_load_ptr_from(&ira->new_irb, &array_len_instruction->base, len_ptr);
82348236 return ira->codegen->builtin_types.entry_usize;
82358237 } else {
8236 add_node_error(ira->codegen, array_len_instruction->base.source_node,
8238 ir_add_error_node(ira, array_len_instruction->base.source_node,
82378239 buf_sprintf("type '%s' has no field 'len'", buf_ptr(&array_value->type_entry->name)));
82388240 // TODO if this is a typedecl, add error note showing the declaration of the type decl
82398241 return ira->codegen->builtin_types.entry_invalid;
......@@ -8276,7 +8278,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
82768278
82778279 TypeStructField *type_field = find_struct_type_field(container_type, field->name);
82788280 if (!type_field) {
8279 add_node_error(ira->codegen, field->source_node,
8281 ir_add_error_node(ira, field->source_node,
82808282 buf_sprintf("no member named '%s' in '%s'",
82818283 buf_ptr(field->name), buf_ptr(&container_type->name)));
82828284 return ira->codegen->builtin_types.entry_invalid;
......@@ -8288,7 +8290,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
82888290 size_t field_index = type_field->src_index;
82898291 AstNode *existing_assign_node = field_assign_nodes[field_index];
82908292 if (existing_assign_node) {
8291 ErrorMsg *msg = add_node_error(ira->codegen, field->source_node, buf_sprintf("duplicate field"));
8293 ErrorMsg *msg = ir_add_error_node(ira, field->source_node, buf_sprintf("duplicate field"));
82928294 add_error_note(ira->codegen, msg, existing_assign_node, buf_sprintf("other field here"));
82938295 continue;
82948296 }
......@@ -8315,7 +8317,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
83158317 bool any_missing = false;
83168318 for (size_t i = 0; i < actual_field_count; i += 1) {
83178319 if (!field_assign_nodes[i]) {
8318 add_node_error(ira->codegen, instruction->source_node,
8320 ir_add_error_node(ira, instruction->source_node,
83198321 buf_sprintf("missing field: '%s'", buf_ptr(container_type->data.structure.fields[i].name)));
83208322 any_missing = true;
83218323 }
......@@ -8330,7 +8332,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
83308332 }
83318333
83328334 if (outside_fn) {
8333 add_node_error(ira->codegen, first_non_const_instruction->source_node,
8335 ir_add_error_node(ira, first_non_const_instruction->source_node,
83348336 buf_sprintf("unable to evaluate constant expression"));
83358337 return ira->codegen->builtin_types.entry_invalid;
83368338 }
......@@ -8401,7 +8403,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
84018403 }
84028404
84038405 if (outside_fn) {
8404 add_node_error(ira->codegen, first_non_const_instruction->source_node,
8406 ir_add_error_node(ira, first_non_const_instruction->source_node,
84058407 buf_sprintf("unable to evaluate constant expression"));
84068408 return ira->codegen->builtin_types.entry_invalid;
84078409 }
......@@ -8415,13 +8417,13 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
84158417 zig_panic("TODO array container init");
84168418 } else if (container_type->id == TypeTableEntryIdVoid) {
84178419 if (elem_count != 0) {
8418 add_node_error(ira->codegen, instruction->base.source_node,
8420 ir_add_error_node(ira, instruction->base.source_node,
84198421 buf_sprintf("void expression expects no arguments"));
84208422 return ira->codegen->builtin_types.entry_invalid;
84218423 }
84228424 return ir_analyze_void(ira, &instruction->base);
84238425 } else {
8424 add_node_error(ira->codegen, instruction->base.source_node,
8426 ir_add_error_node(ira, instruction->base.source_node,
84258427 buf_sprintf("type '%s' does not support array initialization",
84268428 buf_ptr(&container_type->name)));
84278429 return ira->codegen->builtin_types.entry_invalid;
......@@ -8594,7 +8596,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc
85948596 }
85958597
85968598 if (errors.length > 0) {
8597 ErrorMsg *parent_err_msg = add_node_error(ira->codegen, node, buf_sprintf("C import failed"));
8599 ErrorMsg *parent_err_msg = ir_add_error_node(ira, node, buf_sprintf("C import failed"));
85988600 for (size_t i = 0; i < errors.length; i += 1) {
85998601 ErrorMsg *err_msg = errors.at(i);
86008602 err_msg_add_note(parent_err_msg, err_msg);
......@@ -9380,7 +9382,7 @@ static TypeTableEntry *ir_analyze_instruction_alignof(IrAnalyze *ira, IrInstruct
93809382 if (type_entry->id == TypeTableEntryIdInvalid) {
93819383 return ira->codegen->builtin_types.entry_invalid;
93829384 } else if (type_entry->id == TypeTableEntryIdUnreachable) {
9383 add_node_error(ira->codegen, first_executing_node(instruction->type_value->source_node),
9385 ir_add_error(ira, instruction->type_value,
93849386 buf_sprintf("no align available for type '%s'", buf_ptr(&type_entry->name)));
93859387 return ira->codegen->builtin_types.entry_invalid;
93869388 } else {