| ... | ... | @@ -6782,6 +6782,20 @@ fn intCast( |
| 6782 | 6782 | } |
| 6783 | 6783 | |
| 6784 | 6784 | if ((try sema.typeHasOnePossibleValue(block, dest_ty_src, dest_ty))) |opv| { |
| 6785 | // requirement: intCast(u0, input) iff input == 0 |
| 6786 | if (runtime_safety and block.wantSafety()) { |
| 6787 | try sema.requireRuntimeBlock(block, operand_src); |
| 6788 | const target = sema.mod.getTarget(); |
| 6789 | const wanted_info = dest_ty.intInfo(target); |
| 6790 | const wanted_bits = wanted_info.bits; |
| 6791 | |
| 6792 | if (wanted_bits == 0) { |
| 6793 | const zero_inst = try sema.addConstant(sema.typeOf(operand), Value.zero); |
| 6794 | const is_in_range = try block.addBinOp(.cmp_eq, operand, zero_inst); |
| 6795 | try sema.addSafetyCheck(block, is_in_range, .cast_truncated_data); |
| 6796 | } |
| 6797 | } |
| 6798 | |
| 6785 | 6799 | return sema.addConstant(dest_ty, opv); |
| 6786 | 6800 | } |
| 6787 | 6801 | |
| ... | ... | @@ -6794,7 +6808,7 @@ fn intCast( |
| 6794 | 6808 | const actual_bits = actual_info.bits; |
| 6795 | 6809 | const wanted_bits = wanted_info.bits; |
| 6796 | 6810 | |
| 6797 | | // requirement: operand can fit into bit size of destination type |
| 6811 | // requirement: bitSizeOf(operand) <= bitSizeOf(destination type) |
| 6798 | 6812 | if (actual_bits > wanted_bits) { |
| 6799 | 6813 | const max_int = try dest_ty.maxInt(sema.arena, target); |
| 6800 | 6814 | const max_int_inst = try sema.addConstant(operand_ty, max_int); |