| ... | @@ -10441,7 +10441,7 @@ fn zirShr( | ... | @@ -10441,7 +10441,7 @@ fn zirShr( |
| 10441 | // Detect if any ones would be shifted out. | 10441 | // Detect if any ones would be shifted out. |
| 10442 | const truncated = try lhs_val.intTruncBitsAsValue(lhs_ty, sema.arena, .unsigned, rhs_val, target); | 10442 | const truncated = try lhs_val.intTruncBitsAsValue(lhs_ty, sema.arena, .unsigned, rhs_val, target); |
| 10443 | if (!(try truncated.compareWithZeroAdvanced(.eq, sema.kit(block, src)))) { | 10443 | if (!(try truncated.compareWithZeroAdvanced(.eq, sema.kit(block, src)))) { |
| 10444 | return sema.addConstUndef(lhs_ty); | 10444 | return sema.fail(block, src, "exact shift shifted out 1 bits", .{}); |
| 10445 | } | 10445 | } |
| 10446 | } | 10446 | } |
| 10447 | const val = try lhs_val.shr(rhs_val, lhs_ty, sema.arena, target); | 10447 | const val = try lhs_val.shr(rhs_val, lhs_ty, sema.arena, target); |
| ... | @@ -11346,13 +11346,19 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -11346,13 +11346,19 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 11346 | if (maybe_lhs_val) |lhs_val| { | 11346 | if (maybe_lhs_val) |lhs_val| { |
| 11347 | if (maybe_rhs_val) |rhs_val| { | 11347 | if (maybe_rhs_val) |rhs_val| { |
| 11348 | if (is_int) { | 11348 | if (is_int) { |
| 11349 | // TODO: emit compile error if there is a remainder | 11349 | const modulus_val = try lhs_val.intMod(rhs_val, resolved_type, sema.arena, target); |
| | 11350 | if (modulus_val.compareWithZero(.neq)) { |
| | 11351 | return sema.fail(block, src, "exact division produced remainder", .{}); |
| | 11352 | } |
| 11350 | return sema.addConstant( | 11353 | return sema.addConstant( |
| 11351 | resolved_type, | 11354 | resolved_type, |
| 11352 | try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target), | 11355 | try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target), |
| 11353 | ); | 11356 | ); |
| 11354 | } else { | 11357 | } else { |
| 11355 | // TODO: emit compile error if there is a remainder | 11358 | const modulus_val = try lhs_val.floatMod(rhs_val, resolved_type, sema.arena, target); |
| | 11359 | if (modulus_val.compareWithZero(.neq)) { |
| | 11360 | return sema.fail(block, src, "exact division produced remainder", .{}); |
| | 11361 | } |
| 11356 | return sema.addConstant( | 11362 | return sema.addConstant( |
| 11357 | resolved_type, | 11363 | resolved_type, |
| 11358 | try lhs_val.floatDiv(rhs_val, resolved_type, sema.arena, target), | 11364 | try lhs_val.floatDiv(rhs_val, resolved_type, sema.arena, target), |