authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-10 11:15:32-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-10 11:15:32-04:00
log1a51bf63047e9a3cd6ae3273296fded82009235c
treea0ed33775740c091baad17c8dffdc5c9c272cefb
parent4e2b2822f18577edb614bdc3ec6808a0587662e5
signaturelock-open Commit is signed but in an unrecognized format.

hook up result locations for union initializations

```zig export fn entry() void { var x = Foo{ .bar = bar() }; } ``` ```llvm define void @entry() #2 !dbg !44 { Entry: %x = alloca %Foo, align 4 %0 = getelementptr inbounds %Foo, %Foo* %x, i32 0, i32 1, !dbg !68 store i1 true, i1* %0, align 1, !dbg !68 %1 = getelementptr inbounds %Foo, %Foo* %x, i32 0, i32 0, !dbg !68 %2 = bitcast { i32, [4 x i8] }* %1 to %Bar*, !dbg !68 call fastcc void @bar(%Bar* sret %2), !dbg !68 call void @llvm.dbg.declare(metadata %Foo* %x, metadata !48, metadata !DIExpression()), !dbg !69 ret void, !dbg !70 } ```

5 files changed, 56 insertions(+), 128 deletions(-)

BRANCH_TODO-1
...@@ -1,7 +1,6 @@...@@ -1,7 +1,6 @@
1Scratch pad for stuff to do before merging master1Scratch pad for stuff to do before merging master
2=================================================2=================================================
33
4 * union initializations
5 * bitCast4 * bitCast
65
7look at all the ir_gen_node ir_gen_node_extra calls and make sure result locations are properly propagated6look at all the ir_gen_node ir_gen_node_extra calls and make sure result locations are properly propagated
src/all_types.hpp+2-11
...@@ -2204,7 +2204,6 @@ enum IrInstructionId {...@@ -2204,7 +2204,6 @@ enum IrInstructionId {
2204 IrInstructionIdResizeSlice,2204 IrInstructionIdResizeSlice,
2205 IrInstructionIdContainerInitList,2205 IrInstructionIdContainerInitList,
2206 IrInstructionIdContainerInitFields,2206 IrInstructionIdContainerInitFields,
2207 IrInstructionIdUnionInit,
2208 IrInstructionIdUnreachable,2207 IrInstructionIdUnreachable,
2209 IrInstructionIdTypeOf,2208 IrInstructionIdTypeOf,
2210 IrInstructionIdSetCold,2209 IrInstructionIdSetCold,
...@@ -2520,6 +2519,7 @@ struct IrInstructionStorePtr {...@@ -2520,6 +2519,7 @@ struct IrInstructionStorePtr {
2520struct IrInstructionFieldPtr {2519struct IrInstructionFieldPtr {
2521 IrInstruction base;2520 IrInstruction base;
25222521
2522 bool initializing;
2523 IrInstruction *container_ptr;2523 IrInstruction *container_ptr;
2524 Buf *field_name_buffer;2524 Buf *field_name_buffer;
2525 IrInstruction *field_name_expr;2525 IrInstruction *field_name_expr;
...@@ -2536,9 +2536,9 @@ struct IrInstructionStructFieldPtr {...@@ -2536,9 +2536,9 @@ struct IrInstructionStructFieldPtr {
2536struct IrInstructionUnionFieldPtr {2536struct IrInstructionUnionFieldPtr {
2537 IrInstruction base;2537 IrInstruction base;
25382538
2539 bool initializing;
2539 IrInstruction *union_ptr;2540 IrInstruction *union_ptr;
2540 TypeUnionField *field;2541 TypeUnionField *field;
2541 bool is_const;
2542};2542};
25432543
2544struct IrInstructionElemPtr {2544struct IrInstructionElemPtr {
...@@ -2663,15 +2663,6 @@ struct IrInstructionContainerInitFields {...@@ -2663,15 +2663,6 @@ struct IrInstructionContainerInitFields {
2663 IrInstructionContainerInitFieldsField *fields;2663 IrInstructionContainerInitFieldsField *fields;
2664};2664};
26652665
2666struct IrInstructionUnionInit {
2667 IrInstruction base;
2668
2669 ZigType *union_type;
2670 TypeUnionField *field;
2671 IrInstruction *init_value;
2672 LLVMValueRef tmp_ptr;
2673};
2674
2675struct IrInstructionUnreachable {2666struct IrInstructionUnreachable {
2676 IrInstruction base;2667 IrInstruction base;
2677};2668};
src/codegen.cpp+6-43
...@@ -3859,7 +3859,12 @@ static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executab...@@ -3859,7 +3859,12 @@ static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executab
3859 return bitcasted_union_field_ptr;3859 return bitcasted_union_field_ptr;
3860 }3860 }
38613861
3862 if (ir_want_runtime_safety(g, &instruction->base)) {3862 if (instruction->initializing) {
3863 LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, union_ptr, union_type->data.unionation.gen_tag_index, "");
3864 LLVMValueRef tag_value = bigint_to_llvm_const(get_llvm_type(g, union_type->data.unionation.tag_type),
3865 &field->enum_field->value);
3866 gen_store_untyped(g, tag_value, tag_field_ptr, 0, false);
3867 } else if (ir_want_runtime_safety(g, &instruction->base)) {
3863 LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, union_ptr, union_type->data.unionation.gen_tag_index, "");3868 LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, union_ptr, union_type->data.unionation.gen_tag_index, "");
3864 LLVMValueRef tag_value = gen_load_untyped(g, tag_field_ptr, 0, false, "");3869 LLVMValueRef tag_value = gen_load_untyped(g, tag_field_ptr, 0, false, "");
38653870
...@@ -5035,43 +5040,6 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, Ir...@@ -5035,43 +5040,6 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, Ir
5035 return get_handle_value(g, tag_field_ptr, tag_type, ptr_type);5040 return get_handle_value(g, tag_field_ptr, tag_type, ptr_type);
5036}5041}
50375042
5038static LLVMValueRef ir_render_union_init(CodeGen *g, IrExecutable *executable, IrInstructionUnionInit *instruction) {
5039 TypeUnionField *type_union_field = instruction->field;
5040
5041 if (!type_has_bits(type_union_field->type_entry))
5042 return nullptr;
5043
5044 uint32_t field_align_bytes = get_abi_alignment(g, type_union_field->type_entry);
5045 ZigType *ptr_type = get_pointer_to_type_extra(g, type_union_field->type_entry,
5046 false, false, PtrLenSingle, field_align_bytes,
5047 0, 0, false);
5048
5049 LLVMValueRef uncasted_union_ptr;
5050 // Even if safety is off in this block, if the union type has the safety field, we have to populate it
5051 // correctly. Otherwise safety code somewhere other than here could fail.
5052 ZigType *union_type = instruction->union_type;
5053 if (union_type->data.unionation.gen_tag_index != SIZE_MAX) {
5054 LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr,
5055 union_type->data.unionation.gen_tag_index, "");
5056
5057 LLVMValueRef tag_value = bigint_to_llvm_const(get_llvm_type(g, union_type->data.unionation.tag_type),
5058 &type_union_field->enum_field->value);
5059 gen_store_untyped(g, tag_value, tag_field_ptr, 0, false);
5060
5061 uncasted_union_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr,
5062 (unsigned)union_type->data.unionation.gen_union_index, "");
5063 } else {
5064 uncasted_union_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr, (unsigned)0, "");
5065 }
5066
5067 LLVMValueRef field_ptr = LLVMBuildBitCast(g->builder, uncasted_union_ptr, get_llvm_type(g, ptr_type), "");
5068 LLVMValueRef value = ir_llvm_value(g, instruction->init_value);
5069
5070 gen_assign_raw(g, field_ptr, ptr_type, value);
5071
5072 return instruction->tmp_ptr;
5073}
5074
5075static LLVMValueRef ir_render_panic(CodeGen *g, IrExecutable *executable, IrInstructionPanic *instruction) {5043static LLVMValueRef ir_render_panic(CodeGen *g, IrExecutable *executable, IrInstructionPanic *instruction) {
5076 gen_panic(g, ir_llvm_value(g, instruction->msg), get_cur_err_ret_trace_val(g, instruction->base.scope));5044 gen_panic(g, ir_llvm_value(g, instruction->msg), get_cur_err_ret_trace_val(g, instruction->base.scope));
5077 return nullptr;5045 return nullptr;
...@@ -5659,8 +5627,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -5659,8 +5627,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
5659 return ir_render_err_wrap_payload(g, executable, (IrInstructionErrWrapPayload *)instruction);5627 return ir_render_err_wrap_payload(g, executable, (IrInstructionErrWrapPayload *)instruction);
5660 case IrInstructionIdUnionTag:5628 case IrInstructionIdUnionTag:
5661 return ir_render_union_tag(g, executable, (IrInstructionUnionTag *)instruction);5629 return ir_render_union_tag(g, executable, (IrInstructionUnionTag *)instruction);
5662 case IrInstructionIdUnionInit:
5663 return ir_render_union_init(g, executable, (IrInstructionUnionInit *)instruction);
5664 case IrInstructionIdPtrCastGen:5630 case IrInstructionIdPtrCastGen:
5665 return ir_render_ptr_cast(g, executable, (IrInstructionPtrCastGen *)instruction);5631 return ir_render_ptr_cast(g, executable, (IrInstructionPtrCastGen *)instruction);
5666 case IrInstructionIdBitCastGen:5632 case IrInstructionIdBitCastGen:
...@@ -6874,9 +6840,6 @@ static void do_code_gen(CodeGen *g) {...@@ -6874,9 +6840,6 @@ static void do_code_gen(CodeGen *g) {
6874 } else if (instruction->id == IrInstructionIdContainerInitList) {6840 } else if (instruction->id == IrInstructionIdContainerInitList) {
6875 IrInstructionContainerInitList *container_init_list_instruction = (IrInstructionContainerInitList *)instruction;6841 IrInstructionContainerInitList *container_init_list_instruction = (IrInstructionContainerInitList *)instruction;
6876 slot = &container_init_list_instruction->tmp_ptr;6842 slot = &container_init_list_instruction->tmp_ptr;
6877 } else if (instruction->id == IrInstructionIdUnionInit) {
6878 IrInstructionUnionInit *union_init_instruction = (IrInstructionUnionInit *)instruction;
6879 slot = &union_init_instruction->tmp_ptr;
6880 } else if (instruction->id == IrInstructionIdSlice) {6843 } else if (instruction->id == IrInstructionIdSlice) {
6881 IrInstructionSlice *slice_instruction = (IrInstructionSlice *)instruction;6844 IrInstructionSlice *slice_instruction = (IrInstructionSlice *)instruction;
6882 slot = &slice_instruction->tmp_ptr;6845 slot = &slice_instruction->tmp_ptr;
src/ir.cpp+48-61
...@@ -164,7 +164,7 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Zig...@@ -164,7 +164,7 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Zig
164static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr);164static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr);
165static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);165static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);
166static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,166static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
167 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type);167 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type, bool initializing);
168static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var);168static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var);
169static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);169static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);
170static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval, ResultLoc *result_loc);170static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval, ResultLoc *result_loc);
...@@ -616,10 +616,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionRef *) {...@@ -616,10 +616,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionRef *) {
616 return IrInstructionIdRef;616 return IrInstructionIdRef;
617}617}
618618
619static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionInit *) {
620 return IrInstructionIdUnionInit;
621}
622
623static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileErr *) {619static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileErr *) {
624 return IrInstructionIdCompileErr;620 return IrInstructionIdCompileErr;
625}621}
...@@ -1312,12 +1308,13 @@ static IrInstruction *ir_build_field_ptr_instruction(IrBuilder *irb, Scope *scop...@@ -1312,12 +1308,13 @@ static IrInstruction *ir_build_field_ptr_instruction(IrBuilder *irb, Scope *scop
1312}1308}
13131309
1314static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,1310static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
1315 IrInstruction *container_ptr, Buf *field_name)1311 IrInstruction *container_ptr, Buf *field_name, bool initializing)
1316{1312{
1317 IrInstructionFieldPtr *instruction = ir_build_instruction<IrInstructionFieldPtr>(irb, scope, source_node);1313 IrInstructionFieldPtr *instruction = ir_build_instruction<IrInstructionFieldPtr>(irb, scope, source_node);
1318 instruction->container_ptr = container_ptr;1314 instruction->container_ptr = container_ptr;
1319 instruction->field_name_buffer = field_name;1315 instruction->field_name_buffer = field_name;
1320 instruction->field_name_expr = nullptr;1316 instruction->field_name_expr = nullptr;
1317 instruction->initializing = initializing;
13211318
1322 ir_ref_instruction(container_ptr, irb->current_basic_block);1319 ir_ref_instruction(container_ptr, irb->current_basic_block);
13231320
...@@ -1337,9 +1334,10 @@ static IrInstruction *ir_build_struct_field_ptr(IrBuilder *irb, Scope *scope, As...@@ -1337,9 +1334,10 @@ static IrInstruction *ir_build_struct_field_ptr(IrBuilder *irb, Scope *scope, As
1337}1334}
13381335
1339static IrInstruction *ir_build_union_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,1336static IrInstruction *ir_build_union_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
1340 IrInstruction *union_ptr, TypeUnionField *field)1337 IrInstruction *union_ptr, TypeUnionField *field, bool initializing)
1341{1338{
1342 IrInstructionUnionFieldPtr *instruction = ir_build_instruction<IrInstructionUnionFieldPtr>(irb, scope, source_node);1339 IrInstructionUnionFieldPtr *instruction = ir_build_instruction<IrInstructionUnionFieldPtr>(irb, scope, source_node);
1340 instruction->initializing = initializing;
1343 instruction->union_ptr = union_ptr;1341 instruction->union_ptr = union_ptr;
1344 instruction->field = field;1342 instruction->field = field;
13451343
...@@ -1517,19 +1515,6 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop...@@ -1517,19 +1515,6 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop
1517 return &container_init_fields_instruction->base;1515 return &container_init_fields_instruction->base;
1518}1516}
15191517
1520static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode *source_node,
1521 ZigType *union_type, TypeUnionField *field, IrInstruction *init_value)
1522{
1523 IrInstructionUnionInit *union_init_instruction = ir_build_instruction<IrInstructionUnionInit>(irb, scope, source_node);
1524 union_init_instruction->union_type = union_type;
1525 union_init_instruction->field = field;
1526 union_init_instruction->init_value = init_value;
1527
1528 ir_ref_instruction(init_value, irb->current_basic_block);
1529
1530 return &union_init_instruction->base;
1531}
1532
1533static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node) {1518static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1534 IrInstructionUnreachable *unreachable_instruction =1519 IrInstructionUnreachable *unreachable_instruction =
1535 ir_build_instruction<IrInstructionUnreachable>(irb, scope, source_node);1520 ir_build_instruction<IrInstructionUnreachable>(irb, scope, source_node);
...@@ -4121,7 +4106,7 @@ static IrInstruction *ir_gen_field_access(IrBuilder *irb, Scope *scope, AstNode...@@ -4121,7 +4106,7 @@ static IrInstruction *ir_gen_field_access(IrBuilder *irb, Scope *scope, AstNode
4121 if (container_ref_instruction == irb->codegen->invalid_instruction)4106 if (container_ref_instruction == irb->codegen->invalid_instruction)
4122 return container_ref_instruction;4107 return container_ref_instruction;
41234108
4124 return ir_build_field_ptr(irb, scope, node, container_ref_instruction, field_name);4109 return ir_build_field_ptr(irb, scope, node, container_ref_instruction, field_name, false);
4125}4110}
41264111
4127static IrInstruction *ir_gen_overflow_op(IrBuilder *irb, Scope *scope, AstNode *node, IrOverflowOp op) {4112static IrInstruction *ir_gen_overflow_op(IrBuilder *irb, Scope *scope, AstNode *node, IrOverflowOp op) {
...@@ -5594,7 +5579,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -5594,7 +5579,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
5594 AstNode *expr_node = entry_node->data.struct_val_field.expr;5579 AstNode *expr_node = entry_node->data.struct_val_field.expr;
55955580
5596 IrInstruction *field_ptr = ir_build_field_ptr(irb, &result_loc->scope_elide->base, expr_node,5581 IrInstruction *field_ptr = ir_build_field_ptr(irb, &result_loc->scope_elide->base, expr_node,
5597 container_ptr, name);5582 container_ptr, name, true);
5598 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);5583 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
5599 result_loc_inst->base.id = ResultLocIdInstruction;5584 result_loc_inst->base.id = ResultLocIdInstruction;
5600 result_loc_inst->base.source_instruction = field_ptr;5585 result_loc_inst->base.source_instruction = field_ptr;
...@@ -6105,7 +6090,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -6105,7 +6090,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
6105 IrBasicBlock *continue_block = ir_create_basic_block(irb, parent_scope, "ForContinue");6090 IrBasicBlock *continue_block = ir_create_basic_block(irb, parent_scope, "ForContinue");
61066091
6107 Buf *len_field_name = buf_create_from_str("len");6092 Buf *len_field_name = buf_create_from_str("len");
6108 IrInstruction *len_ref = ir_build_field_ptr(irb, parent_scope, node, array_val_ptr, len_field_name);6093 IrInstruction *len_ref = ir_build_field_ptr(irb, parent_scope, node, array_val_ptr, len_field_name, false);
6109 IrInstruction *len_val = ir_build_load_ptr(irb, parent_scope, node, len_ref);6094 IrInstruction *len_val = ir_build_load_ptr(irb, parent_scope, node, len_ref);
6110 ir_build_br(irb, parent_scope, node, cond_block, is_comptime);6095 ir_build_br(irb, parent_scope, node, cond_block, is_comptime);
61116096
...@@ -7496,7 +7481,7 @@ static IrInstruction *ir_gen_cancel_target(IrBuilder *irb, Scope *scope, AstNode...@@ -7496,7 +7481,7 @@ static IrInstruction *ir_gen_cancel_target(IrBuilder *irb, Scope *scope, AstNode
7496 IrInstruction *coro_promise_ptr = ir_build_coro_promise(irb, scope, node, casted_target_inst);7481 IrInstruction *coro_promise_ptr = ir_build_coro_promise(irb, scope, node, casted_target_inst);
7497 Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME);7482 Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME);
7498 IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr,7483 IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr,
7499 atomic_state_field_name);7484 atomic_state_field_name, false);
75007485
7501 // set the is_canceled bit7486 // set the is_canceled bit
7502 IrInstruction *prev_atomic_value = ir_build_atomic_rmw(irb, scope, node,7487 IrInstruction *prev_atomic_value = ir_build_atomic_rmw(irb, scope, node,
...@@ -7575,7 +7560,7 @@ static IrInstruction *ir_gen_resume_target(IrBuilder *irb, Scope *scope, AstNode...@@ -7575,7 +7560,7 @@ static IrInstruction *ir_gen_resume_target(IrBuilder *irb, Scope *scope, AstNode
7575 IrInstruction *coro_promise_ptr = ir_build_coro_promise(irb, scope, node, casted_target_inst);7560 IrInstruction *coro_promise_ptr = ir_build_coro_promise(irb, scope, node, casted_target_inst);
7576 Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME);7561 Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME);
7577 IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr,7562 IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr,
7578 atomic_state_field_name);7563 atomic_state_field_name, false);
75797564
7580 // clear the is_suspended bit7565 // clear the is_suspended bit
7581 IrInstruction *prev_atomic_value = ir_build_atomic_rmw(irb, scope, node,7566 IrInstruction *prev_atomic_value = ir_build_atomic_rmw(irb, scope, node,
...@@ -7642,12 +7627,12 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7642,12 +7627,12 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
76427627
7643 IrInstruction *coro_promise_ptr = ir_build_coro_promise(irb, scope, node, target_inst);7628 IrInstruction *coro_promise_ptr = ir_build_coro_promise(irb, scope, node, target_inst);
7644 Buf *result_ptr_field_name = buf_create_from_str(RESULT_PTR_FIELD_NAME);7629 Buf *result_ptr_field_name = buf_create_from_str(RESULT_PTR_FIELD_NAME);
7645 IrInstruction *result_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_ptr_field_name);7630 IrInstruction *result_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_ptr_field_name, false);
76467631
7647 if (irb->codegen->have_err_ret_tracing) {7632 if (irb->codegen->have_err_ret_tracing) {
7648 IrInstruction *err_ret_trace_ptr = ir_build_error_return_trace(irb, scope, node, IrInstructionErrorReturnTrace::NonNull);7633 IrInstruction *err_ret_trace_ptr = ir_build_error_return_trace(irb, scope, node, IrInstructionErrorReturnTrace::NonNull);
7649 Buf *err_ret_trace_ptr_field_name = buf_create_from_str(ERR_RET_TRACE_PTR_FIELD_NAME);7634 Buf *err_ret_trace_ptr_field_name = buf_create_from_str(ERR_RET_TRACE_PTR_FIELD_NAME);
7650 IrInstruction *err_ret_trace_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_ptr_field_name);7635 IrInstruction *err_ret_trace_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_ptr_field_name, false);
7651 ir_build_store_ptr(irb, scope, node, err_ret_trace_ptr_field_ptr, err_ret_trace_ptr);7636 ir_build_store_ptr(irb, scope, node, err_ret_trace_ptr_field_ptr, err_ret_trace_ptr);
7652 }7637 }
76537638
...@@ -7669,7 +7654,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7669,7 +7654,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
76697654
7670 Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME);7655 Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME);
7671 IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr,7656 IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr,
7672 atomic_state_field_name);7657 atomic_state_field_name, false);
76737658
7674 IrInstruction *promise_type_val = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_promise);7659 IrInstruction *promise_type_val = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_promise);
7675 IrInstruction *const_bool_false = ir_build_const_bool(irb, scope, node, false);7660 IrInstruction *const_bool_false = ir_build_const_bool(irb, scope, node, false);
...@@ -7723,12 +7708,12 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7723,12 +7708,12 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
7723 ir_set_cursor_at_end_and_append_block(irb, no_suspend_block);7708 ir_set_cursor_at_end_and_append_block(irb, no_suspend_block);
7724 if (irb->codegen->have_err_ret_tracing) {7709 if (irb->codegen->have_err_ret_tracing) {
7725 Buf *err_ret_trace_field_name = buf_create_from_str(ERR_RET_TRACE_FIELD_NAME);7710 Buf *err_ret_trace_field_name = buf_create_from_str(ERR_RET_TRACE_FIELD_NAME);
7726 IrInstruction *src_err_ret_trace_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_field_name);7711 IrInstruction *src_err_ret_trace_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_field_name, false);
7727 IrInstruction *dest_err_ret_trace_ptr = ir_build_error_return_trace(irb, scope, node, IrInstructionErrorReturnTrace::NonNull);7712 IrInstruction *dest_err_ret_trace_ptr = ir_build_error_return_trace(irb, scope, node, IrInstructionErrorReturnTrace::NonNull);
7728 ir_build_merge_err_ret_traces(irb, scope, node, coro_promise_ptr, src_err_ret_trace_ptr, dest_err_ret_trace_ptr);7713 ir_build_merge_err_ret_traces(irb, scope, node, coro_promise_ptr, src_err_ret_trace_ptr, dest_err_ret_trace_ptr);
7729 }7714 }
7730 Buf *result_field_name = buf_create_from_str(RESULT_FIELD_NAME);7715 Buf *result_field_name = buf_create_from_str(RESULT_FIELD_NAME);
7731 IrInstruction *promise_result_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_field_name);7716 IrInstruction *promise_result_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_field_name, false);
7732 // If the type of the result handle_is_ptr then this does not actually perform a load. But we need it to,7717 // If the type of the result handle_is_ptr then this does not actually perform a load. But we need it to,
7733 // because we're about to destroy the memory. So we store it into our result variable.7718 // because we're about to destroy the memory. So we store it into our result variable.
7734 IrInstruction *no_suspend_result = ir_build_load_ptr(irb, scope, node, promise_result_ptr);7719 IrInstruction *no_suspend_result = ir_build_load_ptr(irb, scope, node, promise_result_ptr);
...@@ -8152,7 +8137,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -8152,7 +8137,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
8152 build_decl_var_and_init(irb, coro_scope, node, irb->exec->coro_allocator_var, implicit_allocator_ptr,8137 build_decl_var_and_init(irb, coro_scope, node, irb->exec->coro_allocator_var, implicit_allocator_ptr,
8153 "allocator", const_bool_false);8138 "allocator", const_bool_false);
8154 Buf *realloc_field_name = buf_create_from_str(ASYNC_REALLOC_FIELD_NAME);8139 Buf *realloc_field_name = buf_create_from_str(ASYNC_REALLOC_FIELD_NAME);
8155 IrInstruction *realloc_fn_ptr = ir_build_field_ptr(irb, coro_scope, node, implicit_allocator_ptr, realloc_field_name);8140 IrInstruction *realloc_fn_ptr = ir_build_field_ptr(irb, coro_scope, node, implicit_allocator_ptr, realloc_field_name, false);
8156 IrInstruction *realloc_fn = ir_build_load_ptr(irb, coro_scope, node, realloc_fn_ptr);8141 IrInstruction *realloc_fn = ir_build_load_ptr(irb, coro_scope, node, realloc_fn_ptr);
8157 IrInstruction *maybe_coro_mem_ptr = ir_build_coro_alloc_helper(irb, coro_scope, node, realloc_fn, coro_size);8142 IrInstruction *maybe_coro_mem_ptr = ir_build_coro_alloc_helper(irb, coro_scope, node, realloc_fn, coro_size);
8158 IrInstruction *alloc_result_is_ok = ir_build_test_nonnull(irb, coro_scope, node, maybe_coro_mem_ptr);8143 IrInstruction *alloc_result_is_ok = ir_build_test_nonnull(irb, coro_scope, node, maybe_coro_mem_ptr);
...@@ -8172,30 +8157,30 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -8172,30 +8157,30 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
81728157
8173 Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME);8158 Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME);
8174 irb->exec->atomic_state_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr,8159 irb->exec->atomic_state_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr,
8175 atomic_state_field_name);8160 atomic_state_field_name, false);
8176 IrInstruction *zero = ir_build_const_usize(irb, scope, node, 0);8161 IrInstruction *zero = ir_build_const_usize(irb, scope, node, 0);
8177 ir_build_store_ptr(irb, scope, node, irb->exec->atomic_state_field_ptr, zero);8162 ir_build_store_ptr(irb, scope, node, irb->exec->atomic_state_field_ptr, zero);
8178 Buf *result_field_name = buf_create_from_str(RESULT_FIELD_NAME);8163 Buf *result_field_name = buf_create_from_str(RESULT_FIELD_NAME);
8179 irb->exec->coro_result_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_field_name);8164 irb->exec->coro_result_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_field_name, false);
8180 result_ptr_field_name = buf_create_from_str(RESULT_PTR_FIELD_NAME);8165 result_ptr_field_name = buf_create_from_str(RESULT_PTR_FIELD_NAME);
8181 irb->exec->coro_result_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_ptr_field_name);8166 irb->exec->coro_result_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_ptr_field_name, false);
8182 ir_build_store_ptr(irb, scope, node, irb->exec->coro_result_ptr_field_ptr, irb->exec->coro_result_field_ptr);8167 ir_build_store_ptr(irb, scope, node, irb->exec->coro_result_ptr_field_ptr, irb->exec->coro_result_field_ptr);
8183 if (irb->codegen->have_err_ret_tracing) {8168 if (irb->codegen->have_err_ret_tracing) {
8184 // initialize the error return trace8169 // initialize the error return trace
8185 Buf *return_addresses_field_name = buf_create_from_str(RETURN_ADDRESSES_FIELD_NAME);8170 Buf *return_addresses_field_name = buf_create_from_str(RETURN_ADDRESSES_FIELD_NAME);
8186 IrInstruction *return_addresses_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, return_addresses_field_name);8171 IrInstruction *return_addresses_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, return_addresses_field_name, false);
81878172
8188 Buf *err_ret_trace_field_name = buf_create_from_str(ERR_RET_TRACE_FIELD_NAME);8173 Buf *err_ret_trace_field_name = buf_create_from_str(ERR_RET_TRACE_FIELD_NAME);
8189 err_ret_trace_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_field_name);8174 err_ret_trace_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_field_name, false);
8190 ir_build_mark_err_ret_trace_ptr(irb, scope, node, err_ret_trace_ptr);8175 ir_build_mark_err_ret_trace_ptr(irb, scope, node, err_ret_trace_ptr);
81918176
8192 // coordinate with builtin.zig8177 // coordinate with builtin.zig
8193 Buf *index_name = buf_create_from_str("index");8178 Buf *index_name = buf_create_from_str("index");
8194 IrInstruction *index_ptr = ir_build_field_ptr(irb, scope, node, err_ret_trace_ptr, index_name);8179 IrInstruction *index_ptr = ir_build_field_ptr(irb, scope, node, err_ret_trace_ptr, index_name, false);
8195 ir_build_store_ptr(irb, scope, node, index_ptr, zero);8180 ir_build_store_ptr(irb, scope, node, index_ptr, zero);
81968181
8197 Buf *instruction_addresses_name = buf_create_from_str("instruction_addresses");8182 Buf *instruction_addresses_name = buf_create_from_str("instruction_addresses");
8198 IrInstruction *addrs_slice_ptr = ir_build_field_ptr(irb, scope, node, err_ret_trace_ptr, instruction_addresses_name);8183 IrInstruction *addrs_slice_ptr = ir_build_field_ptr(irb, scope, node, err_ret_trace_ptr, instruction_addresses_name, false);
81998184
8200 IrInstruction *slice_value = ir_build_slice(irb, scope, node, return_addresses_ptr, zero, nullptr, false);8185 IrInstruction *slice_value = ir_build_slice(irb, scope, node, return_addresses_ptr, zero, nullptr, false);
8201 ir_build_store_ptr(irb, scope, node, addrs_slice_ptr, slice_value);8186 ir_build_store_ptr(irb, scope, node, addrs_slice_ptr, slice_value);
...@@ -8256,7 +8241,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -8256,7 +8241,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
8256 }8241 }
8257 if (irb->codegen->have_err_ret_tracing) {8242 if (irb->codegen->have_err_ret_tracing) {
8258 Buf *err_ret_trace_ptr_field_name = buf_create_from_str(ERR_RET_TRACE_PTR_FIELD_NAME);8243 Buf *err_ret_trace_ptr_field_name = buf_create_from_str(ERR_RET_TRACE_PTR_FIELD_NAME);
8259 IrInstruction *err_ret_trace_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_ptr_field_name);8244 IrInstruction *err_ret_trace_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_ptr_field_name, false);
8260 IrInstruction *dest_err_ret_trace_ptr = ir_build_load_ptr(irb, scope, node, err_ret_trace_ptr_field_ptr);8245 IrInstruction *dest_err_ret_trace_ptr = ir_build_load_ptr(irb, scope, node, err_ret_trace_ptr_field_ptr);
8261 ir_build_merge_err_ret_traces(irb, scope, node, coro_promise_ptr, err_ret_trace_ptr, dest_err_ret_trace_ptr);8246 ir_build_merge_err_ret_traces(irb, scope, node, coro_promise_ptr, err_ret_trace_ptr, dest_err_ret_trace_ptr);
8262 }8247 }
...@@ -8291,7 +8276,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -8291,7 +8276,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
8291 Buf *shrink_field_name = buf_create_from_str(ASYNC_SHRINK_FIELD_NAME);8276 Buf *shrink_field_name = buf_create_from_str(ASYNC_SHRINK_FIELD_NAME);
8292 IrInstruction *implicit_allocator_ptr = ir_build_get_implicit_allocator(irb, scope, node,8277 IrInstruction *implicit_allocator_ptr = ir_build_get_implicit_allocator(irb, scope, node,
8293 ImplicitAllocatorIdLocalVar);8278 ImplicitAllocatorIdLocalVar);
8294 IrInstruction *shrink_fn_ptr = ir_build_field_ptr(irb, scope, node, implicit_allocator_ptr, shrink_field_name);8279 IrInstruction *shrink_fn_ptr = ir_build_field_ptr(irb, scope, node, implicit_allocator_ptr, shrink_field_name, false);
8295 IrInstruction *shrink_fn = ir_build_load_ptr(irb, scope, node, shrink_fn_ptr);8280 IrInstruction *shrink_fn = ir_build_load_ptr(irb, scope, node, shrink_fn_ptr);
8296 IrInstruction *zero = ir_build_const_usize(irb, scope, node, 0);8281 IrInstruction *zero = ir_build_const_usize(irb, scope, node, 0);
8297 IrInstruction *coro_mem_ptr_maybe = ir_build_coro_free(irb, scope, node, coro_id, irb->exec->coro_handle);8282 IrInstruction *coro_mem_ptr_maybe = ir_build_coro_free(irb, scope, node, coro_id, irb->exec->coro_handle);
...@@ -14722,7 +14707,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc...@@ -14722,7 +14707,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc
14722 ir_assert(async_allocator_inst->value.type->id == ZigTypeIdPointer, &call_instruction->base);14707 ir_assert(async_allocator_inst->value.type->id == ZigTypeIdPointer, &call_instruction->base);
14723 ZigType *container_type = async_allocator_inst->value.type->data.pointer.child_type;14708 ZigType *container_type = async_allocator_inst->value.type->data.pointer.child_type;
14724 IrInstruction *field_ptr_inst = ir_analyze_container_field_ptr(ira, realloc_field_name, &call_instruction->base,14709 IrInstruction *field_ptr_inst = ir_analyze_container_field_ptr(ira, realloc_field_name, &call_instruction->base,
14725 async_allocator_inst, container_type);14710 async_allocator_inst, container_type, false);
14726 if (type_is_invalid(field_ptr_inst->value.type)) {14711 if (type_is_invalid(field_ptr_inst->value.type)) {
14727 return ira->codegen->invalid_instruction;14712 return ira->codegen->invalid_instruction;
14728 }14713 }
...@@ -16580,7 +16565,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -16580,7 +16565,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
16580}16565}
1658116566
16582static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,16567static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
16583 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type)16568 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type, bool initializing)
16584{16569{
16585 Error err;16570 Error err;
1658616571
...@@ -16664,15 +16649,19 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -16664,15 +16649,19 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
16664 if (type_is_invalid(union_val->type))16649 if (type_is_invalid(union_val->type))
16665 return ira->codegen->invalid_instruction;16650 return ira->codegen->invalid_instruction;
1666616651
16667 TypeUnionField *actual_field = find_union_field_by_tag(bare_type, &union_val->data.x_union.tag);16652 if (initializing) {
16668 if (actual_field == nullptr)16653 bigint_init_bigint(&union_val->data.x_union.tag, &field->enum_field->value);
16669 zig_unreachable();16654 } else {
16655 TypeUnionField *actual_field = find_union_field_by_tag(bare_type, &union_val->data.x_union.tag);
16656 if (actual_field == nullptr)
16657 zig_unreachable();
1667016658
16671 if (field != actual_field) {16659 if (field != actual_field) {
16672 ir_add_error_node(ira, source_instr->source_node,16660 ir_add_error_node(ira, source_instr->source_node,
16673 buf_sprintf("accessing union field '%s' while field '%s' is set", buf_ptr(field_name),16661 buf_sprintf("accessing union field '%s' while field '%s' is set", buf_ptr(field_name),
16674 buf_ptr(actual_field->name)));16662 buf_ptr(actual_field->name)));
16675 return ira->codegen->invalid_instruction;16663 return ira->codegen->invalid_instruction;
16664 }
16676 }16665 }
1667716666
16678 ConstExprValue *payload_val = union_val->data.x_union.payload;16667 ConstExprValue *payload_val = union_val->data.x_union.payload;
...@@ -16690,7 +16679,8 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -16690,7 +16679,8 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
16690 }16679 }
16691 }16680 }
1669216681
16693 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, container_ptr, field);16682 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope,
16683 source_instr->source_node, container_ptr, field, initializing);
16694 result->value.type = get_pointer_to_type_extra(ira->codegen, field->type_entry, is_const, is_volatile,16684 result->value.type = get_pointer_to_type_extra(ira->codegen, field->type_entry, is_const, is_volatile,
16695 PtrLenSingle, 0, 0, 0, false);16685 PtrLenSingle, 0, 0, 0, false);
16696 return result;16686 return result;
...@@ -16826,10 +16816,10 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -16826,10 +16816,10 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
16826 if (container_type->id == ZigTypeIdPointer) {16816 if (container_type->id == ZigTypeIdPointer) {
16827 ZigType *bare_type = container_ref_type(container_type);16817 ZigType *bare_type = container_ref_type(container_type);
16828 IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr);16818 IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr);
16829 IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type);16819 IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type, field_ptr_instruction->initializing);
16830 return result;16820 return result;
16831 } else {16821 } else {
16832 IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_ptr, container_type);16822 IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_ptr, container_type, field_ptr_instruction->initializing);
16833 return result;16823 return result;
16834 }16824 }
16835 } else if (is_array_ref(container_type)) {16825 } else if (is_array_ref(container_type)) {
...@@ -18120,7 +18110,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru...@@ -18120,7 +18110,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
18120 }18110 }
1812118111
18122 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb,18112 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb,
18123 instruction->base.scope, instruction->base.source_node, target_value_ptr, field);18113 instruction->base.scope, instruction->base.source_node, target_value_ptr, field, false);
18124 result->value.type = get_pointer_to_type(ira->codegen, field->type_entry,18114 result->value.type = get_pointer_to_type(ira->codegen, field->type_entry,
18125 target_value_ptr->value.type->data.pointer.is_const);18115 target_value_ptr->value.type->data.pointer.is_const);
18126 return result;18116 return result;
...@@ -18386,11 +18376,10 @@ static IrInstruction *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrI...@@ -18386,11 +18376,10 @@ static IrInstruction *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrI
18386 return result;18376 return result;
18387 }18377 }
1838818378
18389 IrInstruction *new_instruction = ir_build_union_init(&ira->new_irb,18379 // this instruction should not get to codegen
18390 instruction->scope, instruction->source_node,18380 IrInstruction *new_instruction = ir_const(ira, instruction, container_type);
18391 container_type, type_field, casted_field_value);18381 // this is how we signal to EndExpr the value is not comptime known
18392 new_instruction->value.type = container_type;18382 new_instruction->value.special = ConstValSpecialRuntime;
18393 ir_add_alloca(ira, new_instruction, container_type);
18394 return new_instruction;18383 return new_instruction;
18395}18384}
1839618385
...@@ -23907,7 +23896,6 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction...@@ -23907,7 +23896,6 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction
23907 switch (instruction->id) {23896 switch (instruction->id) {
23908 case IrInstructionIdInvalid:23897 case IrInstructionIdInvalid:
23909 case IrInstructionIdWidenOrShorten:23898 case IrInstructionIdWidenOrShorten:
23910 case IrInstructionIdUnionInit:
23911 case IrInstructionIdStructFieldPtr:23899 case IrInstructionIdStructFieldPtr:
23912 case IrInstructionIdUnionFieldPtr:23900 case IrInstructionIdUnionFieldPtr:
23913 case IrInstructionIdOptionalWrap:23901 case IrInstructionIdOptionalWrap:
...@@ -24353,7 +24341,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -24353,7 +24341,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {
24353 case IrInstructionIdCast:24341 case IrInstructionIdCast:
24354 case IrInstructionIdContainerInitList:24342 case IrInstructionIdContainerInitList:
24355 case IrInstructionIdContainerInitFields:24343 case IrInstructionIdContainerInitFields:
24356 case IrInstructionIdUnionInit:
24357 case IrInstructionIdFieldPtr:24344 case IrInstructionIdFieldPtr:
24358 case IrInstructionIdElemPtr:24345 case IrInstructionIdElemPtr:
24359 case IrInstructionIdVarPtr:24346 case IrInstructionIdVarPtr:
src/ir_print.cpp-12
...@@ -360,15 +360,6 @@ static void ir_print_container_init_fields(IrPrint *irp, IrInstructionContainerI...@@ -360,15 +360,6 @@ static void ir_print_container_init_fields(IrPrint *irp, IrInstructionContainerI
360 fprintf(irp->f, "} // container init");360 fprintf(irp->f, "} // container init");
361}361}
362362
363static void ir_print_union_init(IrPrint *irp, IrInstructionUnionInit *instruction) {
364 Buf *field_name = instruction->field->enum_field->name;
365
366 fprintf(irp->f, "%s {", buf_ptr(&instruction->union_type->name));
367 fprintf(irp->f, ".%s = ", buf_ptr(field_name));
368 ir_print_other_instruction(irp, instruction->init_value);
369 fprintf(irp->f, "} // union init");
370}
371
372static void ir_print_unreachable(IrPrint *irp, IrInstructionUnreachable *instruction) {363static void ir_print_unreachable(IrPrint *irp, IrInstructionUnreachable *instruction) {
373 fprintf(irp->f, "unreachable");364 fprintf(irp->f, "unreachable");
374}365}
...@@ -1590,9 +1581,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -1590,9 +1581,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
1590 case IrInstructionIdContainerInitFields:1581 case IrInstructionIdContainerInitFields:
1591 ir_print_container_init_fields(irp, (IrInstructionContainerInitFields *)instruction);1582 ir_print_container_init_fields(irp, (IrInstructionContainerInitFields *)instruction);
1592 break;1583 break;
1593 case IrInstructionIdUnionInit:
1594 ir_print_union_init(irp, (IrInstructionUnionInit *)instruction);
1595 break;
1596 case IrInstructionIdUnreachable:1584 case IrInstructionIdUnreachable:
1597 ir_print_unreachable(irp, (IrInstructionUnreachable *)instruction);1585 ir_print_unreachable(irp, (IrInstructionUnreachable *)instruction);
1598 break;1586 break;