| ... | @@ -38,6 +38,7 @@ struct IrAnalyze { | ... | @@ -38,6 +38,7 @@ struct IrAnalyze { |
| 38 | ZigType *explicit_return_type; | 38 | ZigType *explicit_return_type; |
| 39 | AstNode *explicit_return_type_source_node; | 39 | AstNode *explicit_return_type_source_node; |
| 40 | ZigList<IrInstruction *> src_implicit_return_type_list; | 40 | ZigList<IrInstruction *> src_implicit_return_type_list; |
| | 41 | ZigList<IrSuspendPosition> resume_stack; |
| 41 | IrBasicBlock *const_predecessor_bb; | 42 | IrBasicBlock *const_predecessor_bb; |
| 42 | }; | 43 | }; |
| 43 | | 44 | |
| ... | @@ -159,7 +160,6 @@ enum UndefAllowed { | ... | @@ -159,7 +160,6 @@ enum UndefAllowed { |
| 159 | static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope); | 160 | static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope); |
| 160 | static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval, | 161 | static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval, |
| 161 | ResultLoc *result_loc); | 162 | ResultLoc *result_loc); |
| 162 | static IrInstruction *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction); | | |
| 163 | static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type); | 163 | static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type); |
| 164 | static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr); | 164 | static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr); |
| 165 | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg); | 165 | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg); |
| ... | @@ -167,7 +167,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ | ... | @@ -167,7 +167,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 167 | IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type); | 167 | IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type); |
| 168 | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var); | 168 | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var); |
| 169 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op); | 169 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op); |
| 170 | static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval); | 170 | static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval, ResultLoc *result_loc); |
| 171 | static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align); | 171 | static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align); |
| 172 | static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align); | 172 | static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align); |
| 173 | static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ConstExprValue *val); | 173 | static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ConstExprValue *val); |
| ... | @@ -184,6 +184,7 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc | ... | @@ -184,6 +184,7 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc |
| 184 | ZigType *ptr_type); | 184 | ZigType *ptr_type); |
| 185 | static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, | 185 | static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 186 | ZigType *dest_type); | 186 | ZigType *dest_type); |
| | 187 | static IrInstruction *ir_resolve_result_runtime(IrAnalyze *ira, ResultLoc *result_loc, ZigType *elem_type); |
| 187 | | 188 | |
| 188 | static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) { | 189 | static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) { |
| 189 | assert(get_src_ptr_type(const_val->type) != nullptr); | 190 | assert(get_src_ptr_type(const_val->type) != nullptr); |
| ... | @@ -387,6 +388,7 @@ static IrBasicBlock *ir_create_basic_block(IrBuilder *irb, Scope *scope, const c | ... | @@ -387,6 +388,7 @@ static IrBasicBlock *ir_create_basic_block(IrBuilder *irb, Scope *scope, const c |
| 387 | result->scope = scope; | 388 | result->scope = scope; |
| 388 | result->name_hint = name_hint; | 389 | result->name_hint = name_hint; |
| 389 | result->debug_id = exec_next_debug_id(irb->exec); | 390 | result->debug_id = exec_next_debug_id(irb->exec); |
| | 391 | result->index = SIZE_MAX; // set later |
| 390 | return result; | 392 | return result; |
| 391 | } | 393 | } |
| 392 | | 394 | |
| ... | @@ -1036,6 +1038,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAllocaGen *) { | ... | @@ -1036,6 +1038,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAllocaGen *) { |
| 1036 | return IrInstructionIdAllocaGen; | 1038 | return IrInstructionIdAllocaGen; |
| 1037 | } | 1039 | } |
| 1038 | | 1040 | |
| | 1041 | static constexpr IrInstructionId ir_instruction_id(IrInstructionEndExpr *) { |
| | 1042 | return IrInstructionIdEndExpr; |
| | 1043 | } |
| | 1044 | |
| 1039 | template<typename T> | 1045 | template<typename T> |
| 1040 | static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) { | 1046 | static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1041 | T *special_instruction = allocate<T>(1); | 1047 | T *special_instruction = allocate<T>(1); |
| ... | @@ -1373,10 +1379,11 @@ static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *s | ... | @@ -1373,10 +1379,11 @@ static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *s |
| 1373 | static IrInstruction *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_instruction, | 1379 | static IrInstruction *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_instruction, |
| 1374 | ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args, | 1380 | ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args, |
| 1375 | FnInline fn_inline, bool is_async, IrInstruction *async_allocator, IrInstruction *new_stack, | 1381 | FnInline fn_inline, bool is_async, IrInstruction *async_allocator, IrInstruction *new_stack, |
| 1376 | IrInstruction *result_loc) | 1382 | ResultLoc *result_loc, ZigType *return_type) |
| 1377 | { | 1383 | { |
| 1378 | IrInstructionCallGen *call_instruction = ir_build_instruction<IrInstructionCallGen>(&ira->new_irb, | 1384 | IrInstructionCallGen *call_instruction = ir_build_instruction<IrInstructionCallGen>(&ira->new_irb, |
| 1379 | source_instruction->scope, source_instruction->source_node); | 1385 | source_instruction->scope, source_instruction->source_node); |
| | 1386 | call_instruction->base.value.type = return_type; |
| 1380 | call_instruction->fn_entry = fn_entry; | 1387 | call_instruction->fn_entry = fn_entry; |
| 1381 | call_instruction->fn_ref = fn_ref; | 1388 | call_instruction->fn_ref = fn_ref; |
| 1382 | call_instruction->fn_inline = fn_inline; | 1389 | call_instruction->fn_inline = fn_inline; |
| ... | @@ -1385,14 +1392,14 @@ static IrInstruction *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_in | ... | @@ -1385,14 +1392,14 @@ static IrInstruction *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_in |
| 1385 | call_instruction->is_async = is_async; | 1392 | call_instruction->is_async = is_async; |
| 1386 | call_instruction->async_allocator = async_allocator; | 1393 | call_instruction->async_allocator = async_allocator; |
| 1387 | call_instruction->new_stack = new_stack; | 1394 | call_instruction->new_stack = new_stack; |
| 1388 | call_instruction->result_loc = result_loc; | 1395 | call_instruction->result_loc = ir_resolve_result_runtime(ira, result_loc, return_type); |
| 1389 | | 1396 | |
| 1390 | if (fn_ref != nullptr) ir_ref_instruction(fn_ref, ira->new_irb.current_basic_block); | 1397 | if (fn_ref != nullptr) ir_ref_instruction(fn_ref, ira->new_irb.current_basic_block); |
| 1391 | for (size_t i = 0; i < arg_count; i += 1) | 1398 | for (size_t i = 0; i < arg_count; i += 1) |
| 1392 | ir_ref_instruction(args[i], ira->new_irb.current_basic_block); | 1399 | ir_ref_instruction(args[i], ira->new_irb.current_basic_block); |
| 1393 | if (async_allocator != nullptr) ir_ref_instruction(async_allocator, ira->new_irb.current_basic_block); | 1400 | if (async_allocator != nullptr) ir_ref_instruction(async_allocator, ira->new_irb.current_basic_block); |
| 1394 | if (new_stack != nullptr) ir_ref_instruction(new_stack, ira->new_irb.current_basic_block); | 1401 | if (new_stack != nullptr) ir_ref_instruction(new_stack, ira->new_irb.current_basic_block); |
| 1395 | if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); | 1402 | if (call_instruction->result_loc != nullptr) ir_ref_instruction(call_instruction->result_loc, ira->new_irb.current_basic_block); |
| 1396 | | 1403 | |
| 1397 | return &call_instruction->base; | 1404 | return &call_instruction->base; |
| 1398 | } | 1405 | } |
| ... | @@ -3187,6 +3194,19 @@ static IrInstructionAllocaGen *ir_create_alloca_gen(IrAnalyze *ira, IrInstructio | ... | @@ -3187,6 +3194,19 @@ static IrInstructionAllocaGen *ir_create_alloca_gen(IrAnalyze *ira, IrInstructio |
| 3187 | return instruction; | 3194 | return instruction; |
| 3188 | } | 3195 | } |
| 3189 | | 3196 | |
| | 3197 | static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| | 3198 | IrInstruction *value, LVal lval, ResultLoc *result_loc) |
| | 3199 | { |
| | 3200 | IrInstructionEndExpr *instruction = ir_build_instruction<IrInstructionEndExpr>(irb, scope, source_node); |
| | 3201 | instruction->value = value; |
| | 3202 | instruction->lval = lval; |
| | 3203 | instruction->result_loc = result_loc; |
| | 3204 | |
| | 3205 | ir_ref_instruction(value, irb->current_basic_block); |
| | 3206 | |
| | 3207 | return &instruction->base; |
| | 3208 | } |
| | 3209 | |
| 3190 | static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) { | 3210 | static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) { |
| 3191 | results[ReturnKindUnconditional] = 0; | 3211 | results[ReturnKindUnconditional] = 0; |
| 3192 | results[ReturnKindError] = 0; | 3212 | results[ReturnKindError] = 0; |
| ... | @@ -3287,6 +3307,7 @@ static void ir_set_cursor_at_end(IrBuilder *irb, IrBasicBlock *basic_block) { | ... | @@ -3287,6 +3307,7 @@ static void ir_set_cursor_at_end(IrBuilder *irb, IrBasicBlock *basic_block) { |
| 3287 | } | 3307 | } |
| 3288 | | 3308 | |
| 3289 | static void ir_set_cursor_at_end_and_append_block(IrBuilder *irb, IrBasicBlock *basic_block) { | 3309 | static void ir_set_cursor_at_end_and_append_block(IrBuilder *irb, IrBasicBlock *basic_block) { |
| | 3310 | basic_block->index = irb->exec->basic_block_list.length; |
| 3290 | irb->exec->basic_block_list.append(basic_block); | 3311 | irb->exec->basic_block_list.append(basic_block); |
| 3291 | ir_set_cursor_at_end(irb, basic_block); | 3312 | ir_set_cursor_at_end(irb, basic_block); |
| 3292 | } | 3313 | } |
| ... | @@ -3623,6 +3644,8 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode | ... | @@ -3623,6 +3644,8 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 3623 | // keep the last noreturn statement value around in case we need to return it | 3644 | // keep the last noreturn statement value around in case we need to return it |
| 3624 | noreturn_return_value = statement_value; | 3645 | noreturn_return_value = statement_value; |
| 3625 | } | 3646 | } |
| | 3647 | // This logic must be kept in sync with |
| | 3648 | // [STMT_EXPR_TEST_THING] <--- (search this token) |
| 3626 | if (statement_node->type == NodeTypeDefer && statement_value != irb->codegen->invalid_instruction) { | 3649 | if (statement_node->type == NodeTypeDefer && statement_value != irb->codegen->invalid_instruction) { |
| 3627 | // defer starts a new scope | 3650 | // defer starts a new scope |
| 3628 | child_scope = statement_node->data.defer.child_scope; | 3651 | child_scope = statement_node->data.defer.child_scope; |
| ... | @@ -4164,7 +4187,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4164,7 +4187,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4164 | return arg; | 4187 | return arg; |
| 4165 | | 4188 | |
| 4166 | IrInstruction *type_of = ir_build_typeof(irb, scope, node, arg); | 4189 | IrInstruction *type_of = ir_build_typeof(irb, scope, node, arg); |
| 4167 | return ir_lval_wrap(irb, scope, type_of, lval); | 4190 | return ir_lval_wrap(irb, scope, type_of, lval, result_loc); |
| 4168 | } | 4191 | } |
| 4169 | case BuiltinFnIdSetCold: | 4192 | case BuiltinFnIdSetCold: |
| 4170 | { | 4193 | { |
| ... | @@ -4174,7 +4197,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4174,7 +4197,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4174 | return arg0_value; | 4197 | return arg0_value; |
| 4175 | | 4198 | |
| 4176 | IrInstruction *set_cold = ir_build_set_cold(irb, scope, node, arg0_value); | 4199 | IrInstruction *set_cold = ir_build_set_cold(irb, scope, node, arg0_value); |
| 4177 | return ir_lval_wrap(irb, scope, set_cold, lval); | 4200 | return ir_lval_wrap(irb, scope, set_cold, lval, result_loc); |
| 4178 | } | 4201 | } |
| 4179 | case BuiltinFnIdSetRuntimeSafety: | 4202 | case BuiltinFnIdSetRuntimeSafety: |
| 4180 | { | 4203 | { |
| ... | @@ -4184,7 +4207,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4184,7 +4207,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4184 | return arg0_value; | 4207 | return arg0_value; |
| 4185 | | 4208 | |
| 4186 | IrInstruction *set_safety = ir_build_set_runtime_safety(irb, scope, node, arg0_value); | 4209 | IrInstruction *set_safety = ir_build_set_runtime_safety(irb, scope, node, arg0_value); |
| 4187 | return ir_lval_wrap(irb, scope, set_safety, lval); | 4210 | return ir_lval_wrap(irb, scope, set_safety, lval, result_loc); |
| 4188 | } | 4211 | } |
| 4189 | case BuiltinFnIdSetFloatMode: | 4212 | case BuiltinFnIdSetFloatMode: |
| 4190 | { | 4213 | { |
| ... | @@ -4194,7 +4217,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4194,7 +4217,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4194 | return arg0_value; | 4217 | return arg0_value; |
| 4195 | | 4218 | |
| 4196 | IrInstruction *set_float_mode = ir_build_set_float_mode(irb, scope, node, arg0_value); | 4219 | IrInstruction *set_float_mode = ir_build_set_float_mode(irb, scope, node, arg0_value); |
| 4197 | return ir_lval_wrap(irb, scope, set_float_mode, lval); | 4220 | return ir_lval_wrap(irb, scope, set_float_mode, lval, result_loc); |
| 4198 | } | 4221 | } |
| 4199 | case BuiltinFnIdSizeof: | 4222 | case BuiltinFnIdSizeof: |
| 4200 | { | 4223 | { |
| ... | @@ -4204,7 +4227,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4204,7 +4227,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4204 | return arg0_value; | 4227 | return arg0_value; |
| 4205 | | 4228 | |
| 4206 | IrInstruction *size_of = ir_build_size_of(irb, scope, node, arg0_value); | 4229 | IrInstruction *size_of = ir_build_size_of(irb, scope, node, arg0_value); |
| 4207 | return ir_lval_wrap(irb, scope, size_of, lval); | 4230 | return ir_lval_wrap(irb, scope, size_of, lval, result_loc); |
| 4208 | } | 4231 | } |
| 4209 | case BuiltinFnIdImport: | 4232 | case BuiltinFnIdImport: |
| 4210 | { | 4233 | { |
| ... | @@ -4214,12 +4237,12 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4214,12 +4237,12 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4214 | return arg0_value; | 4237 | return arg0_value; |
| 4215 | | 4238 | |
| 4216 | IrInstruction *import = ir_build_import(irb, scope, node, arg0_value); | 4239 | IrInstruction *import = ir_build_import(irb, scope, node, arg0_value); |
| 4217 | return ir_lval_wrap(irb, scope, import, lval); | 4240 | return ir_lval_wrap(irb, scope, import, lval, result_loc); |
| 4218 | } | 4241 | } |
| 4219 | case BuiltinFnIdCImport: | 4242 | case BuiltinFnIdCImport: |
| 4220 | { | 4243 | { |
| 4221 | IrInstruction *c_import = ir_build_c_import(irb, scope, node); | 4244 | IrInstruction *c_import = ir_build_c_import(irb, scope, node); |
| 4222 | return ir_lval_wrap(irb, scope, c_import, lval); | 4245 | return ir_lval_wrap(irb, scope, c_import, lval, result_loc); |
| 4223 | } | 4246 | } |
| 4224 | case BuiltinFnIdCInclude: | 4247 | case BuiltinFnIdCInclude: |
| 4225 | { | 4248 | { |
| ... | @@ -4234,7 +4257,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4234,7 +4257,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4234 | } | 4257 | } |
| 4235 | | 4258 | |
| 4236 | IrInstruction *c_include = ir_build_c_include(irb, scope, node, arg0_value); | 4259 | IrInstruction *c_include = ir_build_c_include(irb, scope, node, arg0_value); |
| 4237 | return ir_lval_wrap(irb, scope, c_include, lval); | 4260 | return ir_lval_wrap(irb, scope, c_include, lval, result_loc); |
| 4238 | } | 4261 | } |
| 4239 | case BuiltinFnIdCDefine: | 4262 | case BuiltinFnIdCDefine: |
| 4240 | { | 4263 | { |
| ... | @@ -4254,7 +4277,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4254,7 +4277,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4254 | } | 4277 | } |
| 4255 | | 4278 | |
| 4256 | IrInstruction *c_define = ir_build_c_define(irb, scope, node, arg0_value, arg1_value); | 4279 | IrInstruction *c_define = ir_build_c_define(irb, scope, node, arg0_value, arg1_value); |
| 4257 | return ir_lval_wrap(irb, scope, c_define, lval); | 4280 | return ir_lval_wrap(irb, scope, c_define, lval, result_loc); |
| 4258 | } | 4281 | } |
| 4259 | case BuiltinFnIdCUndef: | 4282 | case BuiltinFnIdCUndef: |
| 4260 | { | 4283 | { |
| ... | @@ -4269,7 +4292,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4269,7 +4292,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4269 | } | 4292 | } |
| 4270 | | 4293 | |
| 4271 | IrInstruction *c_undef = ir_build_c_undef(irb, scope, node, arg0_value); | 4294 | IrInstruction *c_undef = ir_build_c_undef(irb, scope, node, arg0_value); |
| 4272 | return ir_lval_wrap(irb, scope, c_undef, lval); | 4295 | return ir_lval_wrap(irb, scope, c_undef, lval, result_loc); |
| 4273 | } | 4296 | } |
| 4274 | case BuiltinFnIdCompileErr: | 4297 | case BuiltinFnIdCompileErr: |
| 4275 | { | 4298 | { |
| ... | @@ -4279,7 +4302,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4279,7 +4302,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4279 | return arg0_value; | 4302 | return arg0_value; |
| 4280 | | 4303 | |
| 4281 | IrInstruction *compile_err = ir_build_compile_err(irb, scope, node, arg0_value); | 4304 | IrInstruction *compile_err = ir_build_compile_err(irb, scope, node, arg0_value); |
| 4282 | return ir_lval_wrap(irb, scope, compile_err, lval); | 4305 | return ir_lval_wrap(irb, scope, compile_err, lval, result_loc); |
| 4283 | } | 4306 | } |
| 4284 | case BuiltinFnIdCompileLog: | 4307 | case BuiltinFnIdCompileLog: |
| 4285 | { | 4308 | { |
| ... | @@ -4293,7 +4316,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4293,7 +4316,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4293 | } | 4316 | } |
| 4294 | | 4317 | |
| 4295 | IrInstruction *compile_log = ir_build_compile_log(irb, scope, node, actual_param_count, args); | 4318 | IrInstruction *compile_log = ir_build_compile_log(irb, scope, node, actual_param_count, args); |
| 4296 | return ir_lval_wrap(irb, scope, compile_log, lval); | 4319 | return ir_lval_wrap(irb, scope, compile_log, lval, result_loc); |
| 4297 | } | 4320 | } |
| 4298 | case BuiltinFnIdErrName: | 4321 | case BuiltinFnIdErrName: |
| 4299 | { | 4322 | { |
| ... | @@ -4303,7 +4326,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4303,7 +4326,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4303 | return arg0_value; | 4326 | return arg0_value; |
| 4304 | | 4327 | |
| 4305 | IrInstruction *err_name = ir_build_err_name(irb, scope, node, arg0_value); | 4328 | IrInstruction *err_name = ir_build_err_name(irb, scope, node, arg0_value); |
| 4306 | return ir_lval_wrap(irb, scope, err_name, lval); | 4329 | return ir_lval_wrap(irb, scope, err_name, lval, result_loc); |
| 4307 | } | 4330 | } |
| 4308 | case BuiltinFnIdEmbedFile: | 4331 | case BuiltinFnIdEmbedFile: |
| 4309 | { | 4332 | { |
| ... | @@ -4313,7 +4336,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4313,7 +4336,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4313 | return arg0_value; | 4336 | return arg0_value; |
| 4314 | | 4337 | |
| 4315 | IrInstruction *embed_file = ir_build_embed_file(irb, scope, node, arg0_value); | 4338 | IrInstruction *embed_file = ir_build_embed_file(irb, scope, node, arg0_value); |
| 4316 | return ir_lval_wrap(irb, scope, embed_file, lval); | 4339 | return ir_lval_wrap(irb, scope, embed_file, lval, result_loc); |
| 4317 | } | 4340 | } |
| 4318 | case BuiltinFnIdCmpxchgWeak: | 4341 | case BuiltinFnIdCmpxchgWeak: |
| 4319 | case BuiltinFnIdCmpxchgStrong: | 4342 | case BuiltinFnIdCmpxchgStrong: |
| ... | @@ -4350,7 +4373,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4350,7 +4373,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4350 | | 4373 | |
| 4351 | IrInstruction *cmpxchg = ir_build_cmpxchg_src(irb, scope, node, arg0_value, arg1_value, | 4374 | IrInstruction *cmpxchg = ir_build_cmpxchg_src(irb, scope, node, arg0_value, arg1_value, |
| 4352 | arg2_value, arg3_value, arg4_value, arg5_value, (builtin_fn->id == BuiltinFnIdCmpxchgWeak)); | 4375 | arg2_value, arg3_value, arg4_value, arg5_value, (builtin_fn->id == BuiltinFnIdCmpxchgWeak)); |
| 4353 | return ir_lval_wrap(irb, scope, cmpxchg, lval); | 4376 | return ir_lval_wrap(irb, scope, cmpxchg, lval, result_loc); |
| 4354 | } | 4377 | } |
| 4355 | case BuiltinFnIdFence: | 4378 | case BuiltinFnIdFence: |
| 4356 | { | 4379 | { |
| ... | @@ -4360,7 +4383,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4360,7 +4383,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4360 | return arg0_value; | 4383 | return arg0_value; |
| 4361 | | 4384 | |
| 4362 | IrInstruction *fence = ir_build_fence(irb, scope, node, arg0_value, AtomicOrderUnordered); | 4385 | IrInstruction *fence = ir_build_fence(irb, scope, node, arg0_value, AtomicOrderUnordered); |
| 4363 | return ir_lval_wrap(irb, scope, fence, lval); | 4386 | return ir_lval_wrap(irb, scope, fence, lval, result_loc); |
| 4364 | } | 4387 | } |
| 4365 | case BuiltinFnIdDivExact: | 4388 | case BuiltinFnIdDivExact: |
| 4366 | { | 4389 | { |
| ... | @@ -4375,7 +4398,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4375,7 +4398,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4375 | return arg1_value; | 4398 | return arg1_value; |
| 4376 | | 4399 | |
| 4377 | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivExact, arg0_value, arg1_value, true); | 4400 | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivExact, arg0_value, arg1_value, true); |
| 4378 | return ir_lval_wrap(irb, scope, bin_op, lval); | 4401 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 4379 | } | 4402 | } |
| 4380 | case BuiltinFnIdDivTrunc: | 4403 | case BuiltinFnIdDivTrunc: |
| 4381 | { | 4404 | { |
| ... | @@ -4390,7 +4413,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4390,7 +4413,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4390 | return arg1_value; | 4413 | return arg1_value; |
| 4391 | | 4414 | |
| 4392 | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivTrunc, arg0_value, arg1_value, true); | 4415 | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivTrunc, arg0_value, arg1_value, true); |
| 4393 | return ir_lval_wrap(irb, scope, bin_op, lval); | 4416 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 4394 | } | 4417 | } |
| 4395 | case BuiltinFnIdDivFloor: | 4418 | case BuiltinFnIdDivFloor: |
| 4396 | { | 4419 | { |
| ... | @@ -4405,7 +4428,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4405,7 +4428,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4405 | return arg1_value; | 4428 | return arg1_value; |
| 4406 | | 4429 | |
| 4407 | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivFloor, arg0_value, arg1_value, true); | 4430 | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivFloor, arg0_value, arg1_value, true); |
| 4408 | return ir_lval_wrap(irb, scope, bin_op, lval); | 4431 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 4409 | } | 4432 | } |
| 4410 | case BuiltinFnIdRem: | 4433 | case BuiltinFnIdRem: |
| 4411 | { | 4434 | { |
| ... | @@ -4420,7 +4443,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4420,7 +4443,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4420 | return arg1_value; | 4443 | return arg1_value; |
| 4421 | | 4444 | |
| 4422 | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemRem, arg0_value, arg1_value, true); | 4445 | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemRem, arg0_value, arg1_value, true); |
| 4423 | return ir_lval_wrap(irb, scope, bin_op, lval); | 4446 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 4424 | } | 4447 | } |
| 4425 | case BuiltinFnIdMod: | 4448 | case BuiltinFnIdMod: |
| 4426 | { | 4449 | { |
| ... | @@ -4435,7 +4458,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4435,7 +4458,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4435 | return arg1_value; | 4458 | return arg1_value; |
| 4436 | | 4459 | |
| 4437 | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemMod, arg0_value, arg1_value, true); | 4460 | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemMod, arg0_value, arg1_value, true); |
| 4438 | return ir_lval_wrap(irb, scope, bin_op, lval); | 4461 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 4439 | } | 4462 | } |
| 4440 | case BuiltinFnIdSqrt: | 4463 | case BuiltinFnIdSqrt: |
| 4441 | { | 4464 | { |
| ... | @@ -4450,7 +4473,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4450,7 +4473,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4450 | return arg1_value; | 4473 | return arg1_value; |
| 4451 | | 4474 | |
| 4452 | IrInstruction *ir_sqrt = ir_build_sqrt(irb, scope, node, arg0_value, arg1_value); | 4475 | IrInstruction *ir_sqrt = ir_build_sqrt(irb, scope, node, arg0_value, arg1_value); |
| 4453 | return ir_lval_wrap(irb, scope, ir_sqrt, lval); | 4476 | return ir_lval_wrap(irb, scope, ir_sqrt, lval, result_loc); |
| 4454 | } | 4477 | } |
| 4455 | case BuiltinFnIdTruncate: | 4478 | case BuiltinFnIdTruncate: |
| 4456 | { | 4479 | { |
| ... | @@ -4465,7 +4488,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4465,7 +4488,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4465 | return arg1_value; | 4488 | return arg1_value; |
| 4466 | | 4489 | |
| 4467 | IrInstruction *truncate = ir_build_truncate(irb, scope, node, arg0_value, arg1_value); | 4490 | IrInstruction *truncate = ir_build_truncate(irb, scope, node, arg0_value, arg1_value); |
| 4468 | return ir_lval_wrap(irb, scope, truncate, lval); | 4491 | return ir_lval_wrap(irb, scope, truncate, lval, result_loc); |
| 4469 | } | 4492 | } |
| 4470 | case BuiltinFnIdIntCast: | 4493 | case BuiltinFnIdIntCast: |
| 4471 | { | 4494 | { |
| ... | @@ -4480,7 +4503,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4480,7 +4503,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4480 | return arg1_value; | 4503 | return arg1_value; |
| 4481 | | 4504 | |
| 4482 | IrInstruction *result = ir_build_int_cast(irb, scope, node, arg0_value, arg1_value); | 4505 | IrInstruction *result = ir_build_int_cast(irb, scope, node, arg0_value, arg1_value); |
| 4483 | return ir_lval_wrap(irb, scope, result, lval); | 4506 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 4484 | } | 4507 | } |
| 4485 | case BuiltinFnIdFloatCast: | 4508 | case BuiltinFnIdFloatCast: |
| 4486 | { | 4509 | { |
| ... | @@ -4495,7 +4518,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4495,7 +4518,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4495 | return arg1_value; | 4518 | return arg1_value; |
| 4496 | | 4519 | |
| 4497 | IrInstruction *result = ir_build_float_cast(irb, scope, node, arg0_value, arg1_value); | 4520 | IrInstruction *result = ir_build_float_cast(irb, scope, node, arg0_value, arg1_value); |
| 4498 | return ir_lval_wrap(irb, scope, result, lval); | 4521 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 4499 | } | 4522 | } |
| 4500 | case BuiltinFnIdErrSetCast: | 4523 | case BuiltinFnIdErrSetCast: |
| 4501 | { | 4524 | { |
| ... | @@ -4510,7 +4533,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4510,7 +4533,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4510 | return arg1_value; | 4533 | return arg1_value; |
| 4511 | | 4534 | |
| 4512 | IrInstruction *result = ir_build_err_set_cast(irb, scope, node, arg0_value, arg1_value); | 4535 | IrInstruction *result = ir_build_err_set_cast(irb, scope, node, arg0_value, arg1_value); |
| 4513 | return ir_lval_wrap(irb, scope, result, lval); | 4536 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 4514 | } | 4537 | } |
| 4515 | case BuiltinFnIdFromBytes: | 4538 | case BuiltinFnIdFromBytes: |
| 4516 | { | 4539 | { |
| ... | @@ -4525,7 +4548,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4525,7 +4548,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4525 | return arg1_value; | 4548 | return arg1_value; |
| 4526 | | 4549 | |
| 4527 | IrInstruction *result = ir_build_from_bytes(irb, scope, node, arg0_value, arg1_value); | 4550 | IrInstruction *result = ir_build_from_bytes(irb, scope, node, arg0_value, arg1_value); |
| 4528 | return ir_lval_wrap(irb, scope, result, lval); | 4551 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 4529 | } | 4552 | } |
| 4530 | case BuiltinFnIdToBytes: | 4553 | case BuiltinFnIdToBytes: |
| 4531 | { | 4554 | { |
| ... | @@ -4535,7 +4558,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4535,7 +4558,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4535 | return arg0_value; | 4558 | return arg0_value; |
| 4536 | | 4559 | |
| 4537 | IrInstruction *result = ir_build_to_bytes(irb, scope, node, arg0_value); | 4560 | IrInstruction *result = ir_build_to_bytes(irb, scope, node, arg0_value); |
| 4538 | return ir_lval_wrap(irb, scope, result, lval); | 4561 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 4539 | } | 4562 | } |
| 4540 | case BuiltinFnIdIntToFloat: | 4563 | case BuiltinFnIdIntToFloat: |
| 4541 | { | 4564 | { |
| ... | @@ -4550,7 +4573,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4550,7 +4573,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4550 | return arg1_value; | 4573 | return arg1_value; |
| 4551 | | 4574 | |
| 4552 | IrInstruction *result = ir_build_int_to_float(irb, scope, node, arg0_value, arg1_value); | 4575 | IrInstruction *result = ir_build_int_to_float(irb, scope, node, arg0_value, arg1_value); |
| 4553 | return ir_lval_wrap(irb, scope, result, lval); | 4576 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 4554 | } | 4577 | } |
| 4555 | case BuiltinFnIdFloatToInt: | 4578 | case BuiltinFnIdFloatToInt: |
| 4556 | { | 4579 | { |
| ... | @@ -4565,7 +4588,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4565,7 +4588,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4565 | return arg1_value; | 4588 | return arg1_value; |
| 4566 | | 4589 | |
| 4567 | IrInstruction *result = ir_build_float_to_int(irb, scope, node, arg0_value, arg1_value); | 4590 | IrInstruction *result = ir_build_float_to_int(irb, scope, node, arg0_value, arg1_value); |
| 4568 | return ir_lval_wrap(irb, scope, result, lval); | 4591 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 4569 | } | 4592 | } |
| 4570 | case BuiltinFnIdErrToInt: | 4593 | case BuiltinFnIdErrToInt: |
| 4571 | { | 4594 | { |
| ... | @@ -4575,7 +4598,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4575,7 +4598,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4575 | return arg0_value; | 4598 | return arg0_value; |
| 4576 | | 4599 | |
| 4577 | IrInstruction *result = ir_build_err_to_int(irb, scope, node, arg0_value); | 4600 | IrInstruction *result = ir_build_err_to_int(irb, scope, node, arg0_value); |
| 4578 | return ir_lval_wrap(irb, scope, result, lval); | 4601 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 4579 | } | 4602 | } |
| 4580 | case BuiltinFnIdIntToErr: | 4603 | case BuiltinFnIdIntToErr: |
| 4581 | { | 4604 | { |
| ... | @@ -4585,7 +4608,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4585,7 +4608,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4585 | return arg0_value; | 4608 | return arg0_value; |
| 4586 | | 4609 | |
| 4587 | IrInstruction *result = ir_build_int_to_err(irb, scope, node, arg0_value); | 4610 | IrInstruction *result = ir_build_int_to_err(irb, scope, node, arg0_value); |
| 4588 | return ir_lval_wrap(irb, scope, result, lval); | 4611 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 4589 | } | 4612 | } |
| 4590 | case BuiltinFnIdBoolToInt: | 4613 | case BuiltinFnIdBoolToInt: |
| 4591 | { | 4614 | { |
| ... | @@ -4595,7 +4618,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4595,7 +4618,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4595 | return arg0_value; | 4618 | return arg0_value; |
| 4596 | | 4619 | |
| 4597 | IrInstruction *result = ir_build_bool_to_int(irb, scope, node, arg0_value); | 4620 | IrInstruction *result = ir_build_bool_to_int(irb, scope, node, arg0_value); |
| 4598 | return ir_lval_wrap(irb, scope, result, lval); | 4621 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 4599 | } | 4622 | } |
| 4600 | case BuiltinFnIdIntType: | 4623 | case BuiltinFnIdIntType: |
| 4601 | { | 4624 | { |
| ... | @@ -4610,7 +4633,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4610,7 +4633,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4610 | return arg1_value; | 4633 | return arg1_value; |
| 4611 | | 4634 | |
| 4612 | IrInstruction *int_type = ir_build_int_type(irb, scope, node, arg0_value, arg1_value); | 4635 | IrInstruction *int_type = ir_build_int_type(irb, scope, node, arg0_value, arg1_value); |
| 4613 | return ir_lval_wrap(irb, scope, int_type, lval); | 4636 | return ir_lval_wrap(irb, scope, int_type, lval, result_loc); |
| 4614 | } | 4637 | } |
| 4615 | case BuiltinFnIdVectorType: | 4638 | case BuiltinFnIdVectorType: |
| 4616 | { | 4639 | { |
| ... | @@ -4625,7 +4648,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4625,7 +4648,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4625 | return arg1_value; | 4648 | return arg1_value; |
| 4626 | | 4649 | |
| 4627 | IrInstruction *vector_type = ir_build_vector_type(irb, scope, node, arg0_value, arg1_value); | 4650 | IrInstruction *vector_type = ir_build_vector_type(irb, scope, node, arg0_value, arg1_value); |
| 4628 | return ir_lval_wrap(irb, scope, vector_type, lval); | 4651 | return ir_lval_wrap(irb, scope, vector_type, lval, result_loc); |
| 4629 | } | 4652 | } |
| 4630 | case BuiltinFnIdMemcpy: | 4653 | case BuiltinFnIdMemcpy: |
| 4631 | { | 4654 | { |
| ... | @@ -4645,7 +4668,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4645,7 +4668,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4645 | return arg2_value; | 4668 | return arg2_value; |
| 4646 | | 4669 | |
| 4647 | IrInstruction *ir_memcpy = ir_build_memcpy(irb, scope, node, arg0_value, arg1_value, arg2_value); | 4670 | IrInstruction *ir_memcpy = ir_build_memcpy(irb, scope, node, arg0_value, arg1_value, arg2_value); |
| 4648 | return ir_lval_wrap(irb, scope, ir_memcpy, lval); | 4671 | return ir_lval_wrap(irb, scope, ir_memcpy, lval, result_loc); |
| 4649 | } | 4672 | } |
| 4650 | case BuiltinFnIdMemset: | 4673 | case BuiltinFnIdMemset: |
| 4651 | { | 4674 | { |
| ... | @@ -4665,7 +4688,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4665,7 +4688,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4665 | return arg2_value; | 4688 | return arg2_value; |
| 4666 | | 4689 | |
| 4667 | IrInstruction *ir_memset = ir_build_memset(irb, scope, node, arg0_value, arg1_value, arg2_value); | 4690 | IrInstruction *ir_memset = ir_build_memset(irb, scope, node, arg0_value, arg1_value, arg2_value); |
| 4668 | return ir_lval_wrap(irb, scope, ir_memset, lval); | 4691 | return ir_lval_wrap(irb, scope, ir_memset, lval, result_loc); |
| 4669 | } | 4692 | } |
| 4670 | case BuiltinFnIdMemberCount: | 4693 | case BuiltinFnIdMemberCount: |
| 4671 | { | 4694 | { |
| ... | @@ -4675,7 +4698,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4675,7 +4698,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4675 | return arg0_value; | 4698 | return arg0_value; |
| 4676 | | 4699 | |
| 4677 | IrInstruction *member_count = ir_build_member_count(irb, scope, node, arg0_value); | 4700 | IrInstruction *member_count = ir_build_member_count(irb, scope, node, arg0_value); |
| 4678 | return ir_lval_wrap(irb, scope, member_count, lval); | 4701 | return ir_lval_wrap(irb, scope, member_count, lval, result_loc); |
| 4679 | } | 4702 | } |
| 4680 | case BuiltinFnIdMemberType: | 4703 | case BuiltinFnIdMemberType: |
| 4681 | { | 4704 | { |
| ... | @@ -4691,7 +4714,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4691,7 +4714,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4691 | | 4714 | |
| 4692 | | 4715 | |
| 4693 | IrInstruction *member_type = ir_build_member_type(irb, scope, node, arg0_value, arg1_value); | 4716 | IrInstruction *member_type = ir_build_member_type(irb, scope, node, arg0_value, arg1_value); |
| 4694 | return ir_lval_wrap(irb, scope, member_type, lval); | 4717 | return ir_lval_wrap(irb, scope, member_type, lval, result_loc); |
| 4695 | } | 4718 | } |
| 4696 | case BuiltinFnIdMemberName: | 4719 | case BuiltinFnIdMemberName: |
| 4697 | { | 4720 | { |
| ... | @@ -4707,7 +4730,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4707,7 +4730,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4707 | | 4730 | |
| 4708 | | 4731 | |
| 4709 | IrInstruction *member_name = ir_build_member_name(irb, scope, node, arg0_value, arg1_value); | 4732 | IrInstruction *member_name = ir_build_member_name(irb, scope, node, arg0_value, arg1_value); |
| 4710 | return ir_lval_wrap(irb, scope, member_name, lval); | 4733 | return ir_lval_wrap(irb, scope, member_name, lval, result_loc); |
| 4711 | } | 4734 | } |
| 4712 | case BuiltinFnIdField: | 4735 | case BuiltinFnIdField: |
| 4713 | { | 4736 | { |
| ... | @@ -4736,14 +4759,14 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4736,14 +4759,14 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4736 | return arg0_value; | 4759 | return arg0_value; |
| 4737 | | 4760 | |
| 4738 | IrInstruction *type_info = ir_build_type_info(irb, scope, node, arg0_value); | 4761 | IrInstruction *type_info = ir_build_type_info(irb, scope, node, arg0_value); |
| 4739 | return ir_lval_wrap(irb, scope, type_info, lval); | 4762 | return ir_lval_wrap(irb, scope, type_info, lval, result_loc); |
| 4740 | } | 4763 | } |
| 4741 | case BuiltinFnIdBreakpoint: | 4764 | case BuiltinFnIdBreakpoint: |
| 4742 | return ir_lval_wrap(irb, scope, ir_build_breakpoint(irb, scope, node), lval); | 4765 | return ir_lval_wrap(irb, scope, ir_build_breakpoint(irb, scope, node), lval, result_loc); |
| 4743 | case BuiltinFnIdReturnAddress: | 4766 | case BuiltinFnIdReturnAddress: |
| 4744 | return ir_lval_wrap(irb, scope, ir_build_return_address(irb, scope, node), lval); | 4767 | return ir_lval_wrap(irb, scope, ir_build_return_address(irb, scope, node), lval, result_loc); |
| 4745 | case BuiltinFnIdFrameAddress: | 4768 | case BuiltinFnIdFrameAddress: |
| 4746 | return ir_lval_wrap(irb, scope, ir_build_frame_address(irb, scope, node), lval); | 4769 | return ir_lval_wrap(irb, scope, ir_build_frame_address(irb, scope, node), lval, result_loc); |
| 4747 | case BuiltinFnIdHandle: | 4770 | case BuiltinFnIdHandle: |
| 4748 | if (!irb->exec->fn_entry) { | 4771 | if (!irb->exec->fn_entry) { |
| 4749 | add_node_error(irb->codegen, node, buf_sprintf("@handle() called outside of function definition")); | 4772 | add_node_error(irb->codegen, node, buf_sprintf("@handle() called outside of function definition")); |
| ... | @@ -4753,7 +4776,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4753,7 +4776,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4753 | add_node_error(irb->codegen, node, buf_sprintf("@handle() in non-async function")); | 4776 | add_node_error(irb->codegen, node, buf_sprintf("@handle() in non-async function")); |
| 4754 | return irb->codegen->invalid_instruction; | 4777 | return irb->codegen->invalid_instruction; |
| 4755 | } | 4778 | } |
| 4756 | return ir_lval_wrap(irb, scope, ir_build_handle(irb, scope, node), lval); | 4779 | return ir_lval_wrap(irb, scope, ir_build_handle(irb, scope, node), lval, result_loc); |
| 4757 | case BuiltinFnIdAlignOf: | 4780 | case BuiltinFnIdAlignOf: |
| 4758 | { | 4781 | { |
| 4759 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4782 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| ... | @@ -4762,16 +4785,16 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4762,16 +4785,16 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4762 | return arg0_value; | 4785 | return arg0_value; |
| 4763 | | 4786 | |
| 4764 | IrInstruction *align_of = ir_build_align_of(irb, scope, node, arg0_value); | 4787 | IrInstruction *align_of = ir_build_align_of(irb, scope, node, arg0_value); |
| 4765 | return ir_lval_wrap(irb, scope, align_of, lval); | 4788 | return ir_lval_wrap(irb, scope, align_of, lval, result_loc); |
| 4766 | } | 4789 | } |
| 4767 | case BuiltinFnIdAddWithOverflow: | 4790 | case BuiltinFnIdAddWithOverflow: |
| 4768 | return ir_lval_wrap(irb, scope, ir_gen_overflow_op(irb, scope, node, IrOverflowOpAdd), lval); | 4791 | return ir_lval_wrap(irb, scope, ir_gen_overflow_op(irb, scope, node, IrOverflowOpAdd), lval, result_loc); |
| 4769 | case BuiltinFnIdSubWithOverflow: | 4792 | case BuiltinFnIdSubWithOverflow: |
| 4770 | return ir_lval_wrap(irb, scope, ir_gen_overflow_op(irb, scope, node, IrOverflowOpSub), lval); | 4793 | return ir_lval_wrap(irb, scope, ir_gen_overflow_op(irb, scope, node, IrOverflowOpSub), lval, result_loc); |
| 4771 | case BuiltinFnIdMulWithOverflow: | 4794 | case BuiltinFnIdMulWithOverflow: |
| 4772 | return ir_lval_wrap(irb, scope, ir_gen_overflow_op(irb, scope, node, IrOverflowOpMul), lval); | 4795 | return ir_lval_wrap(irb, scope, ir_gen_overflow_op(irb, scope, node, IrOverflowOpMul), lval, result_loc); |
| 4773 | case BuiltinFnIdShlWithOverflow: | 4796 | case BuiltinFnIdShlWithOverflow: |
| 4774 | return ir_lval_wrap(irb, scope, ir_gen_overflow_op(irb, scope, node, IrOverflowOpShl), lval); | 4797 | return ir_lval_wrap(irb, scope, ir_gen_overflow_op(irb, scope, node, IrOverflowOpShl), lval, result_loc); |
| 4775 | case BuiltinFnIdTypeName: | 4798 | case BuiltinFnIdTypeName: |
| 4776 | { | 4799 | { |
| 4777 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 4800 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| ... | @@ -4780,7 +4803,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4780,7 +4803,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4780 | return arg0_value; | 4803 | return arg0_value; |
| 4781 | | 4804 | |
| 4782 | IrInstruction *type_name = ir_build_type_name(irb, scope, node, arg0_value); | 4805 | IrInstruction *type_name = ir_build_type_name(irb, scope, node, arg0_value); |
| 4783 | return ir_lval_wrap(irb, scope, type_name, lval); | 4806 | return ir_lval_wrap(irb, scope, type_name, lval, result_loc); |
| 4784 | } | 4807 | } |
| 4785 | case BuiltinFnIdPanic: | 4808 | case BuiltinFnIdPanic: |
| 4786 | { | 4809 | { |
| ... | @@ -4790,7 +4813,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4790,7 +4813,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4790 | return arg0_value; | 4813 | return arg0_value; |
| 4791 | | 4814 | |
| 4792 | IrInstruction *panic = ir_build_panic(irb, scope, node, arg0_value); | 4815 | IrInstruction *panic = ir_build_panic(irb, scope, node, arg0_value); |
| 4793 | return ir_lval_wrap(irb, scope, panic, lval); | 4816 | return ir_lval_wrap(irb, scope, panic, lval, result_loc); |
| 4794 | } | 4817 | } |
| 4795 | case BuiltinFnIdPtrCast: | 4818 | case BuiltinFnIdPtrCast: |
| 4796 | { | 4819 | { |
| ... | @@ -4805,7 +4828,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4805,7 +4828,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4805 | return arg1_value; | 4828 | return arg1_value; |
| 4806 | | 4829 | |
| 4807 | IrInstruction *ptr_cast = ir_build_ptr_cast_src(irb, scope, node, arg0_value, arg1_value, true); | 4830 | IrInstruction *ptr_cast = ir_build_ptr_cast_src(irb, scope, node, arg0_value, arg1_value, true); |
| 4808 | return ir_lval_wrap(irb, scope, ptr_cast, lval); | 4831 | return ir_lval_wrap(irb, scope, ptr_cast, lval, result_loc); |
| 4809 | } | 4832 | } |
| 4810 | case BuiltinFnIdBitCast: | 4833 | case BuiltinFnIdBitCast: |
| 4811 | { | 4834 | { |
| ... | @@ -4820,7 +4843,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4820,7 +4843,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4820 | return arg1_value; | 4843 | return arg1_value; |
| 4821 | | 4844 | |
| 4822 | IrInstruction *bit_cast = ir_build_bit_cast(irb, scope, node, arg0_value, arg1_value); | 4845 | IrInstruction *bit_cast = ir_build_bit_cast(irb, scope, node, arg0_value, arg1_value); |
| 4823 | return ir_lval_wrap(irb, scope, bit_cast, lval); | 4846 | return ir_lval_wrap(irb, scope, bit_cast, lval, result_loc); |
| 4824 | } | 4847 | } |
| 4825 | case BuiltinFnIdIntToPtr: | 4848 | case BuiltinFnIdIntToPtr: |
| 4826 | { | 4849 | { |
| ... | @@ -4835,7 +4858,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4835,7 +4858,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4835 | return arg1_value; | 4858 | return arg1_value; |
| 4836 | | 4859 | |
| 4837 | IrInstruction *int_to_ptr = ir_build_int_to_ptr(irb, scope, node, arg0_value, arg1_value); | 4860 | IrInstruction *int_to_ptr = ir_build_int_to_ptr(irb, scope, node, arg0_value, arg1_value); |
| 4838 | return ir_lval_wrap(irb, scope, int_to_ptr, lval); | 4861 | return ir_lval_wrap(irb, scope, int_to_ptr, lval, result_loc); |
| 4839 | } | 4862 | } |
| 4840 | case BuiltinFnIdPtrToInt: | 4863 | case BuiltinFnIdPtrToInt: |
| 4841 | { | 4864 | { |
| ... | @@ -4845,7 +4868,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4845,7 +4868,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4845 | return arg0_value; | 4868 | return arg0_value; |
| 4846 | | 4869 | |
| 4847 | IrInstruction *ptr_to_int = ir_build_ptr_to_int(irb, scope, node, arg0_value); | 4870 | IrInstruction *ptr_to_int = ir_build_ptr_to_int(irb, scope, node, arg0_value); |
| 4848 | return ir_lval_wrap(irb, scope, ptr_to_int, lval); | 4871 | return ir_lval_wrap(irb, scope, ptr_to_int, lval, result_loc); |
| 4849 | } | 4872 | } |
| 4850 | case BuiltinFnIdTagName: | 4873 | case BuiltinFnIdTagName: |
| 4851 | { | 4874 | { |
| ... | @@ -4856,7 +4879,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4856,7 +4879,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4856 | | 4879 | |
| 4857 | IrInstruction *actual_tag = ir_build_union_tag(irb, scope, node, arg0_value); | 4880 | IrInstruction *actual_tag = ir_build_union_tag(irb, scope, node, arg0_value); |
| 4858 | IrInstruction *tag_name = ir_build_tag_name(irb, scope, node, actual_tag); | 4881 | IrInstruction *tag_name = ir_build_tag_name(irb, scope, node, actual_tag); |
| 4859 | return ir_lval_wrap(irb, scope, tag_name, lval); | 4882 | return ir_lval_wrap(irb, scope, tag_name, lval, result_loc); |
| 4860 | } | 4883 | } |
| 4861 | case BuiltinFnIdTagType: | 4884 | case BuiltinFnIdTagType: |
| 4862 | { | 4885 | { |
| ... | @@ -4866,7 +4889,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4866,7 +4889,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4866 | return arg0_value; | 4889 | return arg0_value; |
| 4867 | | 4890 | |
| 4868 | IrInstruction *tag_type = ir_build_tag_type(irb, scope, node, arg0_value); | 4891 | IrInstruction *tag_type = ir_build_tag_type(irb, scope, node, arg0_value); |
| 4869 | return ir_lval_wrap(irb, scope, tag_type, lval); | 4892 | return ir_lval_wrap(irb, scope, tag_type, lval, result_loc); |
| 4870 | } | 4893 | } |
| 4871 | case BuiltinFnIdFieldParentPtr: | 4894 | case BuiltinFnIdFieldParentPtr: |
| 4872 | { | 4895 | { |
| ... | @@ -4886,7 +4909,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4886,7 +4909,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4886 | return arg2_value; | 4909 | return arg2_value; |
| 4887 | | 4910 | |
| 4888 | IrInstruction *field_parent_ptr = ir_build_field_parent_ptr(irb, scope, node, arg0_value, arg1_value, arg2_value, nullptr); | 4911 | IrInstruction *field_parent_ptr = ir_build_field_parent_ptr(irb, scope, node, arg0_value, arg1_value, arg2_value, nullptr); |
| 4889 | return ir_lval_wrap(irb, scope, field_parent_ptr, lval); | 4912 | return ir_lval_wrap(irb, scope, field_parent_ptr, lval, result_loc); |
| 4890 | } | 4913 | } |
| 4891 | case BuiltinFnIdByteOffsetOf: | 4914 | case BuiltinFnIdByteOffsetOf: |
| 4892 | { | 4915 | { |
| ... | @@ -4901,7 +4924,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4901,7 +4924,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4901 | return arg1_value; | 4924 | return arg1_value; |
| 4902 | | 4925 | |
| 4903 | IrInstruction *offset_of = ir_build_byte_offset_of(irb, scope, node, arg0_value, arg1_value); | 4926 | IrInstruction *offset_of = ir_build_byte_offset_of(irb, scope, node, arg0_value, arg1_value); |
| 4904 | return ir_lval_wrap(irb, scope, offset_of, lval); | 4927 | return ir_lval_wrap(irb, scope, offset_of, lval, result_loc); |
| 4905 | } | 4928 | } |
| 4906 | case BuiltinFnIdBitOffsetOf: | 4929 | case BuiltinFnIdBitOffsetOf: |
| 4907 | { | 4930 | { |
| ... | @@ -4916,7 +4939,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4916,7 +4939,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4916 | return arg1_value; | 4939 | return arg1_value; |
| 4917 | | 4940 | |
| 4918 | IrInstruction *offset_of = ir_build_bit_offset_of(irb, scope, node, arg0_value, arg1_value); | 4941 | IrInstruction *offset_of = ir_build_bit_offset_of(irb, scope, node, arg0_value, arg1_value); |
| 4919 | return ir_lval_wrap(irb, scope, offset_of, lval); | 4942 | return ir_lval_wrap(irb, scope, offset_of, lval, result_loc); |
| 4920 | } | 4943 | } |
| 4921 | case BuiltinFnIdInlineCall: | 4944 | case BuiltinFnIdInlineCall: |
| 4922 | case BuiltinFnIdNoInlineCall: | 4945 | case BuiltinFnIdNoInlineCall: |
| ... | @@ -4944,7 +4967,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4944,7 +4967,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4944 | | 4967 | |
| 4945 | IrInstruction *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, false, | 4968 | IrInstruction *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, false, |
| 4946 | fn_inline, false, nullptr, nullptr, result_loc); | 4969 | fn_inline, false, nullptr, nullptr, result_loc); |
| 4947 | return ir_lval_wrap(irb, scope, call, lval); | 4970 | return ir_lval_wrap(irb, scope, call, lval, result_loc); |
| 4948 | } | 4971 | } |
| 4949 | case BuiltinFnIdNewStackCall: | 4972 | case BuiltinFnIdNewStackCall: |
| 4950 | { | 4973 | { |
| ... | @@ -4975,7 +4998,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4975,7 +4998,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4975 | | 4998 | |
| 4976 | IrInstruction *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, false, | 4999 | IrInstruction *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, false, |
| 4977 | FnInlineAuto, false, nullptr, new_stack, result_loc); | 5000 | FnInlineAuto, false, nullptr, new_stack, result_loc); |
| 4978 | return ir_lval_wrap(irb, scope, call, lval); | 5001 | return ir_lval_wrap(irb, scope, call, lval, result_loc); |
| 4979 | } | 5002 | } |
| 4980 | case BuiltinFnIdTypeId: | 5003 | case BuiltinFnIdTypeId: |
| 4981 | { | 5004 | { |
| ... | @@ -4985,7 +5008,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4985,7 +5008,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4985 | return arg0_value; | 5008 | return arg0_value; |
| 4986 | | 5009 | |
| 4987 | IrInstruction *type_id = ir_build_type_id(irb, scope, node, arg0_value); | 5010 | IrInstruction *type_id = ir_build_type_id(irb, scope, node, arg0_value); |
| 4988 | return ir_lval_wrap(irb, scope, type_id, lval); | 5011 | return ir_lval_wrap(irb, scope, type_id, lval, result_loc); |
| 4989 | } | 5012 | } |
| 4990 | case BuiltinFnIdShlExact: | 5013 | case BuiltinFnIdShlExact: |
| 4991 | { | 5014 | { |
| ... | @@ -5000,7 +5023,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -5000,7 +5023,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5000 | return arg1_value; | 5023 | return arg1_value; |
| 5001 | | 5024 | |
| 5002 | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftLeftExact, arg0_value, arg1_value, true); | 5025 | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftLeftExact, arg0_value, arg1_value, true); |
| 5003 | return ir_lval_wrap(irb, scope, bin_op, lval); | 5026 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 5004 | } | 5027 | } |
| 5005 | case BuiltinFnIdShrExact: | 5028 | case BuiltinFnIdShrExact: |
| 5006 | { | 5029 | { |
| ... | @@ -5015,7 +5038,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -5015,7 +5038,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5015 | return arg1_value; | 5038 | return arg1_value; |
| 5016 | | 5039 | |
| 5017 | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftRightExact, arg0_value, arg1_value, true); | 5040 | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftRightExact, arg0_value, arg1_value, true); |
| 5018 | return ir_lval_wrap(irb, scope, bin_op, lval); | 5041 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 5019 | } | 5042 | } |
| 5020 | case BuiltinFnIdSetEvalBranchQuota: | 5043 | case BuiltinFnIdSetEvalBranchQuota: |
| 5021 | { | 5044 | { |
| ... | @@ -5025,7 +5048,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -5025,7 +5048,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5025 | return arg0_value; | 5048 | return arg0_value; |
| 5026 | | 5049 | |
| 5027 | IrInstruction *set_eval_branch_quota = ir_build_set_eval_branch_quota(irb, scope, node, arg0_value); | 5050 | IrInstruction *set_eval_branch_quota = ir_build_set_eval_branch_quota(irb, scope, node, arg0_value); |
| 5028 | return ir_lval_wrap(irb, scope, set_eval_branch_quota, lval); | 5051 | return ir_lval_wrap(irb, scope, set_eval_branch_quota, lval, result_loc); |
| 5029 | } | 5052 | } |
| 5030 | case BuiltinFnIdAlignCast: | 5053 | case BuiltinFnIdAlignCast: |
| 5031 | { | 5054 | { |
| ... | @@ -5040,17 +5063,17 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -5040,17 +5063,17 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5040 | return arg1_value; | 5063 | return arg1_value; |
| 5041 | | 5064 | |
| 5042 | IrInstruction *align_cast = ir_build_align_cast(irb, scope, node, arg0_value, arg1_value); | 5065 | IrInstruction *align_cast = ir_build_align_cast(irb, scope, node, arg0_value, arg1_value); |
| 5043 | return ir_lval_wrap(irb, scope, align_cast, lval); | 5066 | return ir_lval_wrap(irb, scope, align_cast, lval, result_loc); |
| 5044 | } | 5067 | } |
| 5045 | case BuiltinFnIdOpaqueType: | 5068 | case BuiltinFnIdOpaqueType: |
| 5046 | { | 5069 | { |
| 5047 | IrInstruction *opaque_type = ir_build_opaque_type(irb, scope, node); | 5070 | IrInstruction *opaque_type = ir_build_opaque_type(irb, scope, node); |
| 5048 | return ir_lval_wrap(irb, scope, opaque_type, lval); | 5071 | return ir_lval_wrap(irb, scope, opaque_type, lval, result_loc); |
| 5049 | } | 5072 | } |
| 5050 | case BuiltinFnIdThis: | 5073 | case BuiltinFnIdThis: |
| 5051 | { | 5074 | { |
| 5052 | IrInstruction *this_inst = ir_gen_this(irb, scope, node); | 5075 | IrInstruction *this_inst = ir_gen_this(irb, scope, node); |
| 5053 | return ir_lval_wrap(irb, scope, this_inst, lval); | 5076 | return ir_lval_wrap(irb, scope, this_inst, lval, result_loc); |
| 5054 | } | 5077 | } |
| 5055 | case BuiltinFnIdSetAlignStack: | 5078 | case BuiltinFnIdSetAlignStack: |
| 5056 | { | 5079 | { |
| ... | @@ -5060,7 +5083,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -5060,7 +5083,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5060 | return arg0_value; | 5083 | return arg0_value; |
| 5061 | | 5084 | |
| 5062 | IrInstruction *set_align_stack = ir_build_set_align_stack(irb, scope, node, arg0_value); | 5085 | IrInstruction *set_align_stack = ir_build_set_align_stack(irb, scope, node, arg0_value); |
| 5063 | return ir_lval_wrap(irb, scope, set_align_stack, lval); | 5086 | return ir_lval_wrap(irb, scope, set_align_stack, lval, result_loc); |
| 5064 | } | 5087 | } |
| 5065 | case BuiltinFnIdArgType: | 5088 | case BuiltinFnIdArgType: |
| 5066 | { | 5089 | { |
| ... | @@ -5075,7 +5098,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -5075,7 +5098,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5075 | return arg1_value; | 5098 | return arg1_value; |
| 5076 | | 5099 | |
| 5077 | IrInstruction *arg_type = ir_build_arg_type(irb, scope, node, arg0_value, arg1_value); | 5100 | IrInstruction *arg_type = ir_build_arg_type(irb, scope, node, arg0_value, arg1_value); |
| 5078 | return ir_lval_wrap(irb, scope, arg_type, lval); | 5101 | return ir_lval_wrap(irb, scope, arg_type, lval, result_loc); |
| 5079 | } | 5102 | } |
| 5080 | case BuiltinFnIdExport: | 5103 | case BuiltinFnIdExport: |
| 5081 | { | 5104 | { |
| ... | @@ -5095,12 +5118,12 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -5095,12 +5118,12 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5095 | return arg2_value; | 5118 | return arg2_value; |
| 5096 | | 5119 | |
| 5097 | IrInstruction *ir_export = ir_build_export(irb, scope, node, arg0_value, arg1_value, arg2_value); | 5120 | IrInstruction *ir_export = ir_build_export(irb, scope, node, arg0_value, arg1_value, arg2_value); |
| 5098 | return ir_lval_wrap(irb, scope, ir_export, lval); | 5121 | return ir_lval_wrap(irb, scope, ir_export, lval, result_loc); |
| 5099 | } | 5122 | } |
| 5100 | case BuiltinFnIdErrorReturnTrace: | 5123 | case BuiltinFnIdErrorReturnTrace: |
| 5101 | { | 5124 | { |
| 5102 | IrInstruction *error_return_trace = ir_build_error_return_trace(irb, scope, node, IrInstructionErrorReturnTrace::Null); | 5125 | IrInstruction *error_return_trace = ir_build_error_return_trace(irb, scope, node, IrInstructionErrorReturnTrace::Null); |
| 5103 | return ir_lval_wrap(irb, scope, error_return_trace, lval); | 5126 | return ir_lval_wrap(irb, scope, error_return_trace, lval, result_loc); |
| 5104 | } | 5127 | } |
| 5105 | case BuiltinFnIdAtomicRmw: | 5128 | case BuiltinFnIdAtomicRmw: |
| 5106 | { | 5129 | { |
| ... | @@ -5168,7 +5191,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -5168,7 +5191,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5168 | return arg1_value; | 5191 | return arg1_value; |
| 5169 | | 5192 | |
| 5170 | IrInstruction *result = ir_build_int_to_enum(irb, scope, node, arg0_value, arg1_value); | 5193 | IrInstruction *result = ir_build_int_to_enum(irb, scope, node, arg0_value, arg1_value); |
| 5171 | return ir_lval_wrap(irb, scope, result, lval); | 5194 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5172 | } | 5195 | } |
| 5173 | case BuiltinFnIdEnumToInt: | 5196 | case BuiltinFnIdEnumToInt: |
| 5174 | { | 5197 | { |
| ... | @@ -5178,7 +5201,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -5178,7 +5201,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5178 | return arg0_value; | 5201 | return arg0_value; |
| 5179 | | 5202 | |
| 5180 | IrInstruction *result = ir_build_enum_to_int(irb, scope, node, arg0_value); | 5203 | IrInstruction *result = ir_build_enum_to_int(irb, scope, node, arg0_value); |
| 5181 | return ir_lval_wrap(irb, scope, result, lval); | 5204 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5182 | } | 5205 | } |
| 5183 | case BuiltinFnIdCtz: | 5206 | case BuiltinFnIdCtz: |
| 5184 | case BuiltinFnIdPopCount: | 5207 | case BuiltinFnIdPopCount: |
| ... | @@ -5216,7 +5239,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -5216,7 +5239,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5216 | default: | 5239 | default: |
| 5217 | zig_unreachable(); | 5240 | zig_unreachable(); |
| 5218 | } | 5241 | } |
| 5219 | return ir_lval_wrap(irb, scope, result, lval); | 5242 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5220 | } | 5243 | } |
| 5221 | case BuiltinFnIdHasDecl: | 5244 | case BuiltinFnIdHasDecl: |
| 5222 | { | 5245 | { |
| ... | @@ -5231,7 +5254,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -5231,7 +5254,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5231 | return arg1_value; | 5254 | return arg1_value; |
| 5232 | | 5255 | |
| 5233 | IrInstruction *has_decl = ir_build_has_decl(irb, scope, node, arg0_value, arg1_value); | 5256 | IrInstruction *has_decl = ir_build_has_decl(irb, scope, node, arg0_value, arg1_value); |
| 5234 | return ir_lval_wrap(irb, scope, has_decl, lval); | 5257 | return ir_lval_wrap(irb, scope, has_decl, lval, result_loc); |
| 5235 | } | 5258 | } |
| 5236 | } | 5259 | } |
| 5237 | zig_unreachable(); | 5260 | zig_unreachable(); |
| ... | @@ -5271,10 +5294,12 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node | ... | @@ -5271,10 +5294,12 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node |
| 5271 | | 5294 | |
| 5272 | IrInstruction *fn_call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, false, FnInlineAuto, | 5295 | IrInstruction *fn_call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, false, FnInlineAuto, |
| 5273 | is_async, async_allocator, nullptr, result_loc); | 5296 | is_async, async_allocator, nullptr, result_loc); |
| 5274 | return ir_lval_wrap(irb, scope, fn_call, lval); | 5297 | return ir_lval_wrap(irb, scope, fn_call, lval, result_loc); |
| 5275 | } | 5298 | } |
| 5276 | | 5299 | |
| 5277 | static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode *node) { | 5300 | static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| | 5301 | ResultLoc *result_loc) |
| | 5302 | { |
| 5278 | assert(node->type == NodeTypeIfBoolExpr); | 5303 | assert(node->type == NodeTypeIfBoolExpr); |
| 5279 | | 5304 | |
| 5280 | IrInstruction *condition = ir_gen_node(irb, node->data.if_bool_expr.condition, scope); | 5305 | IrInstruction *condition = ir_gen_node(irb, node->data.if_bool_expr.condition, scope); |
| ... | @@ -5295,12 +5320,29 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -5295,12 +5320,29 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode |
| 5295 | IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "Else"); | 5320 | IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "Else"); |
| 5296 | IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "EndIf"); | 5321 | IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "EndIf"); |
| 5297 | | 5322 | |
| 5298 | ir_build_cond_br(irb, scope, condition->source_node, condition, then_block, else_block, is_comptime); | 5323 | IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, condition->source_node, condition, |
| | 5324 | then_block, else_block, is_comptime); |
| | 5325 | |
| | 5326 | ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1); |
| | 5327 | peer_parent->base.id = ResultLocIdPeerParent; |
| | 5328 | peer_parent->base.source_instruction = cond_br_inst; |
| | 5329 | peer_parent->parent = result_loc; |
| | 5330 | peer_parent->peer_count = 2; |
| | 5331 | peer_parent->peers = allocate<ResultLocPeer>(2); |
| | 5332 | peer_parent->peers[0].base.id = ResultLocIdPeer; |
| | 5333 | peer_parent->peers[0].base.source_instruction = cond_br_inst; |
| | 5334 | peer_parent->peers[0].parent = peer_parent; |
| | 5335 | peer_parent->peers[0].next_bb = else_block; |
| | 5336 | peer_parent->peers[1].base.id = ResultLocIdPeer; |
| | 5337 | peer_parent->peers[1].base.source_instruction = cond_br_inst; |
| | 5338 | peer_parent->peers[1].parent = peer_parent; |
| | 5339 | peer_parent->peers[1].next_bb = endif_block; |
| 5299 | | 5340 | |
| 5300 | ir_set_cursor_at_end_and_append_block(irb, then_block); | 5341 | ir_set_cursor_at_end_and_append_block(irb, then_block); |
| 5301 | | 5342 | |
| 5302 | Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime); | 5343 | Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime); |
| 5303 | IrInstruction *then_expr_result = ir_gen_node(irb, then_node, subexpr_scope); | 5344 | IrInstruction *then_expr_result = ir_gen_node_extra(irb, then_node, subexpr_scope, lval, |
| | 5345 | &peer_parent->peers[0].base); |
| 5304 | if (then_expr_result == irb->codegen->invalid_instruction) | 5346 | if (then_expr_result == irb->codegen->invalid_instruction) |
| 5305 | return irb->codegen->invalid_instruction; | 5347 | return irb->codegen->invalid_instruction; |
| 5306 | IrBasicBlock *after_then_block = irb->current_basic_block; | 5348 | IrBasicBlock *after_then_block = irb->current_basic_block; |
| ... | @@ -5310,7 +5352,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -5310,7 +5352,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode |
| 5310 | ir_set_cursor_at_end_and_append_block(irb, else_block); | 5352 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 5311 | IrInstruction *else_expr_result; | 5353 | IrInstruction *else_expr_result; |
| 5312 | if (else_node) { | 5354 | if (else_node) { |
| 5313 | else_expr_result = ir_gen_node(irb, else_node, subexpr_scope); | 5355 | else_expr_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_parent->peers[1].base); |
| 5314 | if (else_expr_result == irb->codegen->invalid_instruction) | 5356 | if (else_expr_result == irb->codegen->invalid_instruction) |
| 5315 | return irb->codegen->invalid_instruction; | 5357 | return irb->codegen->invalid_instruction; |
| 5316 | } else { | 5358 | } else { |
| ... | @@ -5328,7 +5370,8 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -5328,7 +5370,8 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode |
| 5328 | incoming_blocks[0] = after_then_block; | 5370 | incoming_blocks[0] = after_then_block; |
| 5329 | incoming_blocks[1] = after_else_block; | 5371 | incoming_blocks[1] = after_else_block; |
| 5330 | | 5372 | |
| 5331 | return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values); | 5373 | IrInstruction *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values); |
| | 5374 | return ir_lval_wrap(irb, scope, phi, lval, result_loc); |
| 5332 | } | 5375 | } |
| 5333 | | 5376 | |
| 5334 | static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) { | 5377 | static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) { |
| ... | @@ -5346,15 +5389,28 @@ static IrInstruction *ir_gen_prefix_op_id(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -5346,15 +5389,28 @@ static IrInstruction *ir_gen_prefix_op_id(IrBuilder *irb, Scope *scope, AstNode |
| 5346 | return ir_gen_prefix_op_id_lval(irb, scope, node, op_id, LValNone); | 5389 | return ir_gen_prefix_op_id_lval(irb, scope, node, op_id, LValNone); |
| 5347 | } | 5390 | } |
| 5348 | | 5391 | |
| 5349 | static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval) { | 5392 | static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval, |
| 5350 | if (lval != LValPtr) | 5393 | ResultLoc *result_loc) |
| 5351 | return value; | 5394 | { |
| 5352 | if (value == irb->codegen->invalid_instruction) | 5395 | // This logic must be kept in sync with |
| | 5396 | // [STMT_EXPR_TEST_THING] <--- (search this token) |
| | 5397 | if (value == irb->codegen->invalid_instruction || |
| | 5398 | instr_is_unreachable(value) || |
| | 5399 | value->source_node->type == NodeTypeDefer || |
| | 5400 | value->id == IrInstructionIdDeclVarSrc) |
| | 5401 | { |
| 5353 | return value; | 5402 | return value; |
| | 5403 | } |
| | 5404 | |
| | 5405 | if (lval == LValPtr) { |
| | 5406 | // We needed a pointer to a value, but we got a value. So we create |
| | 5407 | // an instruction which just makes a pointer of it. |
| | 5408 | return ir_build_ref(irb, scope, value->source_node, value, false, false); |
| | 5409 | } |
| 5354 | | 5410 | |
| 5355 | // We needed a pointer to a value, but we got a value. So we create | 5411 | // TODO remove the lval parameter here |
| 5356 | // an instruction which just makes a const pointer of it. | 5412 | ir_build_end_expr(irb, scope, value->source_node, value, lval, result_loc); |
| 5357 | return ir_build_ref(irb, scope, value->source_node, value, false, false); | 5413 | return value; |
| 5358 | } | 5414 | } |
| 5359 | | 5415 | |
| 5360 | static PtrLen star_token_to_ptr_len(TokenId token_id) { | 5416 | static PtrLen star_token_to_ptr_len(TokenId token_id) { |
| ... | @@ -5455,7 +5511,9 @@ static IrInstruction *ir_gen_bool_not(IrBuilder *irb, Scope *scope, AstNode *nod | ... | @@ -5455,7 +5511,9 @@ static IrInstruction *ir_gen_bool_not(IrBuilder *irb, Scope *scope, AstNode *nod |
| 5455 | return ir_build_bool_not(irb, scope, node, value); | 5511 | return ir_build_bool_not(irb, scope, node, value); |
| 5456 | } | 5512 | } |
| 5457 | | 5513 | |
| 5458 | static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) { | 5514 | static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| | 5515 | ResultLoc *result_loc) |
| | 5516 | { |
| 5459 | assert(node->type == NodeTypePrefixOpExpr); | 5517 | assert(node->type == NodeTypePrefixOpExpr); |
| 5460 | | 5518 | |
| 5461 | PrefixOp prefix_op = node->data.prefix_op_expr.prefix_op; | 5519 | PrefixOp prefix_op = node->data.prefix_op_expr.prefix_op; |
| ... | @@ -5464,18 +5522,18 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod | ... | @@ -5464,18 +5522,18 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod |
| 5464 | case PrefixOpInvalid: | 5522 | case PrefixOpInvalid: |
| 5465 | zig_unreachable(); | 5523 | zig_unreachable(); |
| 5466 | case PrefixOpBoolNot: | 5524 | case PrefixOpBoolNot: |
| 5467 | return ir_lval_wrap(irb, scope, ir_gen_bool_not(irb, scope, node), lval); | 5525 | return ir_lval_wrap(irb, scope, ir_gen_bool_not(irb, scope, node), lval, result_loc); |
| 5468 | case PrefixOpBinNot: | 5526 | case PrefixOpBinNot: |
| 5469 | return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpBinNot), lval); | 5527 | return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpBinNot), lval, result_loc); |
| 5470 | case PrefixOpNegation: | 5528 | case PrefixOpNegation: |
| 5471 | return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpNegation), lval); | 5529 | return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpNegation), lval, result_loc); |
| 5472 | case PrefixOpNegationWrap: | 5530 | case PrefixOpNegationWrap: |
| 5473 | return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpNegationWrap), lval); | 5531 | return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpNegationWrap), lval, result_loc); |
| 5474 | case PrefixOpOptional: | 5532 | case PrefixOpOptional: |
| 5475 | return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpOptional), lval); | 5533 | return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpOptional), lval, result_loc); |
| 5476 | case PrefixOpAddrOf: { | 5534 | case PrefixOpAddrOf: { |
| 5477 | AstNode *expr_node = node->data.prefix_op_expr.primary_expr; | 5535 | AstNode *expr_node = node->data.prefix_op_expr.primary_expr; |
| 5478 | return ir_lval_wrap(irb, scope, ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr), lval); | 5536 | return ir_lval_wrap(irb, scope, ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr), lval, result_loc); |
| 5479 | } | 5537 | } |
| 5480 | } | 5538 | } |
| 5481 | zig_unreachable(); | 5539 | zig_unreachable(); |
| ... | @@ -7677,33 +7735,33 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop | ... | @@ -7677,33 +7735,33 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 7677 | case NodeTypeTestDecl: | 7735 | case NodeTypeTestDecl: |
| 7678 | zig_unreachable(); | 7736 | zig_unreachable(); |
| 7679 | case NodeTypeBlock: | 7737 | case NodeTypeBlock: |
| 7680 | return ir_lval_wrap(irb, scope, ir_gen_block(irb, scope, node), lval); | 7738 | return ir_lval_wrap(irb, scope, ir_gen_block(irb, scope, node), lval, result_loc); |
| 7681 | case NodeTypeGroupedExpr: | 7739 | case NodeTypeGroupedExpr: |
| 7682 | return ir_gen_node_raw(irb, node->data.grouped_expr, scope, lval, result_loc); | 7740 | return ir_gen_node_raw(irb, node->data.grouped_expr, scope, lval, result_loc); |
| 7683 | case NodeTypeBinOpExpr: | 7741 | case NodeTypeBinOpExpr: |
| 7684 | return ir_lval_wrap(irb, scope, ir_gen_bin_op(irb, scope, node), lval); | 7742 | return ir_lval_wrap(irb, scope, ir_gen_bin_op(irb, scope, node), lval, result_loc); |
| 7685 | case NodeTypeIntLiteral: | 7743 | case NodeTypeIntLiteral: |
| 7686 | return ir_lval_wrap(irb, scope, ir_gen_int_lit(irb, scope, node), lval); | 7744 | return ir_lval_wrap(irb, scope, ir_gen_int_lit(irb, scope, node), lval, result_loc); |
| 7687 | case NodeTypeFloatLiteral: | 7745 | case NodeTypeFloatLiteral: |
| 7688 | return ir_lval_wrap(irb, scope, ir_gen_float_lit(irb, scope, node), lval); | 7746 | return ir_lval_wrap(irb, scope, ir_gen_float_lit(irb, scope, node), lval, result_loc); |
| 7689 | case NodeTypeCharLiteral: | 7747 | case NodeTypeCharLiteral: |
| 7690 | return ir_lval_wrap(irb, scope, ir_gen_char_lit(irb, scope, node), lval); | 7748 | return ir_lval_wrap(irb, scope, ir_gen_char_lit(irb, scope, node), lval, result_loc); |
| 7691 | case NodeTypeSymbol: | 7749 | case NodeTypeSymbol: |
| 7692 | return ir_gen_symbol(irb, scope, node, lval); | 7750 | return ir_gen_symbol(irb, scope, node, lval); |
| 7693 | case NodeTypeFnCallExpr: | 7751 | case NodeTypeFnCallExpr: |
| 7694 | return ir_gen_fn_call(irb, scope, node, lval, result_loc); | 7752 | return ir_gen_fn_call(irb, scope, node, lval, result_loc); |
| 7695 | case NodeTypeIfBoolExpr: | 7753 | case NodeTypeIfBoolExpr: |
| 7696 | return ir_lval_wrap(irb, scope, ir_gen_if_bool_expr(irb, scope, node), lval); | 7754 | return ir_gen_if_bool_expr(irb, scope, node, lval, result_loc); |
| 7697 | case NodeTypePrefixOpExpr: | 7755 | case NodeTypePrefixOpExpr: |
| 7698 | return ir_gen_prefix_op_expr(irb, scope, node, lval); | 7756 | return ir_gen_prefix_op_expr(irb, scope, node, lval, result_loc); |
| 7699 | case NodeTypeContainerInitExpr: | 7757 | case NodeTypeContainerInitExpr: |
| 7700 | return ir_lval_wrap(irb, scope, ir_gen_container_init_expr(irb, scope, node), lval); | 7758 | return ir_lval_wrap(irb, scope, ir_gen_container_init_expr(irb, scope, node), lval, result_loc); |
| 7701 | case NodeTypeVariableDeclaration: | 7759 | case NodeTypeVariableDeclaration: |
| 7702 | return ir_lval_wrap(irb, scope, ir_gen_var_decl(irb, scope, node), lval); | 7760 | return ir_lval_wrap(irb, scope, ir_gen_var_decl(irb, scope, node), lval, result_loc); |
| 7703 | case NodeTypeWhileExpr: | 7761 | case NodeTypeWhileExpr: |
| 7704 | return ir_lval_wrap(irb, scope, ir_gen_while_expr(irb, scope, node), lval); | 7762 | return ir_lval_wrap(irb, scope, ir_gen_while_expr(irb, scope, node), lval, result_loc); |
| 7705 | case NodeTypeForExpr: | 7763 | case NodeTypeForExpr: |
| 7706 | return ir_lval_wrap(irb, scope, ir_gen_for_expr(irb, scope, node), lval); | 7764 | return ir_lval_wrap(irb, scope, ir_gen_for_expr(irb, scope, node), lval, result_loc); |
| 7707 | case NodeTypeArrayAccessExpr: | 7765 | case NodeTypeArrayAccessExpr: |
| 7708 | return ir_gen_array_access(irb, scope, node, lval); | 7766 | return ir_gen_array_access(irb, scope, node, lval); |
| 7709 | case NodeTypeReturnExpr: | 7767 | case NodeTypeReturnExpr: |
| ... | @@ -7743,59 +7801,59 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop | ... | @@ -7743,59 +7801,59 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 7743 | return ir_build_load_ptr(irb, scope, node, unwrapped_ptr); | 7801 | return ir_build_load_ptr(irb, scope, node, unwrapped_ptr); |
| 7744 | } | 7802 | } |
| 7745 | case NodeTypeBoolLiteral: | 7803 | case NodeTypeBoolLiteral: |
| 7746 | return ir_lval_wrap(irb, scope, ir_gen_bool_literal(irb, scope, node), lval); | 7804 | return ir_lval_wrap(irb, scope, ir_gen_bool_literal(irb, scope, node), lval, result_loc); |
| 7747 | case NodeTypeArrayType: | 7805 | case NodeTypeArrayType: |
| 7748 | return ir_lval_wrap(irb, scope, ir_gen_array_type(irb, scope, node), lval); | 7806 | return ir_lval_wrap(irb, scope, ir_gen_array_type(irb, scope, node), lval, result_loc); |
| 7749 | case NodeTypePointerType: | 7807 | case NodeTypePointerType: |
| 7750 | return ir_lval_wrap(irb, scope, ir_gen_pointer_type(irb, scope, node), lval); | 7808 | return ir_lval_wrap(irb, scope, ir_gen_pointer_type(irb, scope, node), lval, result_loc); |
| 7751 | case NodeTypePromiseType: | 7809 | case NodeTypePromiseType: |
| 7752 | return ir_lval_wrap(irb, scope, ir_gen_promise_type(irb, scope, node), lval); | 7810 | return ir_lval_wrap(irb, scope, ir_gen_promise_type(irb, scope, node), lval, result_loc); |
| 7753 | case NodeTypeStringLiteral: | 7811 | case NodeTypeStringLiteral: |
| 7754 | return ir_lval_wrap(irb, scope, ir_gen_string_literal(irb, scope, node), lval); | 7812 | return ir_lval_wrap(irb, scope, ir_gen_string_literal(irb, scope, node), lval, result_loc); |
| 7755 | case NodeTypeUndefinedLiteral: | 7813 | case NodeTypeUndefinedLiteral: |
| 7756 | return ir_lval_wrap(irb, scope, ir_gen_undefined_literal(irb, scope, node), lval); | 7814 | return ir_lval_wrap(irb, scope, ir_gen_undefined_literal(irb, scope, node), lval, result_loc); |
| 7757 | case NodeTypeAsmExpr: | 7815 | case NodeTypeAsmExpr: |
| 7758 | return ir_lval_wrap(irb, scope, ir_gen_asm_expr(irb, scope, node), lval); | 7816 | return ir_lval_wrap(irb, scope, ir_gen_asm_expr(irb, scope, node), lval, result_loc); |
| 7759 | case NodeTypeNullLiteral: | 7817 | case NodeTypeNullLiteral: |
| 7760 | return ir_lval_wrap(irb, scope, ir_gen_null_literal(irb, scope, node), lval); | 7818 | return ir_lval_wrap(irb, scope, ir_gen_null_literal(irb, scope, node), lval, result_loc); |
| 7761 | case NodeTypeIfErrorExpr: | 7819 | case NodeTypeIfErrorExpr: |
| 7762 | return ir_lval_wrap(irb, scope, ir_gen_if_err_expr(irb, scope, node), lval); | 7820 | return ir_lval_wrap(irb, scope, ir_gen_if_err_expr(irb, scope, node), lval, result_loc); |
| 7763 | case NodeTypeIfOptional: | 7821 | case NodeTypeIfOptional: |
| 7764 | return ir_lval_wrap(irb, scope, ir_gen_if_optional_expr(irb, scope, node), lval); | 7822 | return ir_lval_wrap(irb, scope, ir_gen_if_optional_expr(irb, scope, node), lval, result_loc); |
| 7765 | case NodeTypeSwitchExpr: | 7823 | case NodeTypeSwitchExpr: |
| 7766 | return ir_lval_wrap(irb, scope, ir_gen_switch_expr(irb, scope, node), lval); | 7824 | return ir_lval_wrap(irb, scope, ir_gen_switch_expr(irb, scope, node), lval, result_loc); |
| 7767 | case NodeTypeCompTime: | 7825 | case NodeTypeCompTime: |
| 7768 | return ir_gen_comptime(irb, scope, node, lval); | 7826 | return ir_gen_comptime(irb, scope, node, lval); |
| 7769 | case NodeTypeErrorType: | 7827 | case NodeTypeErrorType: |
| 7770 | return ir_lval_wrap(irb, scope, ir_gen_error_type(irb, scope, node), lval); | 7828 | return ir_lval_wrap(irb, scope, ir_gen_error_type(irb, scope, node), lval, result_loc); |
| 7771 | case NodeTypeBreak: | 7829 | case NodeTypeBreak: |
| 7772 | return ir_lval_wrap(irb, scope, ir_gen_break(irb, scope, node), lval); | 7830 | return ir_lval_wrap(irb, scope, ir_gen_break(irb, scope, node), lval, result_loc); |
| 7773 | case NodeTypeContinue: | 7831 | case NodeTypeContinue: |
| 7774 | return ir_lval_wrap(irb, scope, ir_gen_continue(irb, scope, node), lval); | 7832 | return ir_lval_wrap(irb, scope, ir_gen_continue(irb, scope, node), lval, result_loc); |
| 7775 | case NodeTypeUnreachable: | 7833 | case NodeTypeUnreachable: |
| 7776 | return ir_lval_wrap(irb, scope, ir_build_unreachable(irb, scope, node), lval); | 7834 | return ir_lval_wrap(irb, scope, ir_build_unreachable(irb, scope, node), lval, result_loc); |
| 7777 | case NodeTypeDefer: | 7835 | case NodeTypeDefer: |
| 7778 | return ir_lval_wrap(irb, scope, ir_gen_defer(irb, scope, node), lval); | 7836 | return ir_lval_wrap(irb, scope, ir_gen_defer(irb, scope, node), lval, result_loc); |
| 7779 | case NodeTypeSliceExpr: | 7837 | case NodeTypeSliceExpr: |
| 7780 | return ir_lval_wrap(irb, scope, ir_gen_slice(irb, scope, node), lval); | 7838 | return ir_lval_wrap(irb, scope, ir_gen_slice(irb, scope, node), lval, result_loc); |
| 7781 | case NodeTypeUnwrapErrorExpr: | 7839 | case NodeTypeUnwrapErrorExpr: |
| 7782 | return ir_lval_wrap(irb, scope, ir_gen_catch(irb, scope, node), lval); | 7840 | return ir_lval_wrap(irb, scope, ir_gen_catch(irb, scope, node), lval, result_loc); |
| 7783 | case NodeTypeContainerDecl: | 7841 | case NodeTypeContainerDecl: |
| 7784 | return ir_lval_wrap(irb, scope, ir_gen_container_decl(irb, scope, node), lval); | 7842 | return ir_lval_wrap(irb, scope, ir_gen_container_decl(irb, scope, node), lval, result_loc); |
| 7785 | case NodeTypeFnProto: | 7843 | case NodeTypeFnProto: |
| 7786 | return ir_lval_wrap(irb, scope, ir_gen_fn_proto(irb, scope, node), lval); | 7844 | return ir_lval_wrap(irb, scope, ir_gen_fn_proto(irb, scope, node), lval, result_loc); |
| 7787 | case NodeTypeErrorSetDecl: | 7845 | case NodeTypeErrorSetDecl: |
| 7788 | return ir_lval_wrap(irb, scope, ir_gen_err_set_decl(irb, scope, node), lval); | 7846 | return ir_lval_wrap(irb, scope, ir_gen_err_set_decl(irb, scope, node), lval, result_loc); |
| 7789 | case NodeTypeCancel: | 7847 | case NodeTypeCancel: |
| 7790 | return ir_lval_wrap(irb, scope, ir_gen_cancel(irb, scope, node), lval); | 7848 | return ir_lval_wrap(irb, scope, ir_gen_cancel(irb, scope, node), lval, result_loc); |
| 7791 | case NodeTypeResume: | 7849 | case NodeTypeResume: |
| 7792 | return ir_lval_wrap(irb, scope, ir_gen_resume(irb, scope, node), lval); | 7850 | return ir_lval_wrap(irb, scope, ir_gen_resume(irb, scope, node), lval, result_loc); |
| 7793 | case NodeTypeAwaitExpr: | 7851 | case NodeTypeAwaitExpr: |
| 7794 | return ir_lval_wrap(irb, scope, ir_gen_await_expr(irb, scope, node), lval); | 7852 | return ir_lval_wrap(irb, scope, ir_gen_await_expr(irb, scope, node), lval, result_loc); |
| 7795 | case NodeTypeSuspend: | 7853 | case NodeTypeSuspend: |
| 7796 | return ir_lval_wrap(irb, scope, ir_gen_suspend(irb, scope, node), lval); | 7854 | return ir_lval_wrap(irb, scope, ir_gen_suspend(irb, scope, node), lval, result_loc); |
| 7797 | case NodeTypeEnumLiteral: | 7855 | case NodeTypeEnumLiteral: |
| 7798 | return ir_lval_wrap(irb, scope, ir_gen_enum_literal(irb, scope, node), lval); | 7856 | return ir_lval_wrap(irb, scope, ir_gen_enum_literal(irb, scope, node), lval, result_loc); |
| 7799 | } | 7857 | } |
| 7800 | zig_unreachable(); | 7858 | zig_unreachable(); |
| 7801 | } | 7859 | } |
| ... | @@ -10415,6 +10473,33 @@ static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *cons | ... | @@ -10415,6 +10473,33 @@ static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *cons |
| 10415 | ira->const_predecessor_bb = const_predecessor_bb; | 10473 | ira->const_predecessor_bb = const_predecessor_bb; |
| 10416 | } | 10474 | } |
| 10417 | | 10475 | |
| | 10476 | static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction, IrBasicBlock *next_bb, |
| | 10477 | IrSuspendPosition *suspend_pos) |
| | 10478 | { |
| | 10479 | suspend_pos->basic_block_index = ira->old_bb_index; |
| | 10480 | suspend_pos->instruction_index = ira->instruction_index; |
| | 10481 | |
| | 10482 | ira->old_bb_index = next_bb->index; |
| | 10483 | ira->old_irb.current_basic_block = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index); |
| | 10484 | assert(ira->old_irb.current_basic_block == next_bb); |
| | 10485 | ira->instruction_index = 0; |
| | 10486 | ira->const_predecessor_bb = nullptr; |
| | 10487 | next_bb->other = ir_get_new_bb_runtime(ira, next_bb, old_instruction); |
| | 10488 | ira->new_irb.current_basic_block = next_bb->other; |
| | 10489 | return ira->codegen->unreach_instruction; |
| | 10490 | } |
| | 10491 | |
| | 10492 | static IrInstruction *ira_resume(IrAnalyze *ira) { |
| | 10493 | IrSuspendPosition pos = ira->resume_stack.pop(); |
| | 10494 | ira->old_bb_index = pos.basic_block_index; |
| | 10495 | ira->old_irb.current_basic_block = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index); |
| | 10496 | ira->instruction_index = pos.instruction_index; |
| | 10497 | ira->const_predecessor_bb = nullptr; |
| | 10498 | ira->new_irb.current_basic_block = ira->old_irb.current_basic_block->other; |
| | 10499 | assert(ira->new_irb.current_basic_block != nullptr); |
| | 10500 | return ira->codegen->unreach_instruction; |
| | 10501 | } |
| | 10502 | |
| 10418 | static void ir_finish_bb(IrAnalyze *ira) { | 10503 | static void ir_finish_bb(IrAnalyze *ira) { |
| 10419 | ira->new_irb.exec->basic_block_list.append(ira->new_irb.current_basic_block); | 10504 | ira->new_irb.exec->basic_block_list.append(ira->new_irb.current_basic_block); |
| 10420 | ira->instruction_index += 1; | 10505 | ira->instruction_index += 1; |
| ... | @@ -10442,8 +10527,15 @@ static void ir_finish_bb(IrAnalyze *ira) { | ... | @@ -10442,8 +10527,15 @@ static void ir_finish_bb(IrAnalyze *ira) { |
| 10442 | ira->old_bb_index += 1; | 10527 | ira->old_bb_index += 1; |
| 10443 | continue; | 10528 | continue; |
| 10444 | } | 10529 | } |
| 10445 | ira->new_irb.current_basic_block = old_bb->other; | 10530 | // if there is a resume_stack, pop one from there rather than moving on. |
| | 10531 | // the last item of the resume stack will be a basic block that will |
| | 10532 | // move on to the next one below |
| | 10533 | if (ira->resume_stack.length != 0) { |
| | 10534 | ira_resume(ira); |
| | 10535 | return; |
| | 10536 | } |
| 10446 | | 10537 | |
| | 10538 | ira->new_irb.current_basic_block = old_bb->other; |
| 10447 | ir_start_bb(ira, old_bb, nullptr); | 10539 | ir_start_bb(ira, old_bb, nullptr); |
| 10448 | return; | 10540 | return; |
| 10449 | } | 10541 | } |
| ... | @@ -14232,9 +14324,26 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in | ... | @@ -14232,9 +14324,26 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in |
| 14232 | return &result->base; | 14324 | return &result->base; |
| 14233 | } | 14325 | } |
| 14234 | | 14326 | |
| 14235 | static IrInstruction *ir_resolve_result_loc(IrAnalyze *ira, ResultLoc *result_loc, ZigType *elem_type) { | 14327 | static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, ResultLoc *result_loc) { |
| | 14328 | switch (result_loc->id) { |
| | 14329 | case ResultLocIdInvalid: |
| | 14330 | case ResultLocIdPeerParent: |
| | 14331 | case ResultLocIdPeer: |
| | 14332 | zig_unreachable(); |
| | 14333 | case ResultLocIdNone: |
| | 14334 | case ResultLocIdVar: |
| | 14335 | return nullptr; |
| | 14336 | case ResultLocIdReturn: |
| | 14337 | return ira->explicit_return_type; |
| | 14338 | } |
| | 14339 | zig_unreachable(); |
| | 14340 | } |
| | 14341 | |
| | 14342 | static IrInstruction *ir_resolve_result_runtime(IrAnalyze *ira, ResultLoc *result_loc, ZigType *elem_type) { |
| | 14343 | result_loc->implicit_elem_type = elem_type; |
| 14236 | switch (result_loc->id) { | 14344 | switch (result_loc->id) { |
| 14237 | case ResultLocIdInvalid: | 14345 | case ResultLocIdInvalid: |
| | 14346 | case ResultLocIdPeerParent: |
| 14238 | zig_unreachable(); | 14347 | zig_unreachable(); |
| 14239 | case ResultLocIdNone: | 14348 | case ResultLocIdNone: |
| 14240 | return nullptr; | 14349 | return nullptr; |
| ... | @@ -14254,14 +14363,21 @@ static IrInstruction *ir_resolve_result_loc(IrAnalyze *ira, ResultLoc *result_lo | ... | @@ -14254,14 +14363,21 @@ static IrInstruction *ir_resolve_result_loc(IrAnalyze *ira, ResultLoc *result_lo |
| 14254 | return alloca_src->base.child; | 14363 | return alloca_src->base.child; |
| 14255 | } | 14364 | } |
| 14256 | case ResultLocIdReturn: { | 14365 | case ResultLocIdReturn: { |
| 14257 | //ResultLocReturn *result_loc_ret = reinterpret_cast<ResultLocReturn *>(result_loc); | 14366 | ZigType *ptr_return_type = get_pointer_to_type(ira->codegen, ira->explicit_return_type, false); |
| 14258 | // TODO implicit cast? | 14367 | return ir_build_return_ptr(ira, result_loc->source_instruction, ptr_return_type); |
| 14259 | return ir_build_return_ptr(ira, result_loc->source_instruction, elem_type); | | |
| 14260 | } | 14368 | } |
| | 14369 | case ResultLocIdPeer: |
| | 14370 | return nullptr; |
| 14261 | } | 14371 | } |
| 14262 | zig_unreachable(); | 14372 | zig_unreachable(); |
| 14263 | } | 14373 | } |
| 14264 | | 14374 | |
| | 14375 | static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, IrInstruction *value) { |
| | 14376 | IrInstruction *result_inst = ir_resolve_result_runtime(ira, result_loc, value->value.type); |
| | 14377 | result_loc->gen_instruction = value; |
| | 14378 | return result_inst; |
| | 14379 | } |
| | 14380 | |
| 14265 | static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, ZigFn *fn_entry, | 14381 | static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, ZigFn *fn_entry, |
| 14266 | ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, | 14382 | ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, |
| 14267 | IrInstruction *async_allocator_inst) | 14383 | IrInstruction *async_allocator_inst) |
| ... | @@ -14295,12 +14411,9 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc | ... | @@ -14295,12 +14411,9 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc |
| 14295 | ZigType *promise_type = get_promise_type(ira->codegen, return_type); | 14411 | ZigType *promise_type = get_promise_type(ira->codegen, return_type); |
| 14296 | ZigType *async_return_type = get_error_union_type(ira->codegen, alloc_fn_error_set_type, promise_type); | 14412 | ZigType *async_return_type = get_error_union_type(ira->codegen, alloc_fn_error_set_type, promise_type); |
| 14297 | | 14413 | |
| 14298 | IrInstruction *result_loc = ir_resolve_result_loc(ira, call_instruction->result_loc, async_return_type); | 14414 | return ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref, arg_count, |
| 14299 | | 14415 | casted_args, FnInlineAuto, true, async_allocator_inst, nullptr, call_instruction->result_loc, |
| 14300 | IrInstruction *result = ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref, arg_count, | 14416 | async_return_type); |
| 14301 | casted_args, FnInlineAuto, true, async_allocator_inst, nullptr, result_loc); | | |
| 14302 | result->value.type = async_return_type; | | |
| 14303 | return result; | | |
| 14304 | } | 14417 | } |
| 14305 | | 14418 | |
| 14306 | static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node, | 14419 | static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node, |
| ... | @@ -15053,12 +15166,10 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c | ... | @@ -15053,12 +15166,10 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 15053 | } | 15166 | } |
| 15054 | | 15167 | |
| 15055 | assert(async_allocator_inst == nullptr); | 15168 | assert(async_allocator_inst == nullptr); |
| 15056 | IrInstruction *result_loc = ir_resolve_result_loc(ira, call_instruction->result_loc, | | |
| 15057 | impl_fn_type_id->return_type); | | |
| 15058 | IrInstruction *new_call_instruction = ir_build_call_gen(ira, &call_instruction->base, | 15169 | IrInstruction *new_call_instruction = ir_build_call_gen(ira, &call_instruction->base, |
| 15059 | impl_fn, nullptr, impl_param_count, casted_args, fn_inline, | 15170 | impl_fn, nullptr, impl_param_count, casted_args, fn_inline, |
| 15060 | call_instruction->is_async, nullptr, casted_new_stack, result_loc); | 15171 | call_instruction->is_async, nullptr, casted_new_stack, call_instruction->result_loc, |
| 15061 | new_call_instruction->value.type = impl_fn_type_id->return_type; | 15172 | impl_fn_type_id->return_type); |
| 15062 | | 15173 | |
| 15063 | return ir_finish_anal(ira, new_call_instruction); | 15174 | return ir_finish_anal(ira, new_call_instruction); |
| 15064 | } | 15175 | } |
| ... | @@ -15152,10 +15263,9 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c | ... | @@ -15152,10 +15263,9 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 15152 | return ira->codegen->invalid_instruction; | 15263 | return ira->codegen->invalid_instruction; |
| 15153 | } | 15264 | } |
| 15154 | | 15265 | |
| 15155 | IrInstruction *result_loc = ir_resolve_result_loc(ira, call_instruction->result_loc, return_type); | | |
| 15156 | IrInstruction *new_call_instruction = ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref, | 15266 | IrInstruction *new_call_instruction = ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref, |
| 15157 | call_param_count, casted_args, fn_inline, false, nullptr, casted_new_stack, result_loc); | 15267 | call_param_count, casted_args, fn_inline, false, nullptr, casted_new_stack, |
| 15158 | new_call_instruction->value.type = return_type; | 15268 | call_instruction->result_loc, return_type); |
| 15159 | return ir_finish_anal(ira, new_call_instruction); | 15269 | return ir_finish_anal(ira, new_call_instruction); |
| 15160 | } | 15270 | } |
| 15161 | | 15271 | |
| ... | @@ -23466,7 +23576,47 @@ static IrInstruction *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, Ir | ... | @@ -23466,7 +23576,47 @@ static IrInstruction *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, Ir |
| 23466 | return ira->codegen->invalid_instruction; | 23576 | return ira->codegen->invalid_instruction; |
| 23467 | } | 23577 | } |
| 23468 | | 23578 | |
| 23469 | static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) { | 23579 | static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstructionEndExpr *instruction) { |
| | 23580 | IrInstruction *value = instruction->value->child; |
| | 23581 | if (type_is_invalid(value->value.type)) |
| | 23582 | return ira->codegen->invalid_instruction; |
| | 23583 | |
| | 23584 | assert(instruction->lval == LValNone); |
| | 23585 | |
| | 23586 | if (instruction->result_loc->id == ResultLocIdPeer) { |
| | 23587 | ResultLocPeer *result_peer = reinterpret_cast<ResultLocPeer *>(instruction->result_loc); |
| | 23588 | ResultLocPeerParent *peer_parent = result_peer->parent; |
| | 23589 | |
| | 23590 | if (peer_parent->resolved_type == nullptr && !ira->const_predecessor_bb) { |
| | 23591 | instruction->result_loc->implicit_elem_type = value->value.type; |
| | 23592 | instruction->result_loc->gen_instruction = value; |
| | 23593 | IrInstruction *suspended_inst = ira_suspend(ira, &instruction->base, result_peer->next_bb, |
| | 23594 | &result_peer->suspend_pos); |
| | 23595 | bool last_one = (result_peer == &peer_parent->peers[peer_parent->peer_count - 1]); |
| | 23596 | if (!last_one) { |
| | 23597 | return suspended_inst; |
| | 23598 | } |
| | 23599 | IrInstruction **instructions = allocate<IrInstruction *>(peer_parent->peer_count); |
| | 23600 | for (size_t i = 0; i < peer_parent->peer_count; i += 1) { |
| | 23601 | instructions[i] = peer_parent->peers[i].base.gen_instruction; |
| | 23602 | ira->resume_stack.append(peer_parent->peers[peer_parent->peer_count - i - 1].suspend_pos); |
| | 23603 | } |
| | 23604 | ZigType *expected_type = ir_result_loc_expected_type(ira, peer_parent->parent); |
| | 23605 | peer_parent->resolved_type = ir_resolve_peer_types(ira, |
| | 23606 | peer_parent->base.source_instruction->source_node, expected_type, instructions, |
| | 23607 | peer_parent->peer_count); |
| | 23608 | return ira_resume(ira); |
| | 23609 | } |
| | 23610 | } |
| | 23611 | IrInstruction *result_loc = ir_resolve_result(ira, instruction->result_loc, value); |
| | 23612 | if (result_loc != nullptr) { |
| | 23613 | ir_analyze_store_ptr(ira, &instruction->base, result_loc, value); |
| | 23614 | } |
| | 23615 | |
| | 23616 | return ir_const_void(ira, &instruction->base); |
| | 23617 | } |
| | 23618 | |
| | 23619 | static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction *instruction) { |
| 23470 | switch (instruction->id) { | 23620 | switch (instruction->id) { |
| 23471 | case IrInstructionIdInvalid: | 23621 | case IrInstructionIdInvalid: |
| 23472 | case IrInstructionIdWidenOrShorten: | 23622 | case IrInstructionIdWidenOrShorten: |
| ... | @@ -23769,17 +23919,12 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio | ... | @@ -23769,17 +23919,12 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio |
| 23769 | return ir_analyze_instruction_undeclared_ident(ira, (IrInstructionUndeclaredIdent *)instruction); | 23919 | return ir_analyze_instruction_undeclared_ident(ira, (IrInstructionUndeclaredIdent *)instruction); |
| 23770 | case IrInstructionIdAllocaSrc: | 23920 | case IrInstructionIdAllocaSrc: |
| 23771 | return nullptr; | 23921 | return nullptr; |
| | 23922 | case IrInstructionIdEndExpr: |
| | 23923 | return ir_analyze_instruction_end_expr(ira, (IrInstructionEndExpr *)instruction); |
| 23772 | } | 23924 | } |
| 23773 | zig_unreachable(); | 23925 | zig_unreachable(); |
| 23774 | } | 23926 | } |
| 23775 | | 23927 | |
| 23776 | static IrInstruction *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *old_instruction) { | | |
| 23777 | IrInstruction *new_instruction = ir_analyze_instruction_nocast(ira, old_instruction); | | |
| 23778 | ir_assert(new_instruction->value.type != nullptr || new_instruction->value.type != nullptr, old_instruction); | | |
| 23779 | old_instruction->child = new_instruction; | | |
| 23780 | return new_instruction; | | |
| 23781 | } | | |
| 23782 | | | |
| 23783 | // This function attempts to evaluate IR code while doing type checking and other analysis. | 23928 | // This function attempts to evaluate IR code while doing type checking and other analysis. |
| 23784 | // It emits a new IrExecutable which is partially evaluated IR code. | 23929 | // It emits a new IrExecutable which is partially evaluated IR code. |
| 23785 | ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec, | 23930 | ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec, |
| ... | @@ -23825,8 +23970,11 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ | ... | @@ -23825,8 +23970,11 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 23825 | continue; | 23970 | continue; |
| 23826 | } | 23971 | } |
| 23827 | | 23972 | |
| 23828 | IrInstruction *new_instruction = ir_analyze_instruction(ira, old_instruction); | 23973 | IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction); |
| 23829 | if (new_instruction != nullptr) { | 23974 | if (new_instruction != nullptr) { |
| | 23975 | ir_assert(new_instruction->value.type != nullptr || new_instruction->value.type != nullptr, old_instruction); |
| | 23976 | old_instruction->child = new_instruction; |
| | 23977 | |
| 23830 | if (type_is_invalid(new_instruction->value.type) && ir_should_inline(new_exec, old_instruction->scope)) { | 23978 | if (type_is_invalid(new_instruction->value.type) && ir_should_inline(new_exec, old_instruction->scope)) { |
| 23831 | return ira->codegen->builtin_types.entry_invalid; | 23979 | return ira->codegen->builtin_types.entry_invalid; |
| 23832 | } | 23980 | } |
| ... | @@ -23907,6 +24055,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { | ... | @@ -23907,6 +24055,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 23907 | case IrInstructionIdResizeSlice: | 24055 | case IrInstructionIdResizeSlice: |
| 23908 | case IrInstructionIdGlobalAsm: | 24056 | case IrInstructionIdGlobalAsm: |
| 23909 | case IrInstructionIdUndeclaredIdent: | 24057 | case IrInstructionIdUndeclaredIdent: |
| | 24058 | case IrInstructionIdEndExpr: |
| 23910 | return true; | 24059 | return true; |
| 23911 | | 24060 | |
| 23912 | case IrInstructionIdPhi: | 24061 | case IrInstructionIdPhi: |