| ... | ... | @@ -792,6 +792,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrCastGen *) { |
| 792 | 792 | return IrInstructionIdPtrCastGen; |
| 793 | 793 | } |
| 794 | 794 | |
| 795 | static constexpr IrInstructionId ir_instruction_id(IrInstructionBitCastSrc *) { |
| 796 | return IrInstructionIdBitCastSrc; |
| 797 | } |
| 798 | |
| 795 | 799 | static constexpr IrInstructionId ir_instruction_id(IrInstructionBitCastGen *) { |
| 796 | 800 | return IrInstructionIdBitCastGen; |
| 797 | 801 | } |
| ... | ... | @@ -2515,6 +2519,18 @@ static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *sourc |
| 2515 | 2519 | return &instruction->base; |
| 2516 | 2520 | } |
| 2517 | 2521 | |
| 2522 | static IrInstruction *ir_build_bit_cast_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2523 | IrInstruction *operand, ResultLocBitCast *result_loc_bit_cast) |
| 2524 | { |
| 2525 | IrInstructionBitCastSrc *instruction = ir_build_instruction<IrInstructionBitCastSrc>(irb, scope, source_node); |
| 2526 | instruction->operand = operand; |
| 2527 | instruction->result_loc_bit_cast = result_loc_bit_cast; |
| 2528 | |
| 2529 | ir_ref_instruction(operand, irb->current_basic_block); |
| 2530 | |
| 2531 | return &instruction->base; |
| 2532 | } |
| 2533 | |
| 2518 | 2534 | static IrInstruction *ir_build_bit_cast_gen(IrAnalyze *ira, IrInstruction *source_instruction, |
| 2519 | 2535 | IrInstruction *operand, ZigType *ty) |
| 2520 | 2536 | { |
| ... | ... | @@ -4941,7 +4957,8 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4941 | 4957 | if (arg1_value == irb->codegen->invalid_instruction) |
| 4942 | 4958 | return arg1_value; |
| 4943 | 4959 | |
| 4944 | | return ir_lval_wrap(irb, scope, arg1_value, lval, result_loc); |
| 4960 | IrInstruction *bitcast = ir_build_bit_cast_src(irb, scope, arg1_node, arg1_value, result_loc_bit_cast); |
| 4961 | return ir_lval_wrap(irb, scope, bitcast, lval, result_loc); |
| 4945 | 4962 | } |
| 4946 | 4963 | case BuiltinFnIdIntToPtr: |
| 4947 | 4964 | { |
| ... | ... | @@ -14910,9 +14927,15 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 14910 | 14927 | return ira->codegen->invalid_instruction; |
| 14911 | 14928 | } |
| 14912 | 14929 | |
| 14930 | IrInstruction *bitcasted_value; |
| 14931 | if (value != nullptr) { |
| 14932 | bitcasted_value = ir_analyze_bit_cast(ira, result_loc->source_instruction, value, dest_type); |
| 14933 | } else { |
| 14934 | bitcasted_value = nullptr; |
| 14935 | } |
| 14913 | 14936 | |
| 14914 | 14937 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent, |
| 14915 | | dest_type, nullptr); |
| 14938 | dest_type, bitcasted_value); |
| 14916 | 14939 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || |
| 14917 | 14940 | parent_result_loc->value.type->id == ZigTypeIdUnreachable) |
| 14918 | 14941 | { |
| ... | ... | @@ -24168,6 +24191,17 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct |
| 24168 | 24191 | return ir_const_void(ira, &instruction->base); |
| 24169 | 24192 | } |
| 24170 | 24193 | |
| 24194 | static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) { |
| 24195 | IrInstruction *operand = instruction->operand->child; |
| 24196 | if (type_is_invalid(operand->value.type) || instr_is_comptime(operand) || |
| 24197 | instruction->result_loc_bit_cast->parent->gen_instruction == nullptr) |
| 24198 | { |
| 24199 | return operand; |
| 24200 | } |
| 24201 | |
| 24202 | return instruction->result_loc_bit_cast->parent->gen_instruction; |
| 24203 | } |
| 24204 | |
| 24171 | 24205 | static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction *instruction) { |
| 24172 | 24206 | switch (instruction->id) { |
| 24173 | 24207 | case IrInstructionIdInvalid: |
| ... | ... | @@ -24472,6 +24506,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction |
| 24472 | 24506 | return nullptr; |
| 24473 | 24507 | case IrInstructionIdEndExpr: |
| 24474 | 24508 | return ir_analyze_instruction_end_expr(ira, (IrInstructionEndExpr *)instruction); |
| 24509 | case IrInstructionIdBitCastSrc: |
| 24510 | return ir_analyze_instruction_bit_cast_src(ira, (IrInstructionBitCastSrc *)instruction); |
| 24475 | 24511 | } |
| 24476 | 24512 | zig_unreachable(); |
| 24477 | 24513 | } |
| ... | ... | @@ -24663,6 +24699,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 24663 | 24699 | case IrInstructionIdTestComptime: |
| 24664 | 24700 | case IrInstructionIdPtrCastSrc: |
| 24665 | 24701 | case IrInstructionIdPtrCastGen: |
| 24702 | case IrInstructionIdBitCastSrc: |
| 24666 | 24703 | case IrInstructionIdBitCastGen: |
| 24667 | 24704 | case IrInstructionIdWidenOrShorten: |
| 24668 | 24705 | case IrInstructionIdPtrToInt: |