authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-10 12:24:19-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-10 12:24:19-04:00
log17b1ac5d03cd32e047d917a88e029c143cb5d119
tree0bdd3b27eaeaccbc17946a79cca6e8b628bb1d38
parent1a51bf63047e9a3cd6ae3273296fded82009235c
signaturelock-open Commit is signed but in an unrecognized format.

result location semantics for `@bitCast`

```zig export fn entry() void { var x = @bitCast(f32, foo()); } ``` ```llvm define void @entry() #2 !dbg !35 { Entry: %x = alloca float, align 4 %0 = bitcast float* %x to %Foo*, !dbg !42 call fastcc void @foo(%Foo* sret %0), !dbg !42 call void @llvm.dbg.declare(metadata float* %x, metadata !39, metadata !DIExpression()), !dbg !43 ret void, !dbg !44 } ```

5 files changed, 103 insertions(+), 130 deletions(-)

BRANCH_TODO+2-2
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1Scratch pad for stuff to do before merging master1Scratch pad for stuff to do before merging master
2=================================================2=================================================
33
4 * bitCast
5
6look at all the ir_gen_node ir_gen_node_extra calls and make sure result locations are properly propagated4look at all the ir_gen_node ir_gen_node_extra calls and make sure result locations are properly propagated
7 return ir_gen_comptime(irb, scope, node, lval);5 return ir_gen_comptime(irb, scope, node, lval);
86
...@@ -23,3 +21,5 @@ inferred comptime...@@ -23,3 +21,5 @@ inferred comptime
23 return ir_build_ref(irb, scope, value->source_node, value, false, false);21 return ir_build_ref(irb, scope, value->source_node, value, false, false);
2422
25handle if with no else23handle if with no else
24
25
src/all_types.hpp+8-10
...@@ -2267,7 +2267,6 @@ enum IrInstructionId {...@@ -2267,7 +2267,6 @@ enum IrInstructionId {
2267 IrInstructionIdTestComptime,2267 IrInstructionIdTestComptime,
2268 IrInstructionIdPtrCastSrc,2268 IrInstructionIdPtrCastSrc,
2269 IrInstructionIdPtrCastGen,2269 IrInstructionIdPtrCastGen,
2270 IrInstructionIdBitCast,
2271 IrInstructionIdBitCastGen,2270 IrInstructionIdBitCastGen,
2272 IrInstructionIdWidenOrShorten,2271 IrInstructionIdWidenOrShorten,
2273 IrInstructionIdIntToPtr,2272 IrInstructionIdIntToPtr,
...@@ -2645,7 +2644,6 @@ struct IrInstructionContainerInitList {...@@ -2645,7 +2644,6 @@ struct IrInstructionContainerInitList {
2645 IrInstruction *elem_type;2644 IrInstruction *elem_type;
2646 size_t item_count;2645 size_t item_count;
2647 IrInstruction **items;2646 IrInstruction **items;
2648 LLVMValueRef tmp_ptr;
2649};2647};
26502648
2651struct IrInstructionContainerInitFieldsField {2649struct IrInstructionContainerInitFieldsField {
...@@ -3136,18 +3134,10 @@ struct IrInstructionPtrCastGen {...@@ -3136,18 +3134,10 @@ struct IrInstructionPtrCastGen {
3136 bool safety_check_on;3134 bool safety_check_on;
3137};3135};
31383136
3139struct IrInstructionBitCast {
3140 IrInstruction base;
3141
3142 IrInstruction *dest_type;
3143 IrInstruction *value;
3144};
3145
3146struct IrInstructionBitCastGen {3137struct IrInstructionBitCastGen {
3147 IrInstruction base;3138 IrInstruction base;
31483139
3149 IrInstruction *operand;3140 IrInstruction *operand;
3150 LLVMValueRef tmp_ptr;
3151};3141};
31523142
3153struct IrInstructionWidenOrShorten {3143struct IrInstructionWidenOrShorten {
...@@ -3590,6 +3580,7 @@ enum ResultLocId {...@@ -3590,6 +3580,7 @@ enum ResultLocId {
3590 ResultLocIdPeer,3580 ResultLocIdPeer,
3591 ResultLocIdPeerParent,3581 ResultLocIdPeerParent,
3592 ResultLocIdInstruction,3582 ResultLocIdInstruction,
3583 ResultLocIdBitCast,
3593};3584};
35943585
3595struct ResultLoc {3586struct ResultLoc {
...@@ -3644,6 +3635,13 @@ struct ResultLocInstruction {...@@ -3644,6 +3635,13 @@ struct ResultLocInstruction {
3644 ResultLoc base;3635 ResultLoc base;
3645};3636};
36463637
3638// The source_instruction is the destination type
3639struct ResultLocBitCast {
3640 ResultLoc base;
3641
3642 ResultLoc *parent;
3643};
3644
3647static const size_t slice_ptr_index = 0;3645static const size_t slice_ptr_index = 0;
3648static const size_t slice_len_index = 1;3646static const size_t slice_len_index = 1;
36493647
src/codegen.cpp+1-13
...@@ -3145,12 +3145,7 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,...@@ -3145,12 +3145,7 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,
3145 uint32_t alignment = get_abi_alignment(g, actual_type);3145 uint32_t alignment = get_abi_alignment(g, actual_type);
3146 return gen_load_untyped(g, bitcasted_ptr, alignment, false, "");3146 return gen_load_untyped(g, bitcasted_ptr, alignment, false, "");
3147 } else {3147 } else {
3148 assert(instruction->tmp_ptr != nullptr);3148 zig_unreachable();
3149 LLVMTypeRef wanted_ptr_type_ref = LLVMPointerType(get_llvm_type(g, actual_type), 0);
3150 LLVMValueRef bitcasted_ptr = LLVMBuildBitCast(g->builder, instruction->tmp_ptr, wanted_ptr_type_ref, "");
3151 uint32_t alignment = get_abi_alignment(g, wanted_type);
3152 gen_store_untyped(g, value, bitcasted_ptr, alignment, false);
3153 return instruction->tmp_ptr;
3154 }3149 }
3155}3150}
31563151
...@@ -5520,7 +5515,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -5520,7 +5515,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
5520 case IrInstructionIdPtrCastSrc:5515 case IrInstructionIdPtrCastSrc:
5521 case IrInstructionIdCmpxchgSrc:5516 case IrInstructionIdCmpxchgSrc:
5522 case IrInstructionIdLoadPtr:5517 case IrInstructionIdLoadPtr:
5523 case IrInstructionIdBitCast:
5524 case IrInstructionIdGlobalAsm:5518 case IrInstructionIdGlobalAsm:
5525 case IrInstructionIdHasDecl:5519 case IrInstructionIdHasDecl:
5526 case IrInstructionIdUndeclaredIdent:5520 case IrInstructionIdUndeclaredIdent:
...@@ -6837,9 +6831,6 @@ static void do_code_gen(CodeGen *g) {...@@ -6837,9 +6831,6 @@ static void do_code_gen(CodeGen *g) {
6837 slot = &ref_instruction->tmp_ptr;6831 slot = &ref_instruction->tmp_ptr;
6838 assert(instruction->value.type->id == ZigTypeIdPointer);6832 assert(instruction->value.type->id == ZigTypeIdPointer);
6839 slot_type = instruction->value.type->data.pointer.child_type;6833 slot_type = instruction->value.type->data.pointer.child_type;
6840 } else if (instruction->id == IrInstructionIdContainerInitList) {
6841 IrInstructionContainerInitList *container_init_list_instruction = (IrInstructionContainerInitList *)instruction;
6842 slot = &container_init_list_instruction->tmp_ptr;
6843 } else if (instruction->id == IrInstructionIdSlice) {6834 } else if (instruction->id == IrInstructionIdSlice) {
6844 IrInstructionSlice *slice_instruction = (IrInstructionSlice *)instruction;6835 IrInstructionSlice *slice_instruction = (IrInstructionSlice *)instruction;
6845 slot = &slice_instruction->tmp_ptr;6836 slot = &slice_instruction->tmp_ptr;
...@@ -6861,9 +6852,6 @@ static void do_code_gen(CodeGen *g) {...@@ -6861,9 +6852,6 @@ static void do_code_gen(CodeGen *g) {
6861 } else if (instruction->id == IrInstructionIdLoadPtrGen) {6852 } else if (instruction->id == IrInstructionIdLoadPtrGen) {
6862 IrInstructionLoadPtrGen *load_ptr_inst = (IrInstructionLoadPtrGen *)instruction;6853 IrInstructionLoadPtrGen *load_ptr_inst = (IrInstructionLoadPtrGen *)instruction;
6863 slot = &load_ptr_inst->tmp_ptr;6854 slot = &load_ptr_inst->tmp_ptr;
6864 } else if (instruction->id == IrInstructionIdBitCastGen) {
6865 IrInstructionBitCastGen *bit_cast_inst = (IrInstructionBitCastGen *)instruction;
6866 slot = &bit_cast_inst->tmp_ptr;
6867 } else if (instruction->id == IrInstructionIdVectorToArray) {6855 } else if (instruction->id == IrInstructionIdVectorToArray) {
6868 IrInstructionVectorToArray *vector_to_array_instruction = (IrInstructionVectorToArray *)instruction;6856 IrInstructionVectorToArray *vector_to_array_instruction = (IrInstructionVectorToArray *)instruction;
6869 alignment_bytes = get_abi_alignment(g, vector_to_array_instruction->vector->value.type);6857 alignment_bytes = get_abi_alignment(g, vector_to_array_instruction->vector->value.type);
src/ir.cpp+84-94
...@@ -780,10 +780,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrCastGen *) {...@@ -780,10 +780,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrCastGen *) {
780 return IrInstructionIdPtrCastGen;780 return IrInstructionIdPtrCastGen;
781}781}
782782
783static constexpr IrInstructionId ir_instruction_id(IrInstructionBitCast *) {
784 return IrInstructionIdBitCast;
785}
786
787static constexpr IrInstructionId ir_instruction_id(IrInstructionBitCastGen *) {783static constexpr IrInstructionId ir_instruction_id(IrInstructionBitCastGen *) {
788 return IrInstructionIdBitCastGen;784 return IrInstructionIdBitCastGen;
789}785}
...@@ -2429,20 +2425,6 @@ static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *sourc...@@ -2429,20 +2425,6 @@ static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *sourc
2429 return &instruction->base;2425 return &instruction->base;
2430}2426}
24312427
2432static IrInstruction *ir_build_bit_cast(IrBuilder *irb, Scope *scope, AstNode *source_node,
2433 IrInstruction *dest_type, IrInstruction *value)
2434{
2435 IrInstructionBitCast *instruction = ir_build_instruction<IrInstructionBitCast>(
2436 irb, scope, source_node);
2437 instruction->dest_type = dest_type;
2438 instruction->value = value;
2439
2440 ir_ref_instruction(dest_type, irb->current_basic_block);
2441 ir_ref_instruction(value, irb->current_basic_block);
2442
2443 return &instruction->base;
2444}
2445
2446static IrInstruction *ir_build_bit_cast_gen(IrAnalyze *ira, IrInstruction *source_instruction,2428static IrInstruction *ir_build_bit_cast_gen(IrAnalyze *ira, IrInstruction *source_instruction,
2447 IrInstruction *operand, ZigType *ty)2429 IrInstruction *operand, ZigType *ty)
2448{2430{
...@@ -4836,18 +4818,23 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -4836,18 +4818,23 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
4836 }4818 }
4837 case BuiltinFnIdBitCast:4819 case BuiltinFnIdBitCast:
4838 {4820 {
4839 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);4821 AstNode *dest_type_node = node->data.fn_call_expr.params.at(0);
4840 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);4822 IrInstruction *dest_type = ir_gen_node(irb, dest_type_node, scope);
4841 if (arg0_value == irb->codegen->invalid_instruction)4823 if (dest_type == irb->codegen->invalid_instruction)
4842 return arg0_value;4824 return dest_type;
4825
4826 ResultLocBitCast *result_loc_bit_cast = allocate<ResultLocBitCast>(1);
4827 result_loc_bit_cast->base.id = ResultLocIdBitCast;
4828 result_loc_bit_cast->base.source_instruction = dest_type;
4829 result_loc_bit_cast->parent = result_loc;
48434830
4844 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);4831 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4845 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);4832 IrInstruction *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone,
4833 &result_loc_bit_cast->base);
4846 if (arg1_value == irb->codegen->invalid_instruction)4834 if (arg1_value == irb->codegen->invalid_instruction)
4847 return arg1_value;4835 return arg1_value;
48484836
4849 IrInstruction *bit_cast = ir_build_bit_cast(irb, scope, node, arg0_value, arg1_value);4837 return ir_lval_wrap(irb, scope, arg1_value, lval, result_loc);
4850 return ir_lval_wrap(irb, scope, bit_cast, lval, result_loc);
4851 }4838 }
4852 case BuiltinFnIdIntToPtr:4839 case BuiltinFnIdIntToPtr:
4853 {4840 {
...@@ -14059,9 +14046,10 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -14059,9 +14046,10 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
14059 bool var_class_requires_const = false;14046 bool var_class_requires_const = false;
1406014047
14061 IrInstruction *var_ptr = decl_var_instruction->ptr->child;14048 IrInstruction *var_ptr = decl_var_instruction->ptr->child;
14062 // if this assertion trips there may be a missing ir_expr_wrap in pass1 IR generation.14049 // if this is null, a compiler error happened and did not initialize the variable.
14063 ir_assert(var_ptr != nullptr, &decl_var_instruction->base);14050 // if there are no compile errors there may be a missing ir_expr_wrap in pass1 IR generation.
14064 if (type_is_invalid(var_ptr->value.type)) {14051 if (var_ptr == nullptr || type_is_invalid(var_ptr->value.type)) {
14052 ir_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, &decl_var_instruction->base);
14065 var->var_type = ira->codegen->builtin_types.entry_invalid;14053 var->var_type = ira->codegen->builtin_types.entry_invalid;
14066 return ira->codegen->invalid_instruction;14054 return ira->codegen->invalid_instruction;
14067 }14055 }
...@@ -14528,6 +14516,7 @@ static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInstruction *suspe...@@ -14528,6 +14516,7 @@ static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInstruction *suspe
14528 zig_unreachable();14516 zig_unreachable();
14529 case ResultLocIdNone:14517 case ResultLocIdNone:
14530 case ResultLocIdVar:14518 case ResultLocIdVar:
14519 case ResultLocIdBitCast:
14531 return nullptr;14520 return nullptr;
14532 case ResultLocIdInstruction:14521 case ResultLocIdInstruction:
14533 return result_loc->source_instruction->child->value.type;14522 return result_loc->source_instruction->child->value.type;
...@@ -14539,6 +14528,28 @@ static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInstruction *suspe...@@ -14539,6 +14528,28 @@ static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInstruction *suspe
14539 zig_unreachable();14528 zig_unreachable();
14540}14529}
1454114530
14531static bool type_can_bit_cast(ZigType *t) {
14532 switch (t->id) {
14533 case ZigTypeIdInvalid:
14534 zig_unreachable();
14535 case ZigTypeIdMetaType:
14536 case ZigTypeIdOpaque:
14537 case ZigTypeIdBoundFn:
14538 case ZigTypeIdArgTuple:
14539 case ZigTypeIdUnreachable:
14540 case ZigTypeIdComptimeFloat:
14541 case ZigTypeIdComptimeInt:
14542 case ZigTypeIdEnumLiteral:
14543 case ZigTypeIdUndefined:
14544 case ZigTypeIdNull:
14545 case ZigTypeIdPointer:
14546 return false;
14547 default:
14548 // TODO list these types out explicitly, there are probably some other invalid ones here
14549 return true;
14550 }
14551}
14552
14542// give nullptr for value to resolve it at runtime14553// give nullptr for value to resolve it at runtime
14543// returns a result location, or nullptr if the result location was already taken care of14554// returns a result location, or nullptr if the result location was already taken care of
14544// when calling this function, at the callsite must check for result type noreturn and propagate it up14555// when calling this function, at the callsite must check for result type noreturn and propagate it up
...@@ -14676,6 +14687,50 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s...@@ -14676,6 +14687,50 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
14676 result_loc->resolved_loc = parent_result_loc;14687 result_loc->resolved_loc = parent_result_loc;
14677 return result_loc->resolved_loc;14688 return result_loc->resolved_loc;
14678 }14689 }
14690 case ResultLocIdBitCast: {
14691 ResultLocBitCast *result_bit_cast = reinterpret_cast<ResultLocBitCast *>(result_loc);
14692 ZigType *dest_type = ir_resolve_type(ira, result_bit_cast->base.source_instruction->child);
14693 if (type_is_invalid(dest_type))
14694 return ira->codegen->invalid_instruction;
14695
14696 if (get_codegen_ptr_type(dest_type) != nullptr) {
14697 ir_add_error(ira, result_loc->source_instruction,
14698 buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name)));
14699 return ira->codegen->invalid_instruction;
14700 }
14701
14702 if (!type_can_bit_cast(dest_type)) {
14703 ir_add_error(ira, result_loc->source_instruction,
14704 buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name)));
14705 return ira->codegen->invalid_instruction;
14706 }
14707
14708 if (get_codegen_ptr_type(value_type) != nullptr) {
14709 ir_add_error(ira, suspend_source_instr,
14710 buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&value_type->name)));
14711 return ira->codegen->invalid_instruction;
14712 }
14713
14714 if (!type_can_bit_cast(value_type)) {
14715 ir_add_error(ira, suspend_source_instr,
14716 buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&value_type->name)));
14717 return ira->codegen->invalid_instruction;
14718 }
14719
14720
14721 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent,
14722 dest_type, nullptr);
14723 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) ||
14724 parent_result_loc->value.type->id == ZigTypeIdUnreachable)
14725 {
14726 return parent_result_loc;
14727 }
14728 ZigType *ptr_type = get_pointer_to_type(ira->codegen, value_type, false);
14729 result_loc->written = true;
14730 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,
14731 ptr_type, result_bit_cast->base.source_instruction, false);
14732 return result_loc->resolved_loc;
14733 }
14679 }14734 }
14680 zig_unreachable();14735 zig_unreachable();
14681}14736}
...@@ -22755,28 +22810,6 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou...@@ -22755,28 +22810,6 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
22755 zig_unreachable();22810 zig_unreachable();
22756}22811}
2275722812
22758static bool type_can_bit_cast(ZigType *t) {
22759 switch (t->id) {
22760 case ZigTypeIdInvalid:
22761 zig_unreachable();
22762 case ZigTypeIdMetaType:
22763 case ZigTypeIdOpaque:
22764 case ZigTypeIdBoundFn:
22765 case ZigTypeIdArgTuple:
22766 case ZigTypeIdUnreachable:
22767 case ZigTypeIdComptimeFloat:
22768 case ZigTypeIdComptimeInt:
22769 case ZigTypeIdEnumLiteral:
22770 case ZigTypeIdUndefined:
22771 case ZigTypeIdNull:
22772 case ZigTypeIdPointer:
22773 return false;
22774 default:
22775 // TODO list these types out explicitly, there are probably some other invalid ones here
22776 return true;
22777 }
22778}
22779
22780static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,22813static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
22781 ZigType *dest_type)22814 ZigType *dest_type)
22782{22815{
...@@ -22829,50 +22862,10 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_...@@ -22829,50 +22862,10 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
22829 }22862 }
2283022863
22831 IrInstruction *result = ir_build_bit_cast_gen(ira, source_instr, value, dest_type);22864 IrInstruction *result = ir_build_bit_cast_gen(ira, source_instr, value, dest_type);
22832 if (handle_is_ptr(dest_type) && !handle_is_ptr(src_type)) {22865 assert(!(handle_is_ptr(dest_type) && !handle_is_ptr(src_type)));
22833 ir_add_alloca(ira, result, dest_type);
22834 }
22835 return result;22866 return result;
22836}22867}
2283722868
22838static IrInstruction *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBitCast *instruction) {
22839 IrInstruction *dest_type_value = instruction->dest_type->child;
22840 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
22841 if (type_is_invalid(dest_type))
22842 return ira->codegen->invalid_instruction;
22843
22844 IrInstruction *value = instruction->value->child;
22845 ZigType *src_type = value->value.type;
22846 if (type_is_invalid(src_type))
22847 return ira->codegen->invalid_instruction;
22848
22849 if (get_codegen_ptr_type(src_type) != nullptr) {
22850 ir_add_error(ira, value,
22851 buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&src_type->name)));
22852 return ira->codegen->invalid_instruction;
22853 }
22854
22855 if (!type_can_bit_cast(src_type)) {
22856 ir_add_error(ira, dest_type_value,
22857 buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&src_type->name)));
22858 return ira->codegen->invalid_instruction;
22859 }
22860
22861 if (get_codegen_ptr_type(dest_type) != nullptr) {
22862 ir_add_error(ira, dest_type_value,
22863 buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name)));
22864 return ira->codegen->invalid_instruction;
22865 }
22866
22867 if (!type_can_bit_cast(dest_type)) {
22868 ir_add_error(ira, dest_type_value,
22869 buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name)));
22870 return ira->codegen->invalid_instruction;
22871 }
22872
22873 return ir_analyze_bit_cast(ira, &instruction->base, value, dest_type);
22874}
22875
22876static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,22869static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
22877 ZigType *ptr_type)22870 ZigType *ptr_type)
22878{22871{
...@@ -24089,8 +24082,6 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction...@@ -24089,8 +24082,6 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction
24089 return ir_analyze_instruction_panic(ira, (IrInstructionPanic *)instruction);24082 return ir_analyze_instruction_panic(ira, (IrInstructionPanic *)instruction);
24090 case IrInstructionIdPtrCastSrc:24083 case IrInstructionIdPtrCastSrc:
24091 return ir_analyze_instruction_ptr_cast(ira, (IrInstructionPtrCastSrc *)instruction);24084 return ir_analyze_instruction_ptr_cast(ira, (IrInstructionPtrCastSrc *)instruction);
24092 case IrInstructionIdBitCast:
24093 return ir_analyze_instruction_bit_cast(ira, (IrInstructionBitCast *)instruction);
24094 case IrInstructionIdIntToPtr:24085 case IrInstructionIdIntToPtr:
24095 return ir_analyze_instruction_int_to_ptr(ira, (IrInstructionIntToPtr *)instruction);24086 return ir_analyze_instruction_int_to_ptr(ira, (IrInstructionIntToPtr *)instruction);
24096 case IrInstructionIdPtrToInt:24087 case IrInstructionIdPtrToInt:
...@@ -24386,7 +24377,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -24386,7 +24377,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {
24386 case IrInstructionIdTestComptime:24377 case IrInstructionIdTestComptime:
24387 case IrInstructionIdPtrCastSrc:24378 case IrInstructionIdPtrCastSrc:
24388 case IrInstructionIdPtrCastGen:24379 case IrInstructionIdPtrCastGen:
24389 case IrInstructionIdBitCast:
24390 case IrInstructionIdBitCastGen:24380 case IrInstructionIdBitCastGen:
24391 case IrInstructionIdWidenOrShorten:24381 case IrInstructionIdWidenOrShorten:
24392 case IrInstructionIdPtrToInt:24382 case IrInstructionIdPtrToInt:
src/ir_print.cpp+8-11
...@@ -219,6 +219,12 @@ static void ir_print_result_loc_peer(IrPrint *irp, ResultLocPeer *result_loc_pee...@@ -219,6 +219,12 @@ static void ir_print_result_loc_peer(IrPrint *irp, ResultLocPeer *result_loc_pee
219 fprintf(irp->f, ")");219 fprintf(irp->f, ")");
220}220}
221221
222static void ir_print_result_loc_bit_cast(IrPrint *irp, ResultLocBitCast *result_loc_bit_cast) {
223 fprintf(irp->f, "bitcast(ty=");
224 ir_print_other_instruction(irp, result_loc_bit_cast->base.source_instruction);
225 fprintf(irp->f, ")");
226}
227
222static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {228static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {
223 switch (result_loc->id) {229 switch (result_loc->id) {
224 case ResultLocIdInvalid:230 case ResultLocIdInvalid:
...@@ -235,6 +241,8 @@ static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {...@@ -235,6 +241,8 @@ static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {
235 return ir_print_result_loc_instruction(irp, (ResultLocInstruction *)result_loc);241 return ir_print_result_loc_instruction(irp, (ResultLocInstruction *)result_loc);
236 case ResultLocIdPeer:242 case ResultLocIdPeer:
237 return ir_print_result_loc_peer(irp, (ResultLocPeer *)result_loc);243 return ir_print_result_loc_peer(irp, (ResultLocPeer *)result_loc);
244 case ResultLocIdBitCast:
245 return ir_print_result_loc_bit_cast(irp, (ResultLocBitCast *)result_loc);
238 case ResultLocIdPeerParent:246 case ResultLocIdPeerParent:
239 fprintf(irp->f, "peer_parent");247 fprintf(irp->f, "peer_parent");
240 return;248 return;
...@@ -1011,14 +1019,6 @@ static void ir_print_ptr_cast_gen(IrPrint *irp, IrInstructionPtrCastGen *instruc...@@ -1011,14 +1019,6 @@ static void ir_print_ptr_cast_gen(IrPrint *irp, IrInstructionPtrCastGen *instruc
1011 fprintf(irp->f, ")");1019 fprintf(irp->f, ")");
1012}1020}
10131021
1014static void ir_print_bit_cast(IrPrint *irp, IrInstructionBitCast *instruction) {
1015 fprintf(irp->f, "@bitCast(");
1016 ir_print_other_instruction(irp, instruction->dest_type);
1017 fprintf(irp->f, ",");
1018 ir_print_other_instruction(irp, instruction->value);
1019 fprintf(irp->f, ")");
1020}
1021
1022static void ir_print_bit_cast_gen(IrPrint *irp, IrInstructionBitCastGen *instruction) {1022static void ir_print_bit_cast_gen(IrPrint *irp, IrInstructionBitCastGen *instruction) {
1023 fprintf(irp->f, "@bitCast(");1023 fprintf(irp->f, "@bitCast(");
1024 ir_print_other_instruction(irp, instruction->operand);1024 ir_print_other_instruction(irp, instruction->operand);
...@@ -1818,9 +1818,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -1818,9 +1818,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
1818 case IrInstructionIdPtrCastGen:1818 case IrInstructionIdPtrCastGen:
1819 ir_print_ptr_cast_gen(irp, (IrInstructionPtrCastGen *)instruction);1819 ir_print_ptr_cast_gen(irp, (IrInstructionPtrCastGen *)instruction);
1820 break;1820 break;
1821 case IrInstructionIdBitCast:
1822 ir_print_bit_cast(irp, (IrInstructionBitCast *)instruction);
1823 break;
1824 case IrInstructionIdBitCastGen:1821 case IrInstructionIdBitCastGen:
1825 ir_print_bit_cast_gen(irp, (IrInstructionBitCastGen *)instruction);1822 ir_print_bit_cast_gen(irp, (IrInstructionBitCastGen *)instruction);
1826 break;1823 break;