| ... | ... | @@ -188,7 +188,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c |
| 188 | 188 | assert(get_src_ptr_type(const_val->type) != nullptr); |
| 189 | 189 | assert(const_val->special == ConstValSpecialStatic); |
| 190 | 190 | ConstExprValue *result; |
| 191 | | |
| 191 | |
| 192 | 192 | switch (type_has_one_possible_value(g, const_val->type->data.pointer.child_type)) { |
| 193 | 193 | case OnePossibleValueInvalid: |
| 194 | 194 | zig_unreachable(); |
| ... | ... | @@ -200,7 +200,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c |
| 200 | 200 | case OnePossibleValueNo: |
| 201 | 201 | break; |
| 202 | 202 | } |
| 203 | | |
| 203 | |
| 204 | 204 | switch (const_val->data.x_ptr.special) { |
| 205 | 205 | case ConstPtrSpecialInvalid: |
| 206 | 206 | zig_unreachable(); |
| ... | ... | @@ -1011,6 +1011,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAssertNonNull *) |
| 1011 | 1011 | return IrInstructionIdAssertNonNull; |
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionInit2 *) { |
| 1015 | return IrInstructionIdUnionInit2; |
| 1016 | } |
| 1017 | |
| 1014 | 1018 | template<typename T> |
| 1015 | 1019 | static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1016 | 1020 | T *special_instruction = allocate<T>(1); |
| ... | ... | @@ -1312,6 +1316,7 @@ static IrInstruction *ir_build_union_field_ptr(IrBuilder *irb, Scope *scope, Ast |
| 1312 | 1316 | return &instruction->base; |
| 1313 | 1317 | } |
| 1314 | 1318 | |
| 1319 | |
| 1315 | 1320 | static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1316 | 1321 | ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args, |
| 1317 | 1322 | bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator, |
| ... | ... | @@ -3025,6 +3030,21 @@ static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope, |
| 3025 | 3030 | return &instruction->base; |
| 3026 | 3031 | } |
| 3027 | 3032 | |
| 3033 | static IrInstruction *ir_build_union_init_2(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3034 | IrInstruction *union_type_value, IrInstruction *field_name_expr, IrInstruction *value) { |
| 3035 | IrInstructionUnionInit2 *instruction = ir_build_instruction<IrInstructionUnionInit2>(irb, scope, source_node); |
| 3036 | instruction->union_type_value = union_type_value; |
| 3037 | instruction->field_name_expr = field_name_expr; |
| 3038 | instruction->value = value; |
| 3039 | |
| 3040 | ir_ref_instruction(union_type_value, irb->current_basic_block); |
| 3041 | ir_ref_instruction(field_name_expr, irb->current_basic_block); |
| 3042 | ir_ref_instruction(value, irb->current_basic_block); |
| 3043 | |
| 3044 | return &instruction->base; |
| 3045 | } |
| 3046 | |
| 3047 | |
| 3028 | 3048 | static IrInstruction *ir_build_vector_to_array(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3029 | 3049 | IrInstruction *vector, ZigType *result_type) |
| 3030 | 3050 | { |
| ... | ... | @@ -3868,7 +3888,7 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode |
| 3868 | 3888 | TldVar *tld_var = allocate<TldVar>(1); |
| 3869 | 3889 | init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base); |
| 3870 | 3890 | tld_var->base.resolution = TldResolutionInvalid; |
| 3871 | | tld_var->var = add_variable(g, node, &scope_decls->base, var_name, false, |
| 3891 | tld_var->var = add_variable(g, node, &scope_decls->base, var_name, false, |
| 3872 | 3892 | &g->invalid_instruction->value, &tld_var->base, g->builtin_types.entry_invalid); |
| 3873 | 3893 | scope_decls->decl_table.put(var_name, &tld_var->base); |
| 3874 | 3894 | } |
| ... | ... | @@ -5098,6 +5118,29 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5098 | 5118 | } |
| 5099 | 5119 | return ir_lval_wrap(irb, scope, result, lval); |
| 5100 | 5120 | } |
| 5121 | case BuiltinFnIdUnionInit: |
| 5122 | { |
| 5123 | |
| 5124 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5125 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5126 | if (arg0_value == irb->codegen->invalid_instruction) |
| 5127 | return arg0_value; |
| 5128 | |
| 5129 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5130 | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5131 | if (arg1_value == irb->codegen->invalid_instruction) |
| 5132 | return arg1_value; |
| 5133 | |
| 5134 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); |
| 5135 | IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 5136 | if (arg2_value == irb->codegen->invalid_instruction) |
| 5137 | return arg2_value; |
| 5138 | |
| 5139 | IrInstruction *result = ir_build_union_init_2(irb, scope, node, arg0_value, arg1_value, arg2_value); |
| 5140 | |
| 5141 | // TODO: Not sure if we need ir_lval_wrap or not. |
| 5142 | return result; |
| 5143 | } |
| 5101 | 5144 | } |
| 5102 | 5145 | zig_unreachable(); |
| 5103 | 5146 | } |
| ... | ... | @@ -6328,7 +6371,7 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit |
| 6328 | 6371 | prong_values, prong_values_len); |
| 6329 | 6372 | var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, scope, var_symbol_node, var_ptr_value); |
| 6330 | 6373 | } else { |
| 6331 | | var_value = var_is_ptr ? target_value_ptr : ir_build_load_ptr(irb, scope, var_symbol_node, |
| 6374 | var_value = var_is_ptr ? target_value_ptr : ir_build_load_ptr(irb, scope, var_symbol_node, |
| 6332 | 6375 | target_value_ptr); |
| 6333 | 6376 | } |
| 6334 | 6377 | IrInstruction *var_type = nullptr; // infer the type |
| ... | ... | @@ -12372,7 +12415,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 12372 | 12415 | } else { |
| 12373 | 12416 | return is_non_null; |
| 12374 | 12417 | } |
| 12375 | | } else if (is_equality_cmp && |
| 12418 | } else if (is_equality_cmp && |
| 12376 | 12419 | ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdPointer && |
| 12377 | 12420 | op2->value.type->data.pointer.ptr_len == PtrLenC) || |
| 12378 | 12421 | (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdPointer && |
| ... | ... | @@ -19383,7 +19426,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 19383 | 19426 | ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to make dir: %s", err_str(err))); |
| 19384 | 19427 | return ira->codegen->invalid_instruction; |
| 19385 | 19428 | } |
| 19386 | | |
| 19429 | |
| 19387 | 19430 | if ((err = os_write_file(&tmp_c_file_path, &cimport_scope->buf))) { |
| 19388 | 19431 | ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to write .h file: %s", err_str(err))); |
| 19389 | 19432 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -20333,7 +20376,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 20333 | 20376 | return ira->codegen->invalid_instruction; |
| 20334 | 20377 | |
| 20335 | 20378 | // TODO test this at comptime with u8 and non-u8 types |
| 20336 | | // TODO test with dest ptr being a global runtime variable |
| 20379 | // TODO test with dest ptr being a global runtime variable |
| 20337 | 20380 | if (casted_dest_ptr->value.special == ConstValSpecialStatic && |
| 20338 | 20381 | casted_src_ptr->value.special == ConstValSpecialStatic && |
| 20339 | 20382 | casted_count->value.special == ConstValSpecialStatic && |
| ... | ... | @@ -23151,6 +23194,35 @@ static IrInstruction *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, |
| 23151 | 23194 | return ir_const_void(ira, &instruction->base); |
| 23152 | 23195 | } |
| 23153 | 23196 | |
| 23197 | static IrInstruction *ir_analyze_instruction_union_init_2(IrAnalyze *ira, IrInstructionUnionInit2 *union_init_instruction) |
| 23198 | { |
| 23199 | Error err; |
| 23200 | IrInstruction *union_type_value = union_init_instruction->union_type_value->child; |
| 23201 | ZigType *union_type = ir_resolve_type(ira, union_type_value); |
| 23202 | if (type_is_invalid(union_type)) { |
| 23203 | return ira->codegen->invalid_instruction; |
| 23204 | } |
| 23205 | |
| 23206 | if (union_type->id != ZigTypeIdUnion) |
| 23207 | return ira->codegen->invalid_instruction; |
| 23208 | |
| 23209 | if ((err = ensure_complete_type(ira->codegen, union_type))) |
| 23210 | return ira->codegen->invalid_instruction; |
| 23211 | |
| 23212 | IrInstruction *field_name_expr = union_init_instruction->field_name_expr->child; |
| 23213 | Buf *field_name = ir_resolve_str(ira, field_name_expr); |
| 23214 | if (!field_name) |
| 23215 | return ira->codegen->invalid_instruction; |
| 23216 | |
| 23217 | IrInstructionContainerInitFieldsField *fields = allocate<IrInstructionContainerInitFieldsField>(1); |
| 23218 | |
| 23219 | fields[0].name = field_name; |
| 23220 | fields[0].value = union_init_instruction->value; |
| 23221 | fields[0].source_node = union_init_instruction->base.source_node; |
| 23222 | |
| 23223 | return ir_analyze_container_init_fields_union(ira, &union_init_instruction->base, union_type, 1, fields); |
| 23224 | } |
| 23225 | |
| 23154 | 23226 | static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) { |
| 23155 | 23227 | switch (instruction->id) { |
| 23156 | 23228 | case IrInstructionIdInvalid: |
| ... | ... | @@ -23445,6 +23517,8 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio |
| 23445 | 23517 | return ir_analyze_instruction_enum_to_int(ira, (IrInstructionEnumToInt *)instruction); |
| 23446 | 23518 | case IrInstructionIdCheckRuntimeScope: |
| 23447 | 23519 | return ir_analyze_instruction_check_runtime_scope(ira, (IrInstructionCheckRuntimeScope *)instruction); |
| 23520 | case IrInstructionIdUnionInit2: |
| 23521 | return ir_analyze_instruction_union_init_2(ira, (IrInstructionUnionInit2 *)instruction); |
| 23448 | 23522 | } |
| 23449 | 23523 | zig_unreachable(); |
| 23450 | 23524 | } |
| ... | ... | @@ -23681,6 +23755,8 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 23681 | 23755 | case IrInstructionIdEnumToInt: |
| 23682 | 23756 | case IrInstructionIdVectorToArray: |
| 23683 | 23757 | case IrInstructionIdArrayToVector: |
| 23758 | case IrInstructionIdUnionInit2: |
| 23759 | |
| 23684 | 23760 | return false; |
| 23685 | 23761 | |
| 23686 | 23762 | case IrInstructionIdAsm: |