Sema: Added logic to avoid unchecked operations calling preparePanicId (#18416)

Fixes #18415
This commit is contained in:
amp-59 2024-01-03 07:34:24 +00:00 committed by GitHub
parent 60958d135f
commit ca4ee9ae73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -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) {

View 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