| ... | ... | @@ -27851,9 +27851,15 @@ static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, Ir |
| 27851 | 27851 | } |
| 27852 | 27852 | |
| 27853 | 27853 | IrInstGen *result = ir_const(ira, source_instr, ptr_type); |
| 27854 | | result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 27855 | | result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 27856 | | result->value->data.x_ptr.data.hard_coded_addr.addr = addr; |
| 27854 | if (ptr_type->id == ZigTypeIdOptional && addr == 0) { |
| 27855 | result->value->data.x_ptr.special = ConstPtrSpecialNull; |
| 27856 | result->value->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 27857 | } else { |
| 27858 | result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 27859 | result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 27860 | result->value->data.x_ptr.data.hard_coded_addr.addr = addr; |
| 27861 | } |
| 27862 | |
| 27857 | 27863 | return result; |
| 27858 | 27864 | } |
| 27859 | 27865 | |
| ... | ... | @@ -27911,15 +27917,15 @@ static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtr |
| 27911 | 27917 | |
| 27912 | 27918 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 27913 | 27919 | |
| 27914 | | // We check size explicitly so we can use get_src_ptr_type here. |
| 27915 | | if (get_src_ptr_type(target->value->type) == nullptr) { |
| 27920 | ZigType *src_ptr_type = get_src_ptr_type(target->value->type); |
| 27921 | if (src_ptr_type == nullptr) { |
| 27916 | 27922 | ir_add_error(ira, &target->base, |
| 27917 | 27923 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value->type->name))); |
| 27918 | 27924 | return ira->codegen->invalid_inst_gen; |
| 27919 | 27925 | } |
| 27920 | 27926 | |
| 27921 | 27927 | bool has_bits; |
| 27922 | | if ((err = type_has_bits2(ira->codegen, target->value->type, &has_bits))) |
| 27928 | if ((err = type_has_bits2(ira->codegen, src_ptr_type, &has_bits))) |
| 27923 | 27929 | return ira->codegen->invalid_inst_gen; |
| 27924 | 27930 | |
| 27925 | 27931 | if (!has_bits) { |
| ... | ... | @@ -27932,11 +27938,19 @@ static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtr |
| 27932 | 27938 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 27933 | 27939 | if (!val) |
| 27934 | 27940 | return ira->codegen->invalid_inst_gen; |
| 27935 | | if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| 27941 | |
| 27942 | // Since we've already run this type trough get_codegen_ptr_type it is |
| 27943 | // safe to access the x_ptr fields |
| 27944 | if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| 27936 | 27945 | IrInstGen *result = ir_const(ira, &instruction->base.base, usize); |
| 27937 | 27946 | bigint_init_unsigned(&result->value->data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr); |
| 27938 | 27947 | result->value->type = usize; |
| 27939 | 27948 | return result; |
| 27949 | } else if (val->data.x_ptr.special == ConstPtrSpecialNull) { |
| 27950 | IrInstGen *result = ir_const(ira, &instruction->base.base, usize); |
| 27951 | bigint_init_unsigned(&result->value->data.x_bigint, 0); |
| 27952 | result->value->type = usize; |
| 27953 | return result; |
| 27940 | 27954 | } |
| 27941 | 27955 | } |
| 27942 | 27956 | |