| ... | ... | @@ -8151,6 +8151,17 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 8151 | 8151 | } |
| 8152 | 8152 | } |
| 8153 | 8153 | |
| 8154 | // implicit T to *T where T is zero bits |
| 8155 | if (expected_type->id == TypeTableEntryIdPointer && expected_type->data.pointer.ptr_len == PtrLenSingle && |
| 8156 | types_match_const_cast_only(ira, expected_type->data.pointer.child_type, |
| 8157 | actual_type, source_node).id == ConstCastResultIdOk) |
| 8158 | { |
| 8159 | type_ensure_zero_bits_known(ira->codegen, actual_type); |
| 8160 | if (!type_has_bits(actual_type)) { |
| 8161 | return ImplicitCastMatchResultYes; |
| 8162 | } |
| 8163 | } |
| 8164 | |
| 8154 | 8165 | // implicit undefined literal to anything |
| 8155 | 8166 | if (actual_type->id == TypeTableEntryIdUndefined) { |
| 8156 | 8167 | return ImplicitCastMatchResultYes; |
| ... | ... | @@ -8820,7 +8831,7 @@ static void eval_const_expr_implicit_cast(CastOp cast_op, |
| 8820 | 8831 | static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 8821 | 8832 | TypeTableEntry *wanted_type, CastOp cast_op, bool need_alloca) |
| 8822 | 8833 | { |
| 8823 | | if (value->value.special != ConstValSpecialRuntime && |
| 8834 | if ((instr_is_comptime(value) || !type_has_bits(wanted_type)) && |
| 8824 | 8835 | cast_op != CastOpResizeSlice && cast_op != CastOpBytesToSlice) |
| 8825 | 8836 | { |
| 8826 | 8837 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, |
| ... | ... | @@ -9382,9 +9393,19 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi |
| 9382 | 9393 | |
| 9383 | 9394 | if (value->id == IrInstructionIdLoadPtr) { |
| 9384 | 9395 | IrInstructionLoadPtr *load_ptr_inst = (IrInstructionLoadPtr *) value; |
| 9396 | |
| 9385 | 9397 | if (load_ptr_inst->ptr->value.type->data.pointer.is_const) { |
| 9386 | 9398 | return load_ptr_inst->ptr; |
| 9387 | 9399 | } |
| 9400 | |
| 9401 | type_ensure_zero_bits_known(ira->codegen, value->value.type); |
| 9402 | if (type_is_invalid(value->value.type)) { |
| 9403 | return ira->codegen->invalid_instruction; |
| 9404 | } |
| 9405 | |
| 9406 | if (!type_has_bits(value->value.type)) { |
| 9407 | return load_ptr_inst->ptr; |
| 9408 | } |
| 9388 | 9409 | } |
| 9389 | 9410 | |
| 9390 | 9411 | if (instr_is_comptime(value)) { |
| ... | ... | @@ -10340,6 +10361,20 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10340 | 10361 | } |
| 10341 | 10362 | } |
| 10342 | 10363 | |
| 10364 | // explicit cast from T to *T where T is zero bits |
| 10365 | if (wanted_type->id == TypeTableEntryIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle && |
| 10366 | types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, |
| 10367 | actual_type, source_node).id == ConstCastResultIdOk) |
| 10368 | { |
| 10369 | type_ensure_zero_bits_known(ira->codegen, actual_type); |
| 10370 | if (type_is_invalid(actual_type)) { |
| 10371 | return ira->codegen->invalid_instruction; |
| 10372 | } |
| 10373 | if (!type_has_bits(actual_type)) { |
| 10374 | return ir_get_ref(ira, source_instr, value, false, false); |
| 10375 | } |
| 10376 | } |
| 10377 | |
| 10343 | 10378 | |
| 10344 | 10379 | // explicit cast from undefined to anything |
| 10345 | 10380 | if (actual_type->id == TypeTableEntryIdUndefined) { |