| ... | @@ -17575,30 +17575,30 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -17575,30 +17575,30 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17575 | const operand_coerced = try sema.coerce(block, Type.usize, operand_res, operand_src); | 17575 | const operand_coerced = try sema.coerce(block, Type.usize, operand_res, operand_src); |
| 17576 | | 17576 | |
| 17577 | const type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 17577 | const type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 17578 | const type_res = try sema.resolveType(block, src, extra.lhs); | 17578 | const ptr_ty = try sema.resolveType(block, src, extra.lhs); |
| 17579 | try sema.checkPtrType(block, type_src, type_res); | 17579 | const elem_ty = ptr_ty.elemType2(); |
| 17580 | try sema.resolveTypeLayout(block, src, type_res.elemType2()); | 17580 | try sema.checkPtrType(block, type_src, ptr_ty); |
| 17581 | const ptr_align = type_res.ptrAlignment(sema.mod.getTarget()); | | |
| 17582 | const target = sema.mod.getTarget(); | 17581 | const target = sema.mod.getTarget(); |
| | 17582 | const ptr_align = try ptr_ty.ptrAlignmentAdvanced(target, sema.kit(block, src)); |
| 17583 | | 17583 | |
| 17584 | if (try sema.resolveDefinedValue(block, operand_src, operand_coerced)) |val| { | 17584 | if (try sema.resolveDefinedValue(block, operand_src, operand_coerced)) |val| { |
| 17585 | const addr = val.toUnsignedInt(target); | 17585 | const addr = val.toUnsignedInt(target); |
| 17586 | if (!type_res.isAllowzeroPtr() and addr == 0) | 17586 | if (!ptr_ty.isAllowzeroPtr() and addr == 0) |
| 17587 | return sema.fail(block, operand_src, "pointer type '{}' does not allow address zero", .{type_res.fmt(sema.mod)}); | 17587 | return sema.fail(block, operand_src, "pointer type '{}' does not allow address zero", .{ptr_ty.fmt(sema.mod)}); |
| 17588 | if (addr != 0 and addr % ptr_align != 0) | 17588 | if (addr != 0 and addr % ptr_align != 0) |
| 17589 | return sema.fail(block, operand_src, "pointer type '{}' requires aligned address", .{type_res.fmt(sema.mod)}); | 17589 | return sema.fail(block, operand_src, "pointer type '{}' requires aligned address", .{ptr_ty.fmt(sema.mod)}); |
| 17590 | | 17590 | |
| 17591 | const val_payload = try sema.arena.create(Value.Payload.U64); | 17591 | const val_payload = try sema.arena.create(Value.Payload.U64); |
| 17592 | val_payload.* = .{ | 17592 | val_payload.* = .{ |
| 17593 | .base = .{ .tag = .int_u64 }, | 17593 | .base = .{ .tag = .int_u64 }, |
| 17594 | .data = addr, | 17594 | .data = addr, |
| 17595 | }; | 17595 | }; |
| 17596 | return sema.addConstant(type_res, Value.initPayload(&val_payload.base)); | 17596 | return sema.addConstant(ptr_ty, Value.initPayload(&val_payload.base)); |
| 17597 | } | 17597 | } |
| 17598 | | 17598 | |
| 17599 | try sema.requireRuntimeBlock(block, src, operand_src); | 17599 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 17600 | if (block.wantSafety() and try sema.typeHasRuntimeBits(block, sema.src, type_res.elemType2())) { | 17600 | if (block.wantSafety() and try sema.typeHasRuntimeBits(block, sema.src, elem_ty)) { |
| 17601 | if (!type_res.isAllowzeroPtr()) { | 17601 | if (!ptr_ty.isAllowzeroPtr()) { |
| 17602 | const is_non_zero = try block.addBinOp(.cmp_neq, operand_coerced, .zero_usize); | 17602 | const is_non_zero = try block.addBinOp(.cmp_neq, operand_coerced, .zero_usize); |
| 17603 | try sema.addSafetyCheck(block, is_non_zero, .cast_to_null); | 17603 | try sema.addSafetyCheck(block, is_non_zero, .cast_to_null); |
| 17604 | } | 17604 | } |
| ... | @@ -17618,7 +17618,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -17618,7 +17618,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17618 | try sema.addSafetyCheck(block, is_aligned, .incorrect_alignment); | 17618 | try sema.addSafetyCheck(block, is_aligned, .incorrect_alignment); |
| 17619 | } | 17619 | } |
| 17620 | } | 17620 | } |
| 17621 | return block.addBitCast(type_res, operand_coerced); | 17621 | return block.addBitCast(ptr_ty, operand_coerced); |
| 17622 | } | 17622 | } |
| 17623 | | 17623 | |
| 17624 | fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | 17624 | fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |