| ... | @@ -8092,6 +8092,7 @@ fn intCast( | ... | @@ -8092,6 +8092,7 @@ fn intCast( |
| 8092 | const is_in_range = try block.addBinOp(.cmp_lte, diff_unsigned, dest_range); | 8092 | const is_in_range = try block.addBinOp(.cmp_lte, diff_unsigned, dest_range); |
| 8093 | break :ok is_in_range; | 8093 | break :ok is_in_range; |
| 8094 | }; | 8094 | }; |
| | 8095 | // TODO negative_to_unsigned? |
| 8095 | try sema.addSafetyCheck(block, ok, .cast_truncated_data); | 8096 | try sema.addSafetyCheck(block, ok, .cast_truncated_data); |
| 8096 | } else { | 8097 | } else { |
| 8097 | const ok = if (is_vector) ok: { | 8098 | const ok = if (is_vector) ok: { |
| ... | @@ -8116,7 +8117,7 @@ fn intCast( | ... | @@ -8116,7 +8117,7 @@ fn intCast( |
| 8116 | const ok = if (is_vector) ok: { | 8117 | const ok = if (is_vector) ok: { |
| 8117 | const zero_val = try Value.Tag.repeated.create(sema.arena, Value.zero); | 8118 | const zero_val = try Value.Tag.repeated.create(sema.arena, Value.zero); |
| 8118 | const zero_inst = try sema.addConstant(operand_ty, zero_val); | 8119 | const zero_inst = try sema.addConstant(operand_ty, zero_val); |
| 8119 | const is_in_range = try block.addCmpVector(operand, zero_inst, .lte, try sema.addType(operand_ty)); | 8120 | const is_in_range = try block.addCmpVector(operand, zero_inst, .gte, try sema.addType(operand_ty)); |
| 8120 | const all_in_range = try block.addInst(.{ | 8121 | const all_in_range = try block.addInst(.{ |
| 8121 | .tag = .reduce, | 8122 | .tag = .reduce, |
| 8122 | .data = .{ .reduce = .{ | 8123 | .data = .{ .reduce = .{ |
| ... | @@ -8130,7 +8131,7 @@ fn intCast( | ... | @@ -8130,7 +8131,7 @@ fn intCast( |
| 8130 | const is_in_range = try block.addBinOp(.cmp_gte, operand, zero_inst); | 8131 | const is_in_range = try block.addBinOp(.cmp_gte, operand, zero_inst); |
| 8131 | break :ok is_in_range; | 8132 | break :ok is_in_range; |
| 8132 | }; | 8133 | }; |
| 8133 | try sema.addSafetyCheck(block, ok, .cast_truncated_data); | 8134 | try sema.addSafetyCheck(block, ok, .negative_to_unsigned); |
| 8134 | } | 8135 | } |
| 8135 | } | 8136 | } |
| 8136 | return block.addTyOp(.intcast, dest_ty, operand); | 8137 | return block.addTyOp(.intcast, dest_ty, operand); |
| ... | @@ -18849,6 +18850,7 @@ pub const PanicId = enum { | ... | @@ -18849,6 +18850,7 @@ pub const PanicId = enum { |
| 18849 | incorrect_alignment, | 18850 | incorrect_alignment, |
| 18850 | invalid_error_code, | 18851 | invalid_error_code, |
| 18851 | cast_truncated_data, | 18852 | cast_truncated_data, |
| | 18853 | negative_to_unsigned, |
| 18852 | integer_overflow, | 18854 | integer_overflow, |
| 18853 | shl_overflow, | 18855 | shl_overflow, |
| 18854 | shr_overflow, | 18856 | shr_overflow, |
| ... | @@ -19069,6 +19071,7 @@ fn safetyPanic( | ... | @@ -19069,6 +19071,7 @@ fn safetyPanic( |
| 19069 | .incorrect_alignment => "incorrect alignment", | 19071 | .incorrect_alignment => "incorrect alignment", |
| 19070 | .invalid_error_code => "invalid error code", | 19072 | .invalid_error_code => "invalid error code", |
| 19071 | .cast_truncated_data => "integer cast truncated bits", | 19073 | .cast_truncated_data => "integer cast truncated bits", |
| | 19074 | .negative_to_unsigned => "attempt to cast negative value to unsigned integer", |
| 19072 | .integer_overflow => "integer overflow", | 19075 | .integer_overflow => "integer overflow", |
| 19073 | .shl_overflow => "left shift overflowed bits", | 19076 | .shl_overflow => "left shift overflowed bits", |
| 19074 | .shr_overflow => "right shift overflowed bits", | 19077 | .shr_overflow => "right shift overflowed bits", |