diff options
| -rw-r--r-- | src/Sema.zig | 5 | ||||
| -rw-r--r-- | test/cases/no_compile_panic_for_unchecked_arith.zig | 16 |
2 files changed, 20 insertions, 1 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 0c464a0bc1..c0b6f3678a 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -16019,9 +16019,12 @@ fn analyzeArithmetic( }; try sema.requireRuntimeBlock(block, src, runtime_src); + if (block.wantSafety() and want_safety and scalar_tag == .Int) { if (mod.backendSupportsFeature(.safety_checked_instructions)) { - _ = try sema.preparePanicId(block, .integer_overflow); + if (air_tag != air_tag_safe) { + _ = try sema.preparePanicId(block, .integer_overflow); + } return block.addBinOp(air_tag_safe, casted_lhs, casted_rhs); } else { const maybe_op_ov: ?Air.Inst.Tag = switch (air_tag) { diff --git a/test/cases/no_compile_panic_for_unchecked_arith.zig b/test/cases/no_compile_panic_for_unchecked_arith.zig new file mode 100644 index 0000000000..a9aa8272b1 --- /dev/null +++ b/test/cases/no_compile_panic_for_unchecked_arith.zig @@ -0,0 +1,16 @@ +pub const panic = @compileError(""); + +export fn entry() usize { + var x: usize = 0; + x +%= 1; + x -%= 1; + x *%= 2; + x +|= 1; + x -|= 1; + x *|= 2; + return x; +} + +// compile +// output_mode=Obj +// backend=stage2,llvm |
