| ... | ... | @@ -6424,6 +6424,27 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc |
| 6424 | 6424 | return result; |
| 6425 | 6425 | } |
| 6426 | 6426 | |
| 6427 | static IrInstruction *ir_analyze_int_lit_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 6428 | IrInstruction *target, TypeTableEntry *wanted_type) |
| 6429 | { |
| 6430 | assert(wanted_type->id == TypeTableEntryIdPointer); |
| 6431 | |
| 6432 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 6433 | if (!val) |
| 6434 | return ira->codegen->invalid_instruction; |
| 6435 | |
| 6436 | TypeTableEntry *usize_type = ira->codegen->builtin_types.entry_usize; |
| 6437 | if (!ir_num_lit_fits_in_other_type(ira, target, usize_type)) |
| 6438 | return ira->codegen->invalid_instruction; |
| 6439 | |
| 6440 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, |
| 6441 | source_instr->source_node, wanted_type, val->depends_on_compile_var); |
| 6442 | result->value.data.x_ptr.base_ptr = nullptr; |
| 6443 | result->value.data.x_ptr.index = bignum_to_twos_complement(&val->data.x_bignum); |
| 6444 | result->value.data.x_ptr.special = ConstPtrSpecialRuntime; |
| 6445 | return result; |
| 6446 | } |
| 6447 | |
| 6427 | 6448 | static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *source_instr, |
| 6428 | 6449 | IrInstruction *target, TypeTableEntry *wanted_type) |
| 6429 | 6450 | { |
| ... | ... | @@ -6491,6 +6512,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 6491 | 6512 | return ir_analyze_int_to_ptr(ira, source_instr, value, wanted_type); |
| 6492 | 6513 | } |
| 6493 | 6514 | |
| 6515 | // explicit cast from number literal to pointer |
| 6516 | if (wanted_type_canon->id == TypeTableEntryIdPointer && |
| 6517 | (actual_type_canon->id == TypeTableEntryIdNumLitInt)) |
| 6518 | { |
| 6519 | return ir_analyze_int_lit_to_ptr(ira, source_instr, value, wanted_type); |
| 6520 | } |
| 6521 | |
| 6494 | 6522 | // explicit widening or shortening cast |
| 6495 | 6523 | if ((wanted_type_canon->id == TypeTableEntryIdInt && |
| 6496 | 6524 | actual_type_canon->id == TypeTableEntryIdInt) || |