| ... | @@ -23099,8 +23099,14 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -23099,8 +23099,14 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 23099 | } | 23099 | } |
| 23100 | if (ptr_align.compare(.gt, .@"1")) { | 23100 | if (ptr_align.compare(.gt, .@"1")) { |
| 23101 | const align_bytes_minus_1 = ptr_align.toByteUnits().? - 1; | 23101 | const align_bytes_minus_1 = ptr_align.toByteUnits().? - 1; |
| 23102 | const align_minus_1 = Air.internedToRef((try sema.splat(operand_ty, try pt.intValue(Type.usize, align_bytes_minus_1))).toIntern()); | 23102 | const align_mask = Air.internedToRef((try sema.splat(operand_ty, try pt.intValue( |
| 23103 | const remainder = try block.addBinOp(.bit_and, operand_coerced, align_minus_1); | 23103 | Type.usize, |
| | 23104 | if (elem_ty.fnPtrMaskOrNull(zcu)) |mask| |
| | 23105 | align_bytes_minus_1 & mask |
| | 23106 | else |
| | 23107 | align_bytes_minus_1, |
| | 23108 | ))).toIntern()); |
| | 23109 | const remainder = try block.addBinOp(.bit_and, operand_coerced, align_mask); |
| 23104 | const is_aligned = if (is_vector) all_aligned: { | 23110 | const is_aligned = if (is_vector) all_aligned: { |
| 23105 | const splat_zero_usize = Air.internedToRef((try sema.splat(operand_ty, .zero_usize)).toIntern()); | 23111 | const splat_zero_usize = Air.internedToRef((try sema.splat(operand_ty, .zero_usize)).toIntern()); |
| 23106 | const is_aligned = try block.addCmpVector(remainder, splat_zero_usize, .eq); | 23112 | const is_aligned = try block.addCmpVector(remainder, splat_zero_usize, .eq); |
| ... | @@ -23129,8 +23135,14 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -23129,8 +23135,14 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 23129 | } | 23135 | } |
| 23130 | if (ptr_align.compare(.gt, .@"1")) { | 23136 | if (ptr_align.compare(.gt, .@"1")) { |
| 23131 | const align_bytes_minus_1 = ptr_align.toByteUnits().? - 1; | 23137 | const align_bytes_minus_1 = ptr_align.toByteUnits().? - 1; |
| 23132 | const align_minus_1 = Air.internedToRef((try pt.intValue(Type.usize, align_bytes_minus_1)).toIntern()); | 23138 | const align_mask = Air.internedToRef((try pt.intValue( |
| 23133 | const remainder = try block.addBinOp(.bit_and, elem_coerced, align_minus_1); | 23139 | Type.usize, |
| | 23140 | if (elem_ty.fnPtrMaskOrNull(zcu)) |mask| |
| | 23141 | align_bytes_minus_1 & mask |
| | 23142 | else |
| | 23143 | align_bytes_minus_1, |
| | 23144 | )).toIntern()); |
| | 23145 | const remainder = try block.addBinOp(.bit_and, elem_coerced, align_mask); |
| 23134 | const is_aligned = try block.addBinOp(.cmp_eq, remainder, .zero_usize); | 23146 | const is_aligned = try block.addBinOp(.cmp_eq, remainder, .zero_usize); |
| 23135 | try sema.addSafetyCheck(block, src, is_aligned, .incorrect_alignment); | 23147 | try sema.addSafetyCheck(block, src, is_aligned, .incorrect_alignment); |
| 23136 | } | 23148 | } |
| ... | @@ -23710,13 +23722,19 @@ fn ptrCastFull( | ... | @@ -23710,13 +23722,19 @@ fn ptrCastFull( |
| 23710 | try Type.fromInterned(dest_info.child).hasRuntimeBitsSema(pt)) | 23722 | try Type.fromInterned(dest_info.child).hasRuntimeBitsSema(pt)) |
| 23711 | { | 23723 | { |
| 23712 | const align_bytes_minus_1 = dest_align.toByteUnits().? - 1; | 23724 | const align_bytes_minus_1 = dest_align.toByteUnits().? - 1; |
| 23713 | const align_minus_1 = Air.internedToRef((try pt.intValue(Type.usize, align_bytes_minus_1)).toIntern()); | 23725 | const align_mask = Air.internedToRef((try pt.intValue( |
| | 23726 | Type.usize, |
| | 23727 | if (Type.fromInterned(dest_info.child).fnPtrMaskOrNull(zcu)) |mask| |
| | 23728 | align_bytes_minus_1 & mask |
| | 23729 | else |
| | 23730 | align_bytes_minus_1, |
| | 23731 | )).toIntern()); |
| 23714 | const actual_ptr = if (src_info.flags.size == .slice) | 23732 | const actual_ptr = if (src_info.flags.size == .slice) |
| 23715 | try sema.analyzeSlicePtr(block, src, ptr, operand_ty) | 23733 | try sema.analyzeSlicePtr(block, src, ptr, operand_ty) |
| 23716 | else | 23734 | else |
| 23717 | ptr; | 23735 | ptr; |
| 23718 | const ptr_int = try block.addBitCast(.usize, actual_ptr); | 23736 | const ptr_int = try block.addBitCast(.usize, actual_ptr); |
| 23719 | const remainder = try block.addBinOp(.bit_and, ptr_int, align_minus_1); | 23737 | const remainder = try block.addBinOp(.bit_and, ptr_int, align_mask); |
| 23720 | const is_aligned = try block.addBinOp(.cmp_eq, remainder, .zero_usize); | 23738 | const is_aligned = try block.addBinOp(.cmp_eq, remainder, .zero_usize); |
| 23721 | const ok = if (src_info.flags.size == .slice and dest_info.flags.size == .slice) ok: { | 23739 | const ok = if (src_info.flags.size == .slice and dest_info.flags.size == .slice) ok: { |
| 23722 | const len = try sema.analyzeSliceLen(block, operand_src, ptr); | 23740 | const len = try sema.analyzeSliceLen(block, operand_src, ptr); |