mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 22:35:24 +00:00
Sema: Added logic to avoid unchecked operations calling preparePanicId (#18416)
Fixes #18415
This commit is contained in:
parent
60958d135f
commit
ca4ee9ae73
@ -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) {
|
||||
|
||||
16
test/cases/no_compile_panic_for_unchecked_arith.zig
Normal file
16
test/cases/no_compile_panic_for_unchecked_arith.zig
Normal file
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user