zig icon indicating copy to clipboard operation
zig copied to clipboard

Division safety issue not reported in stage2 for minInt / -1

Open cryptocode opened this issue 3 years ago • 0 comments

Zig Version

0.11.0-dev.49+b19161ba9

Steps to Reproduce and Observed Behavior

const std = @import("std");

test "overflow" {
    const x = std.math.minInt(i8) / @as(i8, -1);
    std.debug.print("{}\n", .{x});
}

Succeeds and prints -128, even in Debug builds.

Expected Behavior

-fstage1 correctly outputs:

error: operation caused overflow

but stage2 does not.

-128 / -1 = 128, which does not fit in an i8

cryptocode avatar Nov 03 '22 21:11 cryptocode