| ... | @@ -17,10 +17,6 @@ | ... | @@ -17,10 +17,6 @@ |
| 17 | | 17 | |
| 18 | #include <errno.h> | 18 | #include <errno.h> |
| 19 | | 19 | |
| 20 | struct IrExecContext { | | |
| 21 | ZigList<ZigValue *> mem_slot_list; | | |
| 22 | }; | | |
| 23 | | | |
| 24 | struct IrBuilderSrc { | 20 | struct IrBuilderSrc { |
| 25 | CodeGen *codegen; | 21 | CodeGen *codegen; |
| 26 | IrExecutableSrc *exec; | 22 | IrExecutableSrc *exec; |
| ... | @@ -38,7 +34,6 @@ struct IrAnalyze { | ... | @@ -38,7 +34,6 @@ struct IrAnalyze { |
| 38 | CodeGen *codegen; | 34 | CodeGen *codegen; |
| 39 | IrBuilderSrc old_irb; | 35 | IrBuilderSrc old_irb; |
| 40 | IrBuilderGen new_irb; | 36 | IrBuilderGen new_irb; |
| 41 | IrExecContext exec_context; | | |
| 42 | size_t old_bb_index; | 37 | size_t old_bb_index; |
| 43 | size_t instruction_index; | 38 | size_t instruction_index; |
| 44 | ZigType *explicit_return_type; | 39 | ZigType *explicit_return_type; |
| ... | @@ -48,6 +43,7 @@ struct IrAnalyze { | ... | @@ -48,6 +43,7 @@ struct IrAnalyze { |
| 48 | IrBasicBlockSrc *const_predecessor_bb; | 43 | IrBasicBlockSrc *const_predecessor_bb; |
| 49 | size_t ref_count; | 44 | size_t ref_count; |
| 50 | size_t break_debug_id; // for debugging purposes | 45 | size_t break_debug_id; // for debugging purposes |
| | 46 | IrInstGen *return_ptr; |
| 51 | | 47 | |
| 52 | // For the purpose of using in a debugger | 48 | // For the purpose of using in a debugger |
| 53 | void dump(); | 49 | void dump(); |
| ... | @@ -222,7 +218,8 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst *source_instr, IrInstGen * | ... | @@ -222,7 +218,8 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst *source_instr, IrInstGen * |
| 222 | ResultLoc *result_loc); | 218 | ResultLoc *result_loc); |
| 223 | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutableSrc *exec, AstNode *source_node, Buf *msg); | 219 | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutableSrc *exec, AstNode *source_node, Buf *msg); |
| 224 | static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, | 220 | static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 225 | 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); |
| 226 | static void ir_assert(bool ok, IrInst* source_instruction); | 223 | static void ir_assert(bool ok, IrInst* source_instruction); |
| 227 | static void ir_assert_gen(bool ok, IrInstGen *source_instruction); | 224 | static void ir_assert_gen(bool ok, IrInstGen *source_instruction); |
| 228 | static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var); | 225 | static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var); |
| ... | @@ -236,7 +233,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val) | ... | @@ -236,7 +233,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val) |
| 236 | static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, | 233 | static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, |
| 237 | ZigValue *out_val, ZigValue *ptr_val); | 234 | ZigValue *out_val, ZigValue *ptr_val); |
| 238 | static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr, | 235 | static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr, |
| 239 | ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on); | 236 | IrInst *ptr_src, ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on); |
| 240 | static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed); | 237 | static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed); |
| 241 | static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align); | 238 | static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align); |
| 242 | static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target, | 239 | static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target, |
| ... | @@ -244,11 +241,9 @@ static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, Ir | ... | @@ -244,11 +241,9 @@ static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, Ir |
| 244 | static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, | 241 | static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, |
| 245 | ZigType *dest_type); | 242 | ZigType *dest_type); |
| 246 | static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr, | 243 | static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 247 | ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, | 244 | ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, bool allow_discard); |
| 248 | bool non_null_comptime, bool allow_discard); | | |
| 249 | static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr, | 245 | static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 250 | ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, | 246 | ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, bool allow_discard); |
| 251 | bool non_null_comptime, bool allow_discard); | | |
| 252 | static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr, | 247 | static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr, |
| 253 | IrInstGen *base_ptr, bool safety_check_on, bool initializing); | 248 | IrInstGen *base_ptr, bool safety_check_on, bool initializing); |
| 254 | static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr, | 249 | static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr, |
| ... | @@ -773,7 +768,6 @@ static void ira_deref(IrAnalyze *ira) { | ... | @@ -773,7 +768,6 @@ static void ira_deref(IrAnalyze *ira) { |
| 773 | //destroy(ira->old_irb.exec, "IrExecutableSrc"); | 768 | //destroy(ira->old_irb.exec, "IrExecutableSrc"); |
| 774 | ira->src_implicit_return_type_list.deinit(); | 769 | ira->src_implicit_return_type_list.deinit(); |
| 775 | ira->resume_stack.deinit(); | 770 | ira->resume_stack.deinit(); |
| 776 | ira->exec_context.mem_slot_list.deinit(); | | |
| 777 | destroy(ira, "IrAnalyze"); | 771 | destroy(ira, "IrAnalyze"); |
| 778 | } | 772 | } |
| 779 | | 773 | |
| ... | @@ -887,7 +881,6 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte | ... | @@ -887,7 +881,6 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte |
| 887 | case ZigTypeIdComptimeFloat: | 881 | case ZigTypeIdComptimeFloat: |
| 888 | case ZigTypeIdComptimeInt: | 882 | case ZigTypeIdComptimeInt: |
| 889 | case ZigTypeIdEnumLiteral: | 883 | case ZigTypeIdEnumLiteral: |
| 890 | case ZigTypeIdPointer: | | |
| 891 | case ZigTypeIdUndefined: | 884 | case ZigTypeIdUndefined: |
| 892 | case ZigTypeIdNull: | 885 | case ZigTypeIdNull: |
| 893 | case ZigTypeIdBoundFn: | 886 | case ZigTypeIdBoundFn: |
| ... | @@ -896,6 +889,8 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte | ... | @@ -896,6 +889,8 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte |
| 896 | case ZigTypeIdAnyFrame: | 889 | case ZigTypeIdAnyFrame: |
| 897 | case ZigTypeIdFn: | 890 | case ZigTypeIdFn: |
| 898 | return true; | 891 | return true; |
| | 892 | case ZigTypeIdPointer: |
| | 893 | return expected->data.pointer.inferred_struct_field == actual->data.pointer.inferred_struct_field; |
| 899 | case ZigTypeIdFloat: | 894 | case ZigTypeIdFloat: |
| 900 | return expected->data.floating.bit_count == actual->data.floating.bit_count; | 895 | return expected->data.floating.bit_count == actual->data.floating.bit_count; |
| 901 | case ZigTypeIdInt: | 896 | case ZigTypeIdInt: |
| ... | @@ -958,12 +953,6 @@ static size_t exec_next_debug_id_gen(IrExecutableGen *exec) { | ... | @@ -958,12 +953,6 @@ static size_t exec_next_debug_id_gen(IrExecutableGen *exec) { |
| 958 | return result; | 953 | return result; |
| 959 | } | 954 | } |
| 960 | | 955 | |
| 961 | static size_t exec_next_mem_slot(IrExecutableSrc *exec) { | | |
| 962 | size_t result = exec->mem_slot_count; | | |
| 963 | exec->mem_slot_count += 1; | | |
| 964 | return result; | | |
| 965 | } | | |
| 966 | | | |
| 967 | static ZigFn *exec_fn_entry(IrExecutableSrc *exec) { | 956 | static ZigFn *exec_fn_entry(IrExecutableSrc *exec) { |
| 968 | return exec->fn_entry; | 957 | return exec->fn_entry; |
| 969 | } | 958 | } |
| ... | @@ -1018,16 +1007,46 @@ static void ir_ref_var(ZigVar *var) { | ... | @@ -1018,16 +1007,46 @@ static void ir_ref_var(ZigVar *var) { |
| 1018 | var->ref_count += 1; | 1007 | var->ref_count += 1; |
| 1019 | } | 1008 | } |
| 1020 | | 1009 | |
| | 1010 | static void create_result_ptr(CodeGen *codegen, ZigType *expected_type, |
| | 1011 | ZigValue **out_result, ZigValue **out_result_ptr) |
| | 1012 | { |
| | 1013 | ZigValue *result = create_const_vals(1); |
| | 1014 | ZigValue *result_ptr = create_const_vals(1); |
| | 1015 | result->special = ConstValSpecialUndef; |
| | 1016 | result->type = expected_type; |
| | 1017 | result_ptr->special = ConstValSpecialStatic; |
| | 1018 | result_ptr->type = get_pointer_to_type(codegen, result->type, false); |
| | 1019 | result_ptr->data.x_ptr.mut = ConstPtrMutComptimeVar; |
| | 1020 | result_ptr->data.x_ptr.special = ConstPtrSpecialRef; |
| | 1021 | result_ptr->data.x_ptr.data.ref.pointee = result; |
| | 1022 | |
| | 1023 | *out_result = result; |
| | 1024 | *out_result_ptr = result_ptr; |
| | 1025 | } |
| | 1026 | |
| 1021 | ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) { | 1027 | ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) { |
| 1022 | ZigValue *result = ir_eval_const_value(ira->codegen, scope, node, ira->codegen->builtin_types.entry_type, | 1028 | Error err; |
| 1023 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, nullptr, | | |
| 1024 | node, nullptr, ira->new_irb.exec, nullptr, UndefBad); | | |
| 1025 | | 1029 | |
| | 1030 | ZigValue *result; |
| | 1031 | ZigValue *result_ptr; |
| | 1032 | create_result_ptr(ira->codegen, ira->codegen->builtin_types.entry_type, &result, &result_ptr); |
| | 1033 | |
| | 1034 | if ((err = ir_eval_const_value(ira->codegen, scope, node, result_ptr, |
| | 1035 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, |
| | 1036 | nullptr, nullptr, node, nullptr, ira->new_irb.exec, nullptr, UndefBad))) |
| | 1037 | { |
| | 1038 | return ira->codegen->builtin_types.entry_invalid; |
| | 1039 | } |
| 1026 | if (type_is_invalid(result->type)) | 1040 | if (type_is_invalid(result->type)) |
| 1027 | return ira->codegen->builtin_types.entry_invalid; | 1041 | return ira->codegen->builtin_types.entry_invalid; |
| 1028 | | 1042 | |
| 1029 | assert(result->special != ConstValSpecialRuntime); | 1043 | assert(result->special != ConstValSpecialRuntime); |
| 1030 | return result->data.x_type; | 1044 | ZigType *res_type = result->data.x_type; |
| | 1045 | |
| | 1046 | destroy(result_ptr, "ZigValue"); |
| | 1047 | destroy(result, "ZigValue"); |
| | 1048 | |
| | 1049 | return res_type; |
| 1031 | } | 1050 | } |
| 1032 | | 1051 | |
| 1033 | static IrBasicBlockSrc *ir_create_basic_block(IrBuilderSrc *irb, Scope *scope, const char *name_hint) { | 1052 | static IrBasicBlockSrc *ir_create_basic_block(IrBuilderSrc *irb, Scope *scope, const char *name_hint) { |
| ... | @@ -2304,9 +2323,8 @@ static IrInstGen *ir_build_var_ptr_gen(IrAnalyze *ira, IrInst *source_instr, Zig | ... | @@ -2304,9 +2323,8 @@ static IrInstGen *ir_build_var_ptr_gen(IrAnalyze *ira, IrInst *source_instr, Zig |
| 2304 | return &instruction->base; | 2323 | return &instruction->base; |
| 2305 | } | 2324 | } |
| 2306 | | 2325 | |
| 2307 | static IrInstGen *ir_build_return_ptr(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) { | 2326 | static IrInstGen *ir_build_return_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ty) { |
| 2308 | IrInstGenReturnPtr *instruction = ir_build_inst_gen<IrInstGenReturnPtr>(&ira->new_irb, | 2327 | IrInstGenReturnPtr *instruction = ir_build_inst_gen<IrInstGenReturnPtr>(&ira->new_irb, scope, source_node); |
| 2309 | source_instruction->scope, source_instruction->source_node); | | |
| 2310 | instruction->base.value->type = ty; | 2328 | instruction->base.value->type = ty; |
| 2311 | return &instruction->base; | 2329 | return &instruction->base; |
| 2312 | } | 2330 | } |
| ... | @@ -4582,6 +4600,7 @@ static IrInstSrc *ir_build_reset_result(IrBuilderSrc *irb, Scope *scope, AstNode | ... | @@ -4582,6 +4600,7 @@ static IrInstSrc *ir_build_reset_result(IrBuilderSrc *irb, Scope *scope, AstNode |
| 4582 | { | 4600 | { |
| 4583 | IrInstSrcResetResult *instruction = ir_build_instruction<IrInstSrcResetResult>(irb, scope, source_node); | 4601 | IrInstSrcResetResult *instruction = ir_build_instruction<IrInstSrcResetResult>(irb, scope, source_node); |
| 4584 | instruction->result_loc = result_loc; | 4602 | instruction->result_loc = result_loc; |
| | 4603 | instruction->base.is_gen = true; |
| 4585 | | 4604 | |
| 4586 | return &instruction->base; | 4605 | return &instruction->base; |
| 4587 | } | 4606 | } |
| ... | @@ -5203,12 +5222,6 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) { | ... | @@ -5203,12 +5222,6 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) { |
| 5203 | static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { | 5222 | static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 5204 | assert(node->type == NodeTypeReturnExpr); | 5223 | assert(node->type == NodeTypeReturnExpr); |
| 5205 | | 5224 | |
| 5206 | ZigFn *fn_entry = exec_fn_entry(irb->exec); | | |
| 5207 | if (!fn_entry) { | | |
| 5208 | add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition")); | | |
| 5209 | return irb->codegen->invalid_inst_src; | | |
| 5210 | } | | |
| 5211 | | | |
| 5212 | ScopeDeferExpr *scope_defer_expr = get_scope_defer_expr(scope); | 5225 | ScopeDeferExpr *scope_defer_expr = get_scope_defer_expr(scope); |
| 5213 | if (scope_defer_expr) { | 5226 | if (scope_defer_expr) { |
| 5214 | if (!scope_defer_expr->reported_err) { | 5227 | if (!scope_defer_expr->reported_err) { |
| ... | @@ -5350,7 +5363,6 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s | ... | @@ -5350,7 +5363,6 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s |
| 5350 | ZigVar *variable_entry = allocate<ZigVar>(1, "ZigVar"); | 5363 | ZigVar *variable_entry = allocate<ZigVar>(1, "ZigVar"); |
| 5351 | variable_entry->parent_scope = parent_scope; | 5364 | variable_entry->parent_scope = parent_scope; |
| 5352 | variable_entry->shadowable = is_shadowable; | 5365 | variable_entry->shadowable = is_shadowable; |
| 5353 | variable_entry->mem_slot_index = SIZE_MAX; | | |
| 5354 | variable_entry->is_comptime = is_comptime; | 5366 | variable_entry->is_comptime = is_comptime; |
| 5355 | variable_entry->src_arg_index = SIZE_MAX; | 5367 | variable_entry->src_arg_index = SIZE_MAX; |
| 5356 | variable_entry->const_value = create_const_vals(1); | 5368 | variable_entry->const_value = create_const_vals(1); |
| ... | @@ -5414,7 +5426,6 @@ static ZigVar *ir_create_var(IrBuilderSrc *irb, AstNode *node, Scope *scope, Buf | ... | @@ -5414,7 +5426,6 @@ static ZigVar *ir_create_var(IrBuilderSrc *irb, AstNode *node, Scope *scope, Buf |
| 5414 | (is_underscored ? nullptr : name), src_is_const, gen_is_const, | 5426 | (is_underscored ? nullptr : name), src_is_const, gen_is_const, |
| 5415 | (is_underscored ? true : is_shadowable), is_comptime, false); | 5427 | (is_underscored ? true : is_shadowable), is_comptime, false); |
| 5416 | if (is_comptime != nullptr || gen_is_const) { | 5428 | if (is_comptime != nullptr || gen_is_const) { |
| 5417 | var->mem_slot_index = exec_next_mem_slot(irb->exec); | | |
| 5418 | var->owner_exec = irb->exec; | 5429 | var->owner_exec = irb->exec; |
| 5419 | } | 5430 | } |
| 5420 | assert(var->child_scope); | 5431 | assert(var->child_scope); |
| ... | @@ -5551,6 +5562,10 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode * | ... | @@ -5551,6 +5562,10 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode * |
| 5551 | // only generate unconditional defers | 5562 | // only generate unconditional defers |
| 5552 | | 5563 | |
| 5553 | ir_mark_gen(ir_build_add_implicit_return_type(irb, child_scope, block_node, result, nullptr)); | 5564 | ir_mark_gen(ir_build_add_implicit_return_type(irb, child_scope, block_node, result, nullptr)); |
| | 5565 | ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn"); |
| | 5566 | result_loc_ret->base.id = ResultLocIdReturn; |
| | 5567 | ir_build_reset_result(irb, parent_scope, block_node, &result_loc_ret->base); |
| | 5568 | ir_mark_gen(ir_build_end_expr(irb, parent_scope, block_node, result, &result_loc_ret->base)); |
| 5554 | ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false); | 5569 | ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false); |
| 5555 | return ir_mark_gen(ir_build_return_src(irb, child_scope, result->base.source_node, result)); | 5570 | return ir_mark_gen(ir_build_return_src(irb, child_scope, result->base.source_node, result)); |
| 5556 | } | 5571 | } |
| ... | @@ -7001,6 +7016,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod | ... | @@ -7001,6 +7016,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod |
| 7001 | ResultLocBitCast *result_loc_bit_cast = allocate<ResultLocBitCast>(1); | 7016 | ResultLocBitCast *result_loc_bit_cast = allocate<ResultLocBitCast>(1); |
| 7002 | result_loc_bit_cast->base.id = ResultLocIdBitCast; | 7017 | result_loc_bit_cast->base.id = ResultLocIdBitCast; |
| 7003 | result_loc_bit_cast->base.source_instruction = dest_type; | 7018 | result_loc_bit_cast->base.source_instruction = dest_type; |
| | 7019 | result_loc_bit_cast->base.allow_write_through_const = result_loc->allow_write_through_const; |
| 7004 | ir_ref_instruction(dest_type, irb->current_basic_block); | 7020 | ir_ref_instruction(dest_type, irb->current_basic_block); |
| 7005 | result_loc_bit_cast->parent = result_loc; | 7021 | result_loc_bit_cast->parent = result_loc; |
| 7006 | | 7022 | |
| ... | @@ -8462,9 +8478,8 @@ static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNod | ... | @@ -8462,9 +8478,8 @@ static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNod |
| 8462 | ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, result_loc, is_comptime); | 8478 | ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, result_loc, is_comptime); |
| 8463 | | 8479 | |
| 8464 | ir_set_cursor_at_end_and_append_block(irb, body_block); | 8480 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 8465 | Scope *elem_ptr_scope = node->data.for_expr.elem_is_ptr ? parent_scope : &spill_scope->base; | 8481 | IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, &spill_scope->base, node, array_val_ptr, index_val, |
| 8466 | IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, elem_ptr_scope, node, array_val_ptr, index_val, false, | 8482 | false, PtrLenSingle, nullptr); |
| 8467 | PtrLenSingle, nullptr); | | |
| 8468 | // TODO make it an error to write to element variable or i variable. | 8483 | // TODO make it an error to write to element variable or i variable. |
| 8469 | Buf *elem_var_name = elem_node->data.symbol_expr.symbol; | 8484 | Buf *elem_var_name = elem_node->data.symbol_expr.symbol; |
| 8470 | ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime); | 8485 | ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime); |
| ... | @@ -10255,6 +10270,10 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutableSrc *ir_e | ... | @@ -10255,6 +10270,10 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutableSrc *ir_e |
| 10255 | if (!instr_is_unreachable(result)) { | 10270 | if (!instr_is_unreachable(result)) { |
| 10256 | ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->base.source_node, result, nullptr)); | 10271 | ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->base.source_node, result, nullptr)); |
| 10257 | // no need for save_err_ret_addr because this cannot return error | 10272 | // no need for save_err_ret_addr because this cannot return error |
| | 10273 | ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn"); |
| | 10274 | result_loc_ret->base.id = ResultLocIdReturn; |
| | 10275 | ir_build_reset_result(irb, scope, node, &result_loc_ret->base); |
| | 10276 | ir_mark_gen(ir_build_end_expr(irb, scope, node, result, &result_loc_ret->base)); |
| 10258 | ir_mark_gen(ir_build_return_src(irb, scope, result->base.source_node, result)); | 10277 | ir_mark_gen(ir_build_return_src(irb, scope, result->base.source_node, result)); |
| 10259 | } | 10278 | } |
| 10260 | | 10279 | |
| ... | @@ -10374,23 +10393,17 @@ ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_va | ... | @@ -10374,23 +10393,17 @@ ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_va |
| 10374 | return val; | 10393 | return val; |
| 10375 | } | 10394 | } |
| 10376 | | 10395 | |
| 10377 | static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutableGen *exec) { | 10396 | static Error ir_exec_scan_for_side_effects(CodeGen *codegen, IrExecutableGen *exec) { |
| 10378 | IrBasicBlockGen *bb = exec->basic_block_list.at(0); | 10397 | IrBasicBlockGen *bb = exec->basic_block_list.at(0); |
| 10379 | for (size_t i = 0; i < bb->instruction_list.length; i += 1) { | 10398 | for (size_t i = 0; i < bb->instruction_list.length; i += 1) { |
| 10380 | IrInstGen *instruction = bb->instruction_list.at(i); | 10399 | IrInstGen *instruction = bb->instruction_list.at(i); |
| 10381 | if (instruction->id == IrInstGenIdReturn) { | 10400 | if (instruction->id == IrInstGenIdReturn) { |
| 10382 | IrInstGenReturn *ret_inst = (IrInstGenReturn *)instruction; | 10401 | return ErrorNone; |
| 10383 | IrInstGen *operand = ret_inst->operand; | | |
| 10384 | if (operand->value->special == ConstValSpecialRuntime) { | | |
| 10385 | exec_add_error_node_gen(codegen, exec, operand->base.source_node, | | |
| 10386 | buf_sprintf("unable to evaluate constant expression")); | | |
| 10387 | return codegen->invalid_inst_gen->value; | | |
| 10388 | } | | |
| 10389 | return operand->value; | | |
| 10390 | } else if (ir_inst_gen_has_side_effects(instruction)) { | 10402 | } else if (ir_inst_gen_has_side_effects(instruction)) { |
| 10391 | if (instr_is_comptime(instruction)) { | 10403 | if (instr_is_comptime(instruction)) { |
| 10392 | switch (instruction->id) { | 10404 | switch (instruction->id) { |
| 10393 | case IrInstGenIdUnwrapErrPayload: | 10405 | case IrInstGenIdUnwrapErrPayload: |
| | 10406 | case IrInstGenIdOptionalUnwrapPtr: |
| 10394 | case IrInstGenIdUnionFieldPtr: | 10407 | case IrInstGenIdUnionFieldPtr: |
| 10395 | continue; | 10408 | continue; |
| 10396 | default: | 10409 | default: |
| ... | @@ -10403,7 +10416,7 @@ static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutableGen *exec) { | ... | @@ -10403,7 +10416,7 @@ static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutableGen *exec) { |
| 10403 | } | 10416 | } |
| 10404 | exec_add_error_node_gen(codegen, exec, instruction->base.source_node, | 10417 | exec_add_error_node_gen(codegen, exec, instruction->base.source_node, |
| 10405 | buf_sprintf("unable to evaluate constant expression")); | 10418 | buf_sprintf("unable to evaluate constant expression")); |
| 10406 | return codegen->invalid_inst_gen->value; | 10419 | return ErrorSemanticAnalyzeFail; |
| 10407 | } | 10420 | } |
| 10408 | } | 10421 | } |
| 10409 | zig_unreachable(); | 10422 | zig_unreachable(); |
| ... | @@ -12785,26 +12798,28 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc | ... | @@ -12785,26 +12798,28 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc |
| 12785 | wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value->type)); | 12798 | wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value->type)); |
| 12786 | | 12799 | |
| 12787 | if (instr_is_comptime(array_ptr)) { | 12800 | if (instr_is_comptime(array_ptr)) { |
| 12788 | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr->value, source_instr->source_node); | 12801 | ZigValue *array_ptr_val = ir_resolve_const(ira, array_ptr, UndefBad); |
| | 12802 | if (array_ptr_val == nullptr) |
| | 12803 | return ira->codegen->invalid_inst_gen; |
| | 12804 | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr_val, source_instr->source_node); |
| 12789 | if (pointee == nullptr) | 12805 | if (pointee == nullptr) |
| 12790 | return ira->codegen->invalid_inst_gen; | 12806 | return ira->codegen->invalid_inst_gen; |
| 12791 | if (pointee->special != ConstValSpecialRuntime) { | 12807 | if (pointee->special != ConstValSpecialRuntime) { |
| 12792 | assert(array_ptr->value->type->id == ZigTypeIdPointer); | 12808 | assert(array_ptr_val->type->id == ZigTypeIdPointer); |
| 12793 | ZigType *array_type = array_ptr->value->type->data.pointer.child_type; | 12809 | ZigType *array_type = array_ptr_val->type->data.pointer.child_type; |
| 12794 | assert(is_slice(wanted_type)); | 12810 | assert(is_slice(wanted_type)); |
| 12795 | bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const; | 12811 | bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const; |
| 12796 | | 12812 | |
| 12797 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); | 12813 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12798 | init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, is_const); | 12814 | init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, is_const); |
| 12799 | result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr->value->data.x_ptr.mut; | 12815 | result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut; |
| 12800 | result->value->type = wanted_type; | 12816 | result->value->type = wanted_type; |
| 12801 | return result; | 12817 | return result; |
| 12802 | } | 12818 | } |
| 12803 | } | 12819 | } |
| 12804 | | 12820 | |
| 12805 | if (result_loc == nullptr) result_loc = no_result_loc(); | 12821 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 12806 | IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, | 12822 | IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true); |
| 12807 | false, true); | | |
| 12808 | if (type_is_invalid(result_loc_inst->value->type) || | 12823 | if (type_is_invalid(result_loc_inst->value->type) || |
| 12809 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) | 12824 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) |
| 12810 | { | 12825 | { |
| ... | @@ -13026,10 +13041,13 @@ static IrInstGen *ir_const_fn(IrAnalyze *ira, IrInst *source_instr, ZigFn *fn_en | ... | @@ -13026,10 +13041,13 @@ static IrInstGen *ir_const_fn(IrAnalyze *ira, IrInst *source_instr, ZigFn *fn_en |
| 13026 | return result; | 13041 | return result; |
| 13027 | } | 13042 | } |
| 13028 | | 13043 | |
| 13029 | static IrInstGen *ir_const_bound_fn(IrAnalyze *ira, IrInst *src_inst, ZigFn *fn_entry, IrInstGen *first_arg) { | 13044 | static IrInstGen *ir_const_bound_fn(IrAnalyze *ira, IrInst *src_inst, ZigFn *fn_entry, IrInstGen *first_arg, |
| | 13045 | IrInst *first_arg_src) |
| | 13046 | { |
| 13030 | 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)); |
| 13031 | result->value->data.x_bound_fn.fn = fn_entry; | 13048 | result->value->data.x_bound_fn.fn = fn_entry; |
| 13032 | 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; |
| 13033 | return result; | 13051 | return result; |
| 13034 | } | 13052 | } |
| 13035 | | 13053 | |
| ... | @@ -13127,15 +13145,17 @@ static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed | ... | @@ -13127,15 +13145,17 @@ static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed |
| 13127 | return value->value; | 13145 | return value->value; |
| 13128 | } | 13146 | } |
| 13129 | | 13147 | |
| 13130 | ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, | 13148 | Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 13131 | ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota, | 13149 | ZigValue *return_ptr, size_t *backward_branch_count, size_t *backward_branch_quota, |
| 13132 | ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, | 13150 | ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, |
| 13133 | IrExecutableGen *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed) | 13151 | IrExecutableGen *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed) |
| 13134 | { | 13152 | { |
| 13135 | Error err; | 13153 | Error err; |
| 13136 | | 13154 | |
| 13137 | if (expected_type != nullptr && type_is_invalid(expected_type)) | 13155 | src_assert(return_ptr->type->id == ZigTypeIdPointer, source_node); |
| 13138 | return codegen->invalid_inst_gen->value; | 13156 | |
| | 13157 | if (type_is_invalid(return_ptr->type)) |
| | 13158 | return ErrorSemanticAnalyzeFail; |
| 13139 | | 13159 | |
| 13140 | IrExecutableSrc *ir_executable = allocate<IrExecutableSrc>(1, "IrExecutableSrc"); | 13160 | IrExecutableSrc *ir_executable = allocate<IrExecutableSrc>(1, "IrExecutableSrc"); |
| 13141 | ir_executable->source_node = source_node; | 13161 | ir_executable->source_node = source_node; |
| ... | @@ -13147,11 +13167,11 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, | ... | @@ -13147,11 +13167,11 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 13147 | ir_executable->begin_scope = scope; | 13167 | ir_executable->begin_scope = scope; |
| 13148 | | 13168 | |
| 13149 | if (!ir_gen(codegen, node, scope, ir_executable)) | 13169 | if (!ir_gen(codegen, node, scope, ir_executable)) |
| 13150 | return codegen->invalid_inst_gen->value; | 13170 | return ErrorSemanticAnalyzeFail; |
| 13151 | | 13171 | |
| 13152 | if (ir_executable->first_err_trace_msg != nullptr) { | 13172 | if (ir_executable->first_err_trace_msg != nullptr) { |
| 13153 | codegen->trace_err = ir_executable->first_err_trace_msg; | 13173 | codegen->trace_err = ir_executable->first_err_trace_msg; |
| 13154 | return codegen->invalid_inst_gen->value; | 13174 | return ErrorSemanticAnalyzeFail; |
| 13155 | } | 13175 | } |
| 13156 | | 13176 | |
| 13157 | if (codegen->verbose_ir) { | 13177 | if (codegen->verbose_ir) { |
| ... | @@ -13172,9 +13192,10 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, | ... | @@ -13172,9 +13192,10 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 13172 | analyzed_executable->backward_branch_count = backward_branch_count; | 13192 | analyzed_executable->backward_branch_count = backward_branch_count; |
| 13173 | analyzed_executable->backward_branch_quota = backward_branch_quota; | 13193 | analyzed_executable->backward_branch_quota = backward_branch_quota; |
| 13174 | analyzed_executable->begin_scope = scope; | 13194 | analyzed_executable->begin_scope = scope; |
| 13175 | ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, expected_type_source_node); | 13195 | ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, |
| | 13196 | return_ptr->type->data.pointer.child_type, expected_type_source_node, return_ptr); |
| 13176 | if (type_is_invalid(result_type)) { | 13197 | if (type_is_invalid(result_type)) { |
| 13177 | return codegen->invalid_inst_gen->value; | 13198 | return ErrorSemanticAnalyzeFail; |
| 13178 | } | 13199 | } |
| 13179 | | 13200 | |
| 13180 | if (codegen->verbose_ir) { | 13201 | if (codegen->verbose_ir) { |
| ... | @@ -13183,14 +13204,16 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, | ... | @@ -13183,14 +13204,16 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 13183 | fprintf(stderr, "}\n"); | 13204 | fprintf(stderr, "}\n"); |
| 13184 | } | 13205 | } |
| 13185 | | 13206 | |
| 13186 | ZigValue *result = ir_exec_const_result(codegen, analyzed_executable); | 13207 | if ((err = ir_exec_scan_for_side_effects(codegen, analyzed_executable))) |
| 13187 | if (type_is_invalid(result->type)) | 13208 | return err; |
| 13188 | return codegen->invalid_inst_gen->value; | | |
| 13189 | | 13209 | |
| | 13210 | ZigValue *result = const_ptr_pointee(nullptr, codegen, return_ptr, source_node); |
| | 13211 | if (result == nullptr) |
| | 13212 | return ErrorSemanticAnalyzeFail; |
| 13190 | if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed))) | 13213 | if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed))) |
| 13191 | return codegen->invalid_inst_gen->value; | 13214 | return err; |
| 13192 | | 13215 | |
| 13193 | return result; | 13216 | return ErrorNone; |
| 13194 | } | 13217 | } |
| 13195 | | 13218 | |
| 13196 | static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstGen *err_value) { | 13219 | static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstGen *err_value) { |
| ... | @@ -13372,7 +13395,7 @@ static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -13372,7 +13395,7 @@ static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr, |
| 13372 | } | 13395 | } |
| 13373 | IrInstGen *result_loc_inst = nullptr; | 13396 | IrInstGen *result_loc_inst = nullptr; |
| 13374 | if (result_loc != nullptr) { | 13397 | if (result_loc != nullptr) { |
| 13375 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); | 13398 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true); |
| 13376 | if (type_is_invalid(result_loc_inst->value->type) || | 13399 | if (type_is_invalid(result_loc_inst->value->type) || |
| 13377 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) | 13400 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) |
| 13378 | { | 13401 | { |
| ... | @@ -13396,8 +13419,8 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins | ... | @@ -13396,8 +13419,8 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins |
| 13396 | if (type_is_invalid(casted_payload->value->type)) | 13419 | if (type_is_invalid(casted_payload->value->type)) |
| 13397 | return ira->codegen->invalid_inst_gen; | 13420 | return ira->codegen->invalid_inst_gen; |
| 13398 | | 13421 | |
| 13399 | ZigValue *val = ir_resolve_const(ira, casted_payload, UndefBad); | 13422 | ZigValue *val = ir_resolve_const(ira, casted_payload, UndefOk); |
| 13400 | if (!val) | 13423 | if (val == nullptr) |
| 13401 | return ira->codegen->invalid_inst_gen; | 13424 | return ira->codegen->invalid_inst_gen; |
| 13402 | | 13425 | |
| 13403 | ZigValue *err_set_val = create_const_vals(1); | 13426 | ZigValue *err_set_val = create_const_vals(1); |
| ... | @@ -13417,7 +13440,7 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins | ... | @@ -13417,7 +13440,7 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins |
| 13417 | IrInstGen *result_loc_inst; | 13440 | IrInstGen *result_loc_inst; |
| 13418 | if (handle_is_ptr(wanted_type)) { | 13441 | if (handle_is_ptr(wanted_type)) { |
| 13419 | if (result_loc == nullptr) result_loc = no_result_loc(); | 13442 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 13420 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); | 13443 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true); |
| 13421 | if (type_is_invalid(result_loc_inst->value->type) || | 13444 | if (type_is_invalid(result_loc_inst->value->type) || |
| 13422 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) { | 13445 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) { |
| 13423 | return result_loc_inst; | 13446 | return result_loc_inst; |
| ... | @@ -13529,7 +13552,7 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -13529,7 +13552,7 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr, |
| 13529 | IrInstGen *result_loc_inst; | 13552 | IrInstGen *result_loc_inst; |
| 13530 | if (handle_is_ptr(wanted_type)) { | 13553 | if (handle_is_ptr(wanted_type)) { |
| 13531 | if (result_loc == nullptr) result_loc = no_result_loc(); | 13554 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 13532 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); | 13555 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true); |
| 13533 | if (type_is_invalid(result_loc_inst->value->type) || | 13556 | if (type_is_invalid(result_loc_inst->value->type) || |
| 13534 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) | 13557 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) |
| 13535 | { | 13558 | { |
| ... | @@ -13580,32 +13603,31 @@ static IrInstGen *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInst *source_in | ... | @@ -13580,32 +13603,31 @@ static IrInstGen *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInst *source_in |
| 13580 | return result; | 13603 | return result; |
| 13581 | } | 13604 | } |
| 13582 | | 13605 | |
| 13583 | static IrInstGen *ir_get_ref(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *value, | 13606 | static IrInstGen *ir_get_ref2(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *value, |
| 13584 | bool is_const, bool is_volatile) | 13607 | ZigType *elem_type, bool is_const, bool is_volatile) |
| 13585 | { | 13608 | { |
| 13586 | Error err; | 13609 | Error err; |
| 13587 | | 13610 | |
| 13588 | if (type_is_invalid(value->value->type)) | 13611 | if (type_is_invalid(elem_type)) |
| 13589 | return ira->codegen->invalid_inst_gen; | 13612 | return ira->codegen->invalid_inst_gen; |
| 13590 | | 13613 | |
| 13591 | if (instr_is_comptime(value)) { | 13614 | if (instr_is_comptime(value)) { |
| 13592 | ZigValue *val = ir_resolve_const(ira, value, LazyOk); | 13615 | ZigValue *val = ir_resolve_const(ira, value, LazyOk); |
| 13593 | if (!val) | 13616 | if (!val) |
| 13594 | return ira->codegen->invalid_inst_gen; | 13617 | return ira->codegen->invalid_inst_gen; |
| 13595 | return ir_get_const_ptr(ira, source_instruction, val, value->value->type, | 13618 | return ir_get_const_ptr(ira, source_instruction, val, elem_type, |
| 13596 | ConstPtrMutComptimeConst, is_const, is_volatile, 0); | 13619 | ConstPtrMutComptimeConst, is_const, is_volatile, 0); |
| 13597 | } | 13620 | } |
| 13598 | | 13621 | |
| 13599 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value->type, | 13622 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, elem_type, |
| 13600 | is_const, is_volatile, PtrLenSingle, 0, 0, 0, false); | 13623 | is_const, is_volatile, PtrLenSingle, 0, 0, 0, false); |
| 13601 | | 13624 | |
| 13602 | if ((err = type_resolve(ira->codegen, ptr_type, ResolveStatusZeroBitsKnown))) | 13625 | if ((err = type_resolve(ira->codegen, ptr_type, ResolveStatusZeroBitsKnown))) |
| 13603 | return ira->codegen->invalid_inst_gen; | 13626 | return ira->codegen->invalid_inst_gen; |
| 13604 | | 13627 | |
| 13605 | IrInstGen *result_loc; | 13628 | IrInstGen *result_loc; |
| 13606 | if (type_has_bits(ptr_type) && !handle_is_ptr(value->value->type)) { | 13629 | if (type_has_bits(ptr_type) && !handle_is_ptr(elem_type)) { |
| 13607 | result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value->type, nullptr, true, | 13630 | result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), elem_type, nullptr, true, true); |
| 13608 | false, true); | | |
| 13609 | } else { | 13631 | } else { |
| 13610 | result_loc = nullptr; | 13632 | result_loc = nullptr; |
| 13611 | } | 13633 | } |
| ... | @@ -13615,6 +13637,12 @@ static IrInstGen *ir_get_ref(IrAnalyze *ira, IrInst* source_instruction, IrInstG | ... | @@ -13615,6 +13637,12 @@ static IrInstGen *ir_get_ref(IrAnalyze *ira, IrInst* source_instruction, IrInstG |
| 13615 | return new_instruction; | 13637 | return new_instruction; |
| 13616 | } | 13638 | } |
| 13617 | | 13639 | |
| | 13640 | static IrInstGen *ir_get_ref(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *value, |
| | 13641 | bool is_const, bool is_volatile) |
| | 13642 | { |
| | 13643 | return ir_get_ref2(ira, source_instruction, value, value->value->type, is_const, is_volatile); |
| | 13644 | } |
| | 13645 | |
| 13618 | static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, AstNode *source_node, ZigType *union_type) { | 13646 | static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, AstNode *source_node, ZigType *union_type) { |
| 13619 | assert(union_type->id == ZigTypeIdUnion); | 13647 | assert(union_type->id == ZigTypeIdUnion); |
| 13620 | | 13648 | |
| ... | @@ -14311,8 +14339,7 @@ static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, IrInst* source_inst | ... | @@ -14311,8 +14339,7 @@ static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, IrInst* source_inst |
| 14311 | if (result_loc == nullptr) { | 14339 | if (result_loc == nullptr) { |
| 14312 | result_loc = no_result_loc(); | 14340 | result_loc = no_result_loc(); |
| 14313 | } | 14341 | } |
| 14314 | IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, | 14342 | IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, true, true); |
| 14315 | true, false, true); | | |
| 14316 | if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) { | 14343 | if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) { |
| 14317 | return result_loc_inst; | 14344 | return result_loc_inst; |
| 14318 | } | 14345 | } |
| ... | @@ -14976,7 +15003,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, | ... | @@ -14976,7 +15003,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 14976 | dest_ptr_type = wanted_type->data.maybe.child_type; | 15003 | dest_ptr_type = wanted_type->data.maybe.child_type; |
| 14977 | } | 15004 | } |
| 14978 | if (dest_ptr_type != nullptr) { | 15005 | if (dest_ptr_type != nullptr) { |
| 14979 | return ir_analyze_ptr_cast(ira, source_instr, value, wanted_type, source_instr, true); | 15006 | return ir_analyze_ptr_cast(ira, source_instr, value, source_instr, wanted_type, source_instr, true); |
| 14980 | } | 15007 | } |
| 14981 | } | 15008 | } |
| 14982 | | 15009 | |
| ... | @@ -15018,7 +15045,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, | ... | @@ -15018,7 +15045,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 15018 | actual_type->data.pointer.child_type, source_node, | 15045 | actual_type->data.pointer.child_type, source_node, |
| 15019 | !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) | 15046 | !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| 15020 | { | 15047 | { |
| 15021 | return ir_analyze_ptr_cast(ira, source_instr, value, wanted_type, source_instr, true); | 15048 | return ir_analyze_ptr_cast(ira, source_instr, value, source_instr, wanted_type, source_instr, true); |
| 15022 | } | 15049 | } |
| 15023 | | 15050 | |
| 15024 | // cast from integer to C pointer | 15051 | // cast from integer to C pointer |
| ... | @@ -15195,8 +15222,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns | ... | @@ -15195,8 +15222,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns |
| 15195 | IrInstGen *result_loc_inst; | 15222 | IrInstGen *result_loc_inst; |
| 15196 | if (ptr_type->data.pointer.host_int_bytes != 0 && handle_is_ptr(child_type)) { | 15223 | if (ptr_type->data.pointer.host_int_bytes != 0 && handle_is_ptr(child_type)) { |
| 15197 | if (result_loc == nullptr) result_loc = no_result_loc(); | 15224 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 15198 | result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, | 15225 | result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, true, true); |
| 15199 | true, false, true); | | |
| 15200 | if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) { | 15226 | if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) { |
| 15201 | return result_loc_inst; | 15227 | return result_loc_inst; |
| 15202 | } | 15228 | } |
| ... | @@ -15459,7 +15485,7 @@ static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn | ... | @@ -15459,7 +15485,7 @@ static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn |
| 15459 | casted_operand->value->type->id == ZigTypeIdPointer && | 15485 | casted_operand->value->type->id == ZigTypeIdPointer && |
| 15460 | casted_operand->value->data.rh_ptr == RuntimeHintPtrStack) | 15486 | casted_operand->value->data.rh_ptr == RuntimeHintPtrStack) |
| 15461 | { | 15487 | { |
| 15462 | 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")); |
| 15463 | return ir_unreach_error(ira); | 15489 | return ir_unreach_error(ira); |
| 15464 | } | 15490 | } |
| 15465 | | 15491 | |
| ... | @@ -15622,9 +15648,27 @@ static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type, | ... | @@ -15622,9 +15648,27 @@ static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type, |
| 15622 | } | 15648 | } |
| 15623 | | 15649 | |
| 15624 | // Returns ErrorNotLazy when the value cannot be determined | 15650 | // Returns ErrorNotLazy when the value cannot be determined |
| 15625 | static Error lazy_cmp_zero(AstNode *source_node, ZigValue *val, Cmp *result) { | 15651 | static Error lazy_cmp_zero(CodeGen *codegen, AstNode *source_node, ZigValue *val, Cmp *result) { |
| 15626 | Error err; | 15652 | Error err; |
| 15627 | | 15653 | |
| | 15654 | switch (type_has_one_possible_value(codegen, val->type)) { |
| | 15655 | case OnePossibleValueInvalid: |
| | 15656 | return ErrorSemanticAnalyzeFail; |
| | 15657 | case OnePossibleValueNo: |
| | 15658 | break; |
| | 15659 | case OnePossibleValueYes: |
| | 15660 | switch (val->type->id) { |
| | 15661 | case ZigTypeIdInt: |
| | 15662 | src_assert(val->type->data.integral.bit_count == 0, source_node); |
| | 15663 | *result = CmpEQ; |
| | 15664 | return ErrorNone; |
| | 15665 | case ZigTypeIdUndefined: |
| | 15666 | return ErrorNotLazy; |
| | 15667 | default: |
| | 15668 | zig_unreachable(); |
| | 15669 | } |
| | 15670 | } |
| | 15671 | |
| 15628 | switch (val->special) { | 15672 | switch (val->special) { |
| 15629 | case ConstValSpecialRuntime: | 15673 | case ConstValSpecialRuntime: |
| 15630 | case ConstValSpecialUndef: | 15674 | case ConstValSpecialUndef: |
| ... | @@ -15678,12 +15722,12 @@ static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -15678,12 +15722,12 @@ static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInst* source_instr, |
| 15678 | // Before resolving the values, we special case comparisons against zero. These can often | 15722 | // Before resolving the values, we special case comparisons against zero. These can often |
| 15679 | // be done without resolving lazy values, preventing potential dependency loops. | 15723 | // be done without resolving lazy values, preventing potential dependency loops. |
| 15680 | Cmp op1_cmp_zero; | 15724 | Cmp op1_cmp_zero; |
| 15681 | if ((err = lazy_cmp_zero(source_instr->source_node, op1_val, &op1_cmp_zero))) { | 15725 | if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op1_val, &op1_cmp_zero))) { |
| 15682 | if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally; | 15726 | if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally; |
| 15683 | return ira->codegen->trace_err; | 15727 | return ira->codegen->trace_err; |
| 15684 | } | 15728 | } |
| 15685 | Cmp op2_cmp_zero; | 15729 | Cmp op2_cmp_zero; |
| 15686 | if ((err = lazy_cmp_zero(source_instr->source_node, op2_val, &op2_cmp_zero))) { | 15730 | if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op2_val, &op2_cmp_zero))) { |
| 15687 | if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally; | 15731 | if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally; |
| 15688 | return ira->codegen->trace_err; | 15732 | return ira->codegen->trace_err; |
| 15689 | } | 15733 | } |
| ... | @@ -15847,14 +15891,14 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i | ... | @@ -15847,14 +15891,14 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 15847 | } | 15891 | } |
| 15848 | Cmp op1_cmp_zero; | 15892 | Cmp op1_cmp_zero; |
| 15849 | bool have_op1_cmp_zero = false; | 15893 | bool have_op1_cmp_zero = false; |
| 15850 | if ((err = lazy_cmp_zero(source_instr->source_node, op1->value, &op1_cmp_zero))) { | 15894 | if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op1->value, &op1_cmp_zero))) { |
| 15851 | if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen; | 15895 | if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen; |
| 15852 | } else { | 15896 | } else { |
| 15853 | have_op1_cmp_zero = true; | 15897 | have_op1_cmp_zero = true; |
| 15854 | } | 15898 | } |
| 15855 | Cmp op2_cmp_zero; | 15899 | Cmp op2_cmp_zero; |
| 15856 | bool have_op2_cmp_zero = false; | 15900 | bool have_op2_cmp_zero = false; |
| 15857 | if ((err = lazy_cmp_zero(source_instr->source_node, op2->value, &op2_cmp_zero))) { | 15901 | if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op2->value, &op2_cmp_zero))) { |
| 15858 | if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen; | 15902 | if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen; |
| 15859 | } else { | 15903 | } else { |
| 15860 | have_op2_cmp_zero = true; | 15904 | have_op2_cmp_zero = true; |
| ... | @@ -17083,7 +17127,7 @@ static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -17083,7 +17127,7 @@ static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr, |
| 17083 | bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope); | 17127 | bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope); |
| 17084 | | 17128 | |
| 17085 | IrInstGen *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(), | 17129 | IrInstGen *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(), |
| 17086 | new_type, nullptr, false, false, true); | 17130 | new_type, nullptr, false, true); |
| 17087 | uint32_t new_field_count = op1_field_count + op2_field_count; | 17131 | uint32_t new_field_count = op1_field_count + op2_field_count; |
| 17088 | | 17132 | |
| 17089 | new_type->data.structure.src_field_count = new_field_count; | 17133 | new_type->data.structure.src_field_count = new_field_count; |
| ... | @@ -17669,29 +17713,14 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV | ... | @@ -17669,29 +17713,14 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV |
| 17669 | break; | 17713 | break; |
| 17670 | } | 17714 | } |
| 17671 | | 17715 | |
| 17672 | if (var->var_type != nullptr && !is_comptime_var) { | 17716 | while (var->next_var != nullptr) { |
| 17673 | // This is at least the second time we've seen this variable declaration during analysis. | 17717 | var = var->next_var; |
| 17674 | // This means that this is actually a different variable due to, e.g. an inline while loop. | | |
| 17675 | // We make a new variable so that it can hold a different type, and so the debug info can | | |
| 17676 | // be distinct. | | |
| 17677 | ZigVar *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope, | | |
| 17678 | buf_create_from_str(var->name), var->src_is_const, var->gen_is_const, | | |
| 17679 | var->shadowable, var->is_comptime, true); | | |
| 17680 | new_var->owner_exec = var->owner_exec; | | |
| 17681 | new_var->align_bytes = var->align_bytes; | | |
| 17682 | if (var->mem_slot_index != SIZE_MAX) { | | |
| 17683 | ZigValue *vals = create_const_vals(1); | | |
| 17684 | new_var->mem_slot_index = ira->exec_context.mem_slot_list.length; | | |
| 17685 | ira->exec_context.mem_slot_list.append(vals); | | |
| 17686 | } | | |
| 17687 | | | |
| 17688 | var->next_var = new_var; | | |
| 17689 | var = new_var; | | |
| 17690 | } | 17718 | } |
| 17691 | | 17719 | |
| 17692 | // This must be done after possibly creating a new variable above | 17720 | // This must be done after possibly creating a new variable above |
| 17693 | var->ref_count = 0; | 17721 | var->ref_count = 0; |
| 17694 | | 17722 | |
| | 17723 | var->ptr_instruction = var_ptr; |
| 17695 | var->var_type = result_type; | 17724 | var->var_type = result_type; |
| 17696 | assert(var->var_type); | 17725 | assert(var->var_type); |
| 17697 | | 17726 | |
| ... | @@ -17704,7 +17733,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV | ... | @@ -17704,7 +17733,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV |
| 17704 | var->var_type = ira->codegen->builtin_types.entry_invalid; | 17733 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 17705 | return ir_const_void(ira, &decl_var_instruction->base.base); | 17734 | return ir_const_void(ira, &decl_var_instruction->base.base); |
| 17706 | } | 17735 | } |
| 17707 | var->align_bytes = get_abi_alignment(ira->codegen, result_type); | 17736 | var->align_bytes = get_ptr_align(ira->codegen, var_ptr->value->type); |
| 17708 | } else { | 17737 | } else { |
| 17709 | if (!ir_resolve_align(ira, decl_var_instruction->align_value->child, nullptr, &var->align_bytes)) { | 17738 | if (!ir_resolve_align(ira, decl_var_instruction->align_value->child, nullptr, &var->align_bytes)) { |
| 17710 | var->var_type = ira->codegen->builtin_types.entry_invalid; | 17739 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -17733,16 +17762,8 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV | ... | @@ -17733,16 +17762,8 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV |
| 17733 | var_ptr->value->special = ConstValSpecialRuntime; | 17762 | var_ptr->value->special = ConstValSpecialRuntime; |
| 17734 | ir_analyze_store_ptr(ira, &var_ptr->base, var_ptr, deref, false); | 17763 | ir_analyze_store_ptr(ira, &var_ptr->base, var_ptr, deref, false); |
| 17735 | } | 17764 | } |
| 17736 | | 17765 | if (instr_is_comptime(var_ptr) && (is_comptime_var || (var_class_requires_const && var->gen_is_const))) { |
| 17737 | if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) { | 17766 | return ir_const_void(ira, &decl_var_instruction->base.base); |
| 17738 | assert(var->mem_slot_index < ira->exec_context.mem_slot_list.length); | | |
| 17739 | ZigValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index); | | |
| 17740 | copy_const_val(mem_slot, init_val); | | |
| 17741 | ira_ref(var->owner_exec->analysis); | | |
| 17742 | | | |
| 17743 | if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) { | | |
| 17744 | return ir_const_void(ira, &decl_var_instruction->base.base); | | |
| 17745 | } | | |
| 17746 | } | 17767 | } |
| 17747 | } else if (is_comptime_var) { | 17768 | } else if (is_comptime_var) { |
| 17748 | ir_add_error(ira, &decl_var_instruction->base.base, | 17769 | ir_add_error(ira, &decl_var_instruction->base.base, |
| ... | @@ -18076,6 +18097,7 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType | ... | @@ -18076,6 +18097,7 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType |
| 18076 | | 18097 | |
| 18077 | ZigValue *pointee = create_const_vals(1); | 18098 | ZigValue *pointee = create_const_vals(1); |
| 18078 | pointee->special = ConstValSpecialUndef; | 18099 | pointee->special = ConstValSpecialUndef; |
| | 18100 | pointee->llvm_align = align; |
| 18079 | | 18101 | |
| 18080 | IrInstGenAlloca *result = ir_build_alloca_gen(ira, source_inst, align, name_hint); | 18102 | IrInstGenAlloca *result = ir_build_alloca_gen(ira, source_inst, align, name_hint); |
| 18081 | result->base.value->special = ConstValSpecialStatic; | 18103 | result->base.value->special = ConstValSpecialStatic; |
| ... | @@ -18102,9 +18124,11 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType | ... | @@ -18102,9 +18124,11 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType |
| 18102 | result->base.value->type = get_pointer_to_type_extra(ira->codegen, var_type, false, false, | 18124 | result->base.value->type = get_pointer_to_type_extra(ira->codegen, var_type, false, false, |
| 18103 | PtrLenSingle, align, 0, 0, false); | 18125 | PtrLenSingle, align, 0, 0, false); |
| 18104 | | 18126 | |
| 18105 | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; | 18127 | if (!force_comptime) { |
| 18106 | if (fn_entry != nullptr) { | 18128 | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 18107 | fn_entry->alloca_gen_list.append(result); | 18129 | if (fn_entry != nullptr) { |
| | 18130 | fn_entry->alloca_gen_list.append(result); |
| | 18131 | } |
| 18108 | } | 18132 | } |
| 18109 | return &result->base; | 18133 | return &result->base; |
| 18110 | } | 18134 | } |
| ... | @@ -18192,7 +18216,7 @@ static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out | ... | @@ -18192,7 +18216,7 @@ static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out |
| 18192 | } | 18216 | } |
| 18193 | | 18217 | |
| 18194 | static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInst *suspend_source_instr, | 18218 | static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 18195 | ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime) | 18219 | ResultLoc *result_loc, ZigType *value_type) |
| 18196 | { | 18220 | { |
| 18197 | if (type_is_invalid(value_type)) | 18221 | if (type_is_invalid(value_type)) |
| 18198 | return ira->codegen->invalid_inst_gen; | 18222 | return ira->codegen->invalid_inst_gen; |
| ... | @@ -18209,10 +18233,25 @@ static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInst *suspend_sourc | ... | @@ -18209,10 +18233,25 @@ static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInst *suspend_sourc |
| 18209 | return result_loc->resolved_loc; | 18233 | return result_loc->resolved_loc; |
| 18210 | } | 18234 | } |
| 18211 | | 18235 | |
| | 18236 | static bool result_loc_is_discard(ResultLoc *result_loc_pass1) { |
| | 18237 | if (result_loc_pass1->id == ResultLocIdInstruction && |
| | 18238 | result_loc_pass1->source_instruction->id == IrInstSrcIdConst) |
| | 18239 | { |
| | 18240 | IrInstSrcConst *const_inst = reinterpret_cast<IrInstSrcConst *>(result_loc_pass1->source_instruction); |
| | 18241 | if (value_is_comptime(const_inst->value) && |
| | 18242 | const_inst->value->type->id == ZigTypeIdPointer && |
| | 18243 | const_inst->value->data.x_ptr.special == ConstPtrSpecialDiscard) |
| | 18244 | { |
| | 18245 | return true; |
| | 18246 | } |
| | 18247 | } |
| | 18248 | return false; |
| | 18249 | } |
| | 18250 | |
| 18212 | // when calling this function, at the callsite must check for result type noreturn and propagate it up | 18251 | // when calling this function, at the callsite must check for result type noreturn and propagate it up |
| 18213 | static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr, | 18252 | static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 18214 | ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, | 18253 | ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, |
| 18215 | bool non_null_comptime, bool allow_discard) | 18254 | bool allow_discard) |
| 18216 | { | 18255 | { |
| 18217 | Error err; | 18256 | Error err; |
| 18218 | if (result_loc->resolved_loc != nullptr) { | 18257 | if (result_loc->resolved_loc != nullptr) { |
| ... | @@ -18232,53 +18271,56 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i | ... | @@ -18232,53 +18271,56 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 18232 | return nullptr; | 18271 | return nullptr; |
| 18233 | } | 18272 | } |
| 18234 | // need to return a result location and don't have one. use a stack allocation | 18273 | // need to return a result location and don't have one. use a stack allocation |
| 18235 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type, | 18274 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type); |
| 18236 | force_runtime, non_null_comptime); | | |
| 18237 | } | 18275 | } |
| 18238 | case ResultLocIdVar: { | 18276 | case ResultLocIdVar: { |
| 18239 | ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc); | 18277 | ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc); |
| 18240 | assert(result_loc->source_instruction->id == IrInstSrcIdAlloca); | 18278 | assert(result_loc->source_instruction->id == IrInstSrcIdAlloca); |
| | 18279 | IrInstSrcAlloca *alloca_src = reinterpret_cast<IrInstSrcAlloca *>(result_loc->source_instruction); |
| 18241 | | 18280 | |
| | 18281 | ZigVar *var = result_loc_var->var; |
| | 18282 | if (var->var_type != nullptr && !ir_get_var_is_comptime(var)) { |
| | 18283 | // This is at least the second time we've seen this variable declaration during analysis. |
| | 18284 | // This means that this is actually a different variable due to, e.g. an inline while loop. |
| | 18285 | // We make a new variable so that it can hold a different type, and so the debug info can |
| | 18286 | // be distinct. |
| | 18287 | ZigVar *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope, |
| | 18288 | buf_create_from_str(var->name), var->src_is_const, var->gen_is_const, |
| | 18289 | var->shadowable, var->is_comptime, true); |
| | 18290 | new_var->owner_exec = var->owner_exec; |
| | 18291 | new_var->align_bytes = var->align_bytes; |
| | 18292 | |
| | 18293 | var->next_var = new_var; |
| | 18294 | var = new_var; |
| | 18295 | } |
| 18242 | if (value_type->id == ZigTypeIdUnreachable || value_type->id == ZigTypeIdOpaque) { | 18296 | if (value_type->id == ZigTypeIdUnreachable || value_type->id == ZigTypeIdOpaque) { |
| 18243 | ir_add_error(ira, &result_loc->source_instruction->base, | 18297 | ir_add_error(ira, &result_loc->source_instruction->base, |
| 18244 | buf_sprintf("variable of type '%s' not allowed", buf_ptr(&value_type->name))); | 18298 | buf_sprintf("variable of type '%s' not allowed", buf_ptr(&value_type->name))); |
| 18245 | return ira->codegen->invalid_inst_gen; | 18299 | return ira->codegen->invalid_inst_gen; |
| 18246 | } | 18300 | } |
| 18247 | | 18301 | if (alloca_src->base.child == nullptr || var->ptr_instruction == nullptr) { |
| 18248 | IrInstSrcAlloca *alloca_src = reinterpret_cast<IrInstSrcAlloca *>(result_loc->source_instruction); | 18302 | bool force_comptime; |
| 18249 | bool force_comptime; | 18303 | if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime)) |
| 18250 | if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime)) | 18304 | return ira->codegen->invalid_inst_gen; |
| 18251 | return ira->codegen->invalid_inst_gen; | | |
| 18252 | bool is_comptime = force_comptime || (!force_runtime && value != nullptr && | | |
| 18253 | value->value->special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const); | | |
| 18254 | | | |
| 18255 | if (alloca_src->base.child == nullptr || is_comptime) { | | |
| 18256 | uint32_t align = 0; | 18305 | uint32_t align = 0; |
| 18257 | if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, nullptr, &align)) { | 18306 | if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, nullptr, &align)) { |
| 18258 | return ira->codegen->invalid_inst_gen; | 18307 | return ira->codegen->invalid_inst_gen; |
| 18259 | } | 18308 | } |
| 18260 | IrInstGen *alloca_gen; | 18309 | IrInstGen *alloca_gen = ir_analyze_alloca(ira, &result_loc->source_instruction->base, value_type, |
| 18261 | if (is_comptime && value != nullptr) { | 18310 | align, alloca_src->name_hint, force_comptime); |
| 18262 | if (align > value->value->llvm_align) { | 18311 | if (force_runtime) { |
| 18263 | value->value->llvm_align = align; | 18312 | alloca_gen->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 18264 | } | 18313 | alloca_gen->value->special = ConstValSpecialRuntime; |
| 18265 | alloca_gen = ir_get_ref(ira, &result_loc->source_instruction->base, value, true, false); | | |
| 18266 | } else { | | |
| 18267 | alloca_gen = ir_analyze_alloca(ira, &result_loc->source_instruction->base, value_type, align, | | |
| 18268 | alloca_src->name_hint, force_comptime); | | |
| 18269 | if (force_runtime) { | | |
| 18270 | alloca_gen->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; | | |
| 18271 | alloca_gen->value->special = ConstValSpecialRuntime; | | |
| 18272 | } | | |
| 18273 | } | 18314 | } |
| 18274 | if (alloca_src->base.child != nullptr && !result_loc->written) { | 18315 | if (alloca_src->base.child != nullptr && !result_loc->written) { |
| 18275 | alloca_src->base.child->base.ref_count = 0; | 18316 | alloca_src->base.child->base.ref_count = 0; |
| 18276 | } | 18317 | } |
| 18277 | alloca_src->base.child = alloca_gen; | 18318 | alloca_src->base.child = alloca_gen; |
| | 18319 | var->ptr_instruction = alloca_gen; |
| 18278 | } | 18320 | } |
| 18279 | result_loc->written = true; | 18321 | result_loc->written = true; |
| 18280 | result_loc->resolved_loc = is_comptime ? nullptr : alloca_src->base.child; | 18322 | result_loc->resolved_loc = alloca_src->base.child; |
| 18281 | return result_loc->resolved_loc; | 18323 | return alloca_src->base.child; |
| 18282 | } | 18324 | } |
| 18283 | case ResultLocIdInstruction: { | 18325 | case ResultLocIdInstruction: { |
| 18284 | result_loc->written = true; | 18326 | result_loc->written = true; |
| ... | @@ -18290,27 +18332,8 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i | ... | @@ -18290,27 +18332,8 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 18290 | reinterpret_cast<ResultLocReturn *>(result_loc)->implicit_return_type_done = true; | 18332 | reinterpret_cast<ResultLocReturn *>(result_loc)->implicit_return_type_done = true; |
| 18291 | ira->src_implicit_return_type_list.append(value); | 18333 | ira->src_implicit_return_type_list.append(value); |
| 18292 | } | 18334 | } |
| 18293 | if (!non_null_comptime) { | | |
| 18294 | bool is_comptime = value != nullptr && value->value->special != ConstValSpecialRuntime; | | |
| 18295 | if (is_comptime) | | |
| 18296 | return nullptr; | | |
| 18297 | } | | |
| 18298 | bool has_bits; | | |
| 18299 | if ((err = type_has_bits2(ira->codegen, ira->explicit_return_type, &has_bits))) | | |
| 18300 | return ira->codegen->invalid_inst_gen; | | |
| 18301 | if (!has_bits || !handle_is_ptr(ira->explicit_return_type)) { | | |
| 18302 | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; | | |
| 18303 | if (fn_entry == nullptr || fn_entry->inferred_async_node == nullptr) { | | |
| 18304 | return nullptr; | | |
| 18305 | } | | |
| 18306 | } | | |
| 18307 | | | |
| 18308 | ZigType *ptr_return_type = get_pointer_to_type(ira->codegen, ira->explicit_return_type, false); | | |
| 18309 | result_loc->written = true; | 18335 | result_loc->written = true; |
| 18310 | result_loc->resolved_loc = ir_build_return_ptr(ira, &result_loc->source_instruction->base, ptr_return_type); | 18336 | result_loc->resolved_loc = ira->return_ptr; |
| 18311 | if (ir_should_inline(ira->old_irb.exec, result_loc->source_instruction->base.scope)) { | | |
| 18312 | set_up_result_loc_for_inferred_comptime(result_loc->resolved_loc); | | |
| 18313 | } | | |
| 18314 | return result_loc->resolved_loc; | 18337 | return result_loc->resolved_loc; |
| 18315 | } | 18338 | } |
| 18316 | case ResultLocIdPeer: { | 18339 | case ResultLocIdPeer: { |
| ... | @@ -18319,7 +18342,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i | ... | @@ -18319,7 +18342,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 18319 | | 18342 | |
| 18320 | if (peer_parent->peers.length == 1) { | 18343 | if (peer_parent->peers.length == 1) { |
| 18321 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, | 18344 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 18322 | value_type, value, force_runtime, non_null_comptime, true); | 18345 | value_type, value, force_runtime, true); |
| 18323 | result_peer->suspend_pos.basic_block_index = SIZE_MAX; | 18346 | result_peer->suspend_pos.basic_block_index = SIZE_MAX; |
| 18324 | result_peer->suspend_pos.instruction_index = SIZE_MAX; | 18347 | result_peer->suspend_pos.instruction_index = SIZE_MAX; |
| 18325 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || | 18348 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| ... | @@ -18337,11 +18360,8 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i | ... | @@ -18337,11 +18360,8 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 18337 | return ira->codegen->invalid_inst_gen; | 18360 | return ira->codegen->invalid_inst_gen; |
| 18338 | if (is_condition_comptime) { | 18361 | if (is_condition_comptime) { |
| 18339 | peer_parent->skipped = true; | 18362 | peer_parent->skipped = true; |
| 18340 | if (non_null_comptime) { | 18363 | return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 18341 | return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, | 18364 | value_type, value, force_runtime, true); |
| 18342 | value_type, value, force_runtime, non_null_comptime, true); | | |
| 18343 | } | | |
| 18344 | return nullptr; | | |
| 18345 | } | 18365 | } |
| 18346 | bool peer_parent_has_type; | 18366 | bool peer_parent_has_type; |
| 18347 | if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type))) | 18367 | if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type))) |
| ... | @@ -18349,7 +18369,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i | ... | @@ -18349,7 +18369,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 18349 | if (peer_parent_has_type) { | 18369 | if (peer_parent_has_type) { |
| 18350 | peer_parent->skipped = true; | 18370 | peer_parent->skipped = true; |
| 18351 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, | 18371 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 18352 | value_type, value, force_runtime || !is_condition_comptime, true, true); | 18372 | value_type, value, force_runtime || !is_condition_comptime, true); |
| 18353 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || | 18373 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 18354 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) | 18374 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 18355 | { | 18375 | { |
| ... | @@ -18374,7 +18394,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i | ... | @@ -18374,7 +18394,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 18374 | } | 18394 | } |
| 18375 | | 18395 | |
| 18376 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, | 18396 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 18377 | peer_parent->resolved_type, nullptr, force_runtime, non_null_comptime, true); | 18397 | peer_parent->resolved_type, nullptr, force_runtime, true); |
| 18378 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || | 18398 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 18379 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) | 18399 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 18380 | { | 18400 | { |
| ... | @@ -18387,21 +18407,18 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i | ... | @@ -18387,21 +18407,18 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 18387 | return result_loc->resolved_loc; | 18407 | return result_loc->resolved_loc; |
| 18388 | } | 18408 | } |
| 18389 | case ResultLocIdCast: { | 18409 | case ResultLocIdCast: { |
| 18390 | if (value != nullptr && value->value->special != ConstValSpecialRuntime && !non_null_comptime) | | |
| 18391 | return nullptr; | | |
| 18392 | ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc); | 18410 | ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc); |
| 18393 | ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child); | 18411 | ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child); |
| 18394 | if (type_is_invalid(dest_type)) | 18412 | if (type_is_invalid(dest_type)) |
| 18395 | return ira->codegen->invalid_inst_gen; | 18413 | return ira->codegen->invalid_inst_gen; |
| 18396 | | 18414 | |
| 18397 | if (dest_type == ira->codegen->builtin_types.entry_var) { | 18415 | if (dest_type == ira->codegen->builtin_types.entry_var) { |
| 18398 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type, | 18416 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type); |
| 18399 | force_runtime, non_null_comptime); | | |
| 18400 | } | 18417 | } |
| 18401 | | 18418 | |
| 18402 | IrInstGen *casted_value; | 18419 | IrInstGen *casted_value; |
| 18403 | if (value != nullptr) { | 18420 | if (value != nullptr) { |
| 18404 | casted_value = ir_implicit_cast(ira, value, dest_type); | 18421 | casted_value = ir_implicit_cast2(ira, suspend_source_instr, value, dest_type); |
| 18405 | if (type_is_invalid(casted_value->value->type)) | 18422 | if (type_is_invalid(casted_value->value->type)) |
| 18406 | return ira->codegen->invalid_inst_gen; | 18423 | return ira->codegen->invalid_inst_gen; |
| 18407 | dest_type = casted_value->value->type; | 18424 | dest_type = casted_value->value->type; |
| ... | @@ -18410,7 +18427,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i | ... | @@ -18410,7 +18427,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 18410 | } | 18427 | } |
| 18411 | | 18428 | |
| 18412 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent, | 18429 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent, |
| 18413 | dest_type, casted_value, force_runtime, non_null_comptime, true); | 18430 | dest_type, casted_value, force_runtime, true); |
| 18414 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || | 18431 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 18415 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) | 18432 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 18416 | { | 18433 | { |
| ... | @@ -18460,13 +18477,12 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i | ... | @@ -18460,13 +18477,12 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 18460 | // We will not be able to provide a result location for this value. Create | 18477 | // We will not be able to provide a result location for this value. Create |
| 18461 | // a new result location. | 18478 | // a new result location. |
| 18462 | result_cast->parent->written = false; | 18479 | result_cast->parent->written = false; |
| 18463 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type, | 18480 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type); |
| 18464 | force_runtime, non_null_comptime); | | |
| 18465 | } | 18481 | } |
| 18466 | | 18482 | |
| 18467 | result_loc->written = true; | 18483 | result_loc->written = true; |
| 18468 | result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc, | 18484 | result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc, |
| 18469 | ptr_type, &result_cast->base.source_instruction->base, false); | 18485 | &parent_result_loc->base, ptr_type, &result_cast->base.source_instruction->base, false); |
| 18470 | return result_loc->resolved_loc; | 18486 | return result_loc->resolved_loc; |
| 18471 | } | 18487 | } |
| 18472 | case ResultLocIdBitCast: { | 18488 | case ResultLocIdBitCast: { |
| ... | @@ -18507,12 +18523,13 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i | ... | @@ -18507,12 +18523,13 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 18507 | bitcasted_value = nullptr; | 18523 | bitcasted_value = nullptr; |
| 18508 | } | 18524 | } |
| 18509 | | 18525 | |
| 18510 | if (bitcasted_value == nullptr || type_is_invalid(bitcasted_value->value->type)) { | 18526 | if (bitcasted_value != nullptr && type_is_invalid(bitcasted_value->value->type)) { |
| 18511 | return bitcasted_value; | 18527 | return bitcasted_value; |
| 18512 | } | 18528 | } |
| 18513 | | 18529 | |
| | 18530 | bool parent_was_written = result_bit_cast->parent->written; |
| 18514 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent, | 18531 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent, |
| 18515 | dest_type, bitcasted_value, force_runtime, non_null_comptime, true); | 18532 | dest_type, bitcasted_value, force_runtime, true); |
| 18516 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || | 18533 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 18517 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) | 18534 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 18518 | { | 18535 | { |
| ... | @@ -18522,32 +18539,38 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i | ... | @@ -18522,32 +18539,38 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 18522 | assert(parent_ptr_type->id == ZigTypeIdPointer); | 18539 | assert(parent_ptr_type->id == ZigTypeIdPointer); |
| 18523 | ZigType *child_type = parent_ptr_type->data.pointer.child_type; | 18540 | ZigType *child_type = parent_ptr_type->data.pointer.child_type; |
| 18524 | | 18541 | |
| 18525 | bool has_bits; | 18542 | if (result_loc_is_discard(result_bit_cast->parent)) { |
| 18526 | if ((err = type_has_bits2(ira->codegen, child_type, &has_bits))) { | | |
| 18527 | return ira->codegen->invalid_inst_gen; | | |
| 18528 | } | | |
| 18529 | | | |
| 18530 | // This happens when the bitCast result is assigned to _ | | |
| 18531 | if (!has_bits) { | | |
| 18532 | assert(allow_discard); | 18543 | assert(allow_discard); |
| 18533 | return parent_result_loc; | 18544 | return parent_result_loc; |
| 18534 | } | 18545 | } |
| 18535 | | 18546 | |
| 18536 | if ((err = type_resolve(ira->codegen, child_type, ResolveStatusAlignmentKnown))) { | 18547 | if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown))) { |
| 18537 | return ira->codegen->invalid_inst_gen; | 18548 | return ira->codegen->invalid_inst_gen; |
| 18538 | } | 18549 | } |
| 18539 | | 18550 | |
| 18540 | uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type); | 18551 | if ((err = type_resolve(ira->codegen, value_type, ResolveStatusSizeKnown))) { |
| 18541 | if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) { | | |
| 18542 | return ira->codegen->invalid_inst_gen; | 18552 | return ira->codegen->invalid_inst_gen; |
| 18543 | } | 18553 | } |
| | 18554 | |
| | 18555 | if (child_type != ira->codegen->builtin_types.entry_var) { |
| | 18556 | if (type_size(ira->codegen, child_type) != type_size(ira->codegen, value_type)) { |
| | 18557 | // pointer cast won't work; we need a temporary location. |
| | 18558 | result_bit_cast->parent->written = parent_was_written; |
| | 18559 | result_loc->written = true; |
| | 18560 | result_loc->resolved_loc = ir_resolve_result(ira, suspend_source_instr, no_result_loc(), |
| | 18561 | value_type, bitcasted_value, force_runtime, true); |
| | 18562 | return result_loc->resolved_loc; |
| | 18563 | } |
| | 18564 | } |
| | 18565 | uint64_t parent_ptr_align = 0; |
| | 18566 | if (type_has_bits(value_type)) parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type); |
| 18544 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type, | 18567 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type, |
| 18545 | parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle, | 18568 | parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle, |
| 18546 | parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero); | 18569 | parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero); |
| 18547 | | 18570 | |
| 18548 | result_loc->written = true; | 18571 | result_loc->written = true; |
| 18549 | result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc, | 18572 | result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc, |
| 18550 | ptr_type, &result_bit_cast->base.source_instruction->base, false); | 18573 | &parent_result_loc->base, ptr_type, &result_bit_cast->base.source_instruction->base, false); |
| 18551 | return result_loc->resolved_loc; | 18574 | return result_loc->resolved_loc; |
| 18552 | } | 18575 | } |
| 18553 | } | 18576 | } |
| ... | @@ -18556,25 +18579,19 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i | ... | @@ -18556,25 +18579,19 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 18556 | | 18579 | |
| 18557 | static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr, | 18580 | static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 18558 | ResultLoc *result_loc_pass1, ZigType *value_type, IrInstGen *value, bool force_runtime, | 18581 | ResultLoc *result_loc_pass1, ZigType *value_type, IrInstGen *value, bool force_runtime, |
| 18559 | bool non_null_comptime, bool allow_discard) | 18582 | bool allow_discard) |
| 18560 | { | 18583 | { |
| 18561 | Error err; | 18584 | if (!allow_discard && result_loc_is_discard(result_loc_pass1)) { |
| 18562 | if (!allow_discard && result_loc_pass1->id == ResultLocIdInstruction && | 18585 | result_loc_pass1 = no_result_loc(); |
| 18563 | result_loc_pass1->source_instruction->id == IrInstSrcIdConst) | | |
| 18564 | { | | |
| 18565 | IrInstSrcConst *const_inst = reinterpret_cast<IrInstSrcConst *>(result_loc_pass1->source_instruction); | | |
| 18566 | if (value_is_comptime(const_inst->value) && | | |
| 18567 | const_inst->value->type->id == ZigTypeIdPointer && | | |
| 18568 | const_inst->value->data.x_ptr.special == ConstPtrSpecialDiscard) | | |
| 18569 | { | | |
| 18570 | result_loc_pass1 = no_result_loc(); | | |
| 18571 | } | | |
| 18572 | } | 18586 | } |
| 18573 | bool was_already_resolved = result_loc_pass1->resolved_loc != nullptr; | 18587 | bool was_written = result_loc_pass1->written; |
| 18574 | IrInstGen *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, | 18588 | IrInstGen *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, |
| 18575 | value, force_runtime, non_null_comptime, allow_discard); | 18589 | value, force_runtime, allow_discard); |
| 18576 | if (result_loc == nullptr || (result_loc->value->type->id == ZigTypeIdUnreachable || type_is_invalid(result_loc->value->type))) | 18590 | if (result_loc == nullptr || result_loc->value->type->id == ZigTypeIdUnreachable || |
| | 18591 | type_is_invalid(result_loc->value->type)) |
| | 18592 | { |
| 18577 | return result_loc; | 18593 | return result_loc; |
| | 18594 | } |
| 18578 | | 18595 | |
| 18579 | if ((force_runtime || (value != nullptr && !instr_is_comptime(value))) && | 18596 | if ((force_runtime || (value != nullptr && !instr_is_comptime(value))) && |
| 18580 | result_loc_pass1->written && result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) | 18597 | result_loc_pass1->written && result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) |
| ... | @@ -18583,56 +18600,63 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr | ... | @@ -18583,56 +18600,63 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr |
| 18583 | } | 18600 | } |
| 18584 | | 18601 | |
| 18585 | InferredStructField *isf = result_loc->value->type->data.pointer.inferred_struct_field; | 18602 | InferredStructField *isf = result_loc->value->type->data.pointer.inferred_struct_field; |
| 18586 | if (!was_already_resolved && isf != nullptr) { | 18603 | if (isf != nullptr) { |
| 18587 | // Now it's time to add the field to the struct type. | 18604 | TypeStructField *field; |
| 18588 | uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count; | | |
| 18589 | uint32_t new_field_count = old_field_count + 1; | | |
| 18590 | isf->inferred_struct_type->data.structure.src_field_count = new_field_count; | | |
| 18591 | isf->inferred_struct_type->data.structure.fields = realloc_type_struct_fields( | | |
| 18592 | isf->inferred_struct_type->data.structure.fields, old_field_count, new_field_count); | | |
| 18593 | | | |
| 18594 | TypeStructField *field = isf->inferred_struct_type->data.structure.fields[old_field_count]; | | |
| 18595 | field->name = isf->field_name; | | |
| 18596 | field->type_entry = value_type; | | |
| 18597 | field->type_val = create_const_type(ira->codegen, field->type_entry); | | |
| 18598 | field->src_index = old_field_count; | | |
| 18599 | field->decl_node = value ? value->base.source_node : suspend_source_instr->source_node; | | |
| 18600 | if (value && instr_is_comptime(value)) { | | |
| 18601 | ZigValue *val = ir_resolve_const(ira, value, UndefOk); | | |
| 18602 | if (!val) | | |
| 18603 | return ira->codegen->invalid_inst_gen; | | |
| 18604 | field->is_comptime = true; | | |
| 18605 | field->init_val = create_const_vals(1); | | |
| 18606 | copy_const_val(field->init_val, val); | | |
| 18607 | return result_loc; | | |
| 18608 | } | | |
| 18609 | | | |
| 18610 | ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false); | | |
| 18611 | IrInstGen *casted_ptr; | 18605 | IrInstGen *casted_ptr; |
| 18612 | if (instr_is_comptime(result_loc)) { | 18606 | if (isf->already_resolved) { |
| 18613 | casted_ptr = ir_const(ira, suspend_source_instr, struct_ptr_type); | 18607 | field = find_struct_type_field(isf->inferred_struct_type, isf->field_name); |
| 18614 | copy_const_val(casted_ptr->value, result_loc->value); | | |
| 18615 | casted_ptr->value->type = struct_ptr_type; | | |
| 18616 | } else { | | |
| 18617 | casted_ptr = result_loc; | 18608 | casted_ptr = result_loc; |
| 18618 | } | 18609 | } else { |
| 18619 | if (instr_is_comptime(casted_ptr)) { | 18610 | isf->already_resolved = true; |
| 18620 | ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad); | 18611 | // Now it's time to add the field to the struct type. |
| 18621 | if (!ptr_val) | 18612 | uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count; |
| 18622 | return ira->codegen->invalid_inst_gen; | 18613 | uint32_t new_field_count = old_field_count + 1; |
| 18623 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { | 18614 | isf->inferred_struct_type->data.structure.src_field_count = new_field_count; |
| 18624 | ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, | 18615 | isf->inferred_struct_type->data.structure.fields = realloc_type_struct_fields( |
| 18625 | suspend_source_instr->source_node); | 18616 | isf->inferred_struct_type->data.structure.fields, old_field_count, new_field_count); |
| 18626 | struct_val->special = ConstValSpecialStatic; | 18617 | |
| 18627 | struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields, | 18618 | field = isf->inferred_struct_type->data.structure.fields[old_field_count]; |
| 18628 | old_field_count, new_field_count); | 18619 | field->name = isf->field_name; |
| | 18620 | field->type_entry = value_type; |
| | 18621 | field->type_val = create_const_type(ira->codegen, field->type_entry); |
| | 18622 | field->src_index = old_field_count; |
| | 18623 | field->decl_node = value ? value->base.source_node : suspend_source_instr->source_node; |
| | 18624 | if (value && instr_is_comptime(value)) { |
| | 18625 | ZigValue *val = ir_resolve_const(ira, value, UndefOk); |
| | 18626 | if (!val) |
| | 18627 | return ira->codegen->invalid_inst_gen; |
| | 18628 | field->is_comptime = true; |
| | 18629 | field->init_val = create_const_vals(1); |
| | 18630 | copy_const_val(field->init_val, val); |
| | 18631 | return result_loc; |
| | 18632 | } |
| 18629 | | 18633 | |
| 18630 | ZigValue *field_val = struct_val->data.x_struct.fields[old_field_count]; | 18634 | ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false); |
| 18631 | field_val->special = ConstValSpecialUndef; | 18635 | if (instr_is_comptime(result_loc)) { |
| 18632 | field_val->type = field->type_entry; | 18636 | casted_ptr = ir_const(ira, suspend_source_instr, struct_ptr_type); |
| 18633 | field_val->parent.id = ConstParentIdStruct; | 18637 | copy_const_val(casted_ptr->value, result_loc->value); |
| 18634 | field_val->parent.data.p_struct.struct_val = struct_val; | 18638 | casted_ptr->value->type = struct_ptr_type; |
| 18635 | field_val->parent.data.p_struct.field_index = old_field_count; | 18639 | } else { |
| | 18640 | casted_ptr = result_loc; |
| | 18641 | } |
| | 18642 | if (instr_is_comptime(casted_ptr)) { |
| | 18643 | ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad); |
| | 18644 | if (!ptr_val) |
| | 18645 | return ira->codegen->invalid_inst_gen; |
| | 18646 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| | 18647 | ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, |
| | 18648 | suspend_source_instr->source_node); |
| | 18649 | struct_val->special = ConstValSpecialStatic; |
| | 18650 | struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields, |
| | 18651 | old_field_count, new_field_count); |
| | 18652 | |
| | 18653 | ZigValue *field_val = struct_val->data.x_struct.fields[old_field_count]; |
| | 18654 | field_val->special = ConstValSpecialUndef; |
| | 18655 | field_val->type = field->type_entry; |
| | 18656 | field_val->parent.id = ConstParentIdStruct; |
| | 18657 | field_val->parent.data.p_struct.struct_val = struct_val; |
| | 18658 | field_val->parent.data.p_struct.field_index = old_field_count; |
| | 18659 | } |
| 18636 | } | 18660 | } |
| 18637 | } | 18661 | } |
| 18638 | | 18662 | |
| ... | @@ -18641,36 +18665,35 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr | ... | @@ -18641,36 +18665,35 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr |
| 18641 | result_loc_pass1->resolved_loc = result_loc; | 18665 | result_loc_pass1->resolved_loc = result_loc; |
| 18642 | } | 18666 | } |
| 18643 | | 18667 | |
| | 18668 | if (was_written) { |
| | 18669 | return result_loc; |
| | 18670 | } |
| 18644 | | 18671 | |
| 18645 | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr); | 18672 | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr); |
| 18646 | ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type; | 18673 | ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type; |
| 18647 | if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && | 18674 | if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && |
| 18648 | value_type->id != ZigTypeIdNull) | 18675 | value_type->id != ZigTypeIdNull && value_type->id != ZigTypeIdUndefined) |
| 18649 | { | 18676 | { |
| 18650 | bool has_bits; | 18677 | bool same_comptime_repr = types_have_same_zig_comptime_repr(ira->codegen, actual_elem_type, value_type); |
| 18651 | if ((err = type_has_bits2(ira->codegen, value_type, &has_bits))) | 18678 | if (!same_comptime_repr) { |
| 18652 | return ira->codegen->invalid_inst_gen; | 18679 | result_loc_pass1->written = was_written; |
| 18653 | if (has_bits) { | | |
| 18654 | result_loc_pass1->written = false; | | |
| 18655 | return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true); | 18680 | return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true); |
| 18656 | } | 18681 | } |
| 18657 | } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion) { | 18682 | } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion && |
| 18658 | bool has_bits; | 18683 | value_type->id != ZigTypeIdUndefined) |
| 18659 | if ((err = type_has_bits2(ira->codegen, value_type, &has_bits))) | 18684 | { |
| 18660 | return ira->codegen->invalid_inst_gen; | 18685 | if (value_type->id == ZigTypeIdErrorSet) { |
| 18661 | if (has_bits) { | 18686 | return ir_analyze_unwrap_err_code(ira, suspend_source_instr, result_loc, true); |
| 18662 | if (value_type->id == ZigTypeIdErrorSet) { | 18687 | } else { |
| 18663 | return ir_analyze_unwrap_err_code(ira, suspend_source_instr, result_loc, true); | 18688 | IrInstGen *unwrapped_err_ptr = ir_analyze_unwrap_error_payload(ira, suspend_source_instr, |
| | 18689 | result_loc, false, true); |
| | 18690 | ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type; |
| | 18691 | if (actual_payload_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && |
| | 18692 | value_type->id != ZigTypeIdNull && value_type->id != ZigTypeIdUndefined) |
| | 18693 | { |
| | 18694 | return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, unwrapped_err_ptr, false, true); |
| 18664 | } else { | 18695 | } else { |
| 18665 | IrInstGen *unwrapped_err_ptr = ir_analyze_unwrap_error_payload(ira, suspend_source_instr, | 18696 | return unwrapped_err_ptr; |
| 18666 | result_loc, false, true); | | |
| 18667 | ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type; | | |
| 18668 | if (actual_payload_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && | | |
| 18669 | value_type->id != ZigTypeIdNull) { | | |
| 18670 | return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, unwrapped_err_ptr, false, true); | | |
| 18671 | } else { | | |
| 18672 | return unwrapped_err_ptr; | | |
| 18673 | } | | |
| 18674 | } | 18697 | } |
| 18675 | } | 18698 | } |
| 18676 | } | 18699 | } |
| ... | @@ -18717,7 +18740,7 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr | ... | @@ -18717,7 +18740,7 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr |
| 18717 | return ira->codegen->invalid_inst_gen; | 18740 | return ira->codegen->invalid_inst_gen; |
| 18718 | } | 18741 | } |
| 18719 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, | 18742 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 18720 | implicit_elem_type, nullptr, false, true, true); | 18743 | implicit_elem_type, nullptr, false, true); |
| 18721 | if (result_loc != nullptr) | 18744 | if (result_loc != nullptr) |
| 18722 | return result_loc; | 18745 | return result_loc; |
| 18723 | | 18746 | |
| ... | @@ -18726,7 +18749,7 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr | ... | @@ -18726,7 +18749,7 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr |
| 18726 | instruction->result_loc->id == ResultLocIdReturn) | 18749 | instruction->result_loc->id == ResultLocIdReturn) |
| 18727 | { | 18750 | { |
| 18728 | result_loc = ir_resolve_result(ira, &instruction->base.base, no_result_loc(), | 18751 | result_loc = ir_resolve_result(ira, &instruction->base.base, no_result_loc(), |
| 18729 | implicit_elem_type, nullptr, false, true, true); | 18752 | implicit_elem_type, nullptr, false, true); |
| 18730 | if (result_loc != nullptr && | 18753 | if (result_loc != nullptr && |
| 18731 | (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) | 18754 | (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) |
| 18732 | { | 18755 | { |
| ... | @@ -18829,11 +18852,12 @@ static IrInstGen *ir_analyze_async_call(IrAnalyze *ira, IrInst* source_instr, Zi | ... | @@ -18829,11 +18852,12 @@ static IrInstGen *ir_analyze_async_call(IrAnalyze *ira, IrInst* source_instr, Zi |
| 18829 | } else { | 18852 | } else { |
| 18830 | ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry); | 18853 | ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry); |
| 18831 | IrInstGen *result_loc = ir_resolve_result(ira, source_instr, call_result_loc, | 18854 | IrInstGen *result_loc = ir_resolve_result(ira, source_instr, call_result_loc, |
| 18832 | frame_type, nullptr, true, true, false); | 18855 | frame_type, nullptr, true, false); |
| 18833 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { | 18856 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 18834 | return result_loc; | 18857 | return result_loc; |
| 18835 | } | 18858 | } |
| 18836 | result_loc = ir_implicit_cast(ira, result_loc, get_pointer_to_type(ira->codegen, frame_type, false)); | 18859 | result_loc = ir_implicit_cast2(ira, &call_result_loc->source_instruction->base, result_loc, |
| | 18860 | get_pointer_to_type(ira->codegen, frame_type, false)); |
| 18837 | if (type_is_invalid(result_loc->value->type)) | 18861 | if (type_is_invalid(result_loc->value->type)) |
| 18838 | return ira->codegen->invalid_inst_gen; | 18862 | return ira->codegen->invalid_inst_gen; |
| 18839 | return &ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, arg_count, | 18863 | return &ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, arg_count, |
| ... | @@ -18875,7 +18899,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node | ... | @@ -18875,7 +18899,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node |
| 18875 | } | 18899 | } |
| 18876 | | 18900 | |
| 18877 | static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node, | 18901 | static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node, |
| 18878 | IrInstGen *arg, Scope **child_scope, size_t *next_proto_i, | 18902 | IrInstGen *arg, IrInst *arg_src, Scope **child_scope, size_t *next_proto_i, |
| 18879 | GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstGen **casted_args, | 18903 | GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstGen **casted_args, |
| 18880 | ZigFn *impl_fn) | 18904 | ZigFn *impl_fn) |
| 18881 | { | 18905 | { |
| ... | @@ -18894,7 +18918,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod | ... | @@ -18894,7 +18918,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 18894 | if (type_is_invalid(param_type)) | 18918 | if (type_is_invalid(param_type)) |
| 18895 | return false; | 18919 | return false; |
| 18896 | | 18920 | |
| 18897 | casted_arg = ir_implicit_cast(ira, arg, param_type); | 18921 | casted_arg = ir_implicit_cast2(ira, arg_src, arg, param_type); |
| 18898 | if (type_is_invalid(casted_arg->value->type)) | 18922 | if (type_is_invalid(casted_arg->value->type)) |
| 18899 | return false; | 18923 | return false; |
| 18900 | } else { | 18924 | } else { |
| ... | @@ -18965,41 +18989,28 @@ static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *v | ... | @@ -18965,41 +18989,28 @@ static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *v |
| 18965 | var = var->next_var; | 18989 | var = var->next_var; |
| 18966 | } | 18990 | } |
| 18967 | | 18991 | |
| 18968 | if (var->mem_slot_index != SIZE_MAX && var->owner_exec->analysis == nullptr) { | | |
| 18969 | assert(ira->codegen->errors.length != 0); | | |
| 18970 | return ira->codegen->invalid_inst_gen; | | |
| 18971 | } | | |
| 18972 | if (var->var_type == nullptr || type_is_invalid(var->var_type)) | 18992 | if (var->var_type == nullptr || type_is_invalid(var->var_type)) |
| 18973 | return ira->codegen->invalid_inst_gen; | 18993 | return ira->codegen->invalid_inst_gen; |
| 18974 | | 18994 | |
| 18975 | ZigValue *mem_slot = nullptr; | 18995 | bool is_volatile = false; |
| | 18996 | ZigType *var_ptr_type = get_pointer_to_type_extra(ira->codegen, var->var_type, |
| | 18997 | var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false); |
| | 18998 | |
| | 18999 | if (var->ptr_instruction != nullptr) { |
| | 19000 | return ir_implicit_cast(ira, var->ptr_instruction, var_ptr_type); |
| | 19001 | } |
| 18976 | | 19002 | |
| 18977 | bool comptime_var_mem = ir_get_var_is_comptime(var); | 19003 | bool comptime_var_mem = ir_get_var_is_comptime(var); |
| 18978 | bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern; | 19004 | bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern; |
| 18979 | bool is_volatile = false; | | |
| 18980 | | 19005 | |
| 18981 | IrInstGen *result = ir_build_var_ptr_gen(ira, source_instr, var); | 19006 | IrInstGen *result = ir_build_var_ptr_gen(ira, source_instr, var); |
| 18982 | result->value->type = get_pointer_to_type_extra(ira->codegen, var->var_type, | 19007 | result->value->type = var_ptr_type; |
| 18983 | var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false); | | |
| 18984 | | 19008 | |
| 18985 | if (linkage_makes_it_runtime || var->is_thread_local) | 19009 | if (!linkage_makes_it_runtime && !var->is_thread_local && value_is_comptime(var->const_value)) { |
| 18986 | goto no_mem_slot; | 19010 | ZigValue *val = var->const_value; |
| 18987 | | 19011 | switch (val->special) { |
| 18988 | if (value_is_comptime(var->const_value)) { | | |
| 18989 | mem_slot = var->const_value; | | |
| 18990 | } else if (var->mem_slot_index != SIZE_MAX && (comptime_var_mem || var->gen_is_const)) { | | |
| 18991 | // find the relevant exec_context | | |
| 18992 | assert(var->owner_exec != nullptr); | | |
| 18993 | assert(var->owner_exec->analysis != nullptr); | | |
| 18994 | IrExecContext *exec_context = &var->owner_exec->analysis->exec_context; | | |
| 18995 | assert(var->mem_slot_index < exec_context->mem_slot_list.length); | | |
| 18996 | mem_slot = exec_context->mem_slot_list.at(var->mem_slot_index); | | |
| 18997 | } | | |
| 18998 | | | |
| 18999 | if (mem_slot != nullptr) { | | |
| 19000 | switch (mem_slot->special) { | | |
| 19001 | case ConstValSpecialRuntime: | 19012 | case ConstValSpecialRuntime: |
| 19002 | goto no_mem_slot; | 19013 | break; |
| 19003 | case ConstValSpecialStatic: // fallthrough | 19014 | case ConstValSpecialStatic: // fallthrough |
| 19004 | case ConstValSpecialLazy: // fallthrough | 19015 | case ConstValSpecialLazy: // fallthrough |
| 19005 | case ConstValSpecialUndef: { | 19016 | case ConstValSpecialUndef: { |
| ... | @@ -19015,15 +19026,12 @@ static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *v | ... | @@ -19015,15 +19026,12 @@ static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *v |
| 19015 | result->value->special = ConstValSpecialStatic; | 19026 | result->value->special = ConstValSpecialStatic; |
| 19016 | result->value->data.x_ptr.mut = ptr_mut; | 19027 | result->value->data.x_ptr.mut = ptr_mut; |
| 19017 | result->value->data.x_ptr.special = ConstPtrSpecialRef; | 19028 | result->value->data.x_ptr.special = ConstPtrSpecialRef; |
| 19018 | result->value->data.x_ptr.data.ref.pointee = mem_slot; | 19029 | result->value->data.x_ptr.data.ref.pointee = val; |
| 19019 | return result; | 19030 | return result; |
| 19020 | } | 19031 | } |
| 19021 | } | 19032 | } |
| 19022 | zig_unreachable(); | | |
| 19023 | } | 19033 | } |
| 19024 | | 19034 | |
| 19025 | no_mem_slot: | | |
| 19026 | | | |
| 19027 | bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr); | 19035 | bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr); |
| 19028 | result->value->data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack; | 19036 | result->value->data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack; |
| 19029 | | 19037 | |
| ... | @@ -19166,7 +19174,7 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19166,7 +19174,7 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 19166 | } | 19174 | } |
| 19167 | | 19175 | |
| 19168 | static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr, | 19176 | static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr, |
| 19169 | IrInstGen *new_stack, bool is_async_call_builtin, ZigFn *fn_entry) | 19177 | IrInstGen *new_stack, IrInst *new_stack_src, bool is_async_call_builtin, ZigFn *fn_entry) |
| 19170 | { | 19178 | { |
| 19171 | if (new_stack == nullptr) | 19179 | if (new_stack == nullptr) |
| 19172 | return nullptr; | 19180 | return nullptr; |
| ... | @@ -19191,14 +19199,14 @@ static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19191,14 +19199,14 @@ static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr, |
| 19191 | false, false, PtrLenUnknown, target_fn_align(ira->codegen->zig_target), 0, 0, false); | 19199 | false, false, PtrLenUnknown, target_fn_align(ira->codegen->zig_target), 0, 0, false); |
| 19192 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); | 19200 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); |
| 19193 | ira->codegen->need_frame_size_prefix_data = true; | 19201 | ira->codegen->need_frame_size_prefix_data = true; |
| 19194 | return ir_implicit_cast(ira, new_stack, u8_slice); | 19202 | return ir_implicit_cast2(ira, new_stack_src, new_stack, u8_slice); |
| 19195 | } | 19203 | } |
| 19196 | } | 19204 | } |
| 19197 | | 19205 | |
| 19198 | static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, | 19206 | static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 19199 | ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref, | 19207 | ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref, |
| 19200 | IrInstGen *first_arg_ptr, CallModifier modifier, | 19208 | IrInstGen *first_arg_ptr, IrInst *first_arg_ptr_src, CallModifier modifier, |
| 19201 | IrInstGen *new_stack, bool is_async_call_builtin, | 19209 | IrInstGen *new_stack, IrInst *new_stack_src, bool is_async_call_builtin, |
| 19202 | 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) |
| 19203 | { | 19211 | { |
| 19204 | Error err; | 19212 | Error err; |
| ... | @@ -19285,13 +19293,6 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19285,13 +19293,6 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 19285 | return ira->codegen->invalid_inst_gen; | 19293 | return ira->codegen->invalid_inst_gen; |
| 19286 | } | 19294 | } |
| 19287 | | 19295 | |
| 19288 | if (fn_proto_node->data.fn_proto.is_var_args) { | | |
| 19289 | ir_add_error(ira, source_instr, | | |
| 19290 | buf_sprintf("compiler bug: unable to call var args function at compile time. https://github.com/ziglang/zig/issues/313")); | | |
| 19291 | return ira->codegen->invalid_inst_gen; | | |
| 19292 | } | | |
| 19293 | | | |
| 19294 | | | |
| 19295 | for (size_t call_i = 0; call_i < args_len; call_i += 1) { | 19296 | for (size_t call_i = 0; call_i < args_len; call_i += 1) { |
| 19296 | IrInstGen *old_arg = args_ptr[call_i]; | 19297 | IrInstGen *old_arg = args_ptr[call_i]; |
| 19297 | | 19298 | |
| ... | @@ -19325,10 +19326,17 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19325,10 +19326,17 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 19325 | if (result == nullptr) { | 19326 | if (result == nullptr) { |
| 19326 | // Analyze the fn body block like any other constant expression. | 19327 | // Analyze the fn body block like any other constant expression. |
| 19327 | AstNode *body_node = fn_entry->body_node; | 19328 | AstNode *body_node = fn_entry->body_node; |
| 19328 | result = ir_eval_const_value(ira->codegen, exec_scope, body_node, return_type, | 19329 | ZigValue *result_ptr; |
| 19329 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, fn_entry, | 19330 | create_result_ptr(ira->codegen, return_type, &result, &result_ptr); |
| 19330 | nullptr, source_instr->source_node, nullptr, ira->new_irb.exec, return_type_node, | 19331 | if ((err = ir_eval_const_value(ira->codegen, exec_scope, body_node, result_ptr, |
| 19331 | UndefOk); | 19332 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, |
| | 19333 | fn_entry, nullptr, source_instr->source_node, nullptr, ira->new_irb.exec, return_type_node, |
| | 19334 | UndefOk))) |
| | 19335 | { |
| | 19336 | return ira->codegen->invalid_inst_gen; |
| | 19337 | } |
| | 19338 | destroy(result_ptr, "ZigValue"); |
| | 19339 | result_ptr = nullptr; |
| 19332 | | 19340 | |
| 19333 | if (inferred_err_set_type != nullptr) { | 19341 | if (inferred_err_set_type != nullptr) { |
| 19334 | inferred_err_set_type->data.error_set.incomplete = false; | 19342 | inferred_err_set_type->data.error_set.incomplete = false; |
| ... | @@ -19412,8 +19420,8 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19412,8 +19420,8 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 19412 | return ira->codegen->invalid_inst_gen; | 19420 | return ira->codegen->invalid_inst_gen; |
| 19413 | } | 19421 | } |
| 19414 | | 19422 | |
| 19415 | 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, |
| 19416 | &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)) |
| 19417 | { | 19425 | { |
| 19418 | return ira->codegen->invalid_inst_gen; | 19426 | return ira->codegen->invalid_inst_gen; |
| 19419 | } | 19427 | } |
| ... | @@ -19427,7 +19435,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19427,7 +19435,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 19427 | 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); |
| 19428 | assert(param_decl_node->type == NodeTypeParamDecl); | 19436 | assert(param_decl_node->type == NodeTypeParamDecl); |
| 19429 | | 19437 | |
| 19430 | 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, |
| 19431 | &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)) |
| 19432 | { | 19440 | { |
| 19433 | return ira->codegen->invalid_inst_gen; | 19441 | return ira->codegen->invalid_inst_gen; |
| ... | @@ -19435,14 +19443,21 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19435,14 +19443,21 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 19435 | } | 19443 | } |
| 19436 | | 19444 | |
| 19437 | if (fn_proto_node->data.fn_proto.align_expr != nullptr) { | 19445 | if (fn_proto_node->data.fn_proto.align_expr != nullptr) { |
| 19438 | ZigValue *align_result = ir_eval_const_value(ira->codegen, impl_fn->child_scope, | 19446 | ZigValue *align_result; |
| 19439 | fn_proto_node->data.fn_proto.align_expr, get_align_amt_type(ira->codegen), | 19447 | ZigValue *result_ptr; |
| 19440 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, | 19448 | create_result_ptr(ira->codegen, get_align_amt_type(ira->codegen), &align_result, &result_ptr); |
| 19441 | nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec, | 19449 | if ((err = ir_eval_const_value(ira->codegen, impl_fn->child_scope, |
| 19442 | nullptr, UndefBad); | 19450 | fn_proto_node->data.fn_proto.align_expr, result_ptr, |
| 19443 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, | 19451 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, |
| | 19452 | nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec, |
| | 19453 | nullptr, UndefBad))) |
| | 19454 | { |
| | 19455 | return ira->codegen->invalid_inst_gen; |
| | 19456 | } |
| | 19457 | IrInstGenConst *const_instruction = ir_create_inst_noval<IrInstGenConst>(&ira->new_irb, |
| 19444 | impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr); | 19458 | impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr); |
| 19445 | copy_const_val(const_instruction->base.value, align_result); | 19459 | const_instruction->base.value = align_result; |
| | 19460 | destroy(result_ptr, "ZigValue"); |
| 19446 | | 19461 | |
| 19447 | uint32_t align_bytes = 0; | 19462 | uint32_t align_bytes = 0; |
| 19448 | ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes); | 19463 | ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes); |
| ... | @@ -19468,8 +19483,8 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19468,8 +19483,8 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 19468 | case ReqCompTimeYes: | 19483 | case ReqCompTimeYes: |
| 19469 | // 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. |
| 19470 | 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, |
| 19471 | CallModifierCompileTime, new_stack, is_async_call_builtin, args_ptr, args_len, | 19486 | first_arg_ptr_src, CallModifierCompileTime, new_stack, new_stack_src, is_async_call_builtin, |
| 19472 | ret_ptr, call_result_loc); | 19487 | args_ptr, args_len, ret_ptr, call_result_loc); |
| 19473 | case ReqCompTimeInvalid: | 19488 | case ReqCompTimeInvalid: |
| 19474 | return ira->codegen->invalid_inst_gen; | 19489 | return ira->codegen->invalid_inst_gen; |
| 19475 | case ReqCompTimeNo: | 19490 | case ReqCompTimeNo: |
| ... | @@ -19504,7 +19519,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19504,7 +19519,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 19504 | } | 19519 | } |
| 19505 | | 19520 | |
| 19506 | IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack, | 19521 | IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack, |
| 19507 | is_async_call_builtin, impl_fn); | 19522 | new_stack_src, is_async_call_builtin, impl_fn); |
| 19508 | if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type)) | 19523 | if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type)) |
| 19509 | return ira->codegen->invalid_inst_gen; | 19524 | return ira->codegen->invalid_inst_gen; |
| 19510 | | 19525 | |
| ... | @@ -19519,7 +19534,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19519,7 +19534,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 19519 | IrInstGen *result_loc; | 19534 | IrInstGen *result_loc; |
| 19520 | if (handle_is_ptr(impl_fn_type_id->return_type)) { | 19535 | if (handle_is_ptr(impl_fn_type_id->return_type)) { |
| 19521 | result_loc = ir_resolve_result(ira, source_instr, call_result_loc, | 19536 | result_loc = ir_resolve_result(ira, source_instr, call_result_loc, |
| 19522 | impl_fn_type_id->return_type, nullptr, true, true, false); | 19537 | impl_fn_type_id->return_type, nullptr, true, false); |
| 19523 | if (result_loc != nullptr) { | 19538 | if (result_loc != nullptr) { |
| 19524 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { | 19539 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 19525 | return result_loc; | 19540 | return result_loc; |
| ... | @@ -19589,7 +19604,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19589,7 +19604,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 19589 | return ira->codegen->invalid_inst_gen; | 19604 | return ira->codegen->invalid_inst_gen; |
| 19590 | } | 19605 | } |
| 19591 | | 19606 | |
| 19592 | 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); |
| 19593 | if (type_is_invalid(casted_arg->value->type)) | 19608 | if (type_is_invalid(casted_arg->value->type)) |
| 19594 | return ira->codegen->invalid_inst_gen; | 19609 | return ira->codegen->invalid_inst_gen; |
| 19595 | | 19610 | |
| ... | @@ -19629,7 +19644,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19629,7 +19644,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 19629 | return ira->codegen->invalid_inst_gen; | 19644 | return ira->codegen->invalid_inst_gen; |
| 19630 | } | 19645 | } |
| 19631 | | 19646 | |
| 19632 | IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack, | 19647 | IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack, new_stack_src, |
| 19633 | is_async_call_builtin, fn_entry); | 19648 | is_async_call_builtin, fn_entry); |
| 19634 | if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type)) | 19649 | if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type)) |
| 19635 | return ira->codegen->invalid_inst_gen; | 19650 | return ira->codegen->invalid_inst_gen; |
| ... | @@ -19651,7 +19666,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19651,7 +19666,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 19651 | IrInstGen *result_loc; | 19666 | IrInstGen *result_loc; |
| 19652 | if (handle_is_ptr(return_type)) { | 19667 | if (handle_is_ptr(return_type)) { |
| 19653 | result_loc = ir_resolve_result(ira, source_instr, call_result_loc, | 19668 | result_loc = ir_resolve_result(ira, source_instr, call_result_loc, |
| 19654 | return_type, nullptr, true, true, false); | 19669 | return_type, nullptr, true, false); |
| 19655 | if (result_loc != nullptr) { | 19670 | if (result_loc != nullptr) { |
| 19656 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { | 19671 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 19657 | return result_loc; | 19672 | return result_loc; |
| ... | @@ -19685,13 +19700,15 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19685,13 +19700,15 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 19685 | | 19700 | |
| 19686 | static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_instruction, | 19701 | static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_instruction, |
| 19687 | ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref, | 19702 | ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref, |
| 19688 | IrInstGen *first_arg_ptr, CallModifier modifier) | 19703 | IrInstGen *first_arg_ptr, IrInst *first_arg_ptr_src, CallModifier modifier) |
| 19689 | { | 19704 | { |
| 19690 | IrInstGen *new_stack = nullptr; | 19705 | IrInstGen *new_stack = nullptr; |
| | 19706 | IrInst *new_stack_src = nullptr; |
| 19691 | if (call_instruction->new_stack) { | 19707 | if (call_instruction->new_stack) { |
| 19692 | new_stack = call_instruction->new_stack->child; | 19708 | new_stack = call_instruction->new_stack->child; |
| 19693 | if (type_is_invalid(new_stack->value->type)) | 19709 | if (type_is_invalid(new_stack->value->type)) |
| 19694 | return ira->codegen->invalid_inst_gen; | 19710 | return ira->codegen->invalid_inst_gen; |
| | 19711 | new_stack_src = &call_instruction->new_stack->base; |
| 19695 | } | 19712 | } |
| 19696 | IrInstGen **args_ptr = allocate<IrInstGen *>(call_instruction->arg_count, "IrInstGen *"); | 19713 | IrInstGen **args_ptr = allocate<IrInstGen *>(call_instruction->arg_count, "IrInstGen *"); |
| 19697 | for (size_t i = 0; i < call_instruction->arg_count; i += 1) { | 19714 | for (size_t i = 0; i < call_instruction->arg_count; i += 1) { |
| ... | @@ -19706,8 +19723,9 @@ static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_ins | ... | @@ -19706,8 +19723,9 @@ static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_ins |
| 19706 | return ira->codegen->invalid_inst_gen; | 19723 | return ira->codegen->invalid_inst_gen; |
| 19707 | } | 19724 | } |
| 19708 | 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, |
| 19709 | first_arg_ptr, modifier, new_stack, call_instruction->is_async_call_builtin, | 19726 | first_arg_ptr, first_arg_ptr_src, modifier, new_stack, new_stack_src, |
| 19710 | 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); |
| 19711 | deallocate(args_ptr, call_instruction->arg_count, "IrInstGen *"); | 19729 | deallocate(args_ptr, call_instruction->arg_count, "IrInstGen *"); |
| 19712 | return result; | 19730 | return result; |
| 19713 | } | 19731 | } |
| ... | @@ -19758,12 +19776,14 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19758,12 +19776,14 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr, |
| 19758 | } | 19776 | } |
| 19759 | | 19777 | |
| 19760 | IrInstGen *first_arg_ptr = nullptr; | 19778 | IrInstGen *first_arg_ptr = nullptr; |
| | 19779 | IrInst *first_arg_ptr_src = nullptr; |
| 19761 | ZigFn *fn = nullptr; | 19780 | ZigFn *fn = nullptr; |
| 19762 | if (instr_is_comptime(fn_ref)) { | 19781 | if (instr_is_comptime(fn_ref)) { |
| 19763 | if (fn_ref->value->type->id == ZigTypeIdBoundFn) { | 19782 | if (fn_ref->value->type->id == ZigTypeIdBoundFn) { |
| 19764 | assert(fn_ref->value->special == ConstValSpecialStatic); | 19783 | assert(fn_ref->value->special == ConstValSpecialStatic); |
| 19765 | fn = fn_ref->value->data.x_bound_fn.fn; | 19784 | fn = fn_ref->value->data.x_bound_fn.fn; |
| 19766 | 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; |
| 19767 | if (type_is_invalid(first_arg_ptr->value->type)) | 19787 | if (type_is_invalid(first_arg_ptr->value->type)) |
| 19768 | return ira->codegen->invalid_inst_gen; | 19788 | return ira->codegen->invalid_inst_gen; |
| 19769 | } else { | 19789 | } else { |
| ... | @@ -19805,8 +19825,8 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19805,8 +19825,8 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr, |
| 19805 | return ira->codegen->invalid_inst_gen; | 19825 | return ira->codegen->invalid_inst_gen; |
| 19806 | } | 19826 | } |
| 19807 | | 19827 | |
| 19808 | 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, |
| 19809 | modifier, stack, false, args_ptr, args_len, nullptr, result_loc); | 19829 | modifier, stack, &stack->base, false, args_ptr, args_len, nullptr, result_loc); |
| 19810 | } | 19830 | } |
| 19811 | | 19831 | |
| 19812 | static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCallExtra *instruction) { | 19832 | static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCallExtra *instruction) { |
| ... | @@ -19881,14 +19901,15 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal | ... | @@ -19881,14 +19901,15 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal |
| 19881 | 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; |
| 19882 | CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier; | 19902 | CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier; |
| 19883 | 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, |
| 19884 | fn_ref, nullptr, modifier); | 19904 | fn_ref, nullptr, nullptr, modifier); |
| 19885 | } else if (fn_ref->value->type->id == ZigTypeIdBoundFn) { | 19905 | } else if (fn_ref->value->type->id == ZigTypeIdBoundFn) { |
| 19886 | assert(fn_ref->value->special == ConstValSpecialStatic); | 19906 | assert(fn_ref->value->special == ConstValSpecialStatic); |
| 19887 | 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; |
| 19888 | 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; |
| 19889 | CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier; | 19910 | CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier; |
| 19890 | 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, |
| 19891 | fn_ref, first_arg_ptr, modifier); | 19912 | fn_ref, first_arg_ptr, first_arg_ptr_src, modifier); |
| 19892 | } else { | 19913 | } else { |
| 19893 | ir_add_error(ira, &fn_ref->base, | 19914 | ir_add_error(ira, &fn_ref->base, |
| 19894 | 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))); |
| ... | @@ -19898,7 +19919,7 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal | ... | @@ -19898,7 +19919,7 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal |
| 19898 | | 19919 | |
| 19899 | if (fn_ref->value->type->id == ZigTypeIdFn) { | 19920 | if (fn_ref->value->type->id == ZigTypeIdFn) { |
| 19900 | 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, |
| 19901 | fn_ref, nullptr, modifier); | 19922 | fn_ref, nullptr, nullptr, modifier); |
| 19902 | } else { | 19923 | } else { |
| 19903 | ir_add_error(ira, &fn_ref->base, | 19924 | ir_add_error(ira, &fn_ref->base, |
| 19904 | 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))); |
| ... | @@ -20324,7 +20345,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i | ... | @@ -20324,7 +20345,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i |
| 20324 | | 20345 | |
| 20325 | // In case resolving the parent activates a suspend, do it now | 20346 | // In case resolving the parent activates a suspend, do it now |
| 20326 | IrInstGen *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base.base, peer_parent->parent, | 20347 | IrInstGen *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base.base, peer_parent->parent, |
| 20327 | peer_parent->resolved_type, nullptr, false, false, true); | 20348 | peer_parent->resolved_type, nullptr, false, true); |
| 20328 | if (parent_result_loc != nullptr && | 20349 | if (parent_result_loc != nullptr && |
| 20329 | (type_is_invalid(parent_result_loc->value->type) || parent_result_loc->value->type->id == ZigTypeIdUnreachable)) | 20350 | (type_is_invalid(parent_result_loc->value->type) || parent_result_loc->value->type->id == ZigTypeIdUnreachable)) |
| 20330 | { | 20351 | { |
| ... | @@ -20713,10 +20734,12 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP | ... | @@ -20713,10 +20734,12 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 20713 | return_type = adjust_ptr_align(ira->codegen, return_type, chosen_align); | 20734 | return_type = adjust_ptr_align(ira->codegen, return_type, chosen_align); |
| 20714 | } | 20735 | } |
| 20715 | | 20736 | |
| | 20737 | // TODO The `array_type->id == ZigTypeIdArray` exception here should not be an exception; |
| | 20738 | // the `orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar` clause should be omitted completely. |
| | 20739 | // However there are bugs to fix before this improvement can be made. |
| 20716 | if (orig_array_ptr_val->special != ConstValSpecialRuntime && | 20740 | if (orig_array_ptr_val->special != ConstValSpecialRuntime && |
| 20717 | orig_array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr && | 20741 | orig_array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr && |
| 20718 | (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || | 20742 | (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || array_type->id == ZigTypeIdArray)) |
| 20719 | array_type->id == ZigTypeIdArray)) | | |
| 20720 | { | 20743 | { |
| 20721 | ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val, | 20744 | ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val, |
| 20722 | elem_ptr_instruction->base.base.source_node); | 20745 | elem_ptr_instruction->base.base.source_node); |
| ... | @@ -20781,6 +20804,11 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP | ... | @@ -20781,6 +20804,11 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 20781 | (array_type->id != ZigTypeIdPointer || | 20804 | (array_type->id != ZigTypeIdPointer || |
| 20782 | array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)) | 20805 | array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)) |
| 20783 | { | 20806 | { |
| | 20807 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, |
| | 20808 | elem_ptr_instruction->base.base.source_node, array_ptr_val, UndefOk))) |
| | 20809 | { |
| | 20810 | return ira->codegen->invalid_inst_gen; |
| | 20811 | } |
| 20784 | if (array_type->id == ZigTypeIdPointer) { | 20812 | if (array_type->id == ZigTypeIdPointer) { |
| 20785 | IrInstGen *result = ir_const(ira, &elem_ptr_instruction->base.base, return_type); | 20813 | IrInstGen *result = ir_const(ira, &elem_ptr_instruction->base.base, return_type); |
| 20786 | ZigValue *out_val = result->value; | 20814 | ZigValue *out_val = result->value; |
| ... | @@ -20989,7 +21017,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP | ... | @@ -20989,7 +21017,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 20989 | | 21017 | |
| 20990 | static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira, | 21018 | static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 20991 | ZigType *bare_struct_type, Buf *field_name, IrInst* source_instr, | 21019 | ZigType *bare_struct_type, Buf *field_name, IrInst* source_instr, |
| 20992 | IrInstGen *container_ptr, ZigType *container_type) | 21020 | IrInstGen *container_ptr, IrInst *container_ptr_src, ZigType *container_type) |
| 20993 | { | 21021 | { |
| 20994 | if (!is_slice(bare_struct_type)) { | 21022 | if (!is_slice(bare_struct_type)) { |
| 20995 | ScopeDecls *container_scope = get_container_scope(bare_struct_type); | 21023 | ScopeDecls *container_scope = get_container_scope(bare_struct_type); |
| ... | @@ -21010,7 +21038,8 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira, | ... | @@ -21010,7 +21038,8 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 21010 | if (type_is_invalid(fn_entry->type_entry)) | 21038 | if (type_is_invalid(fn_entry->type_entry)) |
| 21011 | return ira->codegen->invalid_inst_gen; | 21039 | return ira->codegen->invalid_inst_gen; |
| 21012 | | 21040 | |
| 21013 | 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); |
| 21014 | 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); |
| 21015 | } else if (tld->id == TldIdVar) { | 21044 | } else if (tld->id == TldIdVar) { |
| 21016 | 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); |
| ... | @@ -21029,7 +21058,8 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira, | ... | @@ -21029,7 +21058,8 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 21029 | if (var->const_value->type->id == ZigTypeIdFn) { | 21058 | if (var->const_value->type->id == ZigTypeIdFn) { |
| 21030 | 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); |
| 21031 | 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; |
| 21032 | 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); |
| 21033 | 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); |
| 21034 | } | 21064 | } |
| 21035 | } | 21065 | } |
| ... | @@ -21075,7 +21105,7 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins | ... | @@ -21075,7 +21105,7 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins |
| 21075 | IrInstGen *elem = ir_const(ira, source_instr, field_type); | 21105 | IrInstGen *elem = ir_const(ira, source_instr, field_type); |
| 21076 | memoize_field_init_val(ira->codegen, struct_type, field); | 21106 | memoize_field_init_val(ira->codegen, struct_type, field); |
| 21077 | copy_const_val(elem->value, field->init_val); | 21107 | copy_const_val(elem->value, field->init_val); |
| 21078 | return ir_get_ref(ira, source_instr, elem, true, false); | 21108 | return ir_get_ref2(ira, source_instr, elem, field_type, true, false); |
| 21079 | } | 21109 | } |
| 21080 | switch (type_has_one_possible_value(ira->codegen, field_type)) { | 21110 | switch (type_has_one_possible_value(ira->codegen, field_type)) { |
| 21081 | case OnePossibleValueInvalid: | 21111 | case OnePossibleValueInvalid: |
| ... | @@ -21193,7 +21223,8 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name, | ... | @@ -21193,7 +21223,8 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 21193 | } | 21223 | } |
| 21194 | | 21224 | |
| 21195 | static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, | 21225 | static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 21196 | 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) |
| 21197 | { | 21228 | { |
| 21198 | Error err; | 21229 | Error err; |
| 21199 | | 21230 | |
| ... | @@ -21215,13 +21246,13 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name | ... | @@ -21215,13 +21246,13 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name |
| 21215 | 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); |
| 21216 | } else { | 21247 | } else { |
| 21217 | 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, |
| 21218 | source_instr, container_ptr, container_type); | 21249 | source_instr, container_ptr, container_ptr_src, container_type); |
| 21219 | } | 21250 | } |
| 21220 | } | 21251 | } |
| 21221 | | 21252 | |
| 21222 | if (bare_type->id == ZigTypeIdEnum) { | 21253 | if (bare_type->id == ZigTypeIdEnum) { |
| 21223 | 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, |
| 21224 | source_instr, container_ptr, container_type); | 21255 | source_instr, container_ptr, container_ptr_src, container_type); |
| 21225 | } | 21256 | } |
| 21226 | | 21257 | |
| 21227 | if (bare_type->id == ZigTypeIdUnion) { | 21258 | if (bare_type->id == ZigTypeIdUnion) { |
| ... | @@ -21231,7 +21262,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name | ... | @@ -21231,7 +21262,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name |
| 21231 | TypeUnionField *field = find_union_type_field(bare_type, field_name); | 21262 | TypeUnionField *field = find_union_type_field(bare_type, field_name); |
| 21232 | if (field == nullptr) { | 21263 | if (field == nullptr) { |
| 21233 | 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, |
| 21234 | source_instr, container_ptr, container_type); | 21265 | source_instr, container_ptr, container_ptr_src, container_type); |
| 21235 | } | 21266 | } |
| 21236 | | 21267 | |
| 21237 | ZigType *field_type = resolve_union_field_type(ira->codegen, field); | 21268 | ZigType *field_type = resolve_union_field_type(ira->codegen, field); |
| ... | @@ -21425,10 +21456,14 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel | ... | @@ -21425,10 +21456,14 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel |
| 21425 | if (container_type->id == ZigTypeIdPointer) { | 21456 | if (container_type->id == ZigTypeIdPointer) { |
| 21426 | ZigType *bare_type = container_ref_type(container_type); | 21457 | ZigType *bare_type = container_ref_type(container_type); |
| 21427 | 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); |
| 21428 | 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); |
| 21429 | return result; | 21462 | return result; |
| 21430 | } else { | 21463 | } else { |
| 21431 | 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); |
| 21432 | return result; | 21467 | return result; |
| 21433 | } | 21468 | } |
| 21434 | } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) { | 21469 | } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) { |
| ... | @@ -22116,6 +22151,8 @@ static IrInstGen *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstSrc | ... | @@ -22116,6 +22151,8 @@ static IrInstGen *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstSrc |
| 22116 | static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr, | 22151 | static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr, |
| 22117 | IrInstGen *base_ptr, bool safety_check_on, bool initializing) | 22152 | IrInstGen *base_ptr, bool safety_check_on, bool initializing) |
| 22118 | { | 22153 | { |
| | 22154 | Error err; |
| | 22155 | |
| 22119 | ZigType *type_entry = get_ptr_elem_type(ira->codegen, base_ptr); | 22156 | ZigType *type_entry = get_ptr_elem_type(ira->codegen, base_ptr); |
| 22120 | if (type_is_invalid(type_entry)) | 22157 | if (type_is_invalid(type_entry)) |
| 22121 | return ira->codegen->invalid_inst_gen; | 22158 | return ira->codegen->invalid_inst_gen; |
| ... | @@ -22161,7 +22198,7 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou | ... | @@ -22161,7 +22198,7 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou |
| 22161 | | 22198 | |
| 22162 | if (instr_is_comptime(base_ptr)) { | 22199 | if (instr_is_comptime(base_ptr)) { |
| 22163 | ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); | 22200 | ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); |
| 22164 | if (!ptr_val) | 22201 | if (ptr_val == nullptr) |
| 22165 | return ira->codegen->invalid_inst_gen; | 22202 | return ira->codegen->invalid_inst_gen; |
| 22166 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { | 22203 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 22167 | ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); | 22204 | ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| ... | @@ -22185,20 +22222,19 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou | ... | @@ -22185,20 +22222,19 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou |
| 22185 | } | 22222 | } |
| 22186 | break; | 22223 | break; |
| 22187 | case OnePossibleValueYes: { | 22224 | case OnePossibleValueYes: { |
| 22188 | ZigValue *pointee = create_const_vals(1); | | |
| 22189 | pointee->special = ConstValSpecialStatic; | | |
| 22190 | pointee->type = child_type; | | |
| 22191 | pointee->parent.id = ConstParentIdOptionalPayload; | | |
| 22192 | pointee->parent.data.p_optional_payload.optional_val = optional_val; | | |
| 22193 | | | |
| 22194 | optional_val->special = ConstValSpecialStatic; | 22225 | optional_val->special = ConstValSpecialStatic; |
| 22195 | optional_val->data.x_optional = pointee; | 22226 | optional_val->data.x_optional = get_the_one_possible_value(ira->codegen, child_type); |
| 22196 | break; | 22227 | break; |
| 22197 | } | 22228 | } |
| 22198 | } | 22229 | } |
| 22199 | } else if (optional_value_is_null(optional_val)) { | 22230 | } else { |
| 22200 | ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null")); | 22231 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, |
| 22201 | return ira->codegen->invalid_inst_gen; | 22232 | source_instr->source_node, optional_val, UndefBad))) |
| | 22233 | return ira->codegen->invalid_inst_gen; |
| | 22234 | if (optional_value_is_null(optional_val)) { |
| | 22235 | ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null")); |
| | 22236 | return ira->codegen->invalid_inst_gen; |
| | 22237 | } |
| 22202 | } | 22238 | } |
| 22203 | | 22239 | |
| 22204 | IrInstGen *result; | 22240 | IrInstGen *result; |
| ... | @@ -22697,8 +22733,8 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi | ... | @@ -22697,8 +22733,8 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi |
| 22697 | ref_type->data.pointer.explicit_alignment, | 22733 | ref_type->data.pointer.explicit_alignment, |
| 22698 | ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes, | 22734 | ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes, |
| 22699 | ref_type->data.pointer.allow_zero); | 22735 | ref_type->data.pointer.allow_zero); |
| 22700 | return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, new_target_value_ptr_type, | 22736 | return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, |
| 22701 | &instruction->base.base, false); | 22737 | &instruction->target_value_ptr->base, new_target_value_ptr_type, &instruction->base.base, false); |
| 22702 | } else { | 22738 | } else { |
| 22703 | ir_add_error(ira, &instruction->base.base, | 22739 | ir_add_error(ira, &instruction->base.base, |
| 22704 | buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name))); | 22740 | buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name))); |
| ... | @@ -22778,8 +22814,8 @@ static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, | ... | @@ -22778,8 +22814,8 @@ static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, |
| 22778 | ref_type->data.pointer.explicit_alignment, | 22814 | ref_type->data.pointer.explicit_alignment, |
| 22779 | ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes, | 22815 | ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes, |
| 22780 | ref_type->data.pointer.allow_zero); | 22816 | ref_type->data.pointer.allow_zero); |
| 22781 | return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, new_target_value_ptr_type, | 22817 | return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, |
| 22782 | &instruction->base.base, false); | 22818 | &instruction->target_value_ptr->base, new_target_value_ptr_type, &instruction->base.base, false); |
| 22783 | } | 22819 | } |
| 22784 | | 22820 | |
| 22785 | return target_value_ptr; | 22821 | return target_value_ptr; |
| ... | @@ -24775,11 +24811,18 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo | ... | @@ -24775,11 +24811,18 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo |
| 24775 | | 24811 | |
| 24776 | // Execute the C import block like an inline function | 24812 | // Execute the C import block like an inline function |
| 24777 | ZigType *void_type = ira->codegen->builtin_types.entry_void; | 24813 | ZigType *void_type = ira->codegen->builtin_types.entry_void; |
| 24778 | ZigValue *cimport_result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type, | 24814 | ZigValue *cimport_result; |
| | 24815 | ZigValue *result_ptr; |
| | 24816 | create_result_ptr(ira->codegen, void_type, &cimport_result, &result_ptr); |
| | 24817 | if ((err = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, result_ptr, |
| 24779 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, | 24818 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, |
| 24780 | &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad); | 24819 | &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad))) |
| | 24820 | { |
| | 24821 | return ira->codegen->invalid_inst_gen; |
| | 24822 | } |
| 24781 | if (type_is_invalid(cimport_result->type)) | 24823 | if (type_is_invalid(cimport_result->type)) |
| 24782 | return ira->codegen->invalid_inst_gen; | 24824 | return ira->codegen->invalid_inst_gen; |
| | 24825 | destroy(result_ptr, "ZigValue"); |
| 24783 | | 24826 | |
| 24784 | ZigPackage *cur_scope_pkg = scope_package(instruction->base.base.scope); | 24827 | ZigPackage *cur_scope_pkg = scope_package(instruction->base.base.scope); |
| 24785 | Buf *namespace_name = buf_sprintf("%s.cimport:%" ZIG_PRI_usize ":%" ZIG_PRI_usize, | 24828 | Buf *namespace_name = buf_sprintf("%s.cimport:%" ZIG_PRI_usize ":%" ZIG_PRI_usize, |
| ... | @@ -25068,7 +25111,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch | ... | @@ -25068,7 +25111,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch |
| 25068 | | 25111 | |
| 25069 | // TODO let this be volatile | 25112 | // TODO let this be volatile |
| 25070 | 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); |
| 25071 | IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type); | 25114 | IrInstGen *casted_ptr = ir_implicit_cast2(ira, &instruction->ptr->base, ptr, ptr_type); |
| 25072 | if (type_is_invalid(casted_ptr->value->type)) | 25115 | if (type_is_invalid(casted_ptr->value->type)) |
| 25073 | return ira->codegen->invalid_inst_gen; | 25116 | return ira->codegen->invalid_inst_gen; |
| 25074 | | 25117 | |
| ... | @@ -25096,11 +25139,11 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch | ... | @@ -25096,11 +25139,11 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch |
| 25096 | if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order)) | 25139 | if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order)) |
| 25097 | return ira->codegen->invalid_inst_gen; | 25140 | return ira->codegen->invalid_inst_gen; |
| 25098 | | 25141 | |
| 25099 | 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); |
| 25100 | if (type_is_invalid(casted_cmp_value->value->type)) | 25143 | if (type_is_invalid(casted_cmp_value->value->type)) |
| 25101 | return ira->codegen->invalid_inst_gen; | 25144 | return ira->codegen->invalid_inst_gen; |
| 25102 | | 25145 | |
| 25103 | 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); |
| 25104 | if (type_is_invalid(casted_new_value->value->type)) | 25147 | if (type_is_invalid(casted_new_value->value->type)) |
| 25105 | return ira->codegen->invalid_inst_gen; | 25148 | return ira->codegen->invalid_inst_gen; |
| 25106 | | 25149 | |
| ... | @@ -25134,7 +25177,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch | ... | @@ -25134,7 +25177,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch |
| 25134 | IrInstGen *result_loc; | 25177 | IrInstGen *result_loc; |
| 25135 | if (handle_is_ptr(result_type)) { | 25178 | if (handle_is_ptr(result_type)) { |
| 25136 | result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, | 25179 | result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 25137 | result_type, nullptr, true, false, true); | 25180 | result_type, nullptr, true, true); |
| 25138 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { | 25181 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 25139 | return result_loc; | 25182 | return result_loc; |
| 25140 | } | 25183 | } |
| ... | @@ -25191,7 +25234,7 @@ static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTrunc | ... | @@ -25191,7 +25234,7 @@ static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTrunc |
| 25191 | } | 25234 | } |
| 25192 | | 25235 | |
| 25193 | if (dest_type->id == ZigTypeIdComptimeInt) { | 25236 | if (dest_type->id == ZigTypeIdComptimeInt) { |
| 25194 | return ir_implicit_cast(ira, target, dest_type); | 25237 | return ir_implicit_cast2(ira, &instruction->target->base, target, dest_type); |
| 25195 | } | 25238 | } |
| 25196 | | 25239 | |
| 25197 | if (instr_is_comptime(target)) { | 25240 | if (instr_is_comptime(target)) { |
| ... | @@ -25245,7 +25288,7 @@ static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCa | ... | @@ -25245,7 +25288,7 @@ static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCa |
| 25245 | } | 25288 | } |
| 25246 | | 25289 | |
| 25247 | if (instr_is_comptime(target)) { | 25290 | if (instr_is_comptime(target)) { |
| 25248 | return ir_implicit_cast(ira, target, dest_type); | 25291 | return ir_implicit_cast2(ira, &instruction->target->base, target, dest_type); |
| 25249 | } | 25292 | } |
| 25250 | | 25293 | |
| 25251 | if (dest_type->id == ZigTypeIdComptimeInt) { | 25294 | if (dest_type->id == ZigTypeIdComptimeInt) { |
| ... | @@ -25373,7 +25416,7 @@ static IrInstGen *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstSrcFro | ... | @@ -25373,7 +25416,7 @@ static IrInstGen *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstSrcFro |
| 25373 | src_ptr_align, 0, 0, false); | 25416 | src_ptr_align, 0, 0, false); |
| 25374 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); | 25417 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); |
| 25375 | | 25418 | |
| 25376 | IrInstGen *casted_value = ir_implicit_cast(ira, target, u8_slice); | 25419 | IrInstGen *casted_value = ir_implicit_cast2(ira, &instruction->target->base, target, u8_slice); |
| 25377 | if (type_is_invalid(casted_value->value->type)) | 25420 | if (type_is_invalid(casted_value->value->type)) |
| 25378 | return ira->codegen->invalid_inst_gen; | 25421 | return ira->codegen->invalid_inst_gen; |
| 25379 | | 25422 | |
| ... | @@ -25393,7 +25436,7 @@ static IrInstGen *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstSrcFro | ... | @@ -25393,7 +25436,7 @@ static IrInstGen *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstSrcFro |
| 25393 | } | 25436 | } |
| 25394 | | 25437 | |
| 25395 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, | 25438 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 25396 | dest_slice_type, nullptr, true, false, true); | 25439 | dest_slice_type, nullptr, true, true); |
| 25397 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) { | 25440 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) { |
| 25398 | return result_loc; | 25441 | return result_loc; |
| 25399 | } | 25442 | } |
| ... | @@ -25478,7 +25521,7 @@ static IrInstGen *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstSrcToByt | ... | @@ -25478,7 +25521,7 @@ static IrInstGen *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstSrcToByt |
| 25478 | } | 25521 | } |
| 25479 | | 25522 | |
| 25480 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, | 25523 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 25481 | dest_slice_type, nullptr, true, false, true); | 25524 | dest_slice_type, nullptr, true, true); |
| 25482 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { | 25525 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 25483 | return result_loc; | 25526 | return result_loc; |
| 25484 | } | 25527 | } |
| ... | @@ -26508,7 +26551,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i | ... | @@ -26508,7 +26551,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i |
| 26508 | } | 26551 | } |
| 26509 | | 26552 | |
| 26510 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, | 26553 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 26511 | return_type, nullptr, true, false, true); | 26554 | return_type, nullptr, true, true); |
| 26512 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { | 26555 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 26513 | return result_loc; | 26556 | return result_loc; |
| 26514 | } | 26557 | } |
| ... | @@ -27662,7 +27705,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig | ... | @@ -27662,7 +27705,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig |
| 27662 | } | 27705 | } |
| 27663 | | 27706 | |
| 27664 | static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr, | 27707 | static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr, |
| 27665 | ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on) | 27708 | IrInst *ptr_src, ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on) |
| 27666 | { | 27709 | { |
| 27667 | Error err; | 27710 | Error err; |
| 27668 | | 27711 | |
| ... | @@ -27678,7 +27721,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn | ... | @@ -27678,7 +27721,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn |
| 27678 | | 27721 | |
| 27679 | ZigType *src_ptr_type = get_src_ptr_type(src_type); | 27722 | ZigType *src_ptr_type = get_src_ptr_type(src_type); |
| 27680 | if (src_ptr_type == nullptr) { | 27723 | if (src_ptr_type == nullptr) { |
| 27681 | ir_add_error(ira, &ptr->base, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name))); | 27724 | ir_add_error(ira, ptr_src, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name))); |
| 27682 | return ira->codegen->invalid_inst_gen; | 27725 | return ira->codegen->invalid_inst_gen; |
| 27683 | } | 27726 | } |
| 27684 | | 27727 | |
| ... | @@ -27707,11 +27750,11 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn | ... | @@ -27707,11 +27750,11 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn |
| 27707 | if ((err = type_resolve(ira->codegen, src_type, ResolveStatusZeroBitsKnown))) | 27750 | if ((err = type_resolve(ira->codegen, src_type, ResolveStatusZeroBitsKnown))) |
| 27708 | return ira->codegen->invalid_inst_gen; | 27751 | return ira->codegen->invalid_inst_gen; |
| 27709 | | 27752 | |
| 27710 | if (type_has_bits(dest_type) && !type_has_bits(src_type)) { | 27753 | if (type_has_bits(dest_type) && !type_has_bits(src_type) && safety_check_on) { |
| 27711 | ErrorMsg *msg = ir_add_error(ira, source_instr, | 27754 | ErrorMsg *msg = ir_add_error(ira, source_instr, |
| 27712 | buf_sprintf("'%s' and '%s' do not have the same in-memory representation", | 27755 | buf_sprintf("'%s' and '%s' do not have the same in-memory representation", |
| 27713 | buf_ptr(&src_type->name), buf_ptr(&dest_type->name))); | 27756 | buf_ptr(&src_type->name), buf_ptr(&dest_type->name))); |
| 27714 | add_error_note(ira->codegen, msg, ptr->base.source_node, | 27757 | add_error_note(ira->codegen, msg, ptr_src->source_node, |
| 27715 | buf_sprintf("'%s' has no in-memory bits", buf_ptr(&src_type->name))); | 27758 | buf_sprintf("'%s' has no in-memory bits", buf_ptr(&src_type->name))); |
| 27716 | add_error_note(ira->codegen, msg, dest_type_src->source_node, | 27759 | add_error_note(ira->codegen, msg, dest_type_src->source_node, |
| 27717 | buf_sprintf("'%s' has in-memory bits", buf_ptr(&dest_type->name))); | 27760 | buf_sprintf("'%s' has in-memory bits", buf_ptr(&dest_type->name))); |
| ... | @@ -27722,7 +27765,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn | ... | @@ -27722,7 +27765,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn |
| 27722 | bool dest_allows_addr_zero = ptr_allows_addr_zero(dest_type); | 27765 | bool dest_allows_addr_zero = ptr_allows_addr_zero(dest_type); |
| 27723 | UndefAllowed is_undef_allowed = dest_allows_addr_zero ? UndefOk : UndefBad; | 27766 | UndefAllowed is_undef_allowed = dest_allows_addr_zero ? UndefOk : UndefBad; |
| 27724 | ZigValue *val = ir_resolve_const(ira, ptr, is_undef_allowed); | 27767 | ZigValue *val = ir_resolve_const(ira, ptr, is_undef_allowed); |
| 27725 | if (!val) | 27768 | if (val == nullptr) |
| 27726 | return ira->codegen->invalid_inst_gen; | 27769 | return ira->codegen->invalid_inst_gen; |
| 27727 | | 27770 | |
| 27728 | if (value_is_comptime(val) && val->special != ConstValSpecialUndef) { | 27771 | if (value_is_comptime(val) && val->special != ConstValSpecialUndef) { |
| ... | @@ -27737,15 +27780,31 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn | ... | @@ -27737,15 +27780,31 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn |
| 27737 | } | 27780 | } |
| 27738 | | 27781 | |
| 27739 | IrInstGen *result; | 27782 | IrInstGen *result; |
| 27740 | if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) { | 27783 | if (val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 27741 | result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on); | 27784 | result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on); |
| 27742 | | | |
| 27743 | if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown))) | | |
| 27744 | return ira->codegen->invalid_inst_gen; | | |
| 27745 | } else { | 27785 | } else { |
| 27746 | result = ir_const(ira, source_instr, dest_type); | 27786 | result = ir_const(ira, source_instr, dest_type); |
| 27747 | } | 27787 | } |
| 27748 | copy_const_val(result->value, val); | 27788 | InferredStructField *isf = (val->type->id == ZigTypeIdPointer) ? |
| | 27789 | val->type->data.pointer.inferred_struct_field : nullptr; |
| | 27790 | if (isf == nullptr) { |
| | 27791 | copy_const_val(result->value, val); |
| | 27792 | } else { |
| | 27793 | // The destination value should have x_ptr struct pointing to underlying struct value |
| | 27794 | result->value->data.x_ptr.mut = val->data.x_ptr.mut; |
| | 27795 | TypeStructField *field = find_struct_type_field(isf->inferred_struct_type, isf->field_name); |
| | 27796 | assert(field != nullptr); |
| | 27797 | if (field->is_comptime) { |
| | 27798 | result->value->data.x_ptr.special = ConstPtrSpecialRef; |
| | 27799 | result->value->data.x_ptr.data.ref.pointee = field->init_val; |
| | 27800 | } else { |
| | 27801 | assert(val->data.x_ptr.special == ConstPtrSpecialRef); |
| | 27802 | result->value->data.x_ptr.special = ConstPtrSpecialBaseStruct; |
| | 27803 | result->value->data.x_ptr.data.base_struct.struct_val = val->data.x_ptr.data.ref.pointee; |
| | 27804 | result->value->data.x_ptr.data.base_struct.field_index = field->src_index; |
| | 27805 | } |
| | 27806 | result->value->special = ConstValSpecialStatic; |
| | 27807 | } |
| 27749 | result->value->type = dest_type; | 27808 | result->value->type = dest_type; |
| 27750 | | 27809 | |
| 27751 | // Keep the bigger alignment, it can only help- | 27810 | // Keep the bigger alignment, it can only help- |
| ... | @@ -27759,7 +27818,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn | ... | @@ -27759,7 +27818,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn |
| 27759 | | 27818 | |
| 27760 | if (dest_align_bytes > src_align_bytes) { | 27819 | if (dest_align_bytes > src_align_bytes) { |
| 27761 | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment")); | 27820 | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment")); |
| 27762 | add_error_note(ira->codegen, msg, ptr->base.source_node, | 27821 | add_error_note(ira->codegen, msg, ptr_src->source_node, |
| 27763 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_type->name), src_align_bytes)); | 27822 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_type->name), src_align_bytes)); |
| 27764 | add_error_note(ira->codegen, msg, dest_type_src->source_node, | 27823 | add_error_note(ira->codegen, msg, dest_type_src->source_node, |
| 27765 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_type->name), dest_align_bytes)); | 27824 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_type->name), dest_align_bytes)); |
| ... | @@ -27792,8 +27851,8 @@ static IrInstGen *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstSrcPtrCa | ... | @@ -27792,8 +27851,8 @@ static IrInstGen *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstSrcPtrCa |
| 27792 | if (type_is_invalid(src_type)) | 27851 | if (type_is_invalid(src_type)) |
| 27793 | return ira->codegen->invalid_inst_gen; | 27852 | return ira->codegen->invalid_inst_gen; |
| 27794 | | 27853 | |
| 27795 | return ir_analyze_ptr_cast(ira, &instruction->base.base, ptr, dest_type, &dest_type_value->base, | 27854 | return ir_analyze_ptr_cast(ira, &instruction->base.base, ptr, &instruction->ptr->base, |
| 27796 | instruction->safety_check_on); | 27855 | dest_type, &dest_type_value->base, instruction->safety_check_on); |
| 27797 | } | 27856 | } |
| 27798 | | 27857 | |
| 27799 | static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ZigValue *val, size_t len) { | 27858 | static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ZigValue *val, size_t len) { |
| ... | @@ -29206,7 +29265,7 @@ static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndEx | ... | @@ -29206,7 +29265,7 @@ static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndEx |
| 29206 | | 29265 | |
| 29207 | bool was_written = instruction->result_loc->written; | 29266 | bool was_written = instruction->result_loc->written; |
| 29208 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, | 29267 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 29209 | value->value->type, value, false, false, true); | 29268 | value->value->type, value, false, true); |
| 29210 | if (result_loc != nullptr) { | 29269 | if (result_loc != nullptr) { |
| 29211 | if (type_is_invalid(result_loc->value->type)) | 29270 | if (type_is_invalid(result_loc->value->type)) |
| 29212 | return ira->codegen->invalid_inst_gen; | 29271 | return ira->codegen->invalid_inst_gen; |
| ... | @@ -29240,11 +29299,6 @@ static IrInstGen *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstSrc | ... | @@ -29240,11 +29299,6 @@ static IrInstGen *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstSrc |
| 29240 | if (type_is_invalid(operand->value->type)) | 29299 | if (type_is_invalid(operand->value->type)) |
| 29241 | return operand; | 29300 | return operand; |
| 29242 | | 29301 | |
| 29243 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, | | |
| 29244 | &instruction->result_loc_cast->base, operand->value->type, operand, false, false, true); | | |
| 29245 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) | | |
| 29246 | return result_loc; | | |
| 29247 | | | |
| 29248 | ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child); | 29302 | ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child); |
| 29249 | if (type_is_invalid(dest_type)) | 29303 | if (type_is_invalid(dest_type)) |
| 29250 | return ira->codegen->invalid_inst_gen; | 29304 | return ira->codegen->invalid_inst_gen; |
| ... | @@ -29257,15 +29311,18 @@ static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcB | ... | @@ -29257,15 +29311,18 @@ static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcB |
| 29257 | return operand; | 29311 | return operand; |
| 29258 | | 29312 | |
| 29259 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, | 29313 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, |
| 29260 | &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, false, true); | 29314 | &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, true); |
| 29261 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) | 29315 | if (result_loc != nullptr && |
| | 29316 | (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) |
| | 29317 | { |
| 29262 | return result_loc; | 29318 | return result_loc; |
| 29263 | | | |
| 29264 | if (instruction->result_loc_bit_cast->parent->gen_instruction != nullptr) { | | |
| 29265 | return instruction->result_loc_bit_cast->parent->gen_instruction; | | |
| 29266 | } | 29319 | } |
| 29267 | | 29320 | |
| 29268 | return result_loc; | 29321 | ZigType *dest_type = ir_resolve_type(ira, |
| | 29322 | instruction->result_loc_bit_cast->base.source_instruction->child); |
| | 29323 | if (type_is_invalid(dest_type)) |
| | 29324 | return ira->codegen->invalid_inst_gen; |
| | 29325 | return ir_analyze_bit_cast(ira, &instruction->base.base, operand, dest_type); |
| 29269 | } | 29326 | } |
| 29270 | | 29327 | |
| 29271 | static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira, | 29328 | static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira, |
| ... | @@ -29392,9 +29449,12 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i | ... | @@ -29392,9 +29449,12 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i |
| 29392 | IrInstGen *result_loc; | 29449 | IrInstGen *result_loc; |
| 29393 | if (type_has_bits(result_type)) { | 29450 | if (type_has_bits(result_type)) { |
| 29394 | result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, | 29451 | result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 29395 | result_type, nullptr, true, true, true); | 29452 | result_type, nullptr, true, true); |
| 29396 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) | 29453 | if (result_loc != nullptr && |
| | 29454 | (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) |
| | 29455 | { |
| 29397 | return result_loc; | 29456 | return result_loc; |
| | 29457 | } |
| 29398 | } else { | 29458 | } else { |
| 29399 | result_loc = nullptr; | 29459 | result_loc = nullptr; |
| 29400 | } | 29460 | } |
| ... | @@ -29421,7 +29481,7 @@ static IrInstGen *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstSrcResume | ... | @@ -29421,7 +29481,7 @@ static IrInstGen *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstSrcResume |
| 29421 | } | 29481 | } |
| 29422 | | 29482 | |
| 29423 | ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr); | 29483 | ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr); |
| 29424 | IrInstGen *casted_frame = ir_implicit_cast(ira, frame, any_frame_type); | 29484 | IrInstGen *casted_frame = ir_implicit_cast2(ira, &instruction->frame->base, frame, any_frame_type); |
| 29425 | if (type_is_invalid(casted_frame->value->type)) | 29485 | if (type_is_invalid(casted_frame->value->type)) |
| 29426 | return ira->codegen->invalid_inst_gen; | 29486 | return ira->codegen->invalid_inst_gen; |
| 29427 | | 29487 | |
| ... | @@ -29747,7 +29807,7 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc | ... | @@ -29747,7 +29807,7 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc |
| 29747 | // This function attempts to evaluate IR code while doing type checking and other analysis. | 29807 | // This function attempts to evaluate IR code while doing type checking and other analysis. |
| 29748 | // It emits to a new IrExecutableGen which is partially evaluated IR code. | 29808 | // It emits to a new IrExecutableGen which is partially evaluated IR code. |
| 29749 | ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen *new_exec, | 29809 | ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen *new_exec, |
| 29750 | ZigType *expected_type, AstNode *expected_type_source_node) | 29810 | ZigType *expected_type, AstNode *expected_type_source_node, ZigValue *result_ptr) |
| 29751 | { | 29811 | { |
| 29752 | assert(old_exec->first_err_trace_msg == nullptr); | 29812 | assert(old_exec->first_err_trace_msg == nullptr); |
| 29753 | assert(expected_type == nullptr || !type_is_invalid(expected_type)); | 29813 | assert(expected_type == nullptr || !type_is_invalid(expected_type)); |
| ... | @@ -29766,12 +29826,6 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen | ... | @@ -29766,12 +29826,6 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen |
| 29766 | ira->new_irb.codegen = codegen; | 29826 | ira->new_irb.codegen = codegen; |
| 29767 | ira->new_irb.exec = new_exec; | 29827 | ira->new_irb.exec = new_exec; |
| 29768 | | 29828 | |
| 29769 | ZigValue *vals = create_const_vals(ira->old_irb.exec->mem_slot_count); | | |
| 29770 | ira->exec_context.mem_slot_list.resize(ira->old_irb.exec->mem_slot_count); | | |
| 29771 | for (size_t i = 0; i < ira->exec_context.mem_slot_list.length; i += 1) { | | |
| 29772 | ira->exec_context.mem_slot_list.items[i] = &vals[i]; | | |
| 29773 | } | | |
| 29774 | | | |
| 29775 | IrBasicBlockSrc *old_entry_bb = ira->old_irb.exec->basic_block_list.at(0); | 29829 | IrBasicBlockSrc *old_entry_bb = ira->old_irb.exec->basic_block_list.at(0); |
| 29776 | IrBasicBlockGen *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr); | 29830 | IrBasicBlockGen *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr); |
| 29777 | ir_ref_bb_gen(new_entry_bb); | 29831 | ir_ref_bb_gen(new_entry_bb); |
| ... | @@ -29780,6 +29834,19 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen | ... | @@ -29780,6 +29834,19 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen |
| 29780 | | 29834 | |
| 29781 | ir_start_bb(ira, old_entry_bb, nullptr); | 29835 | ir_start_bb(ira, old_entry_bb, nullptr); |
| 29782 | | 29836 | |
| | 29837 | if (result_ptr != nullptr) { |
| | 29838 | assert(result_ptr->type->id == ZigTypeIdPointer); |
| | 29839 | IrInstGenConst *const_inst = ir_create_inst_noval<IrInstGenConst>( |
| | 29840 | &ira->new_irb, new_exec->begin_scope, new_exec->source_node); |
| | 29841 | const_inst->base.value = result_ptr; |
| | 29842 | ira->return_ptr = &const_inst->base; |
| | 29843 | } else { |
| | 29844 | assert(new_exec->begin_scope != nullptr); |
| | 29845 | assert(new_exec->source_node != nullptr); |
| | 29846 | ira->return_ptr = ir_build_return_ptr(ira, new_exec->begin_scope, new_exec->source_node, |
| | 29847 | get_pointer_to_type(codegen, expected_type, false)); |
| | 29848 | } |
| | 29849 | |
| 29783 | while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) { | 29850 | while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) { |
| 29784 | IrInstSrc *old_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index); | 29851 | IrInstSrc *old_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index); |
| 29785 | | 29852 | |
| ... | @@ -29922,7 +29989,6 @@ bool ir_inst_gen_has_side_effects(IrInstGen *instruction) { | ... | @@ -29922,7 +29989,6 @@ bool ir_inst_gen_has_side_effects(IrInstGen *instruction) { |
| 29922 | case IrInstGenIdReturnPtr: | 29989 | case IrInstGenIdReturnPtr: |
| 29923 | case IrInstGenIdStructFieldPtr: | 29990 | case IrInstGenIdStructFieldPtr: |
| 29924 | case IrInstGenIdTestNonNull: | 29991 | case IrInstGenIdTestNonNull: |
| 29925 | case IrInstGenIdOptionalUnwrapPtr: | | |
| 29926 | case IrInstGenIdClz: | 29992 | case IrInstGenIdClz: |
| 29927 | case IrInstGenIdCtz: | 29993 | case IrInstGenIdCtz: |
| 29928 | case IrInstGenIdPopCount: | 29994 | case IrInstGenIdPopCount: |
| ... | @@ -29979,6 +30045,8 @@ bool ir_inst_gen_has_side_effects(IrInstGen *instruction) { | ... | @@ -29979,6 +30045,8 @@ bool ir_inst_gen_has_side_effects(IrInstGen *instruction) { |
| 29979 | return reinterpret_cast<IrInstGenUnwrapErrCode *>(instruction)->initializing; | 30045 | return reinterpret_cast<IrInstGenUnwrapErrCode *>(instruction)->initializing; |
| 29980 | case IrInstGenIdUnionFieldPtr: | 30046 | case IrInstGenIdUnionFieldPtr: |
| 29981 | return reinterpret_cast<IrInstGenUnionFieldPtr *>(instruction)->initializing; | 30047 | return reinterpret_cast<IrInstGenUnionFieldPtr *>(instruction)->initializing; |
| | 30048 | case IrInstGenIdOptionalUnwrapPtr: |
| | 30049 | return reinterpret_cast<IrInstGenOptionalUnwrapPtr *>(instruction)->initializing; |
| 29982 | case IrInstGenIdErrWrapPayload: | 30050 | case IrInstGenIdErrWrapPayload: |
| 29983 | return reinterpret_cast<IrInstGenErrWrapPayload *>(instruction)->result_loc != nullptr; | 30051 | return reinterpret_cast<IrInstGenErrWrapPayload *>(instruction)->result_loc != nullptr; |
| 29984 | case IrInstGenIdErrWrapCode: | 30052 | case IrInstGenIdErrWrapCode: |