authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-28 14:17:25-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-28 14:17:25-05:00
log504ce86ac991938fcd0544d771c7743833060dda
treeb79e8729f96d16ad6d89aeeb2b9f2f2dd8a4fd1a
parent793d81c4e8b75a8a3d8f51917af6634213b7cabc
signaturelock-open Commit is signed but in an unrecognized format.

fix more compile error test regressions


3 files changed, 55 insertions(+), 40 deletions(-)

src/all_types.hpp+1
...@@ -317,6 +317,7 @@ struct ConstErrValue {...@@ -317,6 +317,7 @@ struct ConstErrValue {
317struct ConstBoundFnValue {317struct ConstBoundFnValue {
318 ZigFn *fn;318 ZigFn *fn;
319 IrInstGen *first_arg;319 IrInstGen *first_arg;
320 IrInst *first_arg_src;
320};321};
321322
322struct ConstArgTuple {323struct ConstArgTuple {
src/ir.cpp+48-33
...@@ -218,7 +218,8 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst *source_instr, IrInstGen *...@@ -218,7 +218,8 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst *source_instr, IrInstGen *
218 ResultLoc *result_loc);218 ResultLoc *result_loc);
219static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutableSrc *exec, AstNode *source_node, Buf *msg);219static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutableSrc *exec, AstNode *source_node, Buf *msg);
220static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,220static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
221 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type, bool initializing);221 IrInst* source_instr, IrInstGen *container_ptr, IrInst *container_ptr_src,
222 ZigType *container_type, bool initializing);
222static void ir_assert(bool ok, IrInst* source_instruction);223static void ir_assert(bool ok, IrInst* source_instruction);
223static void ir_assert_gen(bool ok, IrInstGen *source_instruction);224static void ir_assert_gen(bool ok, IrInstGen *source_instruction);
224static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var);225static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var);
...@@ -13040,10 +13041,13 @@ static IrInstGen *ir_const_fn(IrAnalyze *ira, IrInst *source_instr, ZigFn *fn_en...@@ -13040,10 +13041,13 @@ static IrInstGen *ir_const_fn(IrAnalyze *ira, IrInst *source_instr, ZigFn *fn_en
13040 return result;13041 return result;
13041}13042}
1304213043
13043static IrInstGen *ir_const_bound_fn(IrAnalyze *ira, IrInst *src_inst, ZigFn *fn_entry, IrInstGen *first_arg) {13044static IrInstGen *ir_const_bound_fn(IrAnalyze *ira, IrInst *src_inst, ZigFn *fn_entry, IrInstGen *first_arg,
13045 IrInst *first_arg_src)
13046{
13044 IrInstGen *result = ir_const(ira, src_inst, get_bound_fn_type(ira->codegen, fn_entry));13047 IrInstGen *result = ir_const(ira, src_inst, get_bound_fn_type(ira->codegen, fn_entry));
13045 result->value->data.x_bound_fn.fn = fn_entry;13048 result->value->data.x_bound_fn.fn = fn_entry;
13046 result->value->data.x_bound_fn.first_arg = first_arg;13049 result->value->data.x_bound_fn.first_arg = first_arg;
13050 result->value->data.x_bound_fn.first_arg_src = first_arg_src;
13047 return result;13051 return result;
13048}13052}
1304913053
...@@ -15481,7 +15485,7 @@ static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn...@@ -15481,7 +15485,7 @@ static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn
15481 casted_operand->value->type->id == ZigTypeIdPointer &&15485 casted_operand->value->type->id == ZigTypeIdPointer &&
15482 casted_operand->value->data.rh_ptr == RuntimeHintPtrStack)15486 casted_operand->value->data.rh_ptr == RuntimeHintPtrStack)
15483 {15487 {
15484 ir_add_error(ira, &casted_operand->base, buf_sprintf("function returns address of local variable"));15488 ir_add_error(ira, &instruction->operand->base, buf_sprintf("function returns address of local variable"));
15485 return ir_unreach_error(ira);15489 return ir_unreach_error(ira);
15486 }15490 }
1548715491
...@@ -18895,7 +18899,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node...@@ -18895,7 +18899,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
18895}18899}
1889618900
18897static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node,18901static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node,
18898 IrInstGen *arg, Scope **child_scope, size_t *next_proto_i,18902 IrInstGen *arg, IrInst *arg_src, Scope **child_scope, size_t *next_proto_i,
18899 GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstGen **casted_args,18903 GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstGen **casted_args,
18900 ZigFn *impl_fn)18904 ZigFn *impl_fn)
18901{18905{
...@@ -18914,7 +18918,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -18914,7 +18918,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
18914 if (type_is_invalid(param_type))18918 if (type_is_invalid(param_type))
18915 return false;18919 return false;
1891618920
18917 casted_arg = ir_implicit_cast(ira, arg, param_type);18921 casted_arg = ir_implicit_cast2(ira, arg_src, arg, param_type);
18918 if (type_is_invalid(casted_arg->value->type))18922 if (type_is_invalid(casted_arg->value->type))
18919 return false;18923 return false;
18920 } else {18924 } else {
...@@ -19201,7 +19205,7 @@ static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr,...@@ -19201,7 +19205,7 @@ static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr,
1920119205
19202static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,19206static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
19203 ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref,19207 ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref,
19204 IrInstGen *first_arg_ptr, CallModifier modifier,19208 IrInstGen *first_arg_ptr, IrInst *first_arg_ptr_src, CallModifier modifier,
19205 IrInstGen *new_stack, IrInst *new_stack_src, bool is_async_call_builtin,19209 IrInstGen *new_stack, IrInst *new_stack_src, bool is_async_call_builtin,
19206 IrInstGen **args_ptr, size_t args_len, IrInstGen *ret_ptr, ResultLoc *call_result_loc)19210 IrInstGen **args_ptr, size_t args_len, IrInstGen *ret_ptr, ResultLoc *call_result_loc)
19207{19211{
...@@ -19416,8 +19420,8 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -19416,8 +19420,8 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
19416 return ira->codegen->invalid_inst_gen;19420 return ira->codegen->invalid_inst_gen;
19417 }19421 }
1941819422
19419 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, first_arg, &impl_fn->child_scope,19423 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, first_arg, first_arg_ptr_src,
19420 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))19424 &impl_fn->child_scope, &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))
19421 {19425 {
19422 return ira->codegen->invalid_inst_gen;19426 return ira->codegen->invalid_inst_gen;
19423 }19427 }
...@@ -19431,7 +19435,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -19431,7 +19435,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
19431 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);19435 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);
19432 assert(param_decl_node->type == NodeTypeParamDecl);19436 assert(param_decl_node->type == NodeTypeParamDecl);
1943319437
19434 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &impl_fn->child_scope,19438 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &arg->base, &impl_fn->child_scope,
19435 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))19439 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))
19436 {19440 {
19437 return ira->codegen->invalid_inst_gen;19441 return ira->codegen->invalid_inst_gen;
...@@ -19479,7 +19483,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -19479,7 +19483,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
19479 case ReqCompTimeYes:19483 case ReqCompTimeYes:
19480 // Throw out our work and call the function as if it were comptime.19484 // Throw out our work and call the function as if it were comptime.
19481 return ir_analyze_fn_call(ira, source_instr, fn_entry, fn_type, fn_ref, first_arg_ptr,19485 return ir_analyze_fn_call(ira, source_instr, fn_entry, fn_type, fn_ref, first_arg_ptr,
19482 CallModifierCompileTime, new_stack, new_stack_src, is_async_call_builtin,19486 first_arg_ptr_src, CallModifierCompileTime, new_stack, new_stack_src, is_async_call_builtin,
19483 args_ptr, args_len, ret_ptr, call_result_loc);19487 args_ptr, args_len, ret_ptr, call_result_loc);
19484 case ReqCompTimeInvalid:19488 case ReqCompTimeInvalid:
19485 return ira->codegen->invalid_inst_gen;19489 return ira->codegen->invalid_inst_gen;
...@@ -19600,7 +19604,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -19600,7 +19604,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
19600 return ira->codegen->invalid_inst_gen;19604 return ira->codegen->invalid_inst_gen;
19601 }19605 }
1960219606
19603 IrInstGen *casted_arg = ir_implicit_cast(ira, first_arg, param_type);19607 IrInstGen *casted_arg = ir_implicit_cast2(ira, first_arg_ptr_src, first_arg, param_type);
19604 if (type_is_invalid(casted_arg->value->type))19608 if (type_is_invalid(casted_arg->value->type))
19605 return ira->codegen->invalid_inst_gen;19609 return ira->codegen->invalid_inst_gen;
1960619610
...@@ -19696,7 +19700,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -19696,7 +19700,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1969619700
19697static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_instruction,19701static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_instruction,
19698 ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref,19702 ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref,
19699 IrInstGen *first_arg_ptr, CallModifier modifier)19703 IrInstGen *first_arg_ptr, IrInst *first_arg_ptr_src, CallModifier modifier)
19700{19704{
19701 IrInstGen *new_stack = nullptr;19705 IrInstGen *new_stack = nullptr;
19702 IrInst *new_stack_src = nullptr;19706 IrInst *new_stack_src = nullptr;
...@@ -19719,8 +19723,9 @@ static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_ins...@@ -19719,8 +19723,9 @@ static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_ins
19719 return ira->codegen->invalid_inst_gen;19723 return ira->codegen->invalid_inst_gen;
19720 }19724 }
19721 IrInstGen *result = ir_analyze_fn_call(ira, &call_instruction->base.base, fn_entry, fn_type, fn_ref,19725 IrInstGen *result = ir_analyze_fn_call(ira, &call_instruction->base.base, fn_entry, fn_type, fn_ref,
19722 first_arg_ptr, modifier, new_stack, new_stack_src, call_instruction->is_async_call_builtin,19726 first_arg_ptr, first_arg_ptr_src, modifier, new_stack, new_stack_src,
19723 args_ptr, call_instruction->arg_count, ret_ptr, call_instruction->result_loc);19727 call_instruction->is_async_call_builtin, args_ptr, call_instruction->arg_count, ret_ptr,
19728 call_instruction->result_loc);
19724 deallocate(args_ptr, call_instruction->arg_count, "IrInstGen *");19729 deallocate(args_ptr, call_instruction->arg_count, "IrInstGen *");
19725 return result;19730 return result;
19726}19731}
...@@ -19771,12 +19776,14 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,...@@ -19771,12 +19776,14 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,
19771 }19776 }
1977219777
19773 IrInstGen *first_arg_ptr = nullptr;19778 IrInstGen *first_arg_ptr = nullptr;
19779 IrInst *first_arg_ptr_src = nullptr;
19774 ZigFn *fn = nullptr;19780 ZigFn *fn = nullptr;
19775 if (instr_is_comptime(fn_ref)) {19781 if (instr_is_comptime(fn_ref)) {
19776 if (fn_ref->value->type->id == ZigTypeIdBoundFn) {19782 if (fn_ref->value->type->id == ZigTypeIdBoundFn) {
19777 assert(fn_ref->value->special == ConstValSpecialStatic);19783 assert(fn_ref->value->special == ConstValSpecialStatic);
19778 fn = fn_ref->value->data.x_bound_fn.fn;19784 fn = fn_ref->value->data.x_bound_fn.fn;
19779 first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;19785 first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;
19786 first_arg_ptr_src = fn_ref->value->data.x_bound_fn.first_arg_src;
19780 if (type_is_invalid(first_arg_ptr->value->type))19787 if (type_is_invalid(first_arg_ptr->value->type))
19781 return ira->codegen->invalid_inst_gen;19788 return ira->codegen->invalid_inst_gen;
19782 } else {19789 } else {
...@@ -19818,7 +19825,7 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,...@@ -19818,7 +19825,7 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,
19818 return ira->codegen->invalid_inst_gen;19825 return ira->codegen->invalid_inst_gen;
19819 }19826 }
1982019827
19821 return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr,19828 return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr, first_arg_ptr_src,
19822 modifier, stack, &stack->base, false, args_ptr, args_len, nullptr, result_loc);19829 modifier, stack, &stack->base, false, args_ptr, args_len, nullptr, result_loc);
19823}19830}
1982419831
...@@ -19894,14 +19901,15 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal...@@ -19894,14 +19901,15 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal
19894 ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value->type;19901 ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value->type;
19895 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;19902 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;
19896 return ir_analyze_fn_call_src(ira, call_instruction, fn_table_entry, fn_type,19903 return ir_analyze_fn_call_src(ira, call_instruction, fn_table_entry, fn_type,
19897 fn_ref, nullptr, modifier);19904 fn_ref, nullptr, nullptr, modifier);
19898 } else if (fn_ref->value->type->id == ZigTypeIdBoundFn) {19905 } else if (fn_ref->value->type->id == ZigTypeIdBoundFn) {
19899 assert(fn_ref->value->special == ConstValSpecialStatic);19906 assert(fn_ref->value->special == ConstValSpecialStatic);
19900 ZigFn *fn_table_entry = fn_ref->value->data.x_bound_fn.fn;19907 ZigFn *fn_table_entry = fn_ref->value->data.x_bound_fn.fn;
19901 IrInstGen *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;19908 IrInstGen *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;
19909 IrInst *first_arg_ptr_src = fn_ref->value->data.x_bound_fn.first_arg_src;
19902 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;19910 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;
19903 return ir_analyze_fn_call_src(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,19911 return ir_analyze_fn_call_src(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
19904 fn_ref, first_arg_ptr, modifier);19912 fn_ref, first_arg_ptr, first_arg_ptr_src, modifier);
19905 } else {19913 } else {
19906 ir_add_error(ira, &fn_ref->base,19914 ir_add_error(ira, &fn_ref->base,
19907 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));19915 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));
...@@ -19911,7 +19919,7 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal...@@ -19911,7 +19919,7 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal
1991119919
19912 if (fn_ref->value->type->id == ZigTypeIdFn) {19920 if (fn_ref->value->type->id == ZigTypeIdFn) {
19913 return ir_analyze_fn_call_src(ira, call_instruction, nullptr, fn_ref->value->type,19921 return ir_analyze_fn_call_src(ira, call_instruction, nullptr, fn_ref->value->type,
19914 fn_ref, nullptr, modifier);19922 fn_ref, nullptr, nullptr, modifier);
19915 } else {19923 } else {
19916 ir_add_error(ira, &fn_ref->base,19924 ir_add_error(ira, &fn_ref->base,
19917 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));19925 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));
...@@ -21009,7 +21017,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP...@@ -21009,7 +21017,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
2100921017
21010static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,21018static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
21011 ZigType *bare_struct_type, Buf *field_name, IrInst* source_instr,21019 ZigType *bare_struct_type, Buf *field_name, IrInst* source_instr,
21012 IrInstGen *container_ptr, ZigType *container_type)21020 IrInstGen *container_ptr, IrInst *container_ptr_src, ZigType *container_type)
21013{21021{
21014 if (!is_slice(bare_struct_type)) {21022 if (!is_slice(bare_struct_type)) {
21015 ScopeDecls *container_scope = get_container_scope(bare_struct_type);21023 ScopeDecls *container_scope = get_container_scope(bare_struct_type);
...@@ -21030,7 +21038,8 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -21030,7 +21038,8 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
21030 if (type_is_invalid(fn_entry->type_entry))21038 if (type_is_invalid(fn_entry->type_entry))
21031 return ira->codegen->invalid_inst_gen;21039 return ira->codegen->invalid_inst_gen;
2103221040
21033 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn_entry, container_ptr);21041 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn_entry, container_ptr,
21042 container_ptr_src);
21034 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);21043 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);
21035 } else if (tld->id == TldIdVar) {21044 } else if (tld->id == TldIdVar) {
21036 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);21045 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);
...@@ -21049,7 +21058,8 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -21049,7 +21058,8 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
21049 if (var->const_value->type->id == ZigTypeIdFn) {21058 if (var->const_value->type->id == ZigTypeIdFn) {
21050 ir_assert(var->const_value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr);21059 ir_assert(var->const_value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr);
21051 ZigFn *fn = var->const_value->data.x_ptr.data.fn.fn_entry;21060 ZigFn *fn = var->const_value->data.x_ptr.data.fn.fn_entry;
21052 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn, container_ptr);21061 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn, container_ptr,
21062 container_ptr_src);
21053 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);21063 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);
21054 }21064 }
21055 }21065 }
...@@ -21213,7 +21223,8 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,...@@ -21213,7 +21223,8 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
21213}21223}
2121421224
21215static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,21225static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
21216 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type, bool initializing)21226 IrInst* source_instr, IrInstGen *container_ptr, IrInst *container_ptr_src,
21227 ZigType *container_type, bool initializing)
21217{21228{
21218 Error err;21229 Error err;
2121921230
...@@ -21235,13 +21246,13 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name...@@ -21235,13 +21246,13 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
21235 return ir_analyze_struct_field_ptr(ira, source_instr, field, container_ptr, bare_type, initializing);21246 return ir_analyze_struct_field_ptr(ira, source_instr, field, container_ptr, bare_type, initializing);
21236 } else {21247 } else {
21237 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,21248 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
21238 source_instr, container_ptr, container_type);21249 source_instr, container_ptr, container_ptr_src, container_type);
21239 }21250 }
21240 }21251 }
2124121252
21242 if (bare_type->id == ZigTypeIdEnum) {21253 if (bare_type->id == ZigTypeIdEnum) {
21243 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,21254 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
21244 source_instr, container_ptr, container_type);21255 source_instr, container_ptr, container_ptr_src, container_type);
21245 }21256 }
2124621257
21247 if (bare_type->id == ZigTypeIdUnion) {21258 if (bare_type->id == ZigTypeIdUnion) {
...@@ -21251,7 +21262,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name...@@ -21251,7 +21262,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
21251 TypeUnionField *field = find_union_type_field(bare_type, field_name);21262 TypeUnionField *field = find_union_type_field(bare_type, field_name);
21252 if (field == nullptr) {21263 if (field == nullptr) {
21253 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,21264 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
21254 source_instr, container_ptr, container_type);21265 source_instr, container_ptr, container_ptr_src, container_type);
21255 }21266 }
2125621267
21257 ZigType *field_type = resolve_union_field_type(ira->codegen, field);21268 ZigType *field_type = resolve_union_field_type(ira->codegen, field);
...@@ -21445,10 +21456,14 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel...@@ -21445,10 +21456,14 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
21445 if (container_type->id == ZigTypeIdPointer) {21456 if (container_type->id == ZigTypeIdPointer) {
21446 ZigType *bare_type = container_ref_type(container_type);21457 ZigType *bare_type = container_ref_type(container_type);
21447 IrInstGen *container_child = ir_get_deref(ira, &field_ptr_instruction->base.base, container_ptr, nullptr);21458 IrInstGen *container_child = ir_get_deref(ira, &field_ptr_instruction->base.base, container_ptr, nullptr);
21448 IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base, container_child, bare_type, field_ptr_instruction->initializing);21459 IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base,
21460 container_child, &field_ptr_instruction->container_ptr->base, bare_type,
21461 field_ptr_instruction->initializing);
21449 return result;21462 return result;
21450 } else {21463 } else {
21451 IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base, container_ptr, container_type, field_ptr_instruction->initializing);21464 IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base,
21465 container_ptr, &field_ptr_instruction->container_ptr->base, container_type,
21466 field_ptr_instruction->initializing);
21452 return result;21467 return result;
21453 }21468 }
21454 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {21469 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {
...@@ -25096,7 +25111,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch...@@ -25096,7 +25111,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
2509625111
25097 // TODO let this be volatile25112 // TODO let this be volatile
25098 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);25113 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
25099 IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type);25114 IrInstGen *casted_ptr = ir_implicit_cast2(ira, &instruction->ptr->base, ptr, ptr_type);
25100 if (type_is_invalid(casted_ptr->value->type))25115 if (type_is_invalid(casted_ptr->value->type))
25101 return ira->codegen->invalid_inst_gen;25116 return ira->codegen->invalid_inst_gen;
2510225117
...@@ -25124,11 +25139,11 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch...@@ -25124,11 +25139,11 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch
25124 if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order))25139 if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order))
25125 return ira->codegen->invalid_inst_gen;25140 return ira->codegen->invalid_inst_gen;
2512625141
25127 IrInstGen *casted_cmp_value = ir_implicit_cast(ira, cmp_value, operand_type);25142 IrInstGen *casted_cmp_value = ir_implicit_cast2(ira, &instruction->cmp_value->base, cmp_value, operand_type);
25128 if (type_is_invalid(casted_cmp_value->value->type))25143 if (type_is_invalid(casted_cmp_value->value->type))
25129 return ira->codegen->invalid_inst_gen;25144 return ira->codegen->invalid_inst_gen;
2513025145
25131 IrInstGen *casted_new_value = ir_implicit_cast(ira, new_value, operand_type);25146 IrInstGen *casted_new_value = ir_implicit_cast2(ira, &instruction->new_value->base, new_value, operand_type);
25132 if (type_is_invalid(casted_new_value->value->type))25147 if (type_is_invalid(casted_new_value->value->type))
25133 return ira->codegen->invalid_inst_gen;25148 return ira->codegen->invalid_inst_gen;
2513425149
...@@ -25219,7 +25234,7 @@ static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTrunc...@@ -25219,7 +25234,7 @@ static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTrunc
25219 }25234 }
2522025235
25221 if (dest_type->id == ZigTypeIdComptimeInt) {25236 if (dest_type->id == ZigTypeIdComptimeInt) {
25222 return ir_implicit_cast(ira, target, dest_type);25237 return ir_implicit_cast2(ira, &instruction->target->base, target, dest_type);
25223 }25238 }
2522425239
25225 if (instr_is_comptime(target)) {25240 if (instr_is_comptime(target)) {
...@@ -25273,7 +25288,7 @@ static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCa...@@ -25273,7 +25288,7 @@ static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCa
25273 }25288 }
2527425289
25275 if (instr_is_comptime(target)) {25290 if (instr_is_comptime(target)) {
25276 return ir_implicit_cast(ira, target, dest_type);25291 return ir_implicit_cast2(ira, &instruction->target->base, target, dest_type);
25277 }25292 }
2527825293
25279 if (dest_type->id == ZigTypeIdComptimeInt) {25294 if (dest_type->id == ZigTypeIdComptimeInt) {
...@@ -25401,7 +25416,7 @@ static IrInstGen *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstSrcFro...@@ -25401,7 +25416,7 @@ static IrInstGen *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstSrcFro
25401 src_ptr_align, 0, 0, false);25416 src_ptr_align, 0, 0, false);
25402 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);25417 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
2540325418
25404 IrInstGen *casted_value = ir_implicit_cast(ira, target, u8_slice);25419 IrInstGen *casted_value = ir_implicit_cast2(ira, &instruction->target->base, target, u8_slice);
25405 if (type_is_invalid(casted_value->value->type))25420 if (type_is_invalid(casted_value->value->type))
25406 return ira->codegen->invalid_inst_gen;25421 return ira->codegen->invalid_inst_gen;
2540725422
test/compile_errors.zig+6-7
...@@ -1658,7 +1658,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1658,7 +1658,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1658 cases.addTest("return invalid type from test",1658 cases.addTest("return invalid type from test",
1659 \\test "example" { return 1; }1659 \\test "example" { return 1; }
1660 , &[_][]const u8{1660 , &[_][]const u8{
1661 "tmp.zig:1:25: error: integer value 1 cannot be coerced to type 'void'",1661 "tmp.zig:1:25: error: expected type 'void', found 'comptime_int'",
1662 });1662 });
16631663
1664 cases.add("threadlocal qualifier on const",1664 cases.add("threadlocal qualifier on const",
...@@ -2487,7 +2487,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2487,7 +2487,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2487 \\ var rule_set = try Foo.init();2487 \\ var rule_set = try Foo.init();
2488 \\}2488 \\}
2489 , &[_][]const u8{2489 , &[_][]const u8{
2490 "tmp.zig:2:10: error: expected type 'i32', found 'type'",2490 "tmp.zig:2:19: error: expected type 'i32', found 'type'",
2491 });2491 });
24922492
2493 cases.add("slicing single-item pointer",2493 cases.add("slicing single-item pointer",
...@@ -3393,7 +3393,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3393,7 +3393,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3393 \\3393 \\
3394 \\fn b() void {}3394 \\fn b() void {}
3395 , &[_][]const u8{3395 , &[_][]const u8{
3396 "tmp.zig:3:6: error: unreachable code",3396 "tmp.zig:3:5: error: unreachable code",
3397 });3397 });
33983398
3399 cases.add("bad import",3399 cases.add("bad import",
...@@ -4011,8 +4011,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4011,8 +4011,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4011 \\4011 \\
4012 \\export fn entry() usize { return @sizeOf(@TypeOf(Foo)); }4012 \\export fn entry() usize { return @sizeOf(@TypeOf(Foo)); }
4013 , &[_][]const u8{4013 , &[_][]const u8{
4014 "tmp.zig:5:25: error: unable to evaluate constant expression",4014 "tmp.zig:5:25: error: cannot store runtime value in compile time variable",
4015 "tmp.zig:2:12: note: referenced here",4015 "tmp.zig:2:12: note: called from here",
4016 });4016 });
40174017
4018 cases.add("addition with non numbers",4018 cases.add("addition with non numbers",
...@@ -4652,7 +4652,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4652,7 +4652,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4652 \\fn something() anyerror!void { }4652 \\fn something() anyerror!void { }
4653 , &[_][]const u8{4653 , &[_][]const u8{
4654 "tmp.zig:2:5: error: expected type 'void', found 'anyerror'",4654 "tmp.zig:2:5: error: expected type 'void', found 'anyerror'",
4655 "tmp.zig:1:15: note: return type declared here",
4656 });4655 });
46574656
4658 cases.add("invalid pointer for var type",4657 cases.add("invalid pointer for var type",
...@@ -5743,7 +5742,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5743,7 +5742,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5743 \\ @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) });5742 \\ @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) });
5744 \\}5743 \\}
5745 , &[_][]const u8{5744 , &[_][]const u8{
5746 "tmp.zig:3:50: error: expected type 'std.builtin.GlobalLinkage', found 'u32'",5745 "tmp.zig:3:59: error: expected type 'std.builtin.GlobalLinkage', found 'comptime_int'",
5747 });5746 });
57485747
5749 cases.add("struct with invalid field",5748 cases.add("struct with invalid field",